diff options
| author | bors <bors@rust-lang.org> | 2023-09-14 19:56:55 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-09-14 19:56:55 +0000 |
| commit | dac91a82e146d89fefe94dcbb53cd6c2662e354f (patch) | |
| tree | b17e0f57c57a47fb6d4b54df4313174f090ee4e3 /compiler/rustc_ast_lowering/src | |
| parent | ccf817b9bbe449204a227430d0a84a4f1d1798cc (diff) | |
| parent | e324a59eb6ba1a7883bf23ff42d425ca96960f2a (diff) | |
| download | rust-dac91a82e146d89fefe94dcbb53cd6c2662e354f.tar.gz rust-dac91a82e146d89fefe94dcbb53cd6c2662e354f.zip | |
Auto merge of #115677 - matthewjasper:let-expr-recovery, r=b-naber
Improve invalid let expression handling - Move all of the checks for valid let expression positions to parsing. - Add a field to ExprKind::Let in AST/HIR to mark whether it's in a valid location. - Suppress some later errors and MIR construction for invalid let expressions. - Fix a (drop) scope issue that was also responsible for #104172. Fixes #104172 Fixes #104868
Diffstat (limited to 'compiler/rustc_ast_lowering/src')
| -rw-r--r-- | compiler/rustc_ast_lowering/src/expr.rs | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index 7408b4fb0af..57c54f8540c 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -152,13 +152,14 @@ impl<'hir> LoweringContext<'_, 'hir> { let ohs = self.lower_expr(ohs); hir::ExprKind::AddrOf(*k, *m, ohs) } - ExprKind::Let(pat, scrutinee, span) => { + ExprKind::Let(pat, scrutinee, span, is_recovered) => { hir::ExprKind::Let(self.arena.alloc(hir::Let { hir_id: self.next_id(), span: self.lower_span(*span), pat: self.lower_pat(pat), ty: None, init: self.lower_expr(scrutinee), + is_recovered: *is_recovered, })) } ExprKind::If(cond, then, else_opt) => { @@ -558,13 +559,14 @@ impl<'hir> LoweringContext<'_, 'hir> { fn lower_arm(&mut self, arm: &Arm) -> hir::Arm<'hir> { let pat = self.lower_pat(&arm.pat); let guard = arm.guard.as_ref().map(|cond| { - if let ExprKind::Let(pat, scrutinee, span) = &cond.kind { + if let ExprKind::Let(pat, scrutinee, span, is_recovered) = &cond.kind { hir::Guard::IfLet(self.arena.alloc(hir::Let { hir_id: self.next_id(), span: self.lower_span(*span), pat: self.lower_pat(pat), ty: None, init: self.lower_expr(scrutinee), + is_recovered: *is_recovered, })) } else { hir::Guard::If(self.lower_expr(cond)) |
