Ignore ExprKind::DropTemps
for some ref suggestions
This commit is contained in:
parent
ec557aa818
commit
d84c4cd718
4 changed files with 30 additions and 22 deletions
|
@ -1548,6 +1548,23 @@ impl Expr {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// If `Self.kind` is `ExprKind::DropTemps(expr)`, drill down until we get a non-`DropTemps`
|
||||
/// `Expr`. This is used in suggestions to ignore this `ExprKind` as it is semantically
|
||||
/// silent, only signaling the ownership system. By doing this, suggestions that check the
|
||||
/// `ExprKind` of any given `Expr` for presentation don't have to care about `DropTemps`
|
||||
/// beyond remembering to call this function before doing analysis on it.
|
||||
pub fn peel_drop_temps(&self) -> &Self {
|
||||
let mut base_expr = self;
|
||||
loop {
|
||||
match &base_expr.kind {
|
||||
ExprKind::DropTemps(expr) => {
|
||||
base_expr = &expr;
|
||||
}
|
||||
_ => return base_expr,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for Expr {
|
||||
|
|
|
@ -355,6 +355,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
};
|
||||
let is_macro = sp.from_expansion() && !is_desugaring;
|
||||
|
||||
// `ExprKind::DropTemps` is semantically irrelevant for these suggestions.
|
||||
let expr = expr.peel_drop_temps();
|
||||
|
||||
match (&expr.kind, &expected.kind, &checked_ty.kind) {
|
||||
(_, &ty::Ref(_, exp, _), &ty::Ref(_, check, _)) => match (&exp.kind, &check.kind) {
|
||||
(&ty::Str, &ty::Array(arr, _)) |
|
||||
|
|
|
@ -2,10 +2,7 @@ error[E0308]: mismatched types
|
|||
--> $DIR/if-no-match-bindings.rs:18:8
|
||||
|
|
||||
LL | if b_ref() {}
|
||||
| ^^^^^^^
|
||||
| |
|
||||
| expected bool, found &bool
|
||||
| help: consider dereferencing the borrow: `*b_ref()`
|
||||
| ^^^^^^^ expected bool, found &bool
|
||||
|
|
||||
= note: expected type `bool`
|
||||
found type `&bool`
|
||||
|
@ -14,10 +11,7 @@ error[E0308]: mismatched types
|
|||
--> $DIR/if-no-match-bindings.rs:19:8
|
||||
|
|
||||
LL | if b_mut_ref() {}
|
||||
| ^^^^^^^^^^^
|
||||
| |
|
||||
| expected bool, found &mut bool
|
||||
| help: consider dereferencing the borrow: `*b_mut_ref()`
|
||||
| ^^^^^^^^^^^ expected bool, found &mut bool
|
||||
|
|
||||
= note: expected type `bool`
|
||||
found type `&mut bool`
|
||||
|
@ -29,7 +23,7 @@ LL | if &true {}
|
|||
| ^^^^^
|
||||
| |
|
||||
| expected bool, found &bool
|
||||
| help: consider dereferencing the borrow: `*&true`
|
||||
| help: consider removing the borrow: `true`
|
||||
|
|
||||
= note: expected type `bool`
|
||||
found type `&bool`
|
||||
|
@ -41,7 +35,7 @@ LL | if &mut true {}
|
|||
| ^^^^^^^^^
|
||||
| |
|
||||
| expected bool, found &mut bool
|
||||
| help: consider dereferencing the borrow: `*&mut true`
|
||||
| help: consider removing the borrow: `true`
|
||||
|
|
||||
= note: expected type `bool`
|
||||
found type `&mut bool`
|
||||
|
@ -50,10 +44,7 @@ error[E0308]: mismatched types
|
|||
--> $DIR/if-no-match-bindings.rs:24:11
|
||||
|
|
||||
LL | while b_ref() {}
|
||||
| ^^^^^^^
|
||||
| |
|
||||
| expected bool, found &bool
|
||||
| help: consider dereferencing the borrow: `*b_ref()`
|
||||
| ^^^^^^^ expected bool, found &bool
|
||||
|
|
||||
= note: expected type `bool`
|
||||
found type `&bool`
|
||||
|
@ -62,10 +53,7 @@ error[E0308]: mismatched types
|
|||
--> $DIR/if-no-match-bindings.rs:25:11
|
||||
|
|
||||
LL | while b_mut_ref() {}
|
||||
| ^^^^^^^^^^^
|
||||
| |
|
||||
| expected bool, found &mut bool
|
||||
| help: consider dereferencing the borrow: `*b_mut_ref()`
|
||||
| ^^^^^^^^^^^ expected bool, found &mut bool
|
||||
|
|
||||
= note: expected type `bool`
|
||||
found type `&mut bool`
|
||||
|
@ -77,7 +65,7 @@ LL | while &true {}
|
|||
| ^^^^^
|
||||
| |
|
||||
| expected bool, found &bool
|
||||
| help: consider dereferencing the borrow: `*&true`
|
||||
| help: consider removing the borrow: `true`
|
||||
|
|
||||
= note: expected type `bool`
|
||||
found type `&bool`
|
||||
|
@ -89,7 +77,7 @@ LL | while &mut true {}
|
|||
| ^^^^^^^^^
|
||||
| |
|
||||
| expected bool, found &mut bool
|
||||
| help: consider dereferencing the borrow: `*&mut true`
|
||||
| help: consider removing the borrow: `true`
|
||||
|
|
||||
= note: expected type `bool`
|
||||
found type `&mut bool`
|
||||
|
|
|
@ -520,7 +520,7 @@ LL | if &let 0 = 0 {}
|
|||
| ^^^^^^^^^^
|
||||
| |
|
||||
| expected bool, found &bool
|
||||
| help: consider dereferencing the borrow: `*&let 0 = 0`
|
||||
| help: consider removing the borrow: `let 0 = 0`
|
||||
|
|
||||
= note: expected type `bool`
|
||||
found type `&bool`
|
||||
|
@ -708,7 +708,7 @@ LL | while &let 0 = 0 {}
|
|||
| ^^^^^^^^^^
|
||||
| |
|
||||
| expected bool, found &bool
|
||||
| help: consider dereferencing the borrow: `*&let 0 = 0`
|
||||
| help: consider removing the borrow: `let 0 = 0`
|
||||
|
|
||||
= note: expected type `bool`
|
||||
found type `&bool`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue