Cleanup check_cast. Fixes #21554
This also makes the cast error messages somewhat more uniform.
This commit is contained in:
parent
76fbb35831
commit
e7245252cc
7 changed files with 119 additions and 91 deletions
|
|
@ -8,5 +8,5 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// error-pattern: cast from nil: `()` as `u32`
|
||||
// error-pattern: non-scalar cast: `()` as `u32`
|
||||
fn main() { let u = (assert!(true) as u32); }
|
||||
|
|
|
|||
|
|
@ -8,5 +8,5 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// error-pattern: cast to nil: `u32` as `()`
|
||||
// error-pattern: non-scalar cast: `u32` as `()`
|
||||
fn main() { let u = 0u32 as (); }
|
||||
|
|
|
|||
|
|
@ -10,5 +10,5 @@
|
|||
|
||||
fn main() {
|
||||
let nil = ();
|
||||
let _t = nil as usize; //~ ERROR: cast from nil: `()` as `usize`
|
||||
let _t = nil as usize; //~ ERROR: non-scalar cast: `()` as `usize`
|
||||
}
|
||||
|
|
|
|||
15
src/test/compile-fail/issue-21554.rs
Normal file
15
src/test/compile-fail/issue-21554.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
// Copyright 2015 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.
|
||||
|
||||
struct Inches(i32);
|
||||
|
||||
fn main() {
|
||||
Inches as f32; //~ ERROR illegal cast; cast through an integer first
|
||||
}
|
||||
|
|
@ -11,5 +11,5 @@
|
|||
fn main() {
|
||||
let x : i16 = 22;
|
||||
((&x) as *const i16) as f32;
|
||||
//~^ ERROR: cannot cast from pointer to float directly: `*const i16` as `f32`
|
||||
//~^ ERROR illegal cast; cast through an integer first: `*const i16` as `f32`
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue