From ba49ed01f0abd2c18313611ad43424ca827c1498 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 2 Mar 2020 13:10:24 +0100 Subject: [PATCH] clean up E0378 explanation --- src/librustc_error_codes/error_codes/E0378.md | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/librustc_error_codes/error_codes/E0378.md b/src/librustc_error_codes/error_codes/E0378.md index 311483c8900be..7f4374738de28 100644 --- a/src/librustc_error_codes/error_codes/E0378.md +++ b/src/librustc_error_codes/error_codes/E0378.md @@ -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 { + ptr: T, + extra_stuff: i32, +} + +impl DispatchFromDyn> for WrapperExtraField +where + T: DispatchFromDyn, +{} +``` + 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, {} ``` - -Example of illegal `DispatchFromDyn` implementation -(illegal because of extra field) - -```compile-fail,E0378 -#![feature(dispatch_from_dyn)] -use std::ops::DispatchFromDyn; - -struct WrapperExtraField { - ptr: T, - extra_stuff: i32, -} - -impl DispatchFromDyn> for WrapperExtraField -where - T: DispatchFromDyn, -{} -```