Add explanation for E0607
This commit is contained in:
parent
4e68e2a41a
commit
fdfb9a2963
1 changed files with 25 additions and 4 deletions
|
|
@ -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 => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue