Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions compiler/rustc_mir_build/src/builder/expr/as_constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,8 @@ pub(crate) fn as_constant_inner<'tcx>(
// FIXME(generic_const_args): there's a lot to consider here! `Const::Ty` uses valtrees
// and `Const::Unevaluated` does not, we should revisit this before stabilization.
let def_kind = tcx.def_kind(def_id);
if tcx.features().generic_const_args()
|| matches!(def_kind, DefKind::Const | DefKind::AssocConst)
&& tcx.is_direct_const(def_id)
if matches!(def_kind, DefKind::Const | DefKind::AssocConst)

@BoxyUwU BoxyUwU Sep 18, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha when I was reviewing that PR I thought about how I hate precedence on these things and can never tell where the parens go 😆

View changes since the review

&& (tcx.features().generic_const_args() || tcx.is_direct_const(def_id))
{
let kind = match def_kind {
DefKind::AssocConst => {
Expand All @@ -94,7 +93,7 @@ pub(crate) fn as_constant_inner<'tcx>(
}
}
DefKind::Const => ty::AliasConstKind::Free { def_id },
_ => unreachable!(),
kind => bug!("unexpected DefKind in THIR ExprKind::NamedConst: {kind:?}"),
};
let alias = ty::AliasConst::new(tcx, kind, args);
let ct = ty::Const::new_alias(tcx, ty::IsRigid::No, alias);
Expand Down
10 changes: 10 additions & 0 deletions tests/ui/const-generics/gca/const-reference-to-constructor.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//@ check-pass
//@ compile-flags: -Znext-solver
//! https://github.com/rust-lang/rust/issues/162923
#![feature(min_generic_const_args)]
#![feature(generic_const_args)]
enum T<const N: u8 = { T::<0>::B as u8 }> {
A = 2,
B,
}
fn main() {}
Loading