Auto merge of #11376 - Jarcho:issue_11366, r=llogiq

Fix span when linting `explicit_auto_deref` immediately after `needless_borrow`

fixes #11366

changelog: `explicit_auto_deref`: Fix span when linting immediately after `needless_borrow`
This commit is contained in:
bors 2023-08-31 11:30:37 +00:00
commit 77e395e87c
4 changed files with 27 additions and 7 deletions

View file

@ -609,12 +609,14 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
adjusted_ty,
},
));
} else if stability.is_deref_stable() {
} else if stability.is_deref_stable()
&& let Some(parent) = get_parent_expr(cx, expr)
{
self.state = Some((
State::ExplicitDeref { mutability: None },
StateData {
span: expr.span,
hir_id: expr.hir_id,
span: parent.span,
hir_id: parent.hir_id,
adjusted_ty,
},
));

View file

@ -205,7 +205,7 @@ fn main() {
}
}
f_str(&&ref_str); // `needless_borrow` will suggest removing both references
f_str(&ref_str); // `needless_borrow` will suggest removing both references
f_str(&ref_str); // `needless_borrow` will suggest removing only one reference
let x = &&40;
@ -293,4 +293,10 @@ fn main() {
fn return_dyn_assoc<'a>(x: &'a &'a u32) -> &'a <&'a u32 as WithAssoc>::Assoc {
*x
}
// Issue #11366
let _: &mut u32 = match &mut Some(&mut 0u32) {
Some(x) => x,
None => panic!(),
};
}

View file

@ -293,4 +293,10 @@ fn main() {
fn return_dyn_assoc<'a>(x: &'a &'a u32) -> &'a <&'a u32 as WithAssoc>::Assoc {
*x
}
// Issue #11366
let _: &mut u32 = match &mut Some(&mut 0u32) {
Some(x) => &mut *x,
None => panic!(),
};
}

View file

@ -193,10 +193,10 @@ LL | let _ = f_str(**ref_ref_str);
| ^^^^^^^^^^^^^ help: try: `ref_ref_str`
error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:208:13
--> $DIR/explicit_auto_deref.rs:208:12
|
LL | f_str(&&*ref_str); // `needless_borrow` will suggest removing both references
| ^^^^^^^^ help: try: `ref_str`
| ^^^^^^^^^ help: try: `ref_str`
error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:209:12
@ -234,5 +234,11 @@ error: deref which would be done by auto-deref
LL | *x
| ^^ help: try: `x`
error: aborting due to 39 previous errors
error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:299:20
|
LL | Some(x) => &mut *x,
| ^^^^^^^ help: try: `x`
error: aborting due to 40 previous errors