Rollup merge of #65200 - xfix:patch-20, r=GuillaumeGomez
Add ?Sized bound to a supertrait listing in E0038 error documentation This example failed to compile because of implicit `Sized` bound for `A` parameter that wasn't required by `Trait`.
This commit is contained in:
commit
6687edcbef
@ -259,8 +259,8 @@ trait Foo {
|
|||||||
This is similar to the second sub-error, but subtler. It happens in situations
|
This is similar to the second sub-error, but subtler. It happens in situations
|
||||||
like the following:
|
like the following:
|
||||||
|
|
||||||
```compile_fail
|
```compile_fail,E0038
|
||||||
trait Super<A> {}
|
trait Super<A: ?Sized> {}
|
||||||
|
|
||||||
trait Trait: Super<Self> {
|
trait Trait: Super<Self> {
|
||||||
}
|
}
|
||||||
@ -270,17 +270,21 @@ struct Foo;
|
|||||||
impl Super<Foo> for Foo{}
|
impl Super<Foo> for Foo{}
|
||||||
|
|
||||||
impl Trait for Foo {}
|
impl Trait for Foo {}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let x: Box<dyn Trait>;
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Here, the supertrait might have methods as follows:
|
Here, the supertrait might have methods as follows:
|
||||||
|
|
||||||
```
|
```
|
||||||
trait Super<A> {
|
trait Super<A: ?Sized> {
|
||||||
fn get_a(&self) -> A; // note that this is object safe!
|
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
|
`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.
|
`get_a()` will definitely return an object of that type.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user