File tree 3 files changed +16
-2
lines changed
3 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ impl LateLintPass<'_> for NeedlessDeref {
67
67
if span. from_expansion( ) {
68
68
return ;
69
69
}
70
- if matches!( deref_expr. kind, ExprKind :: Path ( ..) ) {
70
+ if matches!( deref_expr. kind, ExprKind :: Path ( ..) | ExprKind :: Field ( .. ) ) {
71
71
if let Some ( parent_node) = map. find( parent_hir_id) {
72
72
if let rustc_hir:: Node :: Local ( ..) = parent_node {
73
73
let outer_ty = cx. typeck_results( ) . node_type( parent_hir_id) ;
Original file line number Diff line number Diff line change @@ -37,6 +37,20 @@ mod should_not_lint2 {
37
37
}
38
38
}
39
39
40
+ // similar to should_not_lint2
41
+ mod should_not_lint3 {
42
+ struct S < ' a > {
43
+ a : & ' a u32 ,
44
+ b : u32 ,
45
+ }
46
+
47
+ fn main ( ) {
48
+ let s = S { a : & 1 , b : 1 } ;
49
+ let x = & mut & * s. a ;
50
+ * x = & 2 ;
51
+ }
52
+ }
53
+
40
54
// this mod explains why we should not lint `& &* (&T)`
41
55
mod false_negative {
42
56
fn foo ( ) {
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ LL | let b = &mut &*bar(a);
17
17
= help: consider using `bar(a)` if you would like to reborrow
18
18
19
19
error: deref on an immutable reference
20
- --> $DIR/needless_deref.rs:45 :23
20
+ --> $DIR/needless_deref.rs:59 :23
21
21
|
22
22
LL | let addr_y = &&*x as *const _ as usize; // assert ok
23
23
| ^^^
You can’t perform that action at this time.
0 commit comments