Skip to content

Commit 37d8664

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

File tree

2 files changed

+32
-28
lines changed

2 files changed

+32
-28
lines changed

compiler/rustc_mir_build/src/builder/block.rs

+19-27
Original file line numberDiff line numberDiff line change
@@ -199,19 +199,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
199199
None,
200200
Some((Some(&destination), initializer_span)),
201201
);
202-
this.visit_primary_bindings(
203-
pattern,
204-
UserTypeProjections::none(),
205-
&mut |this, _, _, node, span, _, _| {
206-
this.storage_live_binding(
207-
block,
208-
node,
209-
span,
210-
OutsideGuard,
211-
ScheduleDrops::Yes,
212-
);
213-
},
214-
);
202+
this.visit_primary_bindings_only(pattern, |this, node, span| {
203+
this.storage_live_binding(
204+
block,
205+
node,
206+
span,
207+
OutsideGuard,
208+
ScheduleDrops::Yes,
209+
);
210+
});
215211
let else_block_span = this.thir[*else_block].span;
216212
let (matching, failure) =
217213
this.in_if_then_scope(last_remainder_scope, else_block_span, |this| {
@@ -295,20 +291,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
295291
});
296292

297293
debug!("ast_block_stmts: pattern={:?}", pattern);
298-
this.visit_primary_bindings(
299-
pattern,
300-
UserTypeProjections::none(),
301-
&mut |this, _, _, node, span, _, _| {
302-
this.storage_live_binding(
303-
block,
304-
node,
305-
span,
306-
OutsideGuard,
307-
ScheduleDrops::Yes,
308-
);
309-
this.schedule_drop_for_binding(node, span, OutsideGuard);
310-
},
311-
)
294+
this.visit_primary_bindings_only(pattern, |this, node, span| {
295+
this.storage_live_binding(
296+
block,
297+
node,
298+
span,
299+
OutsideGuard,
300+
ScheduleDrops::Yes,
301+
);
302+
this.schedule_drop_for_binding(node, span, OutsideGuard);
303+
})
312304
}
313305

314306
// Enter the visibility scope, after evaluating the initializer.

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)