Rollup merge of #97856 - compiler-errors:bad-let-suggestions, r=estebank

Don't suggest adding `let` in certain `if` conditions

Avoid being too eager to suggest `let` in an `if` condition with an `=`, namely when the LHS of the `=` isn't even valid as a pattern (to a first degree approximation).

This heustic I came up with kinda sucks. Let me know if it needs to be refined.
This commit is contained in:
Michael Goulet 2022-06-08 13:32:20 -07:00 committed by GitHub
commit e0409200d9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 142 additions and 8 deletions

View file

@ -1278,6 +1278,22 @@ impl Expr {
},
)
}
// To a first-order approximation, is this a pattern
pub fn is_approximately_pattern(&self) -> bool {
match &self.peel_parens().kind {
ExprKind::Box(_)
| ExprKind::Array(_)
| ExprKind::Call(_, _)
| ExprKind::Tup(_)
| ExprKind::Lit(_)
| ExprKind::Range(_, _, _)
| ExprKind::Underscore
| ExprKind::Path(_, _)
| ExprKind::Struct(_) => true,
_ => false,
}
}
}
/// Limit types of a range (inclusive or exclusive)