Rollup merge of #69634 - GuillaumeGomez:clean-up-e0378, r=Dylan-DPC

clean up E0378 explanation

r? @Dylan-DPC
This commit is contained in:
Yuki Okushi 2020-03-03 17:50:16 +09:00 committed by GitHub
commit 9be7932d35
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,10 +1,28 @@
The `DispatchFromDyn` trait was implemented on something which is not a pointer
or a newtype wrapper around a pointer.
Erroneous code example:
```compile-fail,E0378
#![feature(dispatch_from_dyn)]
use std::ops::DispatchFromDyn;
struct WrapperExtraField<T> {
ptr: T,
extra_stuff: i32,
}
impl<T, U> DispatchFromDyn<WrapperExtraField<U>> for WrapperExtraField<T>
where
T: DispatchFromDyn<U>,
{}
```
The `DispatchFromDyn` trait currently can only be implemented for
builtin pointer types and structs that are newtype wrappers around them
— that is, the struct must have only one field (except for`PhantomData`),
and that field must itself implement `DispatchFromDyn`.
Examples:
```
#![feature(dispatch_from_dyn, unsize)]
use std::{
@ -20,6 +38,8 @@ where
{}
```
Another example:
```
#![feature(dispatch_from_dyn)]
use std::{
@ -37,21 +57,3 @@ where
T: DispatchFromDyn<U>,
{}
```
Example of illegal `DispatchFromDyn` implementation
(illegal because of extra field)
```compile-fail,E0378
#![feature(dispatch_from_dyn)]
use std::ops::DispatchFromDyn;
struct WrapperExtraField<T> {
ptr: T,
extra_stuff: i32,
}
impl<T, U> DispatchFromDyn<WrapperExtraField<U>> for WrapperExtraField<T>
where
T: DispatchFromDyn<U>,
{}
```