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] 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() {}