Skip to content

Commit

Permalink
Better error message for object type with GAT
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Aug 28, 2023
1 parent 690bcc6 commit f8e0dcb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
obligation.cause.span,
"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
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/impl-trait/in-trait/object-safety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ fn main() {
//~| ERROR the trait `Foo` cannot be made into an object
let s = i.baz();
//~^ 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
}
16 changes: 11 additions & 5 deletions tests/ui/impl-trait/in-trait/object-safety.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,20 @@ 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[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
|
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
--> $DIR/object-safety.rs:20:13
Expand Down Expand Up @@ -54,5 +61,4 @@ LL | fn baz(&self) -> impl Debug;

error: aborting due to 4 previous errors

Some errors have detailed explanations: E0038, E0277.
For more information about an error, try `rustc --explain E0038`.
For more information about this error, try `rustc --explain E0038`.

0 comments on commit f8e0dcb

Please sign in to comment.