]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0378.md
Re-use std::sealed::Sealed in os/linux/process.
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0378.md
1 The `DispatchFromDyn` trait was implemented on something which is not a pointer
2 or a newtype wrapper around a pointer.
3
4 Erroneous code example:
5
6 ```compile_fail,E0378
7 #![feature(dispatch_from_dyn)]
8 use std::ops::DispatchFromDyn;
9
10 struct WrapperExtraField<T> {
11     ptr: T,
12     extra_stuff: i32,
13 }
14
15 impl<T, U> DispatchFromDyn<WrapperExtraField<U>> for WrapperExtraField<T>
16 where
17     T: DispatchFromDyn<U>,
18 {}
19 ```
20
21 The `DispatchFromDyn` trait currently can only be implemented for
22 builtin pointer types and structs that are newtype wrappers around them
23 — that is, the struct must have only one field (except for`PhantomData`),
24 and that field must itself implement `DispatchFromDyn`.
25
26 ```
27 #![feature(dispatch_from_dyn, unsize)]
28 use std::{
29     marker::Unsize,
30     ops::DispatchFromDyn,
31 };
32
33 struct Ptr<T: ?Sized>(*const T);
34
35 impl<T: ?Sized, U: ?Sized> DispatchFromDyn<Ptr<U>> for Ptr<T>
36 where
37     T: Unsize<U>,
38 {}
39 ```
40
41 Another example:
42
43 ```
44 #![feature(dispatch_from_dyn)]
45 use std::{
46     ops::DispatchFromDyn,
47     marker::PhantomData,
48 };
49
50 struct Wrapper<T> {
51     ptr: T,
52     _phantom: PhantomData<()>,
53 }
54
55 impl<T, U> DispatchFromDyn<Wrapper<U>> for Wrapper<T>
56 where
57     T: DispatchFromDyn<U>,
58 {}
59 ```