diff --git a/src/librustc_mir/build/block.rs b/src/librustc_mir/build/block.rs index 8c98408e2390a..a8681af57af70 100644 --- a/src/librustc_mir/build/block.rs +++ b/src/librustc_mir/build/block.rs @@ -53,16 +53,20 @@ impl<'a,'tcx> Builder<'a,'tcx> { } StmtKind::Let { remainder_scope, init_scope, pattern, initializer } => { let remainder_scope_id = this.push_scope(remainder_scope, block); + this.declare_bindings(remainder_scope_id, &pattern); let_extent_stack.push(remainder_scope); - unpack!(block = this.in_scope(init_scope, block, move |this, _| { - // FIXME #30046 ^~~~ - if let Some(init) = initializer { - this.expr_into_pattern(block, remainder_scope_id, pattern, init) - } else { - this.declare_bindings(remainder_scope_id, &pattern); - block.unit() - } - })); + + let parent = this.scope_datas[remainder_scope_id].parent_scope; + if let Some(init) = initializer { + unpack!(block = this.in_scope(init_scope, block, move |this, id| { + // FIXME #30046 ^~~~ + + // Don't nest the initializer in the remainder scope. + this.scope_datas[id].parent_scope = parent; + + this.expr_into_pattern(block, pattern, init) + })); + } } } } diff --git a/src/librustc_mir/build/matches/mod.rs b/src/librustc_mir/build/matches/mod.rs index 080183ae1da66..23933e43b20d2 100644 --- a/src/librustc_mir/build/matches/mod.rs +++ b/src/librustc_mir/build/matches/mod.rs @@ -116,45 +116,27 @@ impl<'a,'tcx> Builder<'a,'tcx> { pub fn expr_into_pattern(&mut self, mut block: BasicBlock, - var_scope_id: ScopeId, // lifetime of vars irrefutable_pat: Pattern<'tcx>, initializer: ExprRef<'tcx>) -> BlockAnd<()> { // optimize the case of `let x = ...` match *irrefutable_pat.kind { - PatternKind::Binding { mutability, - name, - mode: BindingMode::ByValue, - var, - ty, - subpattern: None } => { - let index = self.declare_binding(var_scope_id, - mutability, - name, - var, - ty, - irrefutable_pat.span); - let lvalue = Lvalue::Var(index); + PatternKind::Binding { mode: BindingMode::ByValue, + var, subpattern: None, .. } => { + let lvalue = Lvalue::Var(self.var_indices[&var]); return self.into(&lvalue, block, initializer); } _ => {} } let lvalue = unpack!(block = self.as_lvalue(block, initializer)); - self.lvalue_into_pattern(block, - var_scope_id, - irrefutable_pat, - &lvalue) + self.lvalue_into_pattern(block, irrefutable_pat, &lvalue) } pub fn lvalue_into_pattern(&mut self, mut block: BasicBlock, - var_scope_id: ScopeId, irrefutable_pat: Pattern<'tcx>, initializer: &Lvalue<'tcx>) -> BlockAnd<()> { - // first, creating the bindings - self.declare_bindings(var_scope_id, &irrefutable_pat); - // create a dummy candidate let mut candidate = Candidate { span: irrefutable_pat.span, diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index b088425d58a2a..c80f32b48f110 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -283,19 +283,22 @@ impl<'a,'tcx> Builder<'a,'tcx> { .enumerate() .map(|(index, (ty, pattern))| { let lvalue = Lvalue::Arg(index as u32); - if let Some(pattern) = pattern { - let pattern = self.hir.irrefutable_pat(pattern); - unpack!(block = self.lvalue_into_pattern(block, - argument_scope_id, - pattern, - &lvalue)); - } // Make sure we drop (parts of) the argument even when not matched on. let argument_extent = self.scope_auxiliary[argument_scope_id].extent; self.schedule_drop(pattern.as_ref().map_or(ast_block.span, |pat| pat.span), argument_extent, &lvalue, ty); + if let Some(pattern) = pattern { + let pattern = self.hir.irrefutable_pat(pattern); + self.declare_bindings(argument_scope_id, &pattern); + + // Don't have the argument scope around when matching the pattern. + let arg_scope = self.scopes.pop().unwrap(); + unpack!(block = self.lvalue_into_pattern(block, pattern, &lvalue)); + self.scopes.push(arg_scope); + } + let mut name = keywords::Invalid.name(); if let Some(pat) = pattern { if let hir::PatKind::Ident(_, ref ident, _) = pat.node { diff --git a/src/test/debuginfo/function-prologue-stepping-no-stack-check.rs b/src/test/debuginfo/function-prologue-stepping-no-stack-check.rs index f0ecda9299370..b5b6ca7572703 100644 --- a/src/test/debuginfo/function-prologue-stepping-no-stack-check.rs +++ b/src/test/debuginfo/function-prologue-stepping-no-stack-check.rs @@ -247,11 +247,10 @@ // lldb-command:continue #![allow(dead_code, unused_assignments, unused_variables)] -#![feature(omit_gdb_pretty_printer_section, rustc_attrs)] +#![feature(omit_gdb_pretty_printer_section)] #![omit_gdb_pretty_printer_section] #[no_stack_check] -#[rustc_no_mir] // FIXME(#32949) MIR debuginfo shadows arguments with uninit vars. fn immediate_args(a: isize, b: bool, c: f64) { println!(""); } @@ -268,51 +267,43 @@ struct BigStruct { } #[no_stack_check] -#[rustc_no_mir] // FIXME(#32949) MIR debuginfo shadows arguments with uninit vars. fn non_immediate_args(a: BigStruct, b: BigStruct) { println!(""); } #[no_stack_check] -#[rustc_no_mir] // FIXME(#32949) MIR debuginfo shadows arguments with uninit vars. fn binding(a: i64, b: u64, c: f64) { let x = 0; println!(""); } #[no_stack_check] -#[rustc_no_mir] // FIXME(#32949) MIR debuginfo shadows arguments with uninit vars. fn assignment(mut a: u64, b: u64, c: f64) { a = b; println!(""); } #[no_stack_check] -#[rustc_no_mir] // FIXME(#32949) MIR debuginfo shadows arguments with uninit vars. fn function_call(x: u64, y: u64, z: f64) { println!("Hi!") } #[no_stack_check] -#[rustc_no_mir] // FIXME(#32949) MIR debuginfo shadows arguments with uninit vars. fn identifier(x: u64, y: u64, z: f64) -> u64 { x } #[no_stack_check] -#[rustc_no_mir] // FIXME(#32949) MIR debuginfo shadows arguments with uninit vars. fn return_expr(x: u64, y: u64, z: f64) -> u64 { return x; } #[no_stack_check] -#[rustc_no_mir] // FIXME(#32949) MIR debuginfo shadows arguments with uninit vars. fn arithmetic_expr(x: u64, y: u64, z: f64) -> u64 { x + y } #[no_stack_check] -#[rustc_no_mir] // FIXME(#32949) MIR debuginfo shadows arguments with uninit vars. fn if_expr(x: u64, y: u64, z: f64) -> u64 { if x + y < 1000 { x @@ -322,7 +313,6 @@ fn if_expr(x: u64, y: u64, z: f64) -> u64 { } #[no_stack_check] -#[rustc_no_mir] // FIXME(#32949) MIR debuginfo shadows arguments with uninit vars. fn while_expr(mut x: u64, y: u64, z: u64) -> u64 { while x + y < 1000 { x += z @@ -331,7 +321,6 @@ fn while_expr(mut x: u64, y: u64, z: u64) -> u64 { } #[no_stack_check] -#[rustc_no_mir] // FIXME(#32949) MIR debuginfo shadows arguments with uninit vars. fn loop_expr(mut x: u64, y: u64, z: u64) -> u64 { loop { x += z;