Skip to content

Commit

Permalink
Stop bailing out from compilation just because there were incoherent …
Browse files Browse the repository at this point in the history
…traits
  • Loading branch information
oli-obk committed Feb 1, 2024
1 parent 11f32b7 commit ad42fa1
Show file tree
Hide file tree
Showing 135 changed files with 2,213 additions and 251 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,11 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {

tcx.sess.time("coherence_checking", || {
// Check impls constrain their parameters
let mut res =
let res =
tcx.hir().try_par_for_each_module(|module| tcx.ensure().check_mod_impl_wf(module));

for &trait_def_id in tcx.all_local_trait_impls(()).keys() {
res = res.and(tcx.ensure().coherent_trait(trait_def_id));
let _ = tcx.ensure().coherent_trait(trait_def_id);
}
// these queries are executed for side-effects (error reporting):
res.and(tcx.ensure().crate_inherent_impls(()))
Expand Down
1 change: 1 addition & 0 deletions tests/ui/associated-consts/issue-105330.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ fn foo<A: TraitWAssocConst<A=32>>() { //~ ERROR E0658

fn main<A: TraitWAssocConst<A=32>>() {
//~^ ERROR E0658
//~| ERROR E0131
foo::<Demo>();
}
12 changes: 9 additions & 3 deletions tests/ui/associated-consts/issue-105330.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ LL | impl TraitWAssocConst for impl Demo {
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods

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

error: aborting due to 6 previous errors

Some errors have detailed explanations: E0404, E0562, E0658.
For more information about an error, try `rustc --explain E0404`.
Some errors have detailed explanations: E0131, E0404, E0562, E0658.
For more information about an error, try `rustc --explain E0131`.
8 changes: 8 additions & 0 deletions tests/ui/async-await/in-trait/coherence-constrained.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,31 @@ trait Foo {
type T;

async fn foo(&self) -> Self::T;
//~^ ERROR type annotations needed
//~| ERROR type annotations needed
}

struct Bar;

impl Foo for Bar {
//~^ ERROR type annotations needed
type T = ();
//~^ ERROR type annotations needed

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

impl Foo for Bar {
//~^ ERROR conflicting implementations of trait `Foo` for type `Bar`
//~| ERROR type annotations needed
type T = ();
//~^ ERROR type annotations needed

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

fn main() {}
85 changes: 80 additions & 5 deletions tests/ui/async-await/in-trait/coherence-constrained.stderr
Original file line number Diff line number Diff line change
@@ -1,25 +1,100 @@
error[E0284]: type annotations needed: cannot satisfy `<Bar as Foo>::T == ()`
--> $DIR/coherence-constrained.rs:14:5
--> $DIR/coherence-constrained.rs:18:5
|
LL | async fn foo(&self) {}
| ^^^^^^^^^^^^^^^^^^^ cannot satisfy `<Bar as Foo>::T == ()`

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

error[E0119]: conflicting implementations of trait `Foo` for type `Bar`
--> $DIR/coherence-constrained.rs:18:1
--> $DIR/coherence-constrained.rs:23:1
|
LL | impl Foo for Bar {
| ---------------- first implementation here
...
LL | impl Foo for Bar {
| ^^^^^^^^^^^^^^^^ conflicting implementation for `Bar`

error: aborting due to 3 previous errors
error[E0283]: type annotations needed: cannot satisfy `Bar: Foo`
--> $DIR/coherence-constrained.rs:13:14
|
LL | impl Foo for Bar {
| ^^^
|
note: multiple `impl`s satisfying `Bar: Foo` found
--> $DIR/coherence-constrained.rs:13:1
|
LL | impl Foo for Bar {
| ^^^^^^^^^^^^^^^^
...
LL | impl Foo for Bar {
| ^^^^^^^^^^^^^^^^

error[E0284]: type annotations needed
--> $DIR/coherence-constrained.rs:15:14
|
LL | type T = ();
| ^^ cannot infer type
|
= note: cannot satisfy `<Bar as Foo>::T == _`

error[E0284]: type annotations needed: cannot satisfy `<Bar as Foo>::{opaque#0}<'_> == impl Future<Output = ()>`
--> $DIR/coherence-constrained.rs:18:5
|
LL | async fn foo(&self) {}
| ^^^^^^^^^^^^^^^^^^^ cannot satisfy `<Bar as Foo>::{opaque#0}<'_> == impl Future<Output = ()>`

error[E0284]: type annotations needed
--> $DIR/coherence-constrained.rs:6:5
|
LL | async fn foo(&self) -> Self::T;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type
|
= note: cannot satisfy `<Bar as Foo>::{opaque#0}<'_> == _`

error[E0283]: type annotations needed: cannot satisfy `Bar: Foo`
--> $DIR/coherence-constrained.rs:23:14
|
LL | impl Foo for Bar {
| ^^^
|
note: multiple `impl`s satisfying `Bar: Foo` found
--> $DIR/coherence-constrained.rs:13:1
|
LL | impl Foo for Bar {
| ^^^^^^^^^^^^^^^^
...
LL | impl Foo for Bar {
| ^^^^^^^^^^^^^^^^

error[E0284]: type annotations needed
--> $DIR/coherence-constrained.rs:26:14
|
LL | type T = ();
| ^^ cannot infer type
|
= note: cannot satisfy `<Bar as Foo>::T == _`

error[E0284]: type annotations needed: cannot satisfy `<Bar as Foo>::{opaque#0}<'_> == impl Future<Output = ()>`
--> $DIR/coherence-constrained.rs:29:5
|
LL | async fn foo(&self) {}
| ^^^^^^^^^^^^^^^^^^^ cannot satisfy `<Bar as Foo>::{opaque#0}<'_> == impl Future<Output = ()>`

error[E0284]: type annotations needed
--> $DIR/coherence-constrained.rs:6:5
|
LL | async fn foo(&self) -> Self::T;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type
|
= note: cannot satisfy `<Bar as Foo>::{opaque#0}<'_> == _`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 11 previous errors

Some errors have detailed explanations: E0119, E0284.
Some errors have detailed explanations: E0119, E0283, E0284.
For more information about an error, try `rustc --explain E0119`.
3 changes: 3 additions & 0 deletions tests/ui/async-await/issue-67651.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@ trait From {
}

impl From for () {
//~^ ERROR type annotations needed
fn from() {}
}

impl From for () {
//~^ ERROR conflicting implementations of trait
//~| ERROR type annotations needed
fn from() {}
}

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

fn main() {}
51 changes: 48 additions & 3 deletions tests/ui/async-await/issue-67651.stderr
Original file line number Diff line number Diff line change
@@ -1,12 +1,57 @@
error[E0119]: conflicting implementations of trait `From` for type `()`
--> $DIR/issue-67651.rs:11:1
--> $DIR/issue-67651.rs:12:1
|
LL | impl From for () {
| ---------------- first implementation here
...
LL | impl From for () {
| ^^^^^^^^^^^^^^^^ conflicting implementation for `()`

error: aborting due to 1 previous error
error[E0283]: type annotations needed: cannot satisfy `(): From`
--> $DIR/issue-67651.rs:7:15
|
LL | impl From for () {
| ^^
|
note: multiple `impl`s satisfying `(): From` found
--> $DIR/issue-67651.rs:7:1
|
LL | impl From for () {
| ^^^^^^^^^^^^^^^^
...
LL | impl From for () {
| ^^^^^^^^^^^^^^^^

error[E0283]: type annotations needed: cannot satisfy `(): From`
--> $DIR/issue-67651.rs:12:15
|
LL | impl From for () {
| ^^
|
note: multiple `impl`s satisfying `(): From` found
--> $DIR/issue-67651.rs:7:1
|
LL | impl From for () {
| ^^^^^^^^^^^^^^^^
...
LL | impl From for () {
| ^^^^^^^^^^^^^^^^

error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type
--> $DIR/issue-67651.rs:19:18
|
LL | fn from();
| ---------- `From::from` defined here
...
LL | async move { From::from() }
| ^^^^^^^^^^^^ cannot call associated function of trait
|
help: use a fully-qualified path to a specific available implementation
|
LL | async move { </* self type */ as From>::from() }
| +++++++++++++++++++ +

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0119`.
Some errors have detailed explanations: E0119, E0283, E0790.
For more information about an error, try `rustc --explain E0119`.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ impl Go for MyThingy {

impl GoMut for MyThingy {
//~^ ERROR E0119
//~| ERROR E0283
fn go_mut(&mut self, arg: isize) { }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@ LL | impl GoMut for MyThingy {
- impl<G> GoMut for G
where G: Go;

error: aborting due to 1 previous error
error[E0283]: type annotations needed: cannot satisfy `MyThingy: GoMut`
--> $DIR/coherence-blanket-conflicts-with-specific-cross-crate.rs:15:16
|
LL | impl GoMut for MyThingy {
| ^^^^^^^^
|
note: multiple `impl`s satisfying `MyThingy: GoMut` found
--> $DIR/coherence-blanket-conflicts-with-specific-cross-crate.rs:15:1
|
LL | impl GoMut for MyThingy {
| ^^^^^^^^^^^^^^^^^^^^^^^
= note: and another `impl` found in the `go_trait` crate:
- impl<G> GoMut for G
where G: Go;

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0119`.
Some errors have detailed explanations: E0119, E0283.
For more information about an error, try `rustc --explain E0119`.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ struct MyType {

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

fn main() { }
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,39 @@ LL | impl<T> MyTrait<T> for T {
LL | impl MyTrait<MyType> for MyType {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `MyType`

error: aborting due to 1 previous error
error[E0283]: type annotations needed: cannot satisfy `MyType: MyTrait<MyType>`
--> $DIR/coherence-blanket-conflicts-with-specific-multidispatch.rs:22:26
|
LL | impl MyTrait<MyType> for MyType {
| ^^^^^^
|
note: multiple `impl`s satisfying `MyType: MyTrait<MyType>` found
--> $DIR/coherence-blanket-conflicts-with-specific-multidispatch.rs:11:1
|
LL | impl<T> MyTrait<T> for T {
| ^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | impl MyTrait<MyType> for MyType {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0053]: method `get` has an incompatible type for trait
--> $DIR/coherence-blanket-conflicts-with-specific-multidispatch.rs:25:22
|
LL | fn get(&self) -> usize { (*self).clone() }
| ^^^^^
| |
| expected `MyType`, found `usize`
| help: change the output type to match the trait: `MyType`
|
note: type in trait
--> $DIR/coherence-blanket-conflicts-with-specific-multidispatch.rs:8:22
|
LL | fn get(&self) -> T;
| ^
= note: expected signature `fn(&MyType) -> MyType`
found signature `fn(&MyType) -> usize`

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0119`.
Some errors have detailed explanations: E0053, E0119, E0283.
For more information about an error, try `rustc --explain E0053`.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct MyType {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@ LL | impl<T:OtherTrait> MyTrait for T {
LL | impl MyTrait for MyType {
| ^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `MyType`

error: aborting due to 1 previous error
error[E0283]: type annotations needed: cannot satisfy `MyType: MyTrait`
--> $DIR/coherence-blanket-conflicts-with-specific-trait.rs:20:18
|
LL | impl MyTrait for MyType {
| ^^^^^^
|
note: multiple `impl`s satisfying `MyType: MyTrait` found
--> $DIR/coherence-blanket-conflicts-with-specific-trait.rs:12:1
|
LL | impl<T:OtherTrait> MyTrait for T {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | impl MyTrait for MyType {
| ^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0119`.
Some errors have detailed explanations: E0119, E0283.
For more information about an error, try `rustc --explain E0119`.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct MyType {

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

Expand Down
Loading

0 comments on commit ad42fa1

Please sign in to comment.