Skip to content

Commit eb5c4d6

Browse files
committed
Lower const item RHS to const path even on stable
1 parent 2e0a6e5 commit eb5c4d6

File tree

2 files changed

+4
-29
lines changed

2 files changed

+4
-29
lines changed

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
199199
|this| {
200200
let ty = this
201201
.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::ConstTy));
202-
let body = this.lower_const_item(body.as_deref().unwrap());
202+
let body = this.lower_anon_const_to_const_arg(body.as_deref().unwrap());
203203
(ty, body)
204204
},
205205
);
@@ -484,16 +484,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
484484
}
485485
}
486486

487-
fn lower_const_item(&mut self, body: &AnonConst) -> &'hir hir::ConstArg<'hir> {
488-
let mgca = self.tcx.features().min_generic_const_args();
489-
if mgca && let Some(ct_arg) = self.try_lower_as_const_path(body) {
490-
return ct_arg;
491-
}
492-
let anon = self.lower_anon_const_to_anon_const(body);
493-
self.arena
494-
.alloc(hir::ConstArg { hir_id: self.next_id(), kind: hir::ConstArgKind::Anon(anon) })
495-
}
496-
497487
#[instrument(level = "debug", skip(self))]
498488
fn lower_use_tree(
499489
&mut self,
@@ -800,7 +790,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
800790
|this| {
801791
let ty = this
802792
.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::ConstTy));
803-
let body = body.as_deref().map(|body| this.lower_const_item(body));
793+
let body =
794+
body.as_deref().map(|body| this.lower_anon_const_to_const_arg(body));
804795
hir::TraitItemKind::Const(ty, body)
805796
},
806797
);
@@ -993,7 +984,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
993984
let ty = this
994985
.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::ConstTy));
995986
this.lower_define_opaque(hir_id, &define_opaque);
996-
let body = this.lower_const_item(body.as_deref().unwrap());
987+
let body = this.lower_anon_const_to_const_arg(body.as_deref().unwrap());
997988
hir::ImplItemKind::Const(ty, body)
998989
},
999990
),

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2084,22 +2084,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20842084
}
20852085
}
20862086

2087-
/// Assumes mgca feature is enabled.
2088-
fn try_lower_as_const_path(&mut self, body: &AnonConst) -> Option<&'hir hir::ConstArg<'hir>> {
2089-
let ExprKind::Path(qself, path) = &body.value.kind else { return None };
2090-
let qpath = self.lower_qpath(
2091-
body.value.id,
2092-
qself,
2093-
path,
2094-
ParamMode::Optional,
2095-
AllowReturnTypeNotation::No,
2096-
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
2097-
None,
2098-
);
2099-
let ct_kind = hir::ConstArgKind::Path(qpath);
2100-
Some(self.arena.alloc(hir::ConstArg { hir_id: self.next_id(), kind: ct_kind }))
2101-
}
2102-
21032087
/// Used when lowering a type argument that turned out to actually be a const argument.
21042088
///
21052089
/// Only use for that purpose since otherwise it will create a duplicate def.

0 commit comments

Comments
 (0)