fix: Refactor dereference code and fix test

This commit is contained in:
Mariana Miranda 2024-04-08 23:35:19 +01:00
parent 38b8056fc6
commit 8ae7eaefdc
4 changed files with 12 additions and 7 deletions

View File

@ -1014,10 +1014,13 @@ fn report<'tcx>(
},
_ => (0, false),
};
let is_in_tuple = match cx.tcx.parent_hir_node(data.first_expr.hir_id) {
Node::Expr(e) => matches!(e.kind, ExprKind::Tup(_)),
_ => false,
};
let is_in_tuple = matches!(
get_parent_expr(cx, data.first_expr),
Some(Expr {
kind: ExprKind::Tup(..),
..
})
);
let sugg = if !snip_is_macro
&& (calls_field || expr.precedence().order() < precedence)

View File

@ -255,6 +255,7 @@ mod issue_10253 {
fn issue_12268() {
let option = Some((&1,));
let x = (&1,);
// Lint here.
option.unwrap_or((x.0,));
//~^ ERROR: this expression creates a reference which is immediately dereferenced by the
// compiler
}

View File

@ -255,6 +255,7 @@ mod issue_10253 {
fn issue_12268() {
let option = Some((&1,));
let x = (&1,);
// Lint here.
option.unwrap_or((&x.0,));
//~^ ERROR: this expression creates a reference which is immediately dereferenced by the
// compiler
}

View File

@ -164,7 +164,7 @@ LL | let _ = &mut (&mut { x.u }).x;
| ^^^^^^^^^^^^^^ help: change this to: `{ x.u }`
error: this expression creates a reference which is immediately dereferenced by the compiler
--> tests/ui/needless_borrow.rs:259:23
--> tests/ui/needless_borrow.rs:258:23
|
LL | option.unwrap_or((&x.0,));
| ^^^^ help: change this to: `x.0`