File tree Expand file tree Collapse file tree 3 files changed +16
-2
lines changed Expand file tree Collapse file tree 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 {
6767 if span. from_expansion( ) {
6868 return ;
6969 }
70- if matches!( deref_expr. kind, ExprKind :: Path ( ..) ) {
70+ if matches!( deref_expr. kind, ExprKind :: Path ( ..) | ExprKind :: Field ( .. ) ) {
7171 if let Some ( parent_node) = map. find( parent_hir_id) {
7272 if let rustc_hir:: Node :: Local ( ..) = parent_node {
7373 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 {
3737 }
3838}
3939
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+
4054// this mod explains why we should not lint `& &* (&T)`
4155mod false_negative {
4256 fn foo ( ) {
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ LL | let b = &mut &*bar(a);
1717 = help: consider using `bar(a)` if you would like to reborrow
1818
1919error: deref on an immutable reference
20- --> $DIR/needless_deref.rs:45 :23
20+ --> $DIR/needless_deref.rs:59 :23
2121 |
2222LL | let addr_y = &&*x as *const _ as usize; // assert ok
2323 | ^^^
You can’t perform that action at this time.
0 commit comments