Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ?Sized bound to a supertrait listing in E0038 error documentation #65200

Merged
merged 3 commits into from
Oct 12, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/librustc/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ trait Foo {
This is similar to the second sub-error, but subtler. It happens in situations
like the following:

```compile_fail
trait Super<A> {}
```compile_fail,E0038
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

trait Super<A: ?Sized> {}

trait Trait: Super<Self> {
}
Expand All @@ -270,17 +270,21 @@ struct Foo;
impl Super<Foo> for Foo{}

impl Trait for Foo {}

fn main() {
let x: Box<dyn Trait>;
}
```

Here, the supertrait might have methods as follows:

```
trait Super<A> {
fn get_a(&self) -> A; // note that this is object safe!
trait Super<A: ?Sized> {
fn get_a(&self) -> &A; // note that this is object safe!
}
```

If the trait `Foo` was deriving from something like `Super<String>` or
If the trait `Trait` was deriving from something like `Super<String>` or
`Super<T>` (where `Foo` itself is `Foo<T>`), this is okay, because given a type
`get_a()` will definitely return an object of that type.

Expand Down