Skip to content

Commit ee9ff2f

Browse files
committed
No need to re-establish temporaries
1 parent a03fd22 commit ee9ff2f

File tree

2 files changed

+2
-45
lines changed

2 files changed

+2
-45
lines changed

compiler/rustc_mir_build/src/build/matches/mod.rs

+1-33
Original file line numberDiff line numberDiff line change
@@ -993,17 +993,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
993993
}
994994
}
995995

996-
/// A temporary that must be set like `let temp = Deref::deref(&place)` after the candidate
997-
/// `pre_binding_block`. This is because fake edges prevent us from keeping the temporaries we set
998-
/// up while testing which branch to take.
999-
#[derive(Debug, Copy, Clone)]
1000-
struct DerefTemporary<'tcx> {
1001-
place: Place<'tcx>,
1002-
temp: Place<'tcx>,
1003-
ty: Ty<'tcx>,
1004-
span: Span,
1005-
}
1006-
1007996
/// Data extracted from a pattern that doesn't affect which branch is taken. Collected during
1008997
/// pattern simplification and not mutated later.
1009998
#[derive(Debug, Clone, Default)]
@@ -1016,15 +1005,12 @@ struct PatternExtraData<'tcx> {
10161005

10171006
/// Types that must be asserted.
10181007
ascriptions: Vec<Ascription<'tcx>>,
1019-
1020-
/// Temporaries that must be set up in order.
1021-
deref_temps: Vec<DerefTemporary<'tcx>>,
10221008
}
10231009

10241010
impl<'tcx> PatternExtraData<'tcx> {
10251011
fn is_empty(&self) -> bool {
10261012
// FIXME(deref_patterns): can we merge trivial subcandidates that use deref patterns?
1027-
self.bindings.is_empty() && self.ascriptions.is_empty() && self.deref_temps.is_empty()
1013+
self.bindings.is_empty() && self.ascriptions.is_empty()
10281014
}
10291015
}
10301016

@@ -1051,7 +1037,6 @@ impl<'tcx, 'pat> FlatPat<'pat, 'tcx> {
10511037
span: pattern.span,
10521038
bindings: Vec::new(),
10531039
ascriptions: Vec::new(),
1054-
deref_temps: Vec::new(),
10551040
},
10561041
};
10571042
cx.simplify_match_pairs(&mut flat_pat.match_pairs, &mut flat_pat.extra_data);
@@ -2098,23 +2083,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
20982083
block = fresh_block;
20992084
}
21002085

2101-
for d in collected_data.iter() {
2102-
for deref_call in d.deref_temps.iter() {
2103-
// Re-establish `Deref::deref` temporaries because false edges trick borrowck into
2104-
// believing they may not be initialized.
2105-
let next_block = self.cfg.start_new_block();
2106-
self.call_deref(
2107-
block,
2108-
next_block,
2109-
deref_call.place,
2110-
deref_call.ty,
2111-
deref_call.temp,
2112-
deref_call.span,
2113-
);
2114-
block = next_block;
2115-
}
2116-
}
2117-
21182086
self.ascribe_types(block, collected_data.iter().flat_map(|d| &d.ascriptions).cloned());
21192087

21202088
// rust-lang/rust#27282: The `autoref` business deserves some

compiler/rustc_mir_build/src/build/matches/simplify.rs

+1-12
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//! sort of test: for example, testing which variant an enum is, or
1313
//! testing a value against a constant.
1414
15-
use crate::build::matches::{DerefTemporary, MatchPair, PatternExtraData, TestCase};
15+
use crate::build::matches::{MatchPair, PatternExtraData, TestCase};
1616
use crate::build::Builder;
1717

1818
use std::mem;
@@ -44,17 +44,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
4444
// after any bindings in `pat`. This doesn't work for or-patterns: the current structure of
4545
// match lowering forces us to lower bindings inside or-patterns last.
4646
for mut match_pair in mem::take(match_pairs) {
47-
if let TestCase::Deref { temp } = &match_pair.test_case {
48-
// Re-establish these temporaries after matching the candidate in case we have
49-
// bindings that depend on them.
50-
extra_data.deref_temps.push(DerefTemporary {
51-
place: match_pair.place.to_place(self),
52-
temp: *temp,
53-
ty: match_pair.pattern.ty,
54-
span: match_pair.pattern.span,
55-
});
56-
}
57-
5847
self.simplify_match_pairs(&mut match_pair.subpairs, extra_data);
5948
if let TestCase::Irrefutable { binding, ascription } = match_pair.test_case {
6049
if let Some(binding) = binding {

0 commit comments

Comments
 (0)