Move let expression checking to parsing
There was an incomplete version of the check in parsing and a second version in AST validation. This meant that some, but not all, invalid uses were allowed inside macros/disabled cfgs. It also means that later passes have a hard time knowing when the let expression is in a valid location, sometimes causing ICEs. - Add a field to ExprKind::Let in AST/HIR to mark whether it's in a valid location. - Suppress later errors and MIR construction for invalid let expressions.
This commit is contained in:
parent
7b61f7f002
commit
333388fd3c
40 changed files with 915 additions and 2246 deletions
|
@ -816,8 +816,7 @@ trait UnusedDelimLint {
|
|||
let (value, ctx, followed_by_block, left_pos, right_pos, is_kw) = match e.kind {
|
||||
// Do not lint `unused_braces` in `if let` expressions.
|
||||
If(ref cond, ref block, _)
|
||||
if !matches!(cond.kind, Let(_, _, _))
|
||||
|| Self::LINT_EXPR_IN_PATTERN_MATCHING_CTX =>
|
||||
if !matches!(cond.kind, Let(..)) || Self::LINT_EXPR_IN_PATTERN_MATCHING_CTX =>
|
||||
{
|
||||
let left = e.span.lo() + rustc_span::BytePos(2);
|
||||
let right = block.span.lo();
|
||||
|
@ -826,8 +825,7 @@ trait UnusedDelimLint {
|
|||
|
||||
// Do not lint `unused_braces` in `while let` expressions.
|
||||
While(ref cond, ref block, ..)
|
||||
if !matches!(cond.kind, Let(_, _, _))
|
||||
|| Self::LINT_EXPR_IN_PATTERN_MATCHING_CTX =>
|
||||
if !matches!(cond.kind, Let(..)) || Self::LINT_EXPR_IN_PATTERN_MATCHING_CTX =>
|
||||
{
|
||||
let left = e.span.lo() + rustc_span::BytePos(5);
|
||||
let right = block.span.lo();
|
||||
|
@ -1003,7 +1001,7 @@ impl UnusedDelimLint for UnusedParens {
|
|||
self.emit_unused_delims_expr(cx, value, ctx, left_pos, right_pos, is_kw)
|
||||
}
|
||||
}
|
||||
ast::ExprKind::Let(_, ref expr, _) => {
|
||||
ast::ExprKind::Let(_, ref expr, _, _) => {
|
||||
self.check_unused_delims_expr(
|
||||
cx,
|
||||
expr,
|
||||
|
@ -1067,7 +1065,7 @@ impl EarlyLintPass for UnusedParens {
|
|||
}
|
||||
|
||||
match e.kind {
|
||||
ExprKind::Let(ref pat, _, _) | ExprKind::ForLoop(ref pat, ..) => {
|
||||
ExprKind::Let(ref pat, _, _, _) | ExprKind::ForLoop(ref pat, ..) => {
|
||||
self.check_unused_parens_pat(cx, pat, false, false, (true, true));
|
||||
}
|
||||
// We ignore parens in cases like `if (((let Some(0) = Some(1))))` because we already
|
||||
|
@ -1311,7 +1309,7 @@ impl UnusedDelimLint for UnusedBraces {
|
|||
}
|
||||
}
|
||||
}
|
||||
ast::ExprKind::Let(_, ref expr, _) => {
|
||||
ast::ExprKind::Let(_, ref expr, _, _) => {
|
||||
self.check_unused_delims_expr(
|
||||
cx,
|
||||
expr,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue