Avoid emitting trait bound errors of incoherent traits
This commit is contained in:
parent
0984becf01
commit
7f1d523cd0
3 changed files with 17 additions and 18 deletions
|
@ -2364,6 +2364,12 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Err(guar) = self.tcx.ensure().coherent_trait(trait_ref.def_id()) {
|
||||||
|
// Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case
|
||||||
|
// other `Foo` impls are incoherent.
|
||||||
|
return guar;
|
||||||
|
}
|
||||||
|
|
||||||
// This is kind of a hack: it frequently happens that some earlier
|
// This is kind of a hack: it frequently happens that some earlier
|
||||||
// error prevents types from being fully inferred, and then we get
|
// error prevents types from being fully inferred, and then we get
|
||||||
// a bunch of uninteresting errors saying something like "<generic
|
// a bunch of uninteresting errors saying something like "<generic
|
||||||
|
@ -2659,6 +2665,14 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||||
if let Some(e) = self.tainted_by_errors() {
|
if let Some(e) = self.tainted_by_errors() {
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Err(guar) =
|
||||||
|
self.tcx.ensure().coherent_trait(self.tcx.parent(data.projection_ty.def_id))
|
||||||
|
{
|
||||||
|
// Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case
|
||||||
|
// other `Foo` impls are incoherent.
|
||||||
|
return guar;
|
||||||
|
}
|
||||||
let subst = data
|
let subst = data
|
||||||
.projection_ty
|
.projection_ty
|
||||||
.args
|
.args
|
||||||
|
|
|
@ -12,7 +12,6 @@ impl Foo for Bar {
|
||||||
type T = ();
|
type T = ();
|
||||||
|
|
||||||
async fn foo(&self) {}
|
async fn foo(&self) {}
|
||||||
//~^ ERROR type annotations needed: cannot satisfy `<Bar as Foo>::T == ()`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Foo for Bar {
|
impl Foo for Bar {
|
||||||
|
@ -20,7 +19,6 @@ impl Foo for Bar {
|
||||||
type T = ();
|
type T = ();
|
||||||
|
|
||||||
async fn foo(&self) {}
|
async fn foo(&self) {}
|
||||||
//~^ ERROR type annotations needed: cannot satisfy `<Bar as Foo>::T == ()`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -1,17 +1,5 @@
|
||||||
error[E0284]: type annotations needed: cannot satisfy `<Bar as Foo>::T == ()`
|
|
||||||
--> $DIR/coherence-constrained.rs:14: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
|
|
||||||
|
|
|
||||||
LL | async fn foo(&self) {}
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^ cannot satisfy `<Bar as Foo>::T == ()`
|
|
||||||
|
|
||||||
error[E0119]: conflicting implementations of trait `Foo` for type `Bar`
|
error[E0119]: conflicting implementations of trait `Foo` for type `Bar`
|
||||||
--> $DIR/coherence-constrained.rs:18:1
|
--> $DIR/coherence-constrained.rs:17:1
|
||||||
|
|
|
|
||||||
LL | impl Foo for Bar {
|
LL | impl Foo for Bar {
|
||||||
| ---------------- first implementation here
|
| ---------------- first implementation here
|
||||||
|
@ -19,7 +7,6 @@ LL | impl Foo for Bar {
|
||||||
LL | impl Foo for Bar {
|
LL | impl Foo for Bar {
|
||||||
| ^^^^^^^^^^^^^^^^ conflicting implementation for `Bar`
|
| ^^^^^^^^^^^^^^^^ conflicting implementation for `Bar`
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
Some errors have detailed explanations: E0119, E0284.
|
For more information about this error, try `rustc --explain E0119`.
|
||||||
For more information about an error, try `rustc --explain E0119`.
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue