mirror of https://github.com/rust-lang/rust.git
Add E0604
This commit is contained in:
parent
c9bb93576d
commit
d5977df1c1
|
@ -205,12 +205,8 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> {
|
||||||
.emit();
|
.emit();
|
||||||
}
|
}
|
||||||
CastError::CastToChar => {
|
CastError::CastToChar => {
|
||||||
fcx.type_error_message(self.span,
|
struct_span_err!(fcx.tcx.sess, self.span, E0604,
|
||||||
|actual| {
|
"only `u8` can be cast as `char`, not `{}`", self.expr_ty).emit();
|
||||||
format!("only `u8` can be cast as `char`, not `{}`",
|
|
||||||
actual)
|
|
||||||
},
|
|
||||||
self.expr_ty);
|
|
||||||
}
|
}
|
||||||
CastError::NonScalar => {
|
CastError::NonScalar => {
|
||||||
fcx.type_error_message(self.span,
|
fcx.type_error_message(self.span,
|
||||||
|
|
|
@ -4208,6 +4208,23 @@ println!("{}", v[2]);
|
||||||
```
|
```
|
||||||
"##,
|
"##,
|
||||||
|
|
||||||
|
E0604: r##"
|
||||||
|
A cast to `char` was attempted on another type than `u8`.
|
||||||
|
|
||||||
|
Erroneous code example:
|
||||||
|
|
||||||
|
```compile_fail,E0604
|
||||||
|
0u32 as char; // error: only `u8` can be cast as `char`, not `u32`
|
||||||
|
```
|
||||||
|
|
||||||
|
As the error message indicates, only `u8` can be casted into `char`. Example:
|
||||||
|
|
||||||
|
```
|
||||||
|
let c = 86u8 as char; // ok!
|
||||||
|
assert!(c, 'V');
|
||||||
|
```
|
||||||
|
"##,
|
||||||
|
|
||||||
E0609: r##"
|
E0609: r##"
|
||||||
Attempted to access a non-existent field in a struct.
|
Attempted to access a non-existent field in a struct.
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
// 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() {
|
||||||
|
1u32 as char; //~ ERROR E0604
|
||||||
|
}
|
|
@ -92,7 +92,7 @@ error[E0054]: cannot cast as `bool`
|
||||||
|
|
|
|
||||||
= help: compare with zero instead
|
= help: compare with zero instead
|
||||||
|
|
||||||
error: only `u8` can be cast as `char`, not `u32`
|
error[E0604]: only `u8` can be cast as `char`, not `u32`
|
||||||
--> $DIR/cast-rfc0401.rs:51:13
|
--> $DIR/cast-rfc0401.rs:51:13
|
||||||
|
|
|
|
||||||
51 | let _ = 0x61u32 as char;
|
51 | let _ = 0x61u32 as char;
|
||||||
|
|
Loading…
Reference in New Issue