fix: Refactor dereference code and fix test
This commit is contained in:
parent
38b8056fc6
commit
8ae7eaefdc
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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`
|
||||
|
Loading…
x
Reference in New Issue
Block a user