Add E0604

This commit is contained in:
Guillaume Gomez 2017-06-07 20:58:09 +02:00
parent c9bb93576d
commit d5977df1c1
4 changed files with 33 additions and 7 deletions

View File

@ -205,12 +205,8 @@ fn report_cast_error(&self, fcx: &FnCtxt<'a, 'gcx, 'tcx>, e: CastError) {
.emit();
}
CastError::CastToChar => {
fcx.type_error_message(self.span,
|actual| {
format!("only `u8` can be cast as `char`, not `{}`",
actual)
},
self.expr_ty);
struct_span_err!(fcx.tcx.sess, self.span, E0604,
"only `u8` can be cast as `char`, not `{}`", self.expr_ty).emit();
}
CastError::NonScalar => {
fcx.type_error_message(self.span,

View File

@ -4208,6 +4208,23 @@ trait was performed.
```
"##,
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##"
Attempted to access a non-existent field in a struct.

View File

@ -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
}

View File

@ -92,7 +92,7 @@ error[E0054]: cannot cast as `bool`
|
= 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
|
51 | let _ = 0x61u32 as char;