Skip to content

Commit 9810f40

Browse files
committed
Avoid creating an unused HirId
1 parent afc3c1d commit 9810f40

File tree

1 file changed

+26
-23
lines changed
  • compiler/rustc_ast_lowering/src

1 file changed

+26
-23
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+26-23
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11771177
}
11781178

11791179
fn lower_anon_const_as_const_arg(&mut self, anon: &AnonConst) -> hir::ConstArg<'hir> {
1180-
if let ExprKind::Path(qself, path) = &anon.value.kind {
1180+
if let ExprKind::Path(qself, path) = &anon.value.kind
1181+
&& let Some(res) = self
1182+
.resolver
1183+
.get_partial_res(anon.id)
1184+
.and_then(|partial_res| partial_res.full_res())
1185+
// FIXME(min_generic_const_exprs): for now we only lower params to ConstArgKind::Path
1186+
&& let Res::Def(DefKind::ConstParam, _) = res
1187+
{
11811188
let qpath = self.lower_qpath(
11821189
anon.id,
11831190
qself,
@@ -1186,18 +1193,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11861193
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
11871194
None,
11881195
);
1189-
// FIXME(min_generic_const_exprs): for now we only lower params to ConstArgKind::Path
1190-
if let hir::QPath::Resolved(
1191-
_,
1192-
&hir::Path { res: Res::Def(DefKind::ConstParam, _), .. },
1193-
) = qpath
1194-
{
1195-
return ConstArg {
1196-
hir_id: self.lower_node_id(anon.id),
1197-
kind: ConstArgKind::Path(qpath),
1198-
is_desugared_from_effects: false,
1199-
};
1200-
}
1196+
return ConstArg {
1197+
hir_id: self.lower_node_id(anon.id),
1198+
kind: ConstArgKind::Path(qpath),
1199+
is_desugared_from_effects: false,
1200+
};
12011201
}
12021202

12031203
let lowered_anon = self.lower_anon_const(anon);
@@ -2602,12 +2602,11 @@ impl<'hir> GenericArgsCtor<'hir> {
26022602
return;
26032603
}
26042604

2605-
let id = lcx.next_node_id();
2606-
let hir_id = lcx.next_id();
2607-
2608-
let const_arg_kind = match constness {
2605+
let (hir_id, const_arg_kind) = match constness {
26092606
BoundConstness::Never => return,
26102607
BoundConstness::Always(span) => {
2608+
let id = lcx.next_node_id();
2609+
let hir_id = lcx.next_id();
26112610
let span = lcx.lower_span(span);
26122611

26132612
let body = hir::ExprKind::Lit(
@@ -2624,14 +2623,18 @@ impl<'hir> GenericArgsCtor<'hir> {
26242623
);
26252624

26262625
lcx.children.push((def_id, hir::MaybeOwner::NonOwner(hir_id)));
2627-
hir::ConstArgKind::Anon(lcx.arena.alloc(hir::AnonConst {
2628-
def_id,
2626+
(
26292627
hir_id,
2630-
body,
2631-
span,
2632-
}))
2628+
hir::ConstArgKind::Anon(lcx.arena.alloc(hir::AnonConst {
2629+
def_id,
2630+
hir_id,
2631+
body,
2632+
span,
2633+
})),
2634+
)
26332635
}
26342636
BoundConstness::Maybe(span) => {
2637+
let hir_id = lcx.next_id();
26352638
let span = lcx.lower_span(span);
26362639

26372640
let Some(host_param_id) = lcx.host_param_id else {
@@ -2655,7 +2658,7 @@ impl<'hir> GenericArgsCtor<'hir> {
26552658
)
26562659
],
26572660
});
2658-
hir::ConstArgKind::Path(hir::QPath::Resolved(None, path))
2661+
(hir_id, hir::ConstArgKind::Path(hir::QPath::Resolved(None, path)))
26592662
}
26602663
};
26612664

0 commit comments

Comments
 (0)