File tree 6 files changed +92
-22
lines changed
6 files changed +92
-22
lines changed Original file line number Diff line number Diff line change @@ -346,6 +346,7 @@ fn compile_test() {
346
346
347
347
const RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS : & [ & str ] = & [
348
348
"assign_ops2.rs" ,
349
+ "borrow_deref_ref_unfixable.rs" ,
349
350
"cast_size_32bit.rs" ,
350
351
"char_lit_as_u8.rs" ,
351
352
"cmp_owned/without_suggestion.rs" ,
Original file line number Diff line number Diff line change
1
+ // run-rustfix
2
+
3
+ #![allow(dead_code, unused_variables)]
4
+
5
+ fn main() {}
6
+
7
+ mod should_lint {
8
+ fn one_suggestion() {
9
+ let a = &12;
10
+ let b = a;
11
+
12
+ let b = &mut bar(&12);
13
+ }
14
+
15
+ fn bar(x: &u32) -> &u32 {
16
+ x
17
+ }
18
+ }
19
+
20
+ // this mod explains why we should not lint `&mut &* (&T)`
21
+ mod should_not_lint1 {
22
+ fn foo(x: &mut &u32) {
23
+ *x = &1;
24
+ }
25
+
26
+ fn main() {
27
+ let mut x = &0;
28
+ foo(&mut &*x); // should not lint
29
+ assert_eq!(*x, 0);
30
+
31
+ foo(&mut x);
32
+ assert_eq!(*x, 1);
33
+ }
34
+ }
35
+
36
+ // similar to should_not_lint1
37
+ mod should_not_lint2 {
38
+ struct S<'a> {
39
+ a: &'a u32,
40
+ b: u32,
41
+ }
42
+
43
+ fn main() {
44
+ let s = S { a: &1, b: 1 };
45
+ let x = &mut &*s.a;
46
+ *x = &2;
47
+ }
48
+ }
49
+
50
+ // this mod explains why we should not lint `& &* (&T)`
51
+ mod false_negative {
52
+ fn foo() {
53
+ let x = &12;
54
+ let addr_x = &x as *const _ as usize;
55
+ let addr_y = &x as *const _ as usize; // assert ok
56
+ // let addr_y = &x as *const _ as usize; // assert fail
57
+ assert_ne!(addr_x, addr_y);
58
+ }
59
+ }
Original file line number Diff line number Diff line change 5
5
fn main ( ) { }
6
6
7
7
mod should_lint {
8
- fn foo ( ) {
8
+ fn one_suggestion ( ) {
9
9
let a = & 12 ;
10
10
let b = & * a;
11
11
12
- let s = & String :: new ( ) ;
13
- let x: & str = & * s;
14
-
15
12
let b = & mut & * bar ( & 12 ) ;
16
13
}
17
14
Original file line number Diff line number Diff line change @@ -7,31 +7,16 @@ LL | let b = &*a;
7
7
= note: `-D clippy::borrow-deref-ref` implied by `-D warnings`
8
8
9
9
error: deref on an immutable reference
10
- --> $DIR/borrow_deref_ref.rs:13:23
11
- |
12
- LL | let x: &str = &*s;
13
- | ^^^
14
- |
15
- help: if you would like to reborrow, try removing `&*`
16
- |
17
- LL | let x: &str = s;
18
- | ~
19
- help: if you would like to deref, try using `&**`
20
- |
21
- LL | let x: &str = &**s;
22
- | ~~~~
23
-
24
- error: deref on an immutable reference
25
- --> $DIR/borrow_deref_ref.rs:15:22
10
+ --> $DIR/borrow_deref_ref.rs:12:22
26
11
|
27
12
LL | let b = &mut &*bar(&12);
28
13
| ^^^^^^^^^^ help: if you would like to reborrow, try removing `&*`: `bar(&12)`
29
14
30
15
error: deref on an immutable reference
31
- --> $DIR/borrow_deref_ref.rs:58 :23
16
+ --> $DIR/borrow_deref_ref.rs:55 :23
32
17
|
33
18
LL | let addr_y = &&*x as *const _ as usize; // assert ok
34
19
| ^^^ help: if you would like to reborrow, try removing `&*`: `x`
35
20
36
- error: aborting due to 4 previous errors
21
+ error: aborting due to 3 previous errors
37
22
Original file line number Diff line number Diff line change
1
+ #![ allow( dead_code, unused_variables) ]
2
+
3
+ fn main ( ) { }
4
+
5
+ mod should_lint {
6
+ fn two_suggestions ( ) {
7
+ let s = & String :: new ( ) ;
8
+ let x: & str = & * s;
9
+ }
10
+ }
Original file line number Diff line number Diff line change
1
+ error: deref on an immutable reference
2
+ --> $DIR/borrow_deref_ref_unfixable.rs:8:23
3
+ |
4
+ LL | let x: &str = &*s;
5
+ | ^^^
6
+ |
7
+ = note: `-D clippy::borrow-deref-ref` implied by `-D warnings`
8
+ help: if you would like to reborrow, try removing `&*`
9
+ |
10
+ LL | let x: &str = s;
11
+ | ~
12
+ help: if you would like to deref, try using `&**`
13
+ |
14
+ LL | let x: &str = &**s;
15
+ | ~~~~
16
+
17
+ error: aborting due to previous error
18
+
You can’t perform that action at this time.
0 commit comments