Skip to content

Commit 08e7773

Browse files
committed
Avoid follow up "type annotations needed" errors in case there were already coherence errors for the same trait
1 parent ad42fa1 commit 08e7773

File tree

65 files changed

+135
-1120
lines changed

Some content is hidden

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

65 files changed

+135
-1120
lines changed

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1292,6 +1292,11 @@ fn check_impl<'tcx>(
12921292
// therefore don't need to be WF (the trait's `Self: Trait` predicate
12931293
// won't hold).
12941294
let trait_ref = tcx.impl_trait_ref(item.owner_id).unwrap().instantiate_identity();
1295+
if let Err(guar) = tcx.ensure().coherent_trait(trait_ref.def_id) {
1296+
// Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case
1297+
// other `Foo` impls are incoherent.
1298+
wfcx.infcx.set_tainted_by_errors(guar);
1299+
}
12951300
let trait_ref = wfcx.normalize(
12961301
ast_trait_ref.path.span,
12971302
Some(WellFormedLoc::Ty(item.hir_id().expect_owner().def_id)),

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

-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ trait Foo {
1111
struct Bar;
1212

1313
impl Foo for Bar {
14-
//~^ ERROR type annotations needed
1514
type T = ();
1615
//~^ ERROR type annotations needed
1716

@@ -22,7 +21,6 @@ impl Foo for Bar {
2221

2322
impl Foo for Bar {
2423
//~^ ERROR conflicting implementations of trait `Foo` for type `Bar`
25-
//~| ERROR type annotations needed
2624
type T = ();
2725
//~^ ERROR type annotations needed
2826

Original file line numberDiff line numberDiff line change
@@ -1,49 +1,34 @@
11
error[E0284]: type annotations needed: cannot satisfy `<Bar as Foo>::T == ()`
2-
--> $DIR/coherence-constrained.rs:18:5
2+
--> $DIR/coherence-constrained.rs:17: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:29:5
8+
--> $DIR/coherence-constrained.rs:27: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:23:1
14+
--> $DIR/coherence-constrained.rs:22: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[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-
3722
error[E0284]: type annotations needed
38-
--> $DIR/coherence-constrained.rs:15:14
23+
--> $DIR/coherence-constrained.rs:14:14
3924
|
4025
LL | type T = ();
4126
| ^^ cannot infer type
4227
|
4328
= note: cannot satisfy `<Bar as Foo>::T == _`
4429

4530
error[E0284]: type annotations needed: cannot satisfy `<Bar as Foo>::{opaque#0}<'_> == impl Future<Output = ()>`
46-
--> $DIR/coherence-constrained.rs:18:5
31+
--> $DIR/coherence-constrained.rs:17:5
4732
|
4833
LL | async fn foo(&self) {}
4934
| ^^^^^^^^^^^^^^^^^^^ cannot satisfy `<Bar as Foo>::{opaque#0}<'_> == impl Future<Output = ()>`
@@ -56,31 +41,16 @@ LL | async fn foo(&self) -> Self::T;
5641
|
5742
= note: cannot satisfy `<Bar as Foo>::{opaque#0}<'_> == _`
5843

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-
7444
error[E0284]: type annotations needed
75-
--> $DIR/coherence-constrained.rs:26:14
45+
--> $DIR/coherence-constrained.rs:24:14
7646
|
7747
LL | type T = ();
7848
| ^^ cannot infer type
7949
|
8050
= note: cannot satisfy `<Bar as Foo>::T == _`
8151

8252
error[E0284]: type annotations needed: cannot satisfy `<Bar as Foo>::{opaque#0}<'_> == impl Future<Output = ()>`
83-
--> $DIR/coherence-constrained.rs:29:5
53+
--> $DIR/coherence-constrained.rs:27:5
8454
|
8555
LL | async fn foo(&self) {}
8656
| ^^^^^^^^^^^^^^^^^^^ cannot satisfy `<Bar as Foo>::{opaque#0}<'_> == impl Future<Output = ()>`
@@ -94,7 +64,7 @@ LL | async fn foo(&self) -> Self::T;
9464
= note: cannot satisfy `<Bar as Foo>::{opaque#0}<'_> == _`
9565
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
9666

97-
error: aborting due to 11 previous errors
67+
error: aborting due to 9 previous errors
9868

99-
Some errors have detailed explanations: E0119, E0283, E0284.
69+
Some errors have detailed explanations: E0119, E0284.
10070
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,14 +5,11 @@ trait From {
55
}
66

77
impl From for () {
8-
//~^ ERROR type annotations needed
98
fn from() {}
109
}
1110

1211
impl From for () {
1312
//~^ ERROR conflicting implementations of trait
14-
//~| ERROR type annotations needed
15-
fn from() {}
1613
}
1714

1815
fn bar() -> impl core::future::Future<Output = ()> {
+4-34
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,14 @@
11
error[E0119]: conflicting implementations of trait `From` for type `()`
2-
--> $DIR/issue-67651.rs:12:1
2+
--> $DIR/issue-67651.rs:11:1
33
|
44
LL | impl From for () {
55
| ---------------- first implementation here
66
...
77
LL | impl From for () {
88
| ^^^^^^^^^^^^^^^^ conflicting implementation for `()`
99

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-
4010
error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type
41-
--> $DIR/issue-67651.rs:19:18
11+
--> $DIR/issue-67651.rs:16:18
4212
|
4313
LL | fn from();
4414
| ---------- `From::from` defined here
@@ -51,7 +21,7 @@ help: use a fully-qualified path to a specific available implementation
5121
LL | async move { </* self type */ as From>::from() }
5222
| +++++++++++++++++++ +
5323

54-
error: aborting due to 4 previous errors
24+
error: aborting due to 2 previous errors
5525

56-
Some errors have detailed explanations: E0119, E0283, E0790.
26+
Some errors have detailed explanations: E0119, E0790.
5727
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,7 +14,6 @@ impl Go for MyThingy {
1414

1515
impl GoMut for MyThingy {
1616
//~^ ERROR E0119
17-
//~| ERROR E0283
1817
fn go_mut(&mut self, arg: isize) { }
1918
}
2019

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

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

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
11+
error: aborting due to 1 previous error
2712

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

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

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ struct MyType {
2121

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

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

+3-18
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,8 @@ LL | impl<T> MyTrait<T> for T {
77
LL | impl MyTrait<MyType> for MyType {
88
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `MyType`
99

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-
2510
error[E0053]: method `get` has an incompatible type for trait
26-
--> $DIR/coherence-blanket-conflicts-with-specific-multidispatch.rs:25:22
11+
--> $DIR/coherence-blanket-conflicts-with-specific-multidispatch.rs:24:22
2712
|
2813
LL | fn get(&self) -> usize { (*self).clone() }
2914
| ^^^^^
@@ -39,7 +24,7 @@ LL | fn get(&self) -> T;
3924
= note: expected signature `fn(&MyType) -> MyType`
4025
found signature `fn(&MyType) -> usize`
4126

42-
error: aborting due to 3 previous errors
27+
error: aborting due to 2 previous errors
4328

44-
Some errors have detailed explanations: E0053, E0119, E0283.
29+
Some errors have detailed explanations: E0053, E0119.
4530
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,7 +19,6 @@ struct MyType {
1919

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

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

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

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
10+
error: aborting due to 1 previous error
2611

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

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

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

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

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

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

10-
error[E0283]: type annotations needed: cannot satisfy `MyType: MyTrait`
11-
--> $DIR/coherence-blanket-conflicts-with-specific.rs:19: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.rs:11:1
18-
|
19-
LL | impl<T> MyTrait for T {
20-
| ^^^^^^^^^^^^^^^^^^^^^
21-
...
22-
LL | impl MyTrait for MyType {
23-
| ^^^^^^^^^^^^^^^^^^^^^^^
24-
25-
error: aborting due to 2 previous errors
10+
error: aborting due to 1 previous error
2611

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

tests/ui/coherence/coherence-conflicting-negative-trait-impl.rs

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ trait MyTrait {}
77
struct TestType<T>(::std::marker::PhantomData<T>);
88

99
unsafe impl<T: MyTrait + 'static> Send for TestType<T> {}
10-
//~^ ERROR: type annotations needed
1110

1211
impl<T: MyTrait> !Send for TestType<T> {} //~ ERROR found both positive and negative implementation
1312

0 commit comments

Comments
 (0)