Skip to content

Commit 308a970

Browse files
committed
Adjust implementation of coherence ambiguity for OGCA
This actually doesn't work yet because there are pre-existing fundamental issues with equate relations involving consts that need to be normalized. The problem is that we normalize only one layer of the const item and don't actually process the resulting anon const. Normally the created inference variable should be handled, which in this case would cause us to hit the anon const, but that's not happening. Specifically, `visit_const` on `Generalizer` should be updated to be similar to `visit_ty`.
1 parent 4c0dcc8 commit 308a970

3 files changed

Lines changed: 20 additions & 20 deletions

File tree

compiler/rustc_next_trait_solver/src/solve/normalizes_to/anon_const.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_type_ir::{self as ty, Interner};
1+
use rustc_type_ir::{self as ty, Interner, TypingMode};
22
use tracing::instrument;
33

44
use crate::delegate::SolverDelegate;
@@ -14,8 +14,18 @@ where
1414
&mut self,
1515
goal: Goal<I, ty::NormalizesTo<I>>,
1616
) -> QueryResult<I> {
17-
// FIXME(ogca): should we also stop ogca normalization during coherence here or just in normalize_free_alias?
18-
if let Some(normalized_const) = self.evaluate_const(
17+
if self.typing_mode() == TypingMode::Coherence
18+
&& self.cx().anon_const_kind(goal.predicate.alias.def_id) == ty::AnonConstKind::OGCA
19+
{
20+
// During coherence, OGCA consts should be normalized ambiguously
21+
// because they are opaque but eventually resolved to a real value.
22+
// We don't want two OGCAs that have the same value to be treated
23+
// as distinct for coherence purposes. (Just like opaque types.)
24+
//
25+
// We can't rely on evaluate_const below because that particular wrapper
26+
// treats too-generic consts as a successful evaluation.
27+
self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
28+
} else if let Some(normalized_const) = self.evaluate_const(
1929
goal.param_env,
2030
ty::UnevaluatedConst::new(
2131
goal.predicate.alias.def_id.try_into().unwrap(),

compiler/rustc_next_trait_solver/src/solve/normalizes_to/free_alias.rs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
//! Since a free alias is never ambiguous, this just computes the `type_of` of
55
//! the alias and registers the where-clauses of the type alias.
66
7-
use rustc_type_ir::inherent::*;
8-
use rustc_type_ir::{self as ty, Interner, TypingMode};
7+
use rustc_type_ir::{self as ty, Interner};
98

109
use crate::delegate::SolverDelegate;
1110
use crate::solve::{Certainty, EvalCtxt, Goal, GoalSource, QueryResult};
@@ -33,19 +32,7 @@ where
3332
let actual = if free_alias.kind(cx).is_type() {
3433
cx.type_of(free_alias.def_id).instantiate(cx, free_alias.args).into()
3534
} else {
36-
let ct = cx.const_of_item(free_alias.def_id).instantiate(cx, free_alias.args);
37-
if self.typing_mode() == TypingMode::Coherence
38-
&& let ty::ConstKind::Unevaluated(uv) = ct.kind()
39-
&& self.cx().anon_const_kind(uv.def.into()) == ty::AnonConstKind::OGCA
40-
{
41-
// During coherence, OGCA consts should be normalized ambiguously
42-
// because they are opaque but eventually resolved to a real value.
43-
// We don't want two OGCAs that have the same value to be treated
44-
// as distinct for coherence purposes.
45-
// (Just like opaque types.)
46-
return self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS);
47-
}
48-
ct.into()
35+
cx.const_of_item(free_alias.def_id).instantiate(cx, free_alias.args).into()
4936
};
5037

5138
self.instantiate_normalizes_to_term(goal, actual);

tests/ui/const-generics/ogca/coherence-ambiguous.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// FIXME(ogca): this should ERROR not pass!!
2+
//@ check-pass
3+
14
#![feature(generic_const_items, min_generic_const_args, opaque_generic_const_args)]
25
#![expect(incomplete_features)]
36

@@ -11,8 +14,8 @@ trait Trait {}
1114

1215
impl Trait for [(); FOO::<1>] {}
1316
impl Trait for [(); BAR::<1>] {}
14-
//~^ ERROR conflicting implementations of trait `Trait` for type `[(); FOO::<1>]`
17+
// FIXME(ogca): this should ERROR!
1518
impl Trait for [(); BAR::<2>] {}
16-
//~^ ERROR conflicting implementations of trait `Trait` for type `[(); FOO::<1>]`
19+
// FIXME(ogca): this should ERROR!
1720

1821
fn main() {}

0 commit comments

Comments
 (0)