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

clean up E0378 explanation #69634

Merged
merged 1 commit into from
Mar 3, 2020
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
42 changes: 22 additions & 20 deletions src/librustc_error_codes/error_codes/E0378.md
Original file line number Diff line number Diff line change
@@ -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::{
Expand All @@ -20,6 +38,8 @@ where
{}
```

Another example:

```
#![feature(dispatch_from_dyn)]
use std::{
Expand All @@ -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>,
{}
```