Skip to content

Commit 006fd56

Browse files
committed
Make the dangerous_implicit_autorefs lint deny-by-default
1 parent 642e49b commit 006fd56

File tree

4 files changed

+99
-93
lines changed

4 files changed

+99
-93
lines changed

compiler/rustc_lint/src/autorefs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ declare_lint! {
5151
/// }
5252
/// ```
5353
pub DANGEROUS_IMPLICIT_AUTOREFS,
54-
Warn,
54+
Deny,
5555
"implicit reference to a dereference of a raw pointer",
5656
report_in_external_macro
5757
}

tests/ui/lint/implicit_autorefs.fixed

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ check-pass
1+
//@ check-fail
22
//@ run-rustfix
33

44
#![allow(dead_code)] // For the rustfix-ed code.
@@ -8,7 +8,7 @@ use std::ops::Deref;
88

99
unsafe fn test_const(ptr: *const [u8]) {
1010
let _ = (&(*ptr))[..16];
11-
//~^ WARN implicit autoref
11+
//~^ ERROR implicit autoref
1212
}
1313

1414
struct Test {
@@ -17,89 +17,92 @@ struct Test {
1717

1818
unsafe fn test_field(ptr: *const Test) -> *const [u8] {
1919
let l = (&(*ptr).field).len();
20-
//~^ WARN implicit autoref
20+
//~^ ERROR implicit autoref
2121

2222
&raw const (&(*ptr).field)[..l - 1]
23-
//~^ WARN implicit autoref
23+
//~^ ERROR implicit autoref
2424
}
2525

2626
unsafe fn test_builtin_index(a: *mut [String]) {
2727
_ = (&(*a)[0]).len();
28-
//~^ WARN implicit autoref
28+
//~^ ERROR implicit autoref
2929

3030
_ = (&(&(*a))[..1][0]).len();
31-
//~^ WARN implicit autoref
32-
//~^^ WARN implicit autoref
31+
//~^ ERROR implicit autoref
32+
//~^^ ERROR implicit autoref
3333
}
3434

3535
unsafe fn test_overloaded_deref_const(ptr: *const ManuallyDrop<Test>) {
3636
let _ = (&(*ptr)).field;
37-
//~^ WARN implicit autoref
37+
//~^ ERROR implicit autoref
3838
let _ = &raw const (&(*ptr)).field;
39-
//~^ WARN implicit autoref
39+
//~^ ERROR implicit autoref
4040
}
4141

4242
unsafe fn test_overloaded_deref_mut(ptr: *mut ManuallyDrop<Test>) {
4343
let _ = (&(*ptr)).field;
44-
//~^ WARN implicit autoref
44+
//~^ ERROR implicit autoref
4545
}
4646

4747
unsafe fn test_double_overloaded_deref_const(ptr: *const ManuallyDrop<ManuallyDrop<Test>>) {
4848
let _ = (&(*ptr)).field;
49-
//~^ WARN implicit autoref
49+
//~^ ERROR implicit autoref
5050
}
5151

5252
unsafe fn test_manually_overloaded_deref() {
5353
struct W<T>(T);
5454

5555
impl<T> Deref for W<T> {
5656
type Target = T;
57-
fn deref(&self) -> &T { &self.0 }
57+
fn deref(&self) -> &T {
58+
&self.0
59+
}
5860
}
5961

6062
let w: W<i32> = W(5);
6163
let w = &raw const w;
6264
let _p: *const i32 = &raw const *(&**w);
63-
//~^ WARN implicit autoref
65+
//~^ ERROR implicit autoref
6466
}
6567

6668
struct Test2 {
6769
// Derefs to `[u8]`.
68-
field: &'static [u8]
70+
field: &'static [u8],
6971
}
7072

7173
fn test_more_manual_deref(ptr: *const Test2) -> usize {
7274
unsafe { (&(*ptr).field).len() }
73-
//~^ WARN implicit autoref
75+
//~^ ERROR implicit autoref
7476
}
7577

7678
unsafe fn test_no_attr(ptr: *mut ManuallyDrop<u8>) {
77-
ptr.write(ManuallyDrop::new(1)); // Should not warn, as `ManuallyDrop::write` is not
78-
// annotated with `#[rustc_no_implicit_auto_ref]`
79+
// Should not warn, as `ManuallyDrop::write` is not
80+
// annotated with `#[rustc_no_implicit_auto_ref]`
81+
ptr.write(ManuallyDrop::new(1));
7982
}
8083

8184
unsafe fn test_vec_get(ptr: *mut Vec<u8>) {
8285
let _ = (&(*ptr)).get(0);
83-
//~^ WARN implicit autoref
86+
//~^ ERROR implicit autoref
8487
let _ = (&(*ptr)).get_unchecked(0);
85-
//~^ WARN implicit autoref
88+
//~^ ERROR implicit autoref
8689
let _ = (&mut (*ptr)).get_mut(0);
87-
//~^ WARN implicit autoref
90+
//~^ ERROR implicit autoref
8891
let _ = (&mut (*ptr)).get_unchecked_mut(0);
89-
//~^ WARN implicit autoref
92+
//~^ ERROR implicit autoref
9093
}
9194

9295
unsafe fn test_string(ptr: *mut String) {
9396
let _ = (&(*ptr)).len();
94-
//~^ WARN implicit autoref
97+
//~^ ERROR implicit autoref
9598
let _ = (&(*ptr)).is_empty();
96-
//~^ WARN implicit autoref
99+
//~^ ERROR implicit autoref
97100
}
98101

99102
unsafe fn slice_ptr_len_because_of_msrv<T>(slice: *const [T]) {
100103
let _ = (&(&(*slice))[..]).len();
101-
//~^ WARN implicit autoref
102-
//~^^ WARN implicit autoref
104+
//~^ ERROR implicit autoref
105+
//~^^ ERROR implicit autoref
103106
}
104107

105108
fn main() {}

tests/ui/lint/implicit_autorefs.rs

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ check-pass
1+
//@ check-fail
22
//@ run-rustfix
33

44
#![allow(dead_code)] // For the rustfix-ed code.
@@ -8,7 +8,7 @@ use std::ops::Deref;
88

99
unsafe fn test_const(ptr: *const [u8]) {
1010
let _ = (*ptr)[..16];
11-
//~^ WARN implicit autoref
11+
//~^ ERROR implicit autoref
1212
}
1313

1414
struct Test {
@@ -17,89 +17,92 @@ struct Test {
1717

1818
unsafe fn test_field(ptr: *const Test) -> *const [u8] {
1919
let l = (*ptr).field.len();
20-
//~^ WARN implicit autoref
20+
//~^ ERROR implicit autoref
2121

2222
&raw const (*ptr).field[..l - 1]
23-
//~^ WARN implicit autoref
23+
//~^ ERROR implicit autoref
2424
}
2525

2626
unsafe fn test_builtin_index(a: *mut [String]) {
2727
_ = (*a)[0].len();
28-
//~^ WARN implicit autoref
28+
//~^ ERROR implicit autoref
2929

3030
_ = (*a)[..1][0].len();
31-
//~^ WARN implicit autoref
32-
//~^^ WARN implicit autoref
31+
//~^ ERROR implicit autoref
32+
//~^^ ERROR implicit autoref
3333
}
3434

3535
unsafe fn test_overloaded_deref_const(ptr: *const ManuallyDrop<Test>) {
3636
let _ = (*ptr).field;
37-
//~^ WARN implicit autoref
37+
//~^ ERROR implicit autoref
3838
let _ = &raw const (*ptr).field;
39-
//~^ WARN implicit autoref
39+
//~^ ERROR implicit autoref
4040
}
4141

4242
unsafe fn test_overloaded_deref_mut(ptr: *mut ManuallyDrop<Test>) {
4343
let _ = (*ptr).field;
44-
//~^ WARN implicit autoref
44+
//~^ ERROR implicit autoref
4545
}
4646

4747
unsafe fn test_double_overloaded_deref_const(ptr: *const ManuallyDrop<ManuallyDrop<Test>>) {
4848
let _ = (*ptr).field;
49-
//~^ WARN implicit autoref
49+
//~^ ERROR implicit autoref
5050
}
5151

5252
unsafe fn test_manually_overloaded_deref() {
5353
struct W<T>(T);
5454

5555
impl<T> Deref for W<T> {
5656
type Target = T;
57-
fn deref(&self) -> &T { &self.0 }
57+
fn deref(&self) -> &T {
58+
&self.0
59+
}
5860
}
5961

6062
let w: W<i32> = W(5);
6163
let w = &raw const w;
6264
let _p: *const i32 = &raw const **w;
63-
//~^ WARN implicit autoref
65+
//~^ ERROR implicit autoref
6466
}
6567

6668
struct Test2 {
6769
// Derefs to `[u8]`.
68-
field: &'static [u8]
70+
field: &'static [u8],
6971
}
7072

7173
fn test_more_manual_deref(ptr: *const Test2) -> usize {
7274
unsafe { (*ptr).field.len() }
73-
//~^ WARN implicit autoref
75+
//~^ ERROR implicit autoref
7476
}
7577

7678
unsafe fn test_no_attr(ptr: *mut ManuallyDrop<u8>) {
77-
ptr.write(ManuallyDrop::new(1)); // Should not warn, as `ManuallyDrop::write` is not
78-
// annotated with `#[rustc_no_implicit_auto_ref]`
79+
// Should not warn, as `ManuallyDrop::write` is not
80+
// annotated with `#[rustc_no_implicit_auto_ref]`
81+
ptr.write(ManuallyDrop::new(1));
7982
}
8083

8184
unsafe fn test_vec_get(ptr: *mut Vec<u8>) {
8285
let _ = (*ptr).get(0);
83-
//~^ WARN implicit autoref
86+
//~^ ERROR implicit autoref
8487
let _ = (*ptr).get_unchecked(0);
85-
//~^ WARN implicit autoref
88+
//~^ ERROR implicit autoref
8689
let _ = (*ptr).get_mut(0);
87-
//~^ WARN implicit autoref
90+
//~^ ERROR implicit autoref
8891
let _ = (*ptr).get_unchecked_mut(0);
89-
//~^ WARN implicit autoref
92+
//~^ ERROR implicit autoref
9093
}
9194

9295
unsafe fn test_string(ptr: *mut String) {
9396
let _ = (*ptr).len();
94-
//~^ WARN implicit autoref
97+
//~^ ERROR implicit autoref
9598
let _ = (*ptr).is_empty();
96-
//~^ WARN implicit autoref
99+
//~^ ERROR implicit autoref
97100
}
98101

99102
unsafe fn slice_ptr_len_because_of_msrv<T>(slice: *const [T]) {
100103
let _ = (*slice)[..].len();
101-
//~^ WARN implicit autoref
102-
//~^^ WARN implicit autoref
104+
//~^ ERROR implicit autoref
105+
//~^^ ERROR implicit autoref
103106
}
104107

105108
fn main() {}

0 commit comments

Comments
 (0)