Add E0605
This commit is contained in:
parent
d5977df1c1
commit
0e4b8ffccd
5 changed files with 70 additions and 13 deletions
|
|
@ -209,13 +209,13 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> {
|
|||
"only `u8` can be cast as `char`, not `{}`", self.expr_ty).emit();
|
||||
}
|
||||
CastError::NonScalar => {
|
||||
fcx.type_error_message(self.span,
|
||||
|actual| {
|
||||
format!("non-scalar cast: `{}` as `{}`",
|
||||
actual,
|
||||
fcx.ty_to_string(self.cast_ty))
|
||||
},
|
||||
self.expr_ty);
|
||||
struct_span_err!(fcx.tcx.sess, self.span, E0605,
|
||||
"non-scalar cast: `{}` as `{}`",
|
||||
self.expr_ty,
|
||||
fcx.ty_to_string(self.cast_ty))
|
||||
.note("an `as` expression can only be used to convert between \
|
||||
primitive types. Consider using the `From` trait")
|
||||
.emit();
|
||||
}
|
||||
CastError::IllegalCast => {
|
||||
fcx.type_error_message(self.span,
|
||||
|
|
|
|||
|
|
@ -4225,6 +4225,32 @@ assert!(c, 'V');
|
|||
```
|
||||
"##,
|
||||
|
||||
E0605: r##"
|
||||
An invalid cast was attempted.
|
||||
|
||||
Erroneous code examples:
|
||||
|
||||
```compile_fail,E0605
|
||||
let x = 0u8;
|
||||
x as Vec<u8>; // error: non-scalar cast: `u8` as `std::vec::Vec<u8>`
|
||||
|
||||
// Another example
|
||||
|
||||
let v = 0 as *const u8; // So here, `v` is a `*const u8`.
|
||||
v as &u8; // error: non-scalar cast: `*const u8` as `&u8`
|
||||
```
|
||||
|
||||
Only primitive types cast be casted into each others. Examples:
|
||||
|
||||
```
|
||||
let x = 0u8;
|
||||
x as u32; // ok!
|
||||
|
||||
let v = 0 as *const u8;
|
||||
v as *const i8; // ok!
|
||||
```
|
||||
"##,
|
||||
|
||||
E0609: r##"
|
||||
Attempted to access a non-existent field in a struct.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue