Better error message for object type with GAT
This commit is contained in:
parent
690bcc6619
commit
f8e0dcbf56
3 changed files with 13 additions and 7 deletions
|
@ -548,7 +548,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
obligation.cause.span,
|
obligation.cause.span,
|
||||||
"GATs in trait object shouldn't have been considered",
|
"GATs in trait object shouldn't have been considered",
|
||||||
);
|
);
|
||||||
return Err(SelectionError::Unimplemented);
|
return Err(SelectionError::TraitNotObjectSafe(trait_predicate.trait_ref.def_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
// This maybe belongs in wf, but that can't (doesn't) handle
|
// This maybe belongs in wf, but that can't (doesn't) handle
|
||||||
|
|
|
@ -19,5 +19,5 @@ fn main() {
|
||||||
//~| ERROR the trait `Foo` cannot be made into an object
|
//~| ERROR the trait `Foo` cannot be made into an object
|
||||||
let s = i.baz();
|
let s = i.baz();
|
||||||
//~^ ERROR the trait `Foo` cannot be made into an object
|
//~^ ERROR the trait `Foo` cannot be made into an object
|
||||||
//~| ERROR the trait bound `dyn Foo: Foo`
|
//~| ERROR the trait `Foo` cannot be made into an object
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,13 +13,20 @@ LL | fn baz(&self) -> impl Debug;
|
||||||
| ^^^^^^^^^^ ...because method `baz` references an `impl Trait` type in its return type
|
| ^^^^^^^^^^ ...because method `baz` references an `impl Trait` type in its return type
|
||||||
= help: consider moving `baz` to another trait
|
= help: consider moving `baz` to another trait
|
||||||
|
|
||||||
error[E0277]: the trait bound `dyn Foo: Foo` is not satisfied
|
error[E0038]: the trait `Foo` cannot be made into an object
|
||||||
--> $DIR/object-safety.rs:20:15
|
--> $DIR/object-safety.rs:20:15
|
||||||
|
|
|
|
||||||
LL | let s = i.baz();
|
LL | let s = i.baz();
|
||||||
| ^^^ the trait `Foo` is not implemented for `dyn Foo`
|
| ^^^ `Foo` cannot be made into an object
|
||||||
|
|
|
|
||||||
= help: the trait `Foo` is implemented for `u32`
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
|
||||||
|
--> $DIR/object-safety.rs:7:22
|
||||||
|
|
|
||||||
|
LL | trait Foo {
|
||||||
|
| --- this trait cannot be made into an object...
|
||||||
|
LL | fn baz(&self) -> impl Debug;
|
||||||
|
| ^^^^^^^^^^ ...because method `baz` references an `impl Trait` type in its return type
|
||||||
|
= help: consider moving `baz` to another trait
|
||||||
|
|
||||||
error[E0038]: the trait `Foo` cannot be made into an object
|
error[E0038]: the trait `Foo` cannot be made into an object
|
||||||
--> $DIR/object-safety.rs:20:13
|
--> $DIR/object-safety.rs:20:13
|
||||||
|
@ -54,5 +61,4 @@ LL | fn baz(&self) -> impl Debug;
|
||||||
|
|
||||||
error: aborting due to 4 previous errors
|
error: aborting due to 4 previous errors
|
||||||
|
|
||||||
Some errors have detailed explanations: E0038, E0277.
|
For more information about this error, try `rustc --explain E0038`.
|
||||||
For more information about an error, try `rustc --explain E0038`.
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue