mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 02:57:37 +00:00
Fix: #12268: Correct parentheses for needless_borrow suggestion
Clippy no longer adds unnecessary parentheses in suggestion when the expression is a part of a tuple.
This commit is contained in:
parent
e80ca2f381
commit
38b8056fc6
@ -1014,9 +1014,15 @@ 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 sugg = if !snip_is_macro
|
||||
&& (calls_field || expr.precedence().order() < precedence)
|
||||
&& !has_enclosing_paren(&snip)
|
||||
&& !is_in_tuple
|
||||
{
|
||||
format!("({snip})")
|
||||
} else {
|
||||
|
@ -251,3 +251,10 @@ mod issue_10253 {
|
||||
(&S).f::<()>();
|
||||
}
|
||||
}
|
||||
|
||||
fn issue_12268() {
|
||||
let option = Some((&1,));
|
||||
let x = (&1,);
|
||||
// Lint here.
|
||||
option.unwrap_or((x.0,));
|
||||
}
|
||||
|
@ -251,3 +251,10 @@ mod issue_10253 {
|
||||
(&S).f::<()>();
|
||||
}
|
||||
}
|
||||
|
||||
fn issue_12268() {
|
||||
let option = Some((&1,));
|
||||
let x = (&1,);
|
||||
// Lint here.
|
||||
option.unwrap_or((&x.0,));
|
||||
}
|
||||
|
@ -163,5 +163,11 @@ error: this expression borrows a value the compiler would automatically borrow
|
||||
LL | let _ = &mut (&mut { x.u }).x;
|
||||
| ^^^^^^^^^^^^^^ help: change this to: `{ x.u }`
|
||||
|
||||
error: aborting due to 27 previous errors
|
||||
error: this expression creates a reference which is immediately dereferenced by the compiler
|
||||
--> tests/ui/needless_borrow.rs:259:23
|
||||
|
|
||||
LL | option.unwrap_or((&x.0,));
|
||||
| ^^^^ help: change this to: `x.0`
|
||||
|
||||
error: aborting due to 28 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user