Small dedup

This commit is contained in:
Nadrieril 2024-06-17 19:39:09 +02:00
parent 012626b32b
commit cef49f73e7

View File

@ -2059,14 +2059,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
return self.cfg.start_new_block(); return self.cfg.start_new_block();
} }
self.ascribe_types( let ascriptions = parent_data
block, .iter()
parent_data .flat_map(|d| &d.ascriptions)
.iter() .cloned()
.flat_map(|d| &d.ascriptions) .chain(candidate.extra_data.ascriptions);
.cloned() let bindings =
.chain(candidate.extra_data.ascriptions), parent_data.iter().flat_map(|d| &d.bindings).chain(&candidate.extra_data.bindings);
);
self.ascribe_types(block, ascriptions);
// rust-lang/rust#27282: The `autoref` business deserves some // rust-lang/rust#27282: The `autoref` business deserves some
// explanation here. // explanation here.
@ -2153,12 +2154,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
&& let Some(guard) = arm.guard && let Some(guard) = arm.guard
{ {
let tcx = self.tcx; let tcx = self.tcx;
let bindings =
parent_data.iter().flat_map(|d| &d.bindings).chain(&candidate.extra_data.bindings);
self.bind_matched_candidate_for_guard(block, schedule_drops, bindings.clone()); self.bind_matched_candidate_for_guard(block, schedule_drops, bindings.clone());
let guard_frame = let guard_frame = GuardFrame {
GuardFrame { locals: bindings.map(|b| GuardFrameLocal::new(b.var_id)).collect() }; locals: bindings.clone().map(|b| GuardFrameLocal::new(b.var_id)).collect(),
};
debug!("entering guard building context: {:?}", guard_frame); debug!("entering guard building context: {:?}", guard_frame);
self.guard_context.push(guard_frame); self.guard_context.push(guard_frame);
@ -2231,11 +2231,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// ``` // ```
// //
// and that is clearly not correct. // and that is clearly not correct.
let by_value_bindings = parent_data let by_value_bindings =
.iter() bindings.filter(|binding| matches!(binding.binding_mode.0, ByRef::No));
.flat_map(|d| &d.bindings)
.chain(&candidate.extra_data.bindings)
.filter(|binding| matches!(binding.binding_mode.0, ByRef::No));
// Read all of the by reference bindings to ensure that the // Read all of the by reference bindings to ensure that the
// place they refer to can't be modified by the guard. // place they refer to can't be modified by the guard.
for binding in by_value_bindings.clone() { for binding in by_value_bindings.clone() {
@ -2259,7 +2256,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
self.bind_matched_candidate_for_arm_body( self.bind_matched_candidate_for_arm_body(
block, block,
schedule_drops, schedule_drops,
parent_data.iter().flat_map(|d| &d.bindings).chain(&candidate.extra_data.bindings), bindings,
storages_alive, storages_alive,
); );
block block