.emit();
}
CastError::SizedUnsizedCast => {
- fcx.type_error_message(self.span,
- |actual| {
- format!("cannot cast thin pointer `{}` to fat pointer \
- `{}`",
- actual,
- fcx.ty_to_string(self.cast_ty))
- },
- self.expr_ty)
+ struct_span_err!(fcx.tcx.sess, self.span, E0607,
+ "cannot cast thin pointer `{}` to fat pointer `{}`",
+ self.expr_ty,
+ fcx.ty_to_string(self.cast_ty)).emit();
}
}
}
```
"##,
+E0607: r##"
+A cast between a thin and a fat pointer was attempted.
+
+Erroneous code example:
+
+```compile_fail,E0607
+let v = 0 as *const u8;
+v as *const [u8];
+```
+
+First: what are thin and fat pointers?
+
+Thin pointers are "simple" pointers that simply reference a memory address.
+
+Fat pointers are pointers referencing Dynamically Sized Types (also called DST).
+They 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.
+
+So in order to fix this error, don't try to cast directly between thin and fat
+pointers.
+"##,
+
E0609: r##"
Attempted to access a non-existent field in a struct.
--- /dev/null
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn main() {
+ let v = 0 as *const u8;
+ v as *const [u8]; //~ ERROR E0607
+}
61 | let _ = 42usize as *const [u8];
| ^^^^^^^^^^^^^^^^^^^^^^
-error: cannot cast thin pointer `*const u8` to fat pointer `*const [u8]`
+error[E0607]: cannot cast thin pointer `*const u8` to fat pointer `*const [u8]`
--> $DIR/cast-rfc0401.rs:62:13
|
62 | let _ = v as *const [u8];