diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2018-01-21 18:20:18 -0800 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2018-01-22 15:46:50 -0800 |
| commit | fdfb9a2963952f19d9f66a8e50981478fe2bca48 (patch) | |
| tree | 04cf46ac7c1b4cb47db4cf8c45f8dfeebe707fda | |
| parent | 4e68e2a41ad20a76d48e1491706a5ec26de4bf66 (diff) | |
| download | rust-fdfb9a2963952f19d9f66a8e50981478fe2bca48.tar.gz rust-fdfb9a2963952f19d9f66a8e50981478fe2bca48.zip | |
Add explanation for E0607
| -rw-r--r-- | src/librustc_typeck/check/cast.rs | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/src/librustc_typeck/check/cast.rs b/src/librustc_typeck/check/cast.rs index d2f759f5d99..d31a99dd171 100644 --- a/src/librustc_typeck/check/cast.rs +++ b/src/librustc_typeck/check/cast.rs @@ -281,10 +281,31 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> { .emit(); } CastError::SizedUnsizedCast => { - type_error_struct!(fcx.tcx.sess, self.span, self.expr_ty, E0607, - "cannot cast thin pointer `{}` to fat pointer `{}`", - self.expr_ty, - fcx.ty_to_string(self.cast_ty)).emit(); + let mut err = type_error_struct!( + fcx.tcx.sess, + self.span, + self.expr_ty, + E0607, + "cannot cast thin pointer `{}` to fat pointer `{}`", + self.expr_ty, + fcx.ty_to_string(self.cast_ty) + ); + if fcx.tcx.sess.opts.debugging_opts.explain { + err.note( + "Thin pointers are \"simple\" pointers: they are purely a reference to a \ + memory address.\n\n\ + Fat pointers are pointers referencing \"Dynamically Sized Types\" (also \ + called DST). DST don't have a statically known size, therefore they can \ + only exist behind some kind of pointers that contain additional \ + information. Slices and trait objects are DSTs. In the case of slices, \ + the additional information the fat pointer holds is their size."); + err.note("to fix this error, don't try to cast directly between thin and fat \ + pointers"); + err.help("for more information about casts, take a look at [The Book]\ + (https://doc.rust-lang.org/book/first-edition/\ + casting-between-types.html)"); + } + err.emit(); } CastError::UnknownCastPtrKind | CastError::UnknownExprPtrKind => { |
