@@ -21,7 +21,6 @@ use rustc_ast::{
2121use rustc_data_structures:: stack:: ensure_sufficient_stack;
2222use rustc_errors:: { Applicability , Diag , PResult , StashKey , Subdiagnostic } ;
2323use rustc_literal_escaper:: unescape_char;
24- use rustc_macros:: Subdiagnostic ;
2524use rustc_session:: errors:: { ExprParenthesesNeeded , report_lit_error} ;
2625use rustc_session:: lint:: BuiltinLintDiag ;
2726use rustc_session:: lint:: builtin:: BREAK_WITH_LABEL_AND_LOOP ;
@@ -2770,7 +2769,7 @@ impl<'a> Parser<'a> {
27702769 let recovered = if !restrictions. contains ( Restrictions :: ALLOW_LET ) {
27712770 let err = errors:: ExpectedExpressionFoundLet {
27722771 span : self . token . span ,
2773- reason : ForbiddenLetReason :: OtherForbidden ,
2772+ reason : errors :: ForbiddenLetReason :: OtherForbidden ,
27742773 missing_let : None ,
27752774 comparison : None ,
27762775 } ;
@@ -4169,22 +4168,6 @@ pub(crate) fn could_be_unclosed_char_literal(ident: Ident) -> bool {
41694168 && unescape_char ( ident. without_first_quote ( ) . name . as_str ( ) ) . is_ok ( )
41704169}
41714170
4172- /// Used to forbid `let` expressions in certain syntactic locations.
4173- #[ derive( Clone , Copy , Subdiagnostic ) ]
4174- pub ( crate ) enum ForbiddenLetReason {
4175- /// `let` is not valid and the source environment is not important
4176- OtherForbidden ,
4177- /// A let chain with the `||` operator
4178- #[ note( parse_not_supported_or) ]
4179- NotSupportedOr ( #[ primary_span] Span ) ,
4180- /// A let chain with invalid parentheses
4181- ///
4182- /// For example, `let 1 = 1 && (expr && expr)` is allowed
4183- /// but `(let 1 = 1 && (let 1 = 1 && (let 1 = 1))) && let a = 1` is not
4184- #[ note( parse_not_supported_parentheses) ]
4185- NotSupportedParentheses ( #[ primary_span] Span ) ,
4186- }
4187-
41884171/// Whether let chains are allowed on all editions, or it's edition dependent (allowed only on
41894172/// 2024 and later). In case of edition dependence, specify the currently present edition.
41904173pub enum LetChainsPolicy {
@@ -4205,7 +4188,7 @@ struct CondChecker<'a> {
42054188 parser : & ' a Parser < ' a > ,
42064189 let_chains_policy : LetChainsPolicy ,
42074190 depth : u32 ,
4208- forbid_let_reason : Option < ForbiddenLetReason > ,
4191+ forbid_let_reason : Option < errors :: ForbiddenLetReason > ,
42094192 missing_let : Option < errors:: MaybeMissingLet > ,
42104193 comparison : Option < errors:: MaybeComparison > ,
42114194}
@@ -4226,14 +4209,13 @@ impl<'a> CondChecker<'a> {
42264209impl MutVisitor for CondChecker < ' _ > {
42274210 fn visit_expr ( & mut self , e : & mut Expr ) {
42284211 self . depth += 1 ;
4229- use ForbiddenLetReason :: * ;
42304212
42314213 let span = e. span ;
42324214 match e. kind {
42334215 ExprKind :: Let ( _, _, _, ref mut recovered @ Recovered :: No ) => {
42344216 if let Some ( reason) = self . forbid_let_reason {
42354217 let error = match reason {
4236- NotSupportedOr ( or_span) => {
4218+ errors :: ForbiddenLetReason :: NotSupportedOr ( or_span) => {
42374219 self . parser . dcx ( ) . emit_err ( errors:: OrInLetChain { span : or_span } )
42384220 }
42394221 _ => self . parser . dcx ( ) . emit_err ( errors:: ExpectedExpressionFoundLet {
@@ -4260,24 +4242,27 @@ impl MutVisitor for CondChecker<'_> {
42604242 mut_visit:: walk_expr ( self , e) ;
42614243 }
42624244 ExprKind :: Binary ( Spanned { node : BinOpKind :: Or , span : or_span } , _, _)
4263- if let None | Some ( NotSupportedOr ( _) ) = self . forbid_let_reason =>
4245+ if let None | Some ( errors:: ForbiddenLetReason :: NotSupportedOr ( _) ) =
4246+ self . forbid_let_reason =>
42644247 {
42654248 let forbid_let_reason = self . forbid_let_reason ;
4266- self . forbid_let_reason = Some ( NotSupportedOr ( or_span) ) ;
4249+ self . forbid_let_reason = Some ( errors :: ForbiddenLetReason :: NotSupportedOr ( or_span) ) ;
42674250 mut_visit:: walk_expr ( self , e) ;
42684251 self . forbid_let_reason = forbid_let_reason;
42694252 }
42704253 ExprKind :: Paren ( ref inner)
4271- if let None | Some ( NotSupportedParentheses ( _) ) = self . forbid_let_reason =>
4254+ if let None | Some ( errors:: ForbiddenLetReason :: NotSupportedParentheses ( _) ) =
4255+ self . forbid_let_reason =>
42724256 {
42734257 let forbid_let_reason = self . forbid_let_reason ;
4274- self . forbid_let_reason = Some ( NotSupportedParentheses ( inner. span ) ) ;
4258+ self . forbid_let_reason =
4259+ Some ( errors:: ForbiddenLetReason :: NotSupportedParentheses ( inner. span ) ) ;
42754260 mut_visit:: walk_expr ( self , e) ;
42764261 self . forbid_let_reason = forbid_let_reason;
42774262 }
42784263 ExprKind :: Assign ( ref lhs, _, span) => {
42794264 let forbid_let_reason = self . forbid_let_reason ;
4280- self . forbid_let_reason = Some ( OtherForbidden ) ;
4265+ self . forbid_let_reason = Some ( errors :: ForbiddenLetReason :: OtherForbidden ) ;
42814266 let missing_let = self . missing_let ;
42824267 if let ExprKind :: Binary ( _, _, rhs) = & lhs. kind
42834268 && let ExprKind :: Path ( _, _)
@@ -4310,15 +4295,15 @@ impl MutVisitor for CondChecker<'_> {
43104295 | ExprKind :: Tup ( _)
43114296 | ExprKind :: Paren ( _) => {
43124297 let forbid_let_reason = self . forbid_let_reason ;
4313- self . forbid_let_reason = Some ( OtherForbidden ) ;
4298+ self . forbid_let_reason = Some ( errors :: ForbiddenLetReason :: OtherForbidden ) ;
43144299 mut_visit:: walk_expr ( self , e) ;
43154300 self . forbid_let_reason = forbid_let_reason;
43164301 }
43174302 ExprKind :: Cast ( ref mut op, _)
43184303 | ExprKind :: Type ( ref mut op, _)
43194304 | ExprKind :: UnsafeBinderCast ( _, ref mut op, _) => {
43204305 let forbid_let_reason = self . forbid_let_reason ;
4321- self . forbid_let_reason = Some ( OtherForbidden ) ;
4306+ self . forbid_let_reason = Some ( errors :: ForbiddenLetReason :: OtherForbidden ) ;
43224307 self . visit_expr ( op) ;
43234308 self . forbid_let_reason = forbid_let_reason;
43244309 }
0 commit comments