Skip to content

Commit 35a20ce

Browse files
authored
Unrolled build for rust-lang#117133
Rollup merge of rust-lang#117133 - compiler-errors:coherence-constrained, r=oli-obk Merge `impl_wf_inference` (`check_mod_impl_wf`) check into coherence checking Problem here is that we call `collect_impl_trait_in_trait_types` when checking `check_mod_impl_wf` which is performed before coherence. Due to the `tcx.sess.track_errors`, since we end up reporting an error, we never actually proceed to coherence checking, where we would be emitting a more useful impl overlap error. This change means that we may report more errors in some cases, but can at least proceed far enough to leave a useful message for overlapping traits with RPITITs in them. Fixes rust-lang#116982 r? types
2 parents 964ff01 + a947654 commit 35a20ce

File tree

5 files changed

+87
-15
lines changed

5 files changed

+87
-15
lines changed

compiler/rustc_hir_analysis/src/lib.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,11 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
181181
})?;
182182
}
183183

184-
tcx.sess.track_errors(|| {
185-
tcx.sess.time("impl_wf_inference", || {
186-
tcx.hir().for_each_module(|module| tcx.ensure().check_mod_impl_wf(module))
187-
});
188-
})?;
189-
190184
tcx.sess.track_errors(|| {
191185
tcx.sess.time("coherence_checking", || {
186+
// Check impls constrain their parameters
187+
tcx.hir().for_each_module(|module| tcx.ensure().check_mod_impl_wf(module));
188+
192189
for &trait_def_id in tcx.all_local_trait_impls(()).keys() {
193190
tcx.ensure().coherent_trait(trait_def_id);
194191
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// edition: 2021
2+
3+
trait Foo {
4+
type T;
5+
6+
async fn foo(&self) -> Self::T;
7+
}
8+
9+
struct Bar;
10+
11+
impl Foo for Bar {
12+
type T = ();
13+
14+
async fn foo(&self) {}
15+
//~^ ERROR type annotations needed: cannot satisfy `<Bar as Foo>::T == ()`
16+
}
17+
18+
impl Foo for Bar {
19+
//~^ ERROR conflicting implementations of trait `Foo` for type `Bar`
20+
type T = ();
21+
22+
async fn foo(&self) {}
23+
//~^ ERROR type annotations needed: cannot satisfy `<Bar as Foo>::T == ()`
24+
}
25+
26+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
error[E0284]: type annotations needed: cannot satisfy `<Bar as Foo>::T == ()`
2+
--> $DIR/coherence-constrained.rs:14:5
3+
|
4+
LL | async fn foo(&self) {}
5+
| ^^^^^^^^^^^^^^^^^^^ cannot satisfy `<Bar as Foo>::T == ()`
6+
7+
error[E0284]: type annotations needed: cannot satisfy `<Bar as Foo>::T == ()`
8+
--> $DIR/coherence-constrained.rs:22:5
9+
|
10+
LL | async fn foo(&self) {}
11+
| ^^^^^^^^^^^^^^^^^^^ cannot satisfy `<Bar as Foo>::T == ()`
12+
13+
error[E0119]: conflicting implementations of trait `Foo` for type `Bar`
14+
--> $DIR/coherence-constrained.rs:18:1
15+
|
16+
LL | impl Foo for Bar {
17+
| ---------------- first implementation here
18+
...
19+
LL | impl Foo for Bar {
20+
| ^^^^^^^^^^^^^^^^ conflicting implementation for `Bar`
21+
22+
error: aborting due to 3 previous errors
23+
24+
Some errors have detailed explanations: E0119, E0284.
25+
For more information about an error, try `rustc --explain E0119`.

tests/ui/impl-unused-tps.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//~ ERROR overflow evaluating the requirement `([isize; 0], _): Sized
2+
13
trait Foo<A> {
24
fn get(&self, A: &A) { }
35
}
@@ -23,8 +25,7 @@ impl<T:Bar<Out=U>,U> Foo<T> for [isize;3] {
2325
}
2426

2527
impl<T,U> Foo<T> for U {
26-
// OK, T, U are used everywhere. Note that the coherence check
27-
// hasn't executed yet, so no errors about overlap.
28+
//~^ ERROR conflicting implementations of trait `Foo<_>` for type `[isize; 0]`
2829
}
2930

3031
impl<T,U> Bar for T {

tests/ui/impl-unused-tps.stderr

+30-7
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,56 @@
11
error[E0207]: the type parameter `U` is not constrained by the impl trait, self type, or predicates
2-
--> $DIR/impl-unused-tps.rs:13:8
2+
--> $DIR/impl-unused-tps.rs:15:8
33
|
44
LL | impl<T,U> Foo<T> for [isize;1] {
55
| ^ unconstrained type parameter
66

77
error[E0207]: the type parameter `U` is not constrained by the impl trait, self type, or predicates
8-
--> $DIR/impl-unused-tps.rs:30:8
8+
--> $DIR/impl-unused-tps.rs:31:8
99
|
1010
LL | impl<T,U> Bar for T {
1111
| ^ unconstrained type parameter
1212

1313
error[E0207]: the type parameter `U` is not constrained by the impl trait, self type, or predicates
14-
--> $DIR/impl-unused-tps.rs:38:8
14+
--> $DIR/impl-unused-tps.rs:39:8
1515
|
1616
LL | impl<T,U> Bar for T
1717
| ^ unconstrained type parameter
1818

1919
error[E0207]: the type parameter `U` is not constrained by the impl trait, self type, or predicates
20-
--> $DIR/impl-unused-tps.rs:46:8
20+
--> $DIR/impl-unused-tps.rs:47:8
2121
|
2222
LL | impl<T,U,V> Foo<T> for T
2323
| ^ unconstrained type parameter
2424

2525
error[E0207]: the type parameter `V` is not constrained by the impl trait, self type, or predicates
26-
--> $DIR/impl-unused-tps.rs:46:10
26+
--> $DIR/impl-unused-tps.rs:47:10
2727
|
2828
LL | impl<T,U,V> Foo<T> for T
2929
| ^ unconstrained type parameter
3030

31-
error: aborting due to 5 previous errors
31+
error[E0119]: conflicting implementations of trait `Foo<_>` for type `[isize; 0]`
32+
--> $DIR/impl-unused-tps.rs:27:1
33+
|
34+
LL | impl<T> Foo<T> for [isize;0] {
35+
| ---------------------------- first implementation here
36+
...
37+
LL | impl<T,U> Foo<T> for U {
38+
| ^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `[isize; 0]`
39+
40+
error[E0275]: overflow evaluating the requirement `([isize; 0], _): Sized`
41+
|
42+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`impl_unused_tps`)
43+
note: required for `([isize; 0], _)` to implement `Bar`
44+
--> $DIR/impl-unused-tps.rs:31:11
45+
|
46+
LL | impl<T,U> Bar for T {
47+
| - ^^^ ^
48+
| |
49+
| unsatisfied trait bound introduced here
50+
= note: 126 redundant requirements hidden
51+
= note: required for `([isize; 0], _)` to implement `Bar`
52+
53+
error: aborting due to 7 previous errors
3254

33-
For more information about this error, try `rustc --explain E0207`.
55+
Some errors have detailed explanations: E0119, E0207, E0275.
56+
For more information about an error, try `rustc --explain E0119`.

0 commit comments

Comments
 (0)