remove the o from oGCA

This commit is contained in:
khyperia
2026-04-02 12:06:25 +02:00
parent 0e2c554e74
commit 9465366ec4
9 changed files with 77 additions and 79 deletions
@@ -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<I, ty::NormalizesTo<I>>,
) -> QueryResult<I> {
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(),
@@ -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
@@ -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() {}
@@ -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`.
@@ -1,18 +0,0 @@
//@ check-fail
#![feature(generic_const_items, min_generic_const_args, generic_const_args)]
#![expect(incomplete_features)]
type const FOO<const N: usize>: usize = const { N + 1 };
type const BAR<const N: usize>: 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() {}
@@ -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`.
@@ -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<const N: usize>: usize = const { N + 1 };
type const BAR<const N: usize>: 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<const N: usize>: 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<const N: usize>: usize = const { N + 1 };
type const SUB1<const N: usize>: 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() {}
@@ -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`.
@@ -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<const N: usize>: usize = const { N + 1 };
trait Trait {}
impl Trait for [(); ADD1::<1>] {}
impl Trait for [(); ADD1::<2>] {}
fn main() {}