diff options
| author | Dylan DPC <99973273+Dylan-DPC@users.noreply.github.com> | 2022-07-13 19:32:33 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-13 19:32:33 +0530 |
| commit | 0083cd2fd498edb6a4e37bf4c711d11364e0ef20 (patch) | |
| tree | ae0410e11bd58462d2ad36d710b887bf6dcb6dff /compiler/rustc_middle/src | |
| parent | ca4e39400ef33198e2715973d1c67a1d3cee15e7 (diff) | |
| parent | 947cbda5eb557ee3015b2310adfc80a393e42051 (diff) | |
| download | rust-0083cd2fd498edb6a4e37bf4c711d11364e0ef20.tar.gz rust-0083cd2fd498edb6a4e37bf4c711d11364e0ef20.zip | |
Rollup merge of #98574 - dingxiangfei2009:let-else-thir, r=oli-obk
Lower let-else in MIR This MR will switch to lower let-else statements in MIR building instead. To lower let-else in MIR, we build a mini-switch two branches. One branch leads to the matching case, and the other leads to the `else` block. This arrangement will allow temporary lifetime analysis running as-is so that the temporaries are properly extended according to the same rule applied to regular `let` statements. cc https://github.com/rust-lang/rust/issues/87335 Fix #98672
Diffstat (limited to 'compiler/rustc_middle/src')
| -rw-r--r-- | compiler/rustc_middle/src/thir.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/thir/visit.rs | 4 |
2 files changed, 7 insertions, 0 deletions
diff --git a/compiler/rustc_middle/src/thir.rs b/compiler/rustc_middle/src/thir.rs index 3fe6394ad7e..3e5f6bb8f0b 100644 --- a/compiler/rustc_middle/src/thir.rs +++ b/compiler/rustc_middle/src/thir.rs @@ -182,6 +182,9 @@ pub enum StmtKind<'tcx> { /// `let pat: ty = <INIT>` initializer: Option<ExprId>, + /// `let pat: ty = <INIT> else { <ELSE> } + else_block: Option<Block>, + /// The lint level for this `let` statement. lint_level: LintLevel, }, diff --git a/compiler/rustc_middle/src/thir/visit.rs b/compiler/rustc_middle/src/thir/visit.rs index c8d09875c28..97249fdd175 100644 --- a/compiler/rustc_middle/src/thir/visit.rs +++ b/compiler/rustc_middle/src/thir/visit.rs @@ -167,11 +167,15 @@ pub fn walk_stmt<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, stmt: &Stm init_scope: _, ref pattern, lint_level: _, + else_block, } => { if let Some(init) = initializer { visitor.visit_expr(&visitor.thir()[*init]); } visitor.visit_pat(pattern); + if let Some(block) = else_block { + visitor.visit_block(block) + } } } } |
