Skip to content

Commit 4e391cf

Browse files
committed
Auto merge of rust-lang#157617 - Shourya742:2026-06-08-donot-eagerly-normalize-alias-during-coherence, r=lcnr
Do not eagerly normalize alias during coherence closes: rust-lang#157407 r? @lcnr
2 parents 6540795 + 063fdc0 commit 4e391cf

22 files changed

Lines changed: 112 additions & 63 deletions

compiler/rustc_trait_selection/src/traits/coherence.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,16 @@ fn overlap<'tcx>(
278278
// empty environment.
279279
let param_env = ty::ParamEnv::empty();
280280

281-
let impl1_header =
282-
fresh_impl_header_normalized(selcx.infcx, param_env, impl1_def_id, is_of_trait);
283-
let impl2_header =
284-
fresh_impl_header_normalized(selcx.infcx, param_env, impl2_def_id, is_of_trait);
281+
let impl1_header = if tcx.next_trait_solver_in_coherence() {
282+
fresh_impl_header(selcx.infcx, impl1_def_id, is_of_trait)
283+
} else {
284+
fresh_impl_header_normalized(selcx.infcx, param_env, impl1_def_id, is_of_trait)
285+
};
286+
let impl2_header = if tcx.next_trait_solver_in_coherence() {
287+
fresh_impl_header(selcx.infcx, impl2_def_id, is_of_trait)
288+
} else {
289+
fresh_impl_header_normalized(selcx.infcx, param_env, impl2_def_id, is_of_trait)
290+
};
285291

286292
// Equate the headers to find their intersection (the general type, with infer vars,
287293
// that may apply both impls).

tests/ui/associated-types/associated-types-coherence-failure.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
error[E0119]: conflicting implementations of trait `IntoCow<'_, _>` for type `Cow<'_, _>`
1+
error[E0119]: conflicting implementations of trait `IntoCow<'_, _>` for type `<_ as ToOwned>::Owned`
22
--> $DIR/associated-types-coherence-failure.rs:21:1
33
|
44
LL | impl<'a, B: ?Sized> IntoCow<'a, B> for <B as ToOwned>::Owned where B: ToOwned {
55
| ----------------------------------------------------------------------------- first implementation here
66
...
77
LL | impl<'a, B: ?Sized> IntoCow<'a, B> for Cow<'a, B> where B: ToOwned {
8-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Cow<'_, _>`
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `<_ as ToOwned>::Owned`
99

10-
error[E0119]: conflicting implementations of trait `IntoCow<'_, _>` for type `&_`
10+
error[E0119]: conflicting implementations of trait `IntoCow<'_, _>` for type `<_ as ToOwned>::Owned`
1111
--> $DIR/associated-types-coherence-failure.rs:28:1
1212
|
1313
LL | impl<'a, B: ?Sized> IntoCow<'a, B> for <B as ToOwned>::Owned where B: ToOwned {
1414
| ----------------------------------------------------------------------------- first implementation here
1515
...
1616
LL | impl<'a, B: ?Sized> IntoCow<'a, B> for &'a B where B: ToOwned {
17-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `&_`
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `<_ as ToOwned>::Owned`
1818

1919
error: aborting due to 2 previous errors
2020

tests/ui/coherence/coherence-with-closure.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error[E0119]: conflicting implementations of trait `Trait` for type `Wrapper<_>`
1+
error[E0119]: conflicting implementations of trait `Trait` for type `Wrapper<OpaqueClosure>`
22
--> $DIR/coherence-with-closure.rs:12:1
33
|
44
LL | impl Trait for Wrapper<OpaqueClosure> {}
55
| ------------------------------------- first implementation here
66
LL | impl<T: Sync> Trait for Wrapper<T> {}
7-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Wrapper<_>`
7+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Wrapper<OpaqueClosure>`
88

99
error: aborting due to 1 previous error
1010

tests/ui/coherence/coherence-with-coroutine.stock.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error[E0119]: conflicting implementations of trait `Trait` for type `Wrapper<_>`
1+
error[E0119]: conflicting implementations of trait `Trait` for type `Wrapper<OpaqueCoroutine>`
22
--> $DIR/coherence-with-coroutine.rs:23:1
33
|
44
LL | impl Trait for Wrapper<OpaqueCoroutine> {}
55
| --------------------------------------- first implementation here
66
LL | impl<T: Sync> Trait for Wrapper<T> {}
7-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Wrapper<_>`
7+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Wrapper<OpaqueCoroutine>`
88

99
error: aborting due to 1 previous error
1010

tests/ui/coherence/normalize-for-errors.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
error[E0119]: conflicting implementations of trait `MyTrait<_>` for type `(Box<(MyType,)>, _)`
1+
error[E0119]: conflicting implementations of trait `MyTrait<_>` for type `(Box<(MyType,)>, <_ as Iterator>::Item)`
22
--> $DIR/normalize-for-errors.rs:13:1
33
|
44
LL | impl<T: Copy, S: Iterator> MyTrait<S> for (T, S::Item) {}
55
| ------------------------------------------------------ first implementation here
66
LL |
77
LL | impl<S: Iterator> MyTrait<S> for (Box<<(MyType,) as Mirror>::Assoc>, S::Item) {}
8-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(Box<(MyType,)>, _)`
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(Box<(MyType,)>, <_ as Iterator>::Item)`
99
|
1010
= note: upstream crates may add a new impl of trait `std::clone::Clone` for type `std::boxed::Box<(MyType,)>` in future versions
1111
= note: upstream crates may add a new impl of trait `std::marker::Copy` for type `std::boxed::Box<(MyType,)>` in future versions

tests/ui/const-generics/generic_const_exprs/unevaluated-const-ice-119731.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ mod v20 {
2828
impl<const v10: usize> v17<v10, v2> {
2929
//~^ ERROR: maximum number of nodes exceeded in constant v20::v17::<v10, v2>::{constant#0}
3030
//~| ERROR: maximum number of nodes exceeded in constant v20::v17::<v10, v2>::{constant#0}
31+
//~| ERROR: maximum number of nodes exceeded in constant v20::v17::<v10, v2>::{constant#0}
32+
//~| ERROR: maximum number of nodes exceeded in constant v20::v17::<v10, v2>::{constant#0}
33+
//~| ERROR: maximum number of nodes exceeded in constant v20::v17::<v10, v2>::{constant#0}
3134
//~| ERROR: maximum number of nodes exceeded in constant v20::v17::<v10, v2>::{constant#0}
3235
pub const fn v21() -> v18 {
3336
//~^ ERROR cannot find type `v18` in this scope

tests/ui/const-generics/generic_const_exprs/unevaluated-const-ice-119731.stderr

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0432]: unresolved import `v20::v13`
2-
--> $DIR/unevaluated-const-ice-119731.rs:39:15
2+
--> $DIR/unevaluated-const-ice-119731.rs:42:15
33
|
44
LL | pub use v20::{v13, v17};
55
| ^^^ no `v13` in `v20`
@@ -32,7 +32,7 @@ LL + pub const fn v21() -> v11 {}
3232
|
3333

3434
error[E0425]: cannot find type `v18` in this scope
35-
--> $DIR/unevaluated-const-ice-119731.rs:32:31
35+
--> $DIR/unevaluated-const-ice-119731.rs:35:31
3636
|
3737
LL | pub type v11 = [[usize; v4]; v4];
3838
| --------------------------------- similarly named type alias `v11` defined here
@@ -47,7 +47,7 @@ LL + pub const fn v21() -> v11 {
4747
|
4848

4949
error[E0422]: cannot find struct, variant or union type `v18` in this scope
50-
--> $DIR/unevaluated-const-ice-119731.rs:34:13
50+
--> $DIR/unevaluated-const-ice-119731.rs:37:13
5151
|
5252
LL | pub type v11 = [[usize; v4]; v4];
5353
| --------------------------------- similarly named type alias `v11` defined here
@@ -115,6 +115,30 @@ LL | impl<const v10: usize> v17<v10, v2> {
115115
|
116116
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
117117

118+
error: maximum number of nodes exceeded in constant v20::v17::<v10, v2>::{constant#0}
119+
--> $DIR/unevaluated-const-ice-119731.rs:28:37
120+
|
121+
LL | impl<const v10: usize> v17<v10, v2> {
122+
| ^^
123+
|
124+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
125+
126+
error: maximum number of nodes exceeded in constant v20::v17::<v10, v2>::{constant#0}
127+
--> $DIR/unevaluated-const-ice-119731.rs:28:37
128+
|
129+
LL | impl<const v10: usize> v17<v10, v2> {
130+
| ^^
131+
|
132+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
133+
134+
error: maximum number of nodes exceeded in constant v20::v17::<v10, v2>::{constant#0}
135+
--> $DIR/unevaluated-const-ice-119731.rs:28:37
136+
|
137+
LL | impl<const v10: usize> v17<v10, v2> {
138+
| ^^
139+
|
140+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
141+
118142
error[E0592]: duplicate definitions with name `v21`
119143
--> $DIR/unevaluated-const-ice-119731.rs:23:9
120144
|
@@ -124,7 +148,7 @@ LL | pub const fn v21() -> v18 {}
124148
LL | pub const fn v21() -> v18 {
125149
| ------------------------- other definition for `v21`
126150

127-
error: aborting due to 11 previous errors; 2 warnings emitted
151+
error: aborting due to 14 previous errors; 2 warnings emitted
128152

129153
Some errors have detailed explanations: E0422, E0425, E0432, E0592.
130154
For more information about an error, try `rustc --explain E0422`.

tests/ui/const-generics/issues/issue-89304.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1+
//@ check-pass
2+
13
#![feature(generic_const_exprs)]
24
#![allow(incomplete_features)]
35

46
struct GenericStruct<const T: usize> { val: i64 }
57

68
impl<const T: usize> From<GenericStruct<T>> for GenericStruct<{T + 1}> {
7-
//~^ ERROR: conflicting implementations of trait `From<GenericStruct<_>>` for type `GenericStruct<_>`
89
fn from(other: GenericStruct<T>) -> Self {
910
Self { val: other.val }
1011
}
1112
}
1213

1314
impl<const T: usize> From<GenericStruct<{T + 1}>> for GenericStruct<T> {
14-
//~^ ERROR: conflicting implementations of trait `From<GenericStruct<_>>` for type `GenericStruct<_>`
1515
fn from(other: GenericStruct<{T + 1}>) -> Self {
1616
Self { val: other.val }
1717
}

tests/ui/const-generics/issues/issue-89304.stderr

Lines changed: 0 additions & 21 deletions
This file was deleted.

tests/ui/specialization/coherence/default-item-normalization-ambig-1.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error[E0119]: conflicting implementations of trait `Y`
1+
error[E0119]: conflicting implementations of trait `Y` for type `<() as X>::U`
22
--> $DIR/default-item-normalization-ambig-1.rs:20:1
33
|
44
LL | impl Y for <() as X>::U {}
55
| ----------------------- first implementation here
66
LL | impl Y for <i32 as X>::U {}
7-
| ^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation
7+
| ^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `<() as X>::U`
88

99
error: aborting due to 1 previous error
1010

0 commit comments

Comments
 (0)