Skip to content

Commit ad42fa1

Browse files
committed
Stop bailing out from compilation just because there were incoherent traits
1 parent 11f32b7 commit ad42fa1

File tree

135 files changed

+2213
-251
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+2213
-251
lines changed

compiler/rustc_hir_analysis/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,11 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
169169

170170
tcx.sess.time("coherence_checking", || {
171171
// Check impls constrain their parameters
172-
let mut res =
172+
let res =
173173
tcx.hir().try_par_for_each_module(|module| tcx.ensure().check_mod_impl_wf(module));
174174

175175
for &trait_def_id in tcx.all_local_trait_impls(()).keys() {
176-
res = res.and(tcx.ensure().coherent_trait(trait_def_id));
176+
let _ = tcx.ensure().coherent_trait(trait_def_id);
177177
}
178178
// these queries are executed for side-effects (error reporting):
179179
res.and(tcx.ensure().crate_inherent_impls(()))

tests/ui/associated-consts/issue-105330.rs

+1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ fn foo<A: TraitWAssocConst<A=32>>() { //~ ERROR E0658
1414

1515
fn main<A: TraitWAssocConst<A=32>>() {
1616
//~^ ERROR E0658
17+
//~| ERROR E0131
1718
foo::<Demo>();
1819
}

tests/ui/associated-consts/issue-105330.stderr

+9-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,13 @@ LL | impl TraitWAssocConst for impl Demo {
4343
|
4444
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
4545

46-
error: aborting due to 5 previous errors
46+
error[E0131]: `main` function is not allowed to have generic parameters
47+
--> $DIR/issue-105330.rs:15:8
48+
|
49+
LL | fn main<A: TraitWAssocConst<A=32>>() {
50+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `main` cannot have generic parameters
51+
52+
error: aborting due to 6 previous errors
4753

48-
Some errors have detailed explanations: E0404, E0562, E0658.
49-
For more information about an error, try `rustc --explain E0404`.
54+
Some errors have detailed explanations: E0131, E0404, E0562, E0658.
55+
For more information about an error, try `rustc --explain E0131`.

tests/ui/async-await/in-trait/coherence-constrained.rs

+8
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,31 @@ trait Foo {
44
type T;
55

66
async fn foo(&self) -> Self::T;
7+
//~^ ERROR type annotations needed
8+
//~| ERROR type annotations needed
79
}
810

911
struct Bar;
1012

1113
impl Foo for Bar {
14+
//~^ ERROR type annotations needed
1215
type T = ();
16+
//~^ ERROR type annotations needed
1317

1418
async fn foo(&self) {}
1519
//~^ ERROR type annotations needed: cannot satisfy `<Bar as Foo>::T == ()`
20+
//~| ERROR type annotations needed
1621
}
1722

1823
impl Foo for Bar {
1924
//~^ ERROR conflicting implementations of trait `Foo` for type `Bar`
25+
//~| ERROR type annotations needed
2026
type T = ();
27+
//~^ ERROR type annotations needed
2128

2229
async fn foo(&self) {}
2330
//~^ ERROR type annotations needed: cannot satisfy `<Bar as Foo>::T == ()`
31+
//~| ERROR type annotations needed
2432
}
2533

2634
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,100 @@
11
error[E0284]: type annotations needed: cannot satisfy `<Bar as Foo>::T == ()`
2-
--> $DIR/coherence-constrained.rs:14:5
2+
--> $DIR/coherence-constrained.rs:18:5
33
|
44
LL | async fn foo(&self) {}
55
| ^^^^^^^^^^^^^^^^^^^ cannot satisfy `<Bar as Foo>::T == ()`
66

77
error[E0284]: type annotations needed: cannot satisfy `<Bar as Foo>::T == ()`
8-
--> $DIR/coherence-constrained.rs:22:5
8+
--> $DIR/coherence-constrained.rs:29:5
99
|
1010
LL | async fn foo(&self) {}
1111
| ^^^^^^^^^^^^^^^^^^^ cannot satisfy `<Bar as Foo>::T == ()`
1212

1313
error[E0119]: conflicting implementations of trait `Foo` for type `Bar`
14-
--> $DIR/coherence-constrained.rs:18:1
14+
--> $DIR/coherence-constrained.rs:23:1
1515
|
1616
LL | impl Foo for Bar {
1717
| ---------------- first implementation here
1818
...
1919
LL | impl Foo for Bar {
2020
| ^^^^^^^^^^^^^^^^ conflicting implementation for `Bar`
2121

22-
error: aborting due to 3 previous errors
22+
error[E0283]: type annotations needed: cannot satisfy `Bar: Foo`
23+
--> $DIR/coherence-constrained.rs:13:14
24+
|
25+
LL | impl Foo for Bar {
26+
| ^^^
27+
|
28+
note: multiple `impl`s satisfying `Bar: Foo` found
29+
--> $DIR/coherence-constrained.rs:13:1
30+
|
31+
LL | impl Foo for Bar {
32+
| ^^^^^^^^^^^^^^^^
33+
...
34+
LL | impl Foo for Bar {
35+
| ^^^^^^^^^^^^^^^^
36+
37+
error[E0284]: type annotations needed
38+
--> $DIR/coherence-constrained.rs:15:14
39+
|
40+
LL | type T = ();
41+
| ^^ cannot infer type
42+
|
43+
= note: cannot satisfy `<Bar as Foo>::T == _`
44+
45+
error[E0284]: type annotations needed: cannot satisfy `<Bar as Foo>::{opaque#0}<'_> == impl Future<Output = ()>`
46+
--> $DIR/coherence-constrained.rs:18:5
47+
|
48+
LL | async fn foo(&self) {}
49+
| ^^^^^^^^^^^^^^^^^^^ cannot satisfy `<Bar as Foo>::{opaque#0}<'_> == impl Future<Output = ()>`
50+
51+
error[E0284]: type annotations needed
52+
--> $DIR/coherence-constrained.rs:6:5
53+
|
54+
LL | async fn foo(&self) -> Self::T;
55+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type
56+
|
57+
= note: cannot satisfy `<Bar as Foo>::{opaque#0}<'_> == _`
58+
59+
error[E0283]: type annotations needed: cannot satisfy `Bar: Foo`
60+
--> $DIR/coherence-constrained.rs:23:14
61+
|
62+
LL | impl Foo for Bar {
63+
| ^^^
64+
|
65+
note: multiple `impl`s satisfying `Bar: Foo` found
66+
--> $DIR/coherence-constrained.rs:13:1
67+
|
68+
LL | impl Foo for Bar {
69+
| ^^^^^^^^^^^^^^^^
70+
...
71+
LL | impl Foo for Bar {
72+
| ^^^^^^^^^^^^^^^^
73+
74+
error[E0284]: type annotations needed
75+
--> $DIR/coherence-constrained.rs:26:14
76+
|
77+
LL | type T = ();
78+
| ^^ cannot infer type
79+
|
80+
= note: cannot satisfy `<Bar as Foo>::T == _`
81+
82+
error[E0284]: type annotations needed: cannot satisfy `<Bar as Foo>::{opaque#0}<'_> == impl Future<Output = ()>`
83+
--> $DIR/coherence-constrained.rs:29:5
84+
|
85+
LL | async fn foo(&self) {}
86+
| ^^^^^^^^^^^^^^^^^^^ cannot satisfy `<Bar as Foo>::{opaque#0}<'_> == impl Future<Output = ()>`
87+
88+
error[E0284]: type annotations needed
89+
--> $DIR/coherence-constrained.rs:6:5
90+
|
91+
LL | async fn foo(&self) -> Self::T;
92+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type
93+
|
94+
= note: cannot satisfy `<Bar as Foo>::{opaque#0}<'_> == _`
95+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
96+
97+
error: aborting due to 11 previous errors
2398

24-
Some errors have detailed explanations: E0119, E0284.
99+
Some errors have detailed explanations: E0119, E0283, E0284.
25100
For more information about an error, try `rustc --explain E0119`.

tests/ui/async-await/issue-67651.rs

+3
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@ trait From {
55
}
66

77
impl From for () {
8+
//~^ ERROR type annotations needed
89
fn from() {}
910
}
1011

1112
impl From for () {
1213
//~^ ERROR conflicting implementations of trait
14+
//~| ERROR type annotations needed
1315
fn from() {}
1416
}
1517

1618
fn bar() -> impl core::future::Future<Output = ()> {
1719
async move { From::from() }
20+
//~^ ERROR cannot call associated function on trait
1821
}
1922

2023
fn main() {}
+48-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,57 @@
11
error[E0119]: conflicting implementations of trait `From` for type `()`
2-
--> $DIR/issue-67651.rs:11:1
2+
--> $DIR/issue-67651.rs:12:1
33
|
44
LL | impl From for () {
55
| ---------------- first implementation here
66
...
77
LL | impl From for () {
88
| ^^^^^^^^^^^^^^^^ conflicting implementation for `()`
99

10-
error: aborting due to 1 previous error
10+
error[E0283]: type annotations needed: cannot satisfy `(): From`
11+
--> $DIR/issue-67651.rs:7:15
12+
|
13+
LL | impl From for () {
14+
| ^^
15+
|
16+
note: multiple `impl`s satisfying `(): From` found
17+
--> $DIR/issue-67651.rs:7:1
18+
|
19+
LL | impl From for () {
20+
| ^^^^^^^^^^^^^^^^
21+
...
22+
LL | impl From for () {
23+
| ^^^^^^^^^^^^^^^^
24+
25+
error[E0283]: type annotations needed: cannot satisfy `(): From`
26+
--> $DIR/issue-67651.rs:12:15
27+
|
28+
LL | impl From for () {
29+
| ^^
30+
|
31+
note: multiple `impl`s satisfying `(): From` found
32+
--> $DIR/issue-67651.rs:7:1
33+
|
34+
LL | impl From for () {
35+
| ^^^^^^^^^^^^^^^^
36+
...
37+
LL | impl From for () {
38+
| ^^^^^^^^^^^^^^^^
39+
40+
error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type
41+
--> $DIR/issue-67651.rs:19:18
42+
|
43+
LL | fn from();
44+
| ---------- `From::from` defined here
45+
...
46+
LL | async move { From::from() }
47+
| ^^^^^^^^^^^^ cannot call associated function of trait
48+
|
49+
help: use a fully-qualified path to a specific available implementation
50+
|
51+
LL | async move { </* self type */ as From>::from() }
52+
| +++++++++++++++++++ +
53+
54+
error: aborting due to 4 previous errors
1155

12-
For more information about this error, try `rustc --explain E0119`.
56+
Some errors have detailed explanations: E0119, E0283, E0790.
57+
For more information about an error, try `rustc --explain E0119`.

tests/ui/coherence/coherence-blanket-conflicts-with-specific-cross-crate.rs

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ impl Go for MyThingy {
1414

1515
impl GoMut for MyThingy {
1616
//~^ ERROR E0119
17+
//~| ERROR E0283
1718
fn go_mut(&mut self, arg: isize) { }
1819
}
1920

tests/ui/coherence/coherence-blanket-conflicts-with-specific-cross-crate.stderr

+18-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@ LL | impl GoMut for MyThingy {
88
- impl<G> GoMut for G
99
where G: Go;
1010

11-
error: aborting due to 1 previous error
11+
error[E0283]: type annotations needed: cannot satisfy `MyThingy: GoMut`
12+
--> $DIR/coherence-blanket-conflicts-with-specific-cross-crate.rs:15:16
13+
|
14+
LL | impl GoMut for MyThingy {
15+
| ^^^^^^^^
16+
|
17+
note: multiple `impl`s satisfying `MyThingy: GoMut` found
18+
--> $DIR/coherence-blanket-conflicts-with-specific-cross-crate.rs:15:1
19+
|
20+
LL | impl GoMut for MyThingy {
21+
| ^^^^^^^^^^^^^^^^^^^^^^^
22+
= note: and another `impl` found in the `go_trait` crate:
23+
- impl<G> GoMut for G
24+
where G: Go;
25+
26+
error: aborting due to 2 previous errors
1227

13-
For more information about this error, try `rustc --explain E0119`.
28+
Some errors have detailed explanations: E0119, E0283.
29+
For more information about an error, try `rustc --explain E0119`.

tests/ui/coherence/coherence-blanket-conflicts-with-specific-multidispatch.rs

+2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ struct MyType {
2121

2222
impl MyTrait<MyType> for MyType {
2323
//~^ ERROR E0119
24+
//~| ERROR type annotations needed
2425
fn get(&self) -> usize { (*self).clone() }
26+
//~^ ERROR incompatible type
2527
}
2628

2729
fn main() { }

tests/ui/coherence/coherence-blanket-conflicts-with-specific-multidispatch.stderr

+35-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,39 @@ LL | impl<T> MyTrait<T> for T {
77
LL | impl MyTrait<MyType> for MyType {
88
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `MyType`
99

10-
error: aborting due to 1 previous error
10+
error[E0283]: type annotations needed: cannot satisfy `MyType: MyTrait<MyType>`
11+
--> $DIR/coherence-blanket-conflicts-with-specific-multidispatch.rs:22:26
12+
|
13+
LL | impl MyTrait<MyType> for MyType {
14+
| ^^^^^^
15+
|
16+
note: multiple `impl`s satisfying `MyType: MyTrait<MyType>` found
17+
--> $DIR/coherence-blanket-conflicts-with-specific-multidispatch.rs:11:1
18+
|
19+
LL | impl<T> MyTrait<T> for T {
20+
| ^^^^^^^^^^^^^^^^^^^^^^^^
21+
...
22+
LL | impl MyTrait<MyType> for MyType {
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24+
25+
error[E0053]: method `get` has an incompatible type for trait
26+
--> $DIR/coherence-blanket-conflicts-with-specific-multidispatch.rs:25:22
27+
|
28+
LL | fn get(&self) -> usize { (*self).clone() }
29+
| ^^^^^
30+
| |
31+
| expected `MyType`, found `usize`
32+
| help: change the output type to match the trait: `MyType`
33+
|
34+
note: type in trait
35+
--> $DIR/coherence-blanket-conflicts-with-specific-multidispatch.rs:8:22
36+
|
37+
LL | fn get(&self) -> T;
38+
| ^
39+
= note: expected signature `fn(&MyType) -> MyType`
40+
found signature `fn(&MyType) -> usize`
41+
42+
error: aborting due to 3 previous errors
1143

12-
For more information about this error, try `rustc --explain E0119`.
44+
Some errors have detailed explanations: E0053, E0119, E0283.
45+
For more information about an error, try `rustc --explain E0053`.

tests/ui/coherence/coherence-blanket-conflicts-with-specific-trait.rs

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ struct MyType {
1919

2020
impl MyTrait for MyType {
2121
//~^ ERROR E0119
22+
//~| ERROR type annotations needed
2223
fn get(&self) -> usize { self.dummy }
2324
}
2425

tests/ui/coherence/coherence-blanket-conflicts-with-specific-trait.stderr

+18-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,22 @@ LL | impl<T:OtherTrait> MyTrait for T {
77
LL | impl MyTrait for MyType {
88
| ^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `MyType`
99

10-
error: aborting due to 1 previous error
10+
error[E0283]: type annotations needed: cannot satisfy `MyType: MyTrait`
11+
--> $DIR/coherence-blanket-conflicts-with-specific-trait.rs:20:18
12+
|
13+
LL | impl MyTrait for MyType {
14+
| ^^^^^^
15+
|
16+
note: multiple `impl`s satisfying `MyType: MyTrait` found
17+
--> $DIR/coherence-blanket-conflicts-with-specific-trait.rs:12:1
18+
|
19+
LL | impl<T:OtherTrait> MyTrait for T {
20+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21+
...
22+
LL | impl MyTrait for MyType {
23+
| ^^^^^^^^^^^^^^^^^^^^^^^
24+
25+
error: aborting due to 2 previous errors
1126

12-
For more information about this error, try `rustc --explain E0119`.
27+
Some errors have detailed explanations: E0119, E0283.
28+
For more information about an error, try `rustc --explain E0119`.

tests/ui/coherence/coherence-blanket-conflicts-with-specific.rs

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ struct MyType {
1818

1919
impl MyTrait for MyType {
2020
//~^ ERROR E0119
21+
//~| ERROR type annotations needed
2122
fn get(&self) -> usize { self.dummy }
2223
}
2324

0 commit comments

Comments
 (0)