summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_error_codes/src/error_codes/E0378.md
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_error_codes/src/error_codes/E0378.md')
-rw-r--r--compiler/rustc_error_codes/src/error_codes/E0378.md59
1 files changed, 59 insertions, 0 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes/E0378.md b/compiler/rustc_error_codes/src/error_codes/E0378.md
new file mode 100644
index 000000000..c6fe997f3
--- /dev/null
+++ b/compiler/rustc_error_codes/src/error_codes/E0378.md
@@ -0,0 +1,59 @@
+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`.
+
+```
+#![feature(dispatch_from_dyn, unsize)]
+use std::{
+ marker::Unsize,
+ ops::DispatchFromDyn,
+};
+
+struct Ptr<T: ?Sized>(*const T);
+
+impl<T: ?Sized, U: ?Sized> DispatchFromDyn<Ptr<U>> for Ptr<T>
+where
+ T: Unsize<U>,
+{}
+```
+
+Another example:
+
+```
+#![feature(dispatch_from_dyn)]
+use std::{
+ ops::DispatchFromDyn,
+ marker::PhantomData,
+};
+
+struct Wrapper<T> {
+ ptr: T,
+ _phantom: PhantomData<()>,
+}
+
+impl<T, U> DispatchFromDyn<Wrapper<U>> for Wrapper<T>
+where
+ T: DispatchFromDyn<U>,
+{}
+```