From 0e2c554e74754ddb51363d2f216d1367ff64e4f4 Mon Sep 17 00:00:00 2001 From: khyperia <953151+khyperia@users.noreply.github.com> Date: Tue, 31 Mar 2026 11:12:32 +0200 Subject: [PATCH 1/2] rename opaque_generic_const_args to generic_const_args --- compiler/rustc_feature/src/unstable.rs | 6 +++--- compiler/rustc_hir_analysis/src/collect.rs | 12 ++++++------ .../rustc_hir_analysis/src/collect/generics_of.rs | 4 ++-- .../rustc_hir_analysis/src/hir_ty_lowering/mod.rs | 6 +++--- .../src/solve/normalizes_to/anon_const.rs | 6 +++--- compiler/rustc_resolve/src/diagnostics.rs | 6 +++--- compiler/rustc_resolve/src/errors.rs | 6 +++--- compiler/rustc_resolve/src/ident.rs | 10 ++-------- compiler/rustc_resolve/src/late/diagnostics.rs | 4 ++-- compiler/rustc_resolve/src/lib.rs | 2 +- compiler/rustc_span/src/symbol.rs | 2 +- compiler/rustc_trait_selection/src/traits/mod.rs | 4 ++-- compiler/rustc_type_ir/src/const_kind.rs | 4 ++-- .../ui/const-generics/{ogca => gca}/basic-fail.rs | 2 +- .../const-generics/{ogca => gca}/basic-fail.stderr | 0 tests/ui/const-generics/{ogca => gca}/basic.rs | 2 +- .../{ogca => gca}/coherence-ambiguous.rs | 2 +- .../{ogca => gca}/coherence-ambiguous.stderr | 0 .../{ogca => gca}/generic-param-rhs.rs | 2 +- .../{ogca => gca}/generic-param-rhs.stderr | 0 .../{ogca => gca}/rhs-but-not-root.rs | 4 ++-- .../{ogca => gca}/rhs-but-not-root.stderr | 0 .../const-generics/mgca/adt_expr_arg_simple.stderr | 2 +- .../mgca/early-bound-param-lt-bad.stderr | 2 +- .../mgca/explicit_anon_consts.stderr | 14 +++++++------- .../mgca/selftyalias-containing-param.stderr | 2 +- tests/ui/const-generics/mgca/selftyparam.stderr | 2 +- .../mgca/size-of-generic-ptr-in-array-len.stderr | 2 +- .../mgca/tuple_ctor_complex_args.stderr | 2 +- .../mgca/tuple_expr_arg_complex.stderr | 2 +- .../mgca/type_const-on-generic-expr.stderr | 4 ++-- .../mgca/type_const-on-generic_expr-2.stderr | 6 +++--- ...-args.rs => feature-gate-generic-const-args.rs} | 2 +- ...derr => feature-gate-generic-const-args.stderr} | 4 ++-- 34 files changed, 61 insertions(+), 67 deletions(-) rename tests/ui/const-generics/{ogca => gca}/basic-fail.rs (91%) rename tests/ui/const-generics/{ogca => gca}/basic-fail.stderr (100%) rename tests/ui/const-generics/{ogca => gca}/basic.rs (90%) rename tests/ui/const-generics/{ogca => gca}/coherence-ambiguous.rs (84%) rename tests/ui/const-generics/{ogca => gca}/coherence-ambiguous.stderr (100%) rename tests/ui/const-generics/{ogca => gca}/generic-param-rhs.rs (79%) rename tests/ui/const-generics/{ogca => gca}/generic-param-rhs.stderr (100%) rename tests/ui/const-generics/{ogca => gca}/rhs-but-not-root.rs (77%) rename tests/ui/const-generics/{ogca => gca}/rhs-but-not-root.stderr (100%) rename tests/ui/feature-gates/{feature-gate-opaque-generic-const-args.rs => feature-gate-generic-const-args.rs} (80%) rename tests/ui/feature-gates/{feature-gate-opaque-generic-const-args.stderr => feature-gate-generic-const-args.stderr} (57%) diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index 224b7273314b..a9ad07be319c 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -520,6 +520,8 @@ pub fn internal(&self, feature: Symbol) -> bool { (unstable, frontmatter, "1.88.0", Some(136889)), /// Allows defining gen blocks and `gen fn`. (unstable, gen_blocks, "1.75.0", Some(117078)), + /// Allows using generics in more complex const expressions, based on definitional equality. + (unstable, generic_const_args, "1.95.0", Some(151972)), /// Allows non-trivial generic constants which have to have wfness manually propagated to callers (incomplete, generic_const_exprs, "1.56.0", Some(76560)), /// Allows generic parameters and where-clauses on free & associated const items. @@ -623,8 +625,6 @@ pub fn internal(&self, feature: Symbol) -> bool { (unstable, offset_of_enum, "1.75.0", Some(120141)), /// Allows using fields with slice type in offset_of! (unstable, offset_of_slice, "1.81.0", Some(126151)), - /// Allows using generics in more complex const expressions, based on definitional equality. - (unstable, opaque_generic_const_args, "1.95.0", Some(151972)), /// Allows using `#[optimize(X)]`. (unstable, optimize_attribute, "1.34.0", Some(54882)), /// Allows specifying nop padding on functions for dynamic patching. @@ -806,6 +806,6 @@ struct FeatureUsage { /// Some features require one or more other features to be enabled. pub const DEPENDENT_FEATURES: &[(Symbol, &[Symbol])] = &[ - (sym::opaque_generic_const_args, &[sym::min_generic_const_args]), + (sym::generic_const_args, &[sym::min_generic_const_args]), (sym::unsized_const_params, &[sym::adt_const_params]), ]; diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index 80ef2001cc72..cfda0300f3f0 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -1598,8 +1598,8 @@ fn anon_const_kind<'tcx>(tcx: TyCtxt<'tcx>, def: LocalDefId) -> ty::AnonConstKin let parent_hir_node = tcx.hir_node(tcx.parent_hir_id(const_arg_id)); if tcx.features().generic_const_exprs() { ty::AnonConstKind::GCE - } else if tcx.features().opaque_generic_const_args() { - // Only anon consts that are the RHS of a const item can be OGCA. + } else if tcx.features().generic_const_args() { + // Only anon consts that are the RHS of a const item can be GCA. // Note: We can't just check tcx.parent because it needs to be EXACTLY // the RHS, not just part of the RHS. if !is_anon_const_rhs_of_const_item(tcx, def) { @@ -1607,9 +1607,9 @@ fn anon_const_kind<'tcx>(tcx: TyCtxt<'tcx>, def: LocalDefId) -> ty::AnonConstKin } let body = tcx.hir_body_owned_by(def); - let mut visitor = OGCAParamVisitor(tcx); + let mut visitor = GCAParamVisitor(tcx); match visitor.visit_body(body) { - ControlFlow::Break(UsesParam) => ty::AnonConstKind::OGCA, + ControlFlow::Break(UsesParam) => ty::AnonConstKind::GCA, ControlFlow::Continue(()) => ty::AnonConstKind::MCG, } } else if tcx.features().min_generic_const_args() { @@ -1650,11 +1650,11 @@ fn is_anon_const_rhs_of_const_item<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) def_id == rhs_anon.def_id } -struct OGCAParamVisitor<'tcx>(TyCtxt<'tcx>); +struct GCAParamVisitor<'tcx>(TyCtxt<'tcx>); struct UsesParam; -impl<'tcx> Visitor<'tcx> for OGCAParamVisitor<'tcx> { +impl<'tcx> Visitor<'tcx> for GCAParamVisitor<'tcx> { type NestedFilter = nested_filter::OnlyBodies; type Result = ControlFlow; diff --git a/compiler/rustc_hir_analysis/src/collect/generics_of.rs b/compiler/rustc_hir_analysis/src/collect/generics_of.rs index ea98beb95580..3647c91fb7f1 100644 --- a/compiler/rustc_hir_analysis/src/collect/generics_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/generics_of.rs @@ -97,8 +97,8 @@ fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> { match tcx.anon_const_kind(def_id) { // Stable: anon consts are not able to use any generic parameters... ty::AnonConstKind::MCG => None, - // OGCA anon consts inherit their parent's generics. - ty::AnonConstKind::OGCA => Some(parent_did), + // GCA anon consts inherit their parent's generics. + ty::AnonConstKind::GCA => Some(parent_did), // we provide generics to repeat expr counts as a backwards compatibility hack. #76200 ty::AnonConstKind::RepeatExprCount => Some(parent_did), diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs index 91660fc65537..9ec5632a7498 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs @@ -387,7 +387,7 @@ impl<'tcx> ForbidMCGParamUsesFolder<'tcx> { fn error(&self) -> ErrorGuaranteed { let msg = if self.is_self_alias { "generic `Self` types are currently not permitted in anonymous constants" - } else if self.tcx.features().opaque_generic_const_args() { + } else if self.tcx.features().generic_const_args() { "generic parameters in const blocks are only allowed as the direct value of a `type const`" } else { "generic parameters may not be used in const operations" @@ -408,8 +408,8 @@ fn error(&self) -> ErrorGuaranteed { } } if self.tcx.features().min_generic_const_args() { - if !self.tcx.features().opaque_generic_const_args() { - diag.help("add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items"); + if !self.tcx.features().generic_const_args() { + diag.help("add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items"); } else { diag.help("consider factoring the expression into a `type const` item and use it as the const argument instead"); } diff --git a/compiler/rustc_next_trait_solver/src/solve/normalizes_to/anon_const.rs b/compiler/rustc_next_trait_solver/src/solve/normalizes_to/anon_const.rs index eb6a1b51421c..894910dfb6c1 100644 --- a/compiler/rustc_next_trait_solver/src/solve/normalizes_to/anon_const.rs +++ b/compiler/rustc_next_trait_solver/src/solve/normalizes_to/anon_const.rs @@ -15,11 +15,11 @@ pub(super) fn normalize_anon_const( goal: Goal>, ) -> QueryResult { if self.typing_mode() == TypingMode::Coherence - && self.cx().anon_const_kind(goal.predicate.alias.def_id) == ty::AnonConstKind::OGCA + && self.cx().anon_const_kind(goal.predicate.alias.def_id) == ty::AnonConstKind::GCA { - // During coherence, OGCA consts should be normalized ambiguously + // During coherence, GCA consts should be normalized ambiguously // because they are opaque but eventually resolved to a real value. - // We don't want two OGCAs that have the same value to be treated + // We don't want two GCAs that have the same value to be treated // as distinct for coherence purposes. (Just like opaque types.) // // We can't rely on evaluate_const below because that particular wrapper diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 97c88064e979..cab37f5c0faa 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -1011,14 +1011,14 @@ pub(crate) fn into_struct_error( ResolutionError::ParamInTyOfConstParam { name } => { self.dcx().create_err(errs::ParamInTyOfConstParam { span, name }) } - ResolutionError::ParamInNonTrivialAnonConst { is_ogca, name, param_kind: is_type } => { + ResolutionError::ParamInNonTrivialAnonConst { is_gca, name, param_kind: is_type } => { self.dcx().create_err(errs::ParamInNonTrivialAnonConst { span, name, param_kind: is_type, help: self.tcx.sess.is_nightly_build(), - is_ogca, - help_ogca: is_ogca, + is_gca, + help_gca: is_gca, }) } ResolutionError::ParamInEnumDiscriminant { name, param_kind: is_type } => self diff --git a/compiler/rustc_resolve/src/errors.rs b/compiler/rustc_resolve/src/errors.rs index c9dad4dcd4a7..ea2eeb64acc4 100644 --- a/compiler/rustc_resolve/src/errors.rs +++ b/compiler/rustc_resolve/src/errors.rs @@ -407,7 +407,7 @@ pub(crate) struct SelfInConstGenericTy { #[derive(Diagnostic)] #[diag( - "{$is_ogca -> + "{$is_gca -> [true] generic parameters in const blocks are only allowed as the direct value of a `type const` *[false] generic parameters may not be used in const operations }" @@ -421,11 +421,11 @@ pub(crate) struct ParamInNonTrivialAnonConst { pub(crate) param_kind: ParamKindInNonTrivialAnonConst, #[help("add `#![feature(generic_const_exprs)]` to allow generic const expressions")] pub(crate) help: bool, - pub(crate) is_ogca: bool, + pub(crate) is_gca: bool, #[help( "consider factoring the expression into a `type const` item and use it as the const argument instead" )] - pub(crate) help_ogca: bool, + pub(crate) help_gca: bool, } #[derive(Debug)] diff --git a/compiler/rustc_resolve/src/ident.rs b/compiler/rustc_resolve/src/ident.rs index 069018139145..b7561d58401a 100644 --- a/compiler/rustc_resolve/src/ident.rs +++ b/compiler/rustc_resolve/src/ident.rs @@ -1568,10 +1568,7 @@ fn validate_res_from_ribs( } NoConstantGenericsReason::NonTrivialConstArg => { ResolutionError::ParamInNonTrivialAnonConst { - is_ogca: self - .tcx - .features() - .opaque_generic_const_args(), + is_gca: self.tcx.features().generic_const_args(), name: rib_ident.name, param_kind: ParamKindInNonTrivialAnonConst::Type, } @@ -1663,10 +1660,7 @@ fn validate_res_from_ribs( } NoConstantGenericsReason::NonTrivialConstArg => { ResolutionError::ParamInNonTrivialAnonConst { - is_ogca: self - .tcx - .features() - .opaque_generic_const_args(), + is_gca: self.tcx.features().generic_const_args(), name: rib_ident.name, param_kind: ParamKindInNonTrivialAnonConst::Const { name: rib_ident.name, diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index cf048231bd60..7539e3c4f499 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -3921,8 +3921,8 @@ pub(crate) fn emit_forbidden_non_static_lifetime_error( name: lifetime_ref.ident.name, param_kind: errors::ParamKindInNonTrivialAnonConst::Lifetime, help: self.r.tcx.sess.is_nightly_build(), - is_ogca: self.r.tcx.features().opaque_generic_const_args(), - help_ogca: self.r.tcx.features().opaque_generic_const_args(), + is_gca: self.r.tcx.features().generic_const_args(), + help_gca: self.r.tcx.features().generic_const_args(), }) .emit() } diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 72d5cdcf1f3b..d75f2981a772 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -308,7 +308,7 @@ enum ResolutionError<'ra> { /// /// This error is only emitted when using `min_const_generics`. ParamInNonTrivialAnonConst { - is_ogca: bool, + is_gca: bool, name: Symbol, param_kind: ParamKindInNonTrivialAnonConst, }, diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 30bf8dd7c220..53e2527057bc 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1014,6 +1014,7 @@ generic_assert, generic_associated_types, generic_associated_types_extended, + generic_const_args, generic_const_exprs, generic_const_items, generic_const_parameter_types, @@ -1414,7 +1415,6 @@ on_move, on_unimplemented, opaque, - opaque_generic_const_args, opaque_module_name_placeholder: "", ops, opt_out_copy, diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index bdad1b259b73..41b7b5b925cf 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -676,9 +676,9 @@ pub fn try_evaluate_const<'tcx>( (args, typing_env) } - Some(ty::AnonConstKind::OGCA) => { + Some(ty::AnonConstKind::GCA) => { if infcx.typing_mode() != TypingMode::PostAnalysis { - // OGCA anon consts should be treated as always having generics + // GCA anon consts should be treated as always having generics // during anything before codegen (or maybe MIR opts too). return Err(EvaluateConstErr::HasGenericsOrInfers); } diff --git a/compiler/rustc_type_ir/src/const_kind.rs b/compiler/rustc_type_ir/src/const_kind.rs index 9786608ab4bc..2877364762f4 100644 --- a/compiler/rustc_type_ir/src/const_kind.rs +++ b/compiler/rustc_type_ir/src/const_kind.rs @@ -210,9 +210,9 @@ pub enum AnonConstKind { GCE, /// stable `min_const_generics` anon consts are not allowed to use any generic parameters MCG, - /// `feature(opaque_generic_const_args)` anon consts are allowed to use arbitrary + /// `feature(generic_const_args)` anon consts are allowed to use arbitrary /// generic parameters in scope, but only if they syntactically reference them. - OGCA, + GCA, /// anon consts used as the length of a repeat expr are syntactically allowed to use generic parameters /// but must not depend on the actual instantiation. See #76200 for more information RepeatExprCount, diff --git a/tests/ui/const-generics/ogca/basic-fail.rs b/tests/ui/const-generics/gca/basic-fail.rs similarity index 91% rename from tests/ui/const-generics/ogca/basic-fail.rs rename to tests/ui/const-generics/gca/basic-fail.rs index e3db3dea3735..4b638279988d 100644 --- a/tests/ui/const-generics/ogca/basic-fail.rs +++ b/tests/ui/const-generics/gca/basic-fail.rs @@ -1,6 +1,6 @@ #![feature(generic_const_items)] #![feature(min_generic_const_args)] -#![feature(opaque_generic_const_args)] +#![feature(generic_const_args)] #![expect(incomplete_features)] type const ADD1: usize = const { N + 1 }; diff --git a/tests/ui/const-generics/ogca/basic-fail.stderr b/tests/ui/const-generics/gca/basic-fail.stderr similarity index 100% rename from tests/ui/const-generics/ogca/basic-fail.stderr rename to tests/ui/const-generics/gca/basic-fail.stderr diff --git a/tests/ui/const-generics/ogca/basic.rs b/tests/ui/const-generics/gca/basic.rs similarity index 90% rename from tests/ui/const-generics/ogca/basic.rs rename to tests/ui/const-generics/gca/basic.rs index e736484b5c3c..e80540d621de 100644 --- a/tests/ui/const-generics/ogca/basic.rs +++ b/tests/ui/const-generics/gca/basic.rs @@ -2,7 +2,7 @@ #![feature(generic_const_items)] #![feature(min_generic_const_args)] -#![feature(opaque_generic_const_args)] +#![feature(generic_const_args)] #![expect(incomplete_features)] type const ADD1: usize = const { N + 1 }; diff --git a/tests/ui/const-generics/ogca/coherence-ambiguous.rs b/tests/ui/const-generics/gca/coherence-ambiguous.rs similarity index 84% rename from tests/ui/const-generics/ogca/coherence-ambiguous.rs rename to tests/ui/const-generics/gca/coherence-ambiguous.rs index bb20c0457c03..7c8b2b33548c 100644 --- a/tests/ui/const-generics/ogca/coherence-ambiguous.rs +++ b/tests/ui/const-generics/gca/coherence-ambiguous.rs @@ -1,6 +1,6 @@ //@ check-fail -#![feature(generic_const_items, min_generic_const_args, opaque_generic_const_args)] +#![feature(generic_const_items, min_generic_const_args, generic_const_args)] #![expect(incomplete_features)] type const FOO: usize = const { N + 1 }; diff --git a/tests/ui/const-generics/ogca/coherence-ambiguous.stderr b/tests/ui/const-generics/gca/coherence-ambiguous.stderr similarity index 100% rename from tests/ui/const-generics/ogca/coherence-ambiguous.stderr rename to tests/ui/const-generics/gca/coherence-ambiguous.stderr diff --git a/tests/ui/const-generics/ogca/generic-param-rhs.rs b/tests/ui/const-generics/gca/generic-param-rhs.rs similarity index 79% rename from tests/ui/const-generics/ogca/generic-param-rhs.rs rename to tests/ui/const-generics/gca/generic-param-rhs.rs index a62b509190bd..ed4467d6f003 100644 --- a/tests/ui/const-generics/ogca/generic-param-rhs.rs +++ b/tests/ui/const-generics/gca/generic-param-rhs.rs @@ -1,4 +1,4 @@ -#![feature(min_generic_const_args, opaque_generic_const_args)] +#![feature(min_generic_const_args, generic_const_args)] #![expect(incomplete_features)] fn foo() {} diff --git a/tests/ui/const-generics/ogca/generic-param-rhs.stderr b/tests/ui/const-generics/gca/generic-param-rhs.stderr similarity index 100% rename from tests/ui/const-generics/ogca/generic-param-rhs.stderr rename to tests/ui/const-generics/gca/generic-param-rhs.stderr diff --git a/tests/ui/const-generics/ogca/rhs-but-not-root.rs b/tests/ui/const-generics/gca/rhs-but-not-root.rs similarity index 77% rename from tests/ui/const-generics/ogca/rhs-but-not-root.rs rename to tests/ui/const-generics/gca/rhs-but-not-root.rs index bb6c6b667e1d..6c0337dbbd47 100644 --- a/tests/ui/const-generics/ogca/rhs-but-not-root.rs +++ b/tests/ui/const-generics/gca/rhs-but-not-root.rs @@ -1,9 +1,9 @@ #![feature(generic_const_items)] #![feature(min_generic_const_args)] -#![feature(opaque_generic_const_args)] +#![feature(generic_const_args)] #![expect(incomplete_features)] -// Anon consts must be the root of the RHS to be OGCA. +// Anon consts must be the root of the RHS to be GCA. type const FOO: usize = ID::; //~^ ERROR generic parameters in const blocks are only allowed as the direct value of a `type const` type const ID: usize = N; diff --git a/tests/ui/const-generics/ogca/rhs-but-not-root.stderr b/tests/ui/const-generics/gca/rhs-but-not-root.stderr similarity index 100% rename from tests/ui/const-generics/ogca/rhs-but-not-root.stderr rename to tests/ui/const-generics/gca/rhs-but-not-root.stderr diff --git a/tests/ui/const-generics/mgca/adt_expr_arg_simple.stderr b/tests/ui/const-generics/mgca/adt_expr_arg_simple.stderr index f1d5e5c67475..0060c94875b5 100644 --- a/tests/ui/const-generics/mgca/adt_expr_arg_simple.stderr +++ b/tests/ui/const-generics/mgca/adt_expr_arg_simple.stderr @@ -10,7 +10,7 @@ error: generic parameters may not be used in const operations LL | foo::<{ Some:: { 0: const { N + 1 } } }>(); | ^ | - = help: add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items + = help: add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/mgca/early-bound-param-lt-bad.stderr b/tests/ui/const-generics/mgca/early-bound-param-lt-bad.stderr index e0804158952d..b25199bca2e2 100644 --- a/tests/ui/const-generics/mgca/early-bound-param-lt-bad.stderr +++ b/tests/ui/const-generics/mgca/early-bound-param-lt-bad.stderr @@ -4,7 +4,7 @@ error: generic parameters may not be used in const operations LL | T: Trait | ^^ | - = help: add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items + = help: add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/mgca/explicit_anon_consts.stderr b/tests/ui/const-generics/mgca/explicit_anon_consts.stderr index 1c72afce52c7..f634ec1cf12e 100644 --- a/tests/ui/const-generics/mgca/explicit_anon_consts.stderr +++ b/tests/ui/const-generics/mgca/explicit_anon_consts.stderr @@ -40,7 +40,7 @@ error: generic parameters may not be used in const operations LL | type const ITEM3: usize = const { N }; | ^ | - = help: add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items + = help: add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items error: generic parameters may not be used in const operations --> $DIR/explicit_anon_consts.rs:60:31 @@ -48,7 +48,7 @@ error: generic parameters may not be used in const operations LL | T3: Trait, | ^ | - = help: add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items + = help: add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items error: generic parameters may not be used in const operations --> $DIR/explicit_anon_consts.rs:69:58 @@ -56,7 +56,7 @@ error: generic parameters may not be used in const operations LL | struct Default3; | ^ | - = help: add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items + = help: add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items error: generic parameters may not be used in const operations --> $DIR/explicit_anon_consts.rs:28:27 @@ -64,7 +64,7 @@ error: generic parameters may not be used in const operations LL | let _3 = [(); const { N }]; | ^ | - = help: add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items + = help: add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items error: generic parameters may not be used in const operations --> $DIR/explicit_anon_consts.rs:33:26 @@ -72,7 +72,7 @@ error: generic parameters may not be used in const operations LL | let _6: [(); const { N }] = todo!(); | ^ | - = help: add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items + = help: add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items error: generic parameters may not be used in const operations --> $DIR/explicit_anon_consts.rs:11:41 @@ -80,7 +80,7 @@ error: generic parameters may not be used in const operations LL | type Adt3 = Foo; | ^ | - = help: add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items + = help: add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items error: generic parameters may not be used in const operations --> $DIR/explicit_anon_consts.rs:19:42 @@ -88,7 +88,7 @@ error: generic parameters may not be used in const operations LL | type Arr3 = [(); const { N }]; | ^ | - = help: add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items + = help: add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items error: aborting due to 13 previous errors diff --git a/tests/ui/const-generics/mgca/selftyalias-containing-param.stderr b/tests/ui/const-generics/mgca/selftyalias-containing-param.stderr index 1c841e39e673..cf5974fd83df 100644 --- a/tests/ui/const-generics/mgca/selftyalias-containing-param.stderr +++ b/tests/ui/const-generics/mgca/selftyalias-containing-param.stderr @@ -9,7 +9,7 @@ note: not a concrete type | LL | impl S { | ^^^^ - = help: add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items + = help: add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/mgca/selftyparam.stderr b/tests/ui/const-generics/mgca/selftyparam.stderr index c3e0770fb978..74d8f083ee09 100644 --- a/tests/ui/const-generics/mgca/selftyparam.stderr +++ b/tests/ui/const-generics/mgca/selftyparam.stderr @@ -4,7 +4,7 @@ error: generic parameters may not be used in const operations LL | fn foo() -> [(); const { let _: Self; 1 }]; | ^^^^ | - = help: add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items + = help: add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/mgca/size-of-generic-ptr-in-array-len.stderr b/tests/ui/const-generics/mgca/size-of-generic-ptr-in-array-len.stderr index 61e934380c36..694d4c8ebabd 100644 --- a/tests/ui/const-generics/mgca/size-of-generic-ptr-in-array-len.stderr +++ b/tests/ui/const-generics/mgca/size-of-generic-ptr-in-array-len.stderr @@ -10,7 +10,7 @@ error: generic parameters may not be used in const operations LL | [0; const { size_of::<*mut T>() }]; | ^ | - = help: add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items + = help: add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/mgca/tuple_ctor_complex_args.stderr b/tests/ui/const-generics/mgca/tuple_ctor_complex_args.stderr index 2961c714d141..3a873ec33fb1 100644 --- a/tests/ui/const-generics/mgca/tuple_ctor_complex_args.stderr +++ b/tests/ui/const-generics/mgca/tuple_ctor_complex_args.stderr @@ -10,7 +10,7 @@ error: generic parameters may not be used in const operations LL | with_point::<{ Point(const { N + 1 }, N) }>(); | ^ | - = help: add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items + = help: add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/mgca/tuple_expr_arg_complex.stderr b/tests/ui/const-generics/mgca/tuple_expr_arg_complex.stderr index 95a98d857b1d..a9d412964da2 100644 --- a/tests/ui/const-generics/mgca/tuple_expr_arg_complex.stderr +++ b/tests/ui/const-generics/mgca/tuple_expr_arg_complex.stderr @@ -22,7 +22,7 @@ error: generic parameters may not be used in const operations LL | takes_nested_tuple::<{ (N, (N, const { N + 1 })) }>(); | ^ | - = help: add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items + = help: add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items error: aborting due to 4 previous errors diff --git a/tests/ui/const-generics/mgca/type_const-on-generic-expr.stderr b/tests/ui/const-generics/mgca/type_const-on-generic-expr.stderr index 475d2cf312d6..0c88fbfb8578 100644 --- a/tests/ui/const-generics/mgca/type_const-on-generic-expr.stderr +++ b/tests/ui/const-generics/mgca/type_const-on-generic-expr.stderr @@ -4,7 +4,7 @@ error: generic parameters may not be used in const operations LL | type const FREE1: usize = const { std::mem::size_of::() }; | ^ | - = help: add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items + = help: add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items error: generic parameters may not be used in const operations --> $DIR/type_const-on-generic-expr.rs:8:51 @@ -12,7 +12,7 @@ error: generic parameters may not be used in const operations LL | type const FREE2: usize = const { I + 1 }; | ^ | - = help: add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items + = help: add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/mgca/type_const-on-generic_expr-2.stderr b/tests/ui/const-generics/mgca/type_const-on-generic_expr-2.stderr index e13d6fbcdd82..78e38d800524 100644 --- a/tests/ui/const-generics/mgca/type_const-on-generic_expr-2.stderr +++ b/tests/ui/const-generics/mgca/type_const-on-generic_expr-2.stderr @@ -4,7 +4,7 @@ error: generic parameters may not be used in const operations LL | type const N1: usize = const { std::mem::size_of::() }; | ^ | - = help: add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items + = help: add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items error: generic parameters may not be used in const operations --> $DIR/type_const-on-generic_expr-2.rs:15:52 @@ -12,7 +12,7 @@ error: generic parameters may not be used in const operations LL | type const N2: usize = const { I + 1 }; | ^ | - = help: add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items + = help: add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items error: generic parameters may not be used in const operations --> $DIR/type_const-on-generic_expr-2.rs:17:40 @@ -20,7 +20,7 @@ error: generic parameters may not be used in const operations LL | type const N3: usize = const { 2 & X }; | ^ | - = help: add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items + = help: add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items error: aborting due to 3 previous errors diff --git a/tests/ui/feature-gates/feature-gate-opaque-generic-const-args.rs b/tests/ui/feature-gates/feature-gate-generic-const-args.rs similarity index 80% rename from tests/ui/feature-gates/feature-gate-opaque-generic-const-args.rs rename to tests/ui/feature-gates/feature-gate-generic-const-args.rs index f18f59cf60bd..b62e7fb08099 100644 --- a/tests/ui/feature-gates/feature-gate-opaque-generic-const-args.rs +++ b/tests/ui/feature-gates/feature-gate-generic-const-args.rs @@ -3,6 +3,6 @@ type const INC: usize = const { N + 1 }; //~^ ERROR generic parameters may not be used in const operations -//~| HELP add `#![feature(opaque_generic_const_args)]` +//~| HELP add `#![feature(generic_const_args)]` fn main() {} diff --git a/tests/ui/feature-gates/feature-gate-opaque-generic-const-args.stderr b/tests/ui/feature-gates/feature-gate-generic-const-args.stderr similarity index 57% rename from tests/ui/feature-gates/feature-gate-opaque-generic-const-args.stderr rename to tests/ui/feature-gates/feature-gate-generic-const-args.stderr index ef771e77f692..27794b43966c 100644 --- a/tests/ui/feature-gates/feature-gate-opaque-generic-const-args.stderr +++ b/tests/ui/feature-gates/feature-gate-generic-const-args.stderr @@ -1,10 +1,10 @@ error: generic parameters may not be used in const operations - --> $DIR/feature-gate-opaque-generic-const-args.rs:4:49 + --> $DIR/feature-gate-generic-const-args.rs:4:49 | LL | type const INC: usize = const { N + 1 }; | ^ | - = help: add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items + = help: add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items error: aborting due to 1 previous error From 9465366ec44cc3cbfab1a39433b8d0c8e70c9a85 Mon Sep 17 00:00:00 2001 From: khyperia <953151+khyperia@users.noreply.github.com> Date: Thu, 2 Apr 2026 12:06:25 +0200 Subject: [PATCH 2/2] remove the o from oGCA --- .../src/solve/normalizes_to/anon_const.rs | 15 ++-------- .../rustc_trait_selection/src/traits/mod.rs | 19 +++---------- ...fail.rs => basic-different-definitions.rs} | 4 +-- tests/ui/const-generics/gca/basic-fail.stderr | 11 -------- .../const-generics/gca/coherence-ambiguous.rs | 18 ------------ .../gca/coherence-ambiguous.stderr | 20 ------------- tests/ui/const-generics/gca/coherence-fail.rs | 28 +++++++++++++++++++ .../const-generics/gca/coherence-fail.stderr | 27 ++++++++++++++++++ tests/ui/const-generics/gca/coherence-ok.rs | 14 ++++++++++ 9 files changed, 77 insertions(+), 79 deletions(-) rename tests/ui/const-generics/gca/{basic-fail.rs => basic-different-definitions.rs} (87%) delete mode 100644 tests/ui/const-generics/gca/basic-fail.stderr delete mode 100644 tests/ui/const-generics/gca/coherence-ambiguous.rs delete mode 100644 tests/ui/const-generics/gca/coherence-ambiguous.stderr create mode 100644 tests/ui/const-generics/gca/coherence-fail.rs create mode 100644 tests/ui/const-generics/gca/coherence-fail.stderr create mode 100644 tests/ui/const-generics/gca/coherence-ok.rs diff --git a/compiler/rustc_next_trait_solver/src/solve/normalizes_to/anon_const.rs b/compiler/rustc_next_trait_solver/src/solve/normalizes_to/anon_const.rs index 894910dfb6c1..46312be5ea9a 100644 --- a/compiler/rustc_next_trait_solver/src/solve/normalizes_to/anon_const.rs +++ b/compiler/rustc_next_trait_solver/src/solve/normalizes_to/anon_const.rs @@ -1,4 +1,4 @@ -use rustc_type_ir::{self as ty, Interner, TypingMode}; +use rustc_type_ir::{self as ty, Interner}; use tracing::instrument; use crate::delegate::SolverDelegate; @@ -14,18 +14,7 @@ pub(super) fn normalize_anon_const( &mut self, goal: Goal>, ) -> QueryResult { - if self.typing_mode() == TypingMode::Coherence - && self.cx().anon_const_kind(goal.predicate.alias.def_id) == ty::AnonConstKind::GCA - { - // During coherence, GCA consts should be normalized ambiguously - // because they are opaque but eventually resolved to a real value. - // We don't want two GCAs that have the same value to be treated - // as distinct for coherence purposes. (Just like opaque types.) - // - // We can't rely on evaluate_const below because that particular wrapper - // treats too-generic consts as a successful evaluation. - self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS) - } else if let Some(normalized_const) = self.evaluate_const( + if let Some(normalized_const) = self.evaluate_const( goal.param_env, ty::UnevaluatedConst::new( goal.predicate.alias.def_id.try_into().unwrap(), diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index 41b7b5b925cf..94ce7631b3c8 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -676,21 +676,10 @@ pub fn try_evaluate_const<'tcx>( (args, typing_env) } - Some(ty::AnonConstKind::GCA) => { - if infcx.typing_mode() != TypingMode::PostAnalysis { - // GCA anon consts should be treated as always having generics - // during anything before codegen (or maybe MIR opts too). - return Err(EvaluateConstErr::HasGenericsOrInfers); - } - - if uv.args.has_non_region_param() || uv.args.has_non_region_infer() { - return Err(EvaluateConstErr::HasGenericsOrInfers); - } - - let typing_env = ty::TypingEnv::fully_monomorphized(); - (uv.args, typing_env) - } - Some(ty::AnonConstKind::MCG) | Some(ty::AnonConstKind::NonTypeSystem) | None => { + Some(ty::AnonConstKind::GCA) + | Some(ty::AnonConstKind::MCG) + | Some(ty::AnonConstKind::NonTypeSystem) + | None => { // We are only dealing with "truly" generic/uninferred constants here: // - GCEConsts have been handled separately // - Repeat expr count back compat consts have also been handled separately diff --git a/tests/ui/const-generics/gca/basic-fail.rs b/tests/ui/const-generics/gca/basic-different-definitions.rs similarity index 87% rename from tests/ui/const-generics/gca/basic-fail.rs rename to tests/ui/const-generics/gca/basic-different-definitions.rs index 4b638279988d..d96c718617d2 100644 --- a/tests/ui/const-generics/gca/basic-fail.rs +++ b/tests/ui/const-generics/gca/basic-different-definitions.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![feature(generic_const_items)] #![feature(min_generic_const_args)] #![feature(generic_const_args)] @@ -11,8 +13,6 @@ type const OTHER_ONE: usize = INC::<0>; -// Not definitionally equal. const ARR: [(); ADD1::<0>] = [(); INC::<0>]; -//~^ ERROR mismatched types fn main() {} diff --git a/tests/ui/const-generics/gca/basic-fail.stderr b/tests/ui/const-generics/gca/basic-fail.stderr deleted file mode 100644 index b1808deacd27..000000000000 --- a/tests/ui/const-generics/gca/basic-fail.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0308]: mismatched types - --> $DIR/basic-fail.rs:15:30 - | -LL | const ARR: [(); ADD1::<0>] = [(); INC::<0>]; - | --------------- ^^^^^^^^^^^^^^ expected an array with a size of const { N + 1 }, found one with a size of const { N + 1 } - | | - | expected because of the type of the constant - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/const-generics/gca/coherence-ambiguous.rs b/tests/ui/const-generics/gca/coherence-ambiguous.rs deleted file mode 100644 index 7c8b2b33548c..000000000000 --- a/tests/ui/const-generics/gca/coherence-ambiguous.rs +++ /dev/null @@ -1,18 +0,0 @@ -//@ check-fail - -#![feature(generic_const_items, min_generic_const_args, generic_const_args)] -#![expect(incomplete_features)] - -type const FOO: usize = const { N + 1 }; - -type const BAR: usize = const { N + 1 }; - -trait Trait {} - -impl Trait for [(); FOO::<1>] {} -impl Trait for [(); BAR::<1>] {} -//~^ ERROR conflicting implementations of trait `Trait` for type `[(); FOO::<1>]` -impl Trait for [(); BAR::<2>] {} -//~^ ERROR conflicting implementations of trait `Trait` for type `[(); FOO::<1>]` - -fn main() {} diff --git a/tests/ui/const-generics/gca/coherence-ambiguous.stderr b/tests/ui/const-generics/gca/coherence-ambiguous.stderr deleted file mode 100644 index 919a0c8d70e9..000000000000 --- a/tests/ui/const-generics/gca/coherence-ambiguous.stderr +++ /dev/null @@ -1,20 +0,0 @@ -error[E0119]: conflicting implementations of trait `Trait` for type `[(); FOO::<1>]` - --> $DIR/coherence-ambiguous.rs:13:1 - | -LL | impl Trait for [(); FOO::<1>] {} - | ----------------------------- first implementation here -LL | impl Trait for [(); BAR::<1>] {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `[(); FOO::<1>]` - -error[E0119]: conflicting implementations of trait `Trait` for type `[(); FOO::<1>]` - --> $DIR/coherence-ambiguous.rs:15:1 - | -LL | impl Trait for [(); FOO::<1>] {} - | ----------------------------- first implementation here -... -LL | impl Trait for [(); BAR::<2>] {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `[(); FOO::<1>]` - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0119`. diff --git a/tests/ui/const-generics/gca/coherence-fail.rs b/tests/ui/const-generics/gca/coherence-fail.rs new file mode 100644 index 000000000000..1b181d792d36 --- /dev/null +++ b/tests/ui/const-generics/gca/coherence-fail.rs @@ -0,0 +1,28 @@ +#![feature(generic_const_items, min_generic_const_args, generic_const_args)] +#![expect(incomplete_features)] + +// computing the same value with different constant items but same generic arguments should fail +trait Trait1 {} +type const FOO: usize = const { N + 1 }; +type const BAR: usize = const { N + 1 }; +impl Trait1 for [(); FOO::<1>] {} +impl Trait1 for [(); BAR::<1>] {} +//~^ ERROR conflicting implementations of trait `Trait1` for type `[(); 2]` + +// computing the same value with the same constant item but different generic arguments should fail +type const DIV2: usize = const { N / 2 }; +trait Trait2 {} +impl Trait2 for [(); DIV2::<2>] {} +impl Trait2 for [(); DIV2::<3>] {} +//~^ ERROR conflicting implementations of trait `Trait2` for type `[(); 1]` + +// computing the same value with different constant items and different generic arguments should +// fail +trait Trait3 {} +type const ADD1: usize = const { N + 1 }; +type const SUB1: usize = const { N - 1 }; +impl Trait3 for [(); ADD1::<1>] {} +impl Trait3 for [(); SUB1::<3>] {} +//~^ ERROR conflicting implementations of trait `Trait3` for type `[(); 2]` + +fn main() {} diff --git a/tests/ui/const-generics/gca/coherence-fail.stderr b/tests/ui/const-generics/gca/coherence-fail.stderr new file mode 100644 index 000000000000..e8122c1b832f --- /dev/null +++ b/tests/ui/const-generics/gca/coherence-fail.stderr @@ -0,0 +1,27 @@ +error[E0119]: conflicting implementations of trait `Trait1` for type `[(); 2]` + --> $DIR/coherence-fail.rs:9:1 + | +LL | impl Trait1 for [(); FOO::<1>] {} + | ------------------------------ first implementation here +LL | impl Trait1 for [(); BAR::<1>] {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `[(); 2]` + +error[E0119]: conflicting implementations of trait `Trait2` for type `[(); 1]` + --> $DIR/coherence-fail.rs:16:1 + | +LL | impl Trait2 for [(); DIV2::<2>] {} + | ------------------------------- first implementation here +LL | impl Trait2 for [(); DIV2::<3>] {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `[(); 1]` + +error[E0119]: conflicting implementations of trait `Trait3` for type `[(); 2]` + --> $DIR/coherence-fail.rs:25:1 + | +LL | impl Trait3 for [(); ADD1::<1>] {} + | ------------------------------- first implementation here +LL | impl Trait3 for [(); SUB1::<3>] {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `[(); 2]` + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0119`. diff --git a/tests/ui/const-generics/gca/coherence-ok.rs b/tests/ui/const-generics/gca/coherence-ok.rs new file mode 100644 index 000000000000..447f25bfdc36 --- /dev/null +++ b/tests/ui/const-generics/gca/coherence-ok.rs @@ -0,0 +1,14 @@ +//@ check-pass +#![feature(generic_const_items, min_generic_const_args, generic_const_args)] +#![expect(incomplete_features)] + +// computing different values with the same type const item should be fine + +type const ADD1: usize = const { N + 1 }; + +trait Trait {} + +impl Trait for [(); ADD1::<1>] {} +impl Trait for [(); ADD1::<2>] {} + +fn main() {}