File tree 4 files changed +27
-7
lines changed
4 files changed +27
-7
lines changed Original file line number Diff line number Diff line change @@ -609,12 +609,14 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
609
609
adjusted_ty,
610
610
} ,
611
611
) ) ;
612
- } else if stability. is_deref_stable ( ) {
612
+ } else if stability. is_deref_stable ( )
613
+ && let Some ( parent) = get_parent_expr ( cx, expr)
614
+ {
613
615
self . state = Some ( (
614
616
State :: ExplicitDeref { mutability : None } ,
615
617
StateData {
616
- span : expr . span ,
617
- hir_id : expr . hir_id ,
618
+ span : parent . span ,
619
+ hir_id : parent . hir_id ,
618
620
adjusted_ty,
619
621
} ,
620
622
) ) ;
Original file line number Diff line number Diff line change @@ -205,7 +205,7 @@ fn main() {
205
205
}
206
206
}
207
207
208
- f_str(&& ref_str); // `needless_borrow` will suggest removing both references
208
+ f_str(&ref_str); // `needless_borrow` will suggest removing both references
209
209
f_str(&ref_str); // `needless_borrow` will suggest removing only one reference
210
210
211
211
let x = &&40;
@@ -293,4 +293,10 @@ fn main() {
293
293
fn return_dyn_assoc<'a>(x: &'a &'a u32) -> &'a <&'a u32 as WithAssoc>::Assoc {
294
294
*x
295
295
}
296
+
297
+ // Issue #11366
298
+ let _: &mut u32 = match &mut Some(&mut 0u32) {
299
+ Some(x) => x,
300
+ None => panic!(),
301
+ };
296
302
}
Original file line number Diff line number Diff line change @@ -293,4 +293,10 @@ fn main() {
293
293
fn return_dyn_assoc < ' a > ( x: & ' a & ' a u32) -> & ' a < & ' a u32 as WithAssoc > :: Assoc {
294
294
* x
295
295
}
296
+
297
+ // Issue #11366
298
+ let _: & mut u32 = match & mut Some ( & mut 0u32 ) {
299
+ Some ( x) => & mut * x,
300
+ None => panic!( ) ,
301
+ } ;
296
302
}
Original file line number Diff line number Diff line change @@ -193,10 +193,10 @@ LL | let _ = f_str(**ref_ref_str);
193
193
| ^^^^^^^^^^^^^ help: try: `ref_ref_str`
194
194
195
195
error: deref which would be done by auto-deref
196
- --> $DIR/explicit_auto_deref.rs:208:13
196
+ --> $DIR/explicit_auto_deref.rs:208:12
197
197
|
198
198
LL | f_str(&&*ref_str); // `needless_borrow` will suggest removing both references
199
- | ^^^^^^^^ help: try: `ref_str`
199
+ | ^ ^^^^^^^^ help: try: `ref_str`
200
200
201
201
error: deref which would be done by auto-deref
202
202
--> $DIR/explicit_auto_deref.rs:209:12
@@ -234,5 +234,11 @@ error: deref which would be done by auto-deref
234
234
LL | *x
235
235
| ^^ help: try: `x`
236
236
237
- error: aborting due to 39 previous errors
237
+ error: deref which would be done by auto-deref
238
+ --> $DIR/explicit_auto_deref.rs:299:20
239
+ |
240
+ LL | Some(x) => &mut *x,
241
+ | ^^^^^^^ help: try: `x`
242
+
243
+ error: aborting due to 40 previous errors
238
244
You can’t perform that action at this time.
0 commit comments