Skip to content

Commit 46fc1d4

Browse files
committed
Stop eagerly creating AnonConst defs
Sometimes they end up lowering into a ConstArgKind::Path, which has no def associated with it. So we now create the defs only when we're sure the lowered AnonConst will be in the HIR.
1 parent d1fcc94 commit 46fc1d4

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2416,8 +2416,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24162416
}
24172417

24182418
fn lower_anon_const(&mut self, c: &AnonConst) -> &'hir hir::AnonConst {
2419+
// Some ast::AnonConst's turn into ConstArgKind::Path's, so we create their def
2420+
// only when we're sure they're going to stay as an AnonConst.
2421+
let def_id = self.create_def(
2422+
self.current_hir_id_owner.def_id,
2423+
c.id,
2424+
kw::Empty,
2425+
DefKind::AnonConst,
2426+
c.value.span,
2427+
);
24192428
self.arena.alloc(self.with_new_scopes(c.value.span, |this| hir::AnonConst {
2420-
def_id: this.local_def_id(c.id),
2429+
def_id,
24212430
hir_id: this.lower_node_id(c.id),
24222431
body: this.lower_const_body(c.value.span, Some(&c.value)),
24232432
span: this.lower_span(c.value.span),

compiler/rustc_resolve/src/def_collector.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,6 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
309309
}
310310
}
311311

312-
fn visit_anon_const(&mut self, constant: &'a AnonConst) {
313-
let def = self.create_def(constant.id, kw::Empty, DefKind::AnonConst, constant.value.span);
314-
self.with_parent(def, |this| visit::walk_anon_const(this, constant));
315-
}
316-
317312
fn visit_expr(&mut self, expr: &'a Expr) {
318313
let parent_def = match expr.kind {
319314
ExprKind::MacCall(..) => return self.visit_macro_invoc(expr.id),

0 commit comments

Comments
 (0)