Skip to content

Commit 21e5195

Browse files
committed
(DO NOT MERGE) Don't build user-type projections unnecessarily
1 parent 5bc6231 commit 21e5195

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

compiler/rustc_mir_build/src/builder/block.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
199199
None,
200200
Some((Some(&destination), initializer_span)),
201201
);
202-
this.visit_primary_bindings(
202+
this.visit_primary_bindings_only(
203203
pattern,
204-
UserTypeProjections::none(),
205-
&mut |this, _, _, node, span, _, _| {
204+
|this, node, span| {
206205
this.storage_live_binding(
207206
block,
208207
node,
@@ -295,10 +294,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
295294
});
296295

297296
debug!("ast_block_stmts: pattern={:?}", pattern);
298-
this.visit_primary_bindings(
297+
this.visit_primary_bindings_only(
299298
pattern,
300-
UserTypeProjections::none(),
301-
&mut |this, _, _, node, span, _, _| {
299+
|this, node, span| {
302300
this.storage_live_binding(
303301
block,
304302
node,

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

+13-1
Original file line numberDiff line numberDiff line change
@@ -849,10 +849,22 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
849849
}
850850
}
851851

852+
pub(crate) fn visit_primary_bindings_only(
853+
&mut self,
854+
pattern: &Pat<'tcx>,
855+
mut f: impl FnMut(&mut Self, LocalVarId, Span),
856+
) {
857+
pattern.walk_always(|pat| {
858+
if let PatKind::Binding { var, is_primary: true, .. } = pat.kind {
859+
f(self, var, pat.span);
860+
}
861+
});
862+
}
863+
852864
/// Visit all of the primary bindings in a patterns, that is, visit the
853865
/// leftmost occurrence of each variable bound in a pattern. A variable
854866
/// will occur more than once in an or-pattern.
855-
pub(super) fn visit_primary_bindings(
867+
fn visit_primary_bindings(
856868
&mut self,
857869
pattern: &Pat<'tcx>,
858870
pattern_user_ty: UserTypeProjections,

0 commit comments

Comments
 (0)