]> git.lizzy.rs Git - rust.git/blob - src/librustc_error_codes/error_codes/E0378.md
Update const_forget.rs
[rust.git] / src / librustc_error_codes / error_codes / E0378.md
1 The `DispatchFromDyn` trait currently can only be implemented for
2 builtin pointer types and structs that are newtype wrappers around them
3 — that is, the struct must have only one field (except for`PhantomData`),
4 and that field must itself implement `DispatchFromDyn`.
5
6 Examples:
7
8 ```
9 #![feature(dispatch_from_dyn, unsize)]
10 use std::{
11     marker::Unsize,
12     ops::DispatchFromDyn,
13 };
14
15 struct Ptr<T: ?Sized>(*const T);
16
17 impl<T: ?Sized, U: ?Sized> DispatchFromDyn<Ptr<U>> for Ptr<T>
18 where
19     T: Unsize<U>,
20 {}
21 ```
22
23 ```
24 #![feature(dispatch_from_dyn)]
25 use std::{
26     ops::DispatchFromDyn,
27     marker::PhantomData,
28 };
29
30 struct Wrapper<T> {
31     ptr: T,
32     _phantom: PhantomData<()>,
33 }
34
35 impl<T, U> DispatchFromDyn<Wrapper<U>> for Wrapper<T>
36 where
37     T: DispatchFromDyn<U>,
38 {}
39 ```
40
41 Example of illegal `DispatchFromDyn` implementation
42 (illegal because of extra field)
43
44 ```compile-fail,E0378
45 #![feature(dispatch_from_dyn)]
46 use std::ops::DispatchFromDyn;
47
48 struct WrapperExtraField<T> {
49     ptr: T,
50     extra_stuff: i32,
51 }
52
53 impl<T, U> DispatchFromDyn<WrapperExtraField<U>> for WrapperExtraField<T>
54 where
55     T: DispatchFromDyn<U>,
56 {}
57 ```