File tree Expand file tree Collapse file tree 4 files changed +27
-7
lines changed Expand file tree Collapse file tree 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> {
609609 adjusted_ty,
610610 } ,
611611 ) ) ;
612- } else if stability. is_deref_stable ( ) {
612+ } else if stability. is_deref_stable ( )
613+ && let Some ( parent) = get_parent_expr ( cx, expr)
614+ {
613615 self . state = Some ( (
614616 State :: ExplicitDeref { mutability : None } ,
615617 StateData {
616- span : expr . span ,
617- hir_id : expr . hir_id ,
618+ span : parent . span ,
619+ hir_id : parent . hir_id ,
618620 adjusted_ty,
619621 } ,
620622 ) ) ;
Original file line number Diff line number Diff line change @@ -205,7 +205,7 @@ fn main() {
205205 }
206206 }
207207
208- f_str(&& ref_str); // `needless_borrow` will suggest removing both references
208+ f_str(&ref_str); // `needless_borrow` will suggest removing both references
209209 f_str(&ref_str); // `needless_borrow` will suggest removing only one reference
210210
211211 let x = &&40;
@@ -293,4 +293,10 @@ fn main() {
293293 fn return_dyn_assoc<'a>(x: &'a &'a u32) -> &'a <&'a u32 as WithAssoc>::Assoc {
294294 *x
295295 }
296+
297+ // Issue #11366
298+ let _: &mut u32 = match &mut Some(&mut 0u32) {
299+ Some(x) => x,
300+ None => panic!(),
301+ };
296302}
Original file line number Diff line number Diff line change @@ -293,4 +293,10 @@ fn main() {
293293 fn return_dyn_assoc < ' a > ( x: & ' a & ' a u32) -> & ' a < & ' a u32 as WithAssoc > :: Assoc {
294294 * x
295295 }
296+
297+ // Issue #11366
298+ let _: & mut u32 = match & mut Some ( & mut 0u32 ) {
299+ Some ( x) => & mut * x,
300+ None => panic!( ) ,
301+ } ;
296302}
Original file line number Diff line number Diff line change @@ -193,10 +193,10 @@ LL | let _ = f_str(**ref_ref_str);
193193 | ^^^^^^^^^^^^^ help: try: `ref_ref_str`
194194
195195error: deref which would be done by auto-deref
196- --> $DIR/explicit_auto_deref.rs:208:13
196+ --> $DIR/explicit_auto_deref.rs:208:12
197197 |
198198LL | f_str(&&*ref_str); // `needless_borrow` will suggest removing both references
199- | ^^^^^^^^ help: try: `ref_str`
199+ | ^ ^^^^^^^^ help: try: `ref_str`
200200
201201error: deref which would be done by auto-deref
202202 --> $DIR/explicit_auto_deref.rs:209:12
@@ -234,5 +234,11 @@ error: deref which would be done by auto-deref
234234LL | *x
235235 | ^^ help: try: `x`
236236
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
238244
You can’t perform that action at this time.
0 commit comments