Fix span when linting explicit_auto_deref immediately after needless_borrow

This commit is contained in:
Jason Newcomb 2023-08-21 22:28:17 -04:00
parent d9e6aac8bb
commit 82f2e52469
4 changed files with 27 additions and 7 deletions

View File

@ -609,12 +609,14 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
adjusted_ty, 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(( self.state = Some((
State::ExplicitDeref { mutability: None }, State::ExplicitDeref { mutability: None },
StateData { StateData {
span: expr.span, span: parent.span,
hir_id: expr.hir_id, hir_id: parent.hir_id,
adjusted_ty, 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 f_str(&ref_str); // `needless_borrow` will suggest removing only one reference
let x = &&40; let x = &&40;
@ -293,4 +293,10 @@ fn main() {
fn return_dyn_assoc<'a>(x: &'a &'a u32) -> &'a <&'a u32 as WithAssoc>::Assoc { fn return_dyn_assoc<'a>(x: &'a &'a u32) -> &'a <&'a u32 as WithAssoc>::Assoc {
*x *x
} }
// Issue #11366
let _: &mut u32 = match &mut Some(&mut 0u32) {
Some(x) => x,
None => panic!(),
};
} }

View File

@ -293,4 +293,10 @@ fn to_assoc(&self) -> &Self::Assoc {
fn return_dyn_assoc<'a>(x: &'a &'a u32) -> &'a <&'a u32 as WithAssoc>::Assoc { fn return_dyn_assoc<'a>(x: &'a &'a u32) -> &'a <&'a u32 as WithAssoc>::Assoc {
*x *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` | ^^^^^^^^^^^^^ help: try: `ref_ref_str`
error: deref which would be done by auto-deref 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 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 error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:209:12 --> $DIR/explicit_auto_deref.rs:209:12
@ -234,5 +234,11 @@ error: deref which would be done by auto-deref
LL | *x LL | *x
| ^^ help: try: `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