Rollup merge of #100011 - compiler-errors:let-chain-restriction, r=fee1-dead

Use Parser's `restrictions` instead of `let_expr_allowed`

This also means that the `ALLOW_LET` flag is reset properly for subexpressions, so we can properly deny things like `a && (b && let c = d)`. Also the parser is a tiny bit smaller now.

It doesn't reject _all_ bad `let` expr usages, just a bit more.

cc `@c410-f3r`
This commit is contained in:
Matthias Krüger 2022-08-02 07:30:44 +02:00 committed by GitHub
commit beb4cdddde
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 365 additions and 306 deletions

View file

@ -47,6 +47,7 @@ bitflags::bitflags! {
const STMT_EXPR = 1 << 0;
const NO_STRUCT_LITERAL = 1 << 1;
const CONST_EXPR = 1 << 2;
const ALLOW_LET = 1 << 3;
}
}
@ -147,15 +148,12 @@ pub struct Parser<'a> {
/// This allows us to recover when the user forget to add braces around
/// multiple statements in the closure body.
pub current_closure: Option<ClosureSpans>,
/// Used to track where `let`s are allowed. For example, `if true && let 1 = 1` is valid
/// but `[1, 2, 3][let _ = ()]` is not.
let_expr_allowed: bool,
}
// This type is used a lot, e.g. it's cloned when matching many declarative macro rules. Make sure
// it doesn't unintentionally get bigger.
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(Parser<'_>, 336);
rustc_data_structures::static_assert_size!(Parser<'_>, 328);
/// Stores span information about a closure.
#[derive(Clone)]
@ -462,7 +460,6 @@ impl<'a> Parser<'a> {
inner_attr_ranges: Default::default(),
},
current_closure: None,
let_expr_allowed: false,
};
// Make parser point to the first token.