]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_mir_build/src/build/expr/into.rs
Merge commit 'c4416f20dcaec5d93077f72470e83e150fb923b1' into sync-rustfmt
[rust.git] / compiler / rustc_mir_build / src / build / expr / into.rs
index ea677d727e0172003df6f27b95a0f5af1345b5a4..cffb67ef013282f5491640f9167cb44b872067d0 100644 (file)
@@ -63,6 +63,17 @@ pub(crate) fn expr_into_dest(
                         (if_then_scope, then_source_info),
                         LintLevel::Inherited,
                         |this| {
+                            let source_info = if this.is_let(cond) {
+                                let variable_scope = this.new_source_scope(
+                                    then_expr.span,
+                                    LintLevel::Inherited,
+                                    None,
+                                );
+                                this.source_scope = variable_scope;
+                                SourceInfo { span: then_expr.span, scope: variable_scope }
+                            } else {
+                                this.source_info(then_expr.span)
+                            };
                             let (then_block, else_block) =
                                 this.in_if_then_scope(condition_scope, |this| {
                                     let then_blk = unpack!(this.then_else_break(
@@ -70,7 +81,7 @@ pub(crate) fn expr_into_dest(
                                         &this.thir[cond],
                                         Some(condition_scope),
                                         condition_scope,
-                                        then_expr.span
+                                        source_info
                                     ));
 
                                     this.expr_into_dest(destination, then_blk, then_expr)
@@ -576,4 +587,12 @@ pub(crate) fn expr_into_dest(
 
         block_and
     }
+
+    fn is_let(&self, expr: ExprId) -> bool {
+        match self.thir[expr].kind {
+            ExprKind::Let { .. } => true,
+            ExprKind::Scope { value, .. } => self.is_let(value),
+            _ => false,
+        }
+    }
 }