From 1376c5a617be5c25655d0d7cb63e3beaa5a6e026 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:20:39 +0200 Subject: Merging upstream version 1.70.0+dfsg1. Signed-off-by: Daniel Baumann --- compiler/rustc_mir_build/src/build/matches/mod.rs | 34 +++++++++++++---------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'compiler/rustc_mir_build/src/build/matches/mod.rs') diff --git a/compiler/rustc_mir_build/src/build/matches/mod.rs b/compiler/rustc_mir_build/src/build/matches/mod.rs index de2851a1a..4926ff85d 100644 --- a/compiler/rustc_mir_build/src/build/matches/mod.rs +++ b/compiler/rustc_mir_build/src/build/matches/mod.rs @@ -556,6 +556,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { _ => { let place_builder = unpack!(block = self.as_place_builder(block, initializer)); + + if let Some(place) = place_builder.try_to_place(self) { + let source_info = self.source_info(initializer.span); + self.cfg.push_place_mention(block, source_info, place); + } + self.place_into_pattern(block, &irrefutable_pat, place_builder, true) } } @@ -576,13 +582,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { false, &mut [&mut candidate], ); + // For matches and function arguments, the place that is being matched // can be set when creating the variables. But the place for // let PATTERN = ... might not even exist until we do the assignment. // so we set it here instead. if set_match_place { - let mut candidate_ref = &candidate; - while let Some(next) = { + let mut next = Some(&candidate); + while let Some(candidate_ref) = next.take() { for binding in &candidate_ref.bindings { let local = self.var_local_id(binding.var_id, OutsideGuard); // `try_to_place` may fail if it is unable to resolve the given @@ -600,9 +607,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // }; // ``` if let Some(place) = initializer.try_to_place(self) { - let Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::Var( + let LocalInfo::User(BindingForm::Var( VarBindingForm { opt_match_place: Some((ref mut match_place, _)), .. }, - )))) = self.local_decls[local].local_info else { + )) = **self.local_decls[local].local_info.as_mut().assert_crate_local() else { bug!("Let binding to non-user variable.") }; *match_place = Some(place); @@ -610,9 +617,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } // All of the subcandidates should bind the same locals, so we // only visit the first one. - candidate_ref.subcandidates.get(0) - } { - candidate_ref = next; + next = candidate_ref.subcandidates.get(0) } } @@ -1749,7 +1754,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let fake_borrow_ty = tcx.mk_imm_ref(tcx.lifetimes.re_erased, fake_borrow_deref_ty); let mut fake_borrow_temp = LocalDecl::new(fake_borrow_ty, temp_span); fake_borrow_temp.internal = self.local_decls[matched_place.local].internal; - fake_borrow_temp.local_info = Some(Box::new(LocalInfo::FakeBorrow)); + fake_borrow_temp.local_info = ClearCrossCrate::Set(Box::new(LocalInfo::FakeBorrow)); let fake_borrow_temp = self.local_decls.push(fake_borrow_temp); (matched_place, fake_borrow_temp) @@ -1881,6 +1886,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // let place = Foo::new(); // match place { Foo { .. } if { let tmp1 = &place; inspect(*tmp1) } // => { let tmp2 = place; feed(tmp2) }, ... } + // ``` // // And an input like: // @@ -2218,8 +2224,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { user_ty: if user_ty.is_empty() { None } else { Some(Box::new(user_ty)) }, source_info, internal: false, - is_block_tail: None, - local_info: Some(Box::new(LocalInfo::User(ClearCrossCrate::Set(BindingForm::Var( + local_info: ClearCrossCrate::Set(Box::new(LocalInfo::User(BindingForm::Var( VarBindingForm { binding_mode, // hypothetically, `visit_primary_bindings` could try to unzip @@ -2230,13 +2235,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { opt_match_place, pat_span, }, - ))))), + )))), }; let for_arm_body = self.local_decls.push(local); self.var_debug_info.push(VarDebugInfo { name, source_info: debug_source_info, value: VarDebugInfoContents::Place(for_arm_body.into()), + argument_index: None, }); let locals = if has_guard.0 { let ref_for_guard = self.local_decls.push(LocalDecl::<'tcx> { @@ -2247,15 +2253,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { user_ty: None, source_info, internal: false, - is_block_tail: None, - local_info: Some(Box::new(LocalInfo::User(ClearCrossCrate::Set( + local_info: ClearCrossCrate::Set(Box::new(LocalInfo::User( BindingForm::RefForGuard, - )))), + ))), }); self.var_debug_info.push(VarDebugInfo { name, source_info: debug_source_info, value: VarDebugInfoContents::Place(ref_for_guard.into()), + argument_index: None, }); LocalsForNode::ForGuard { ref_for_guard, for_arm_body } } else { -- cgit v1.2.3