Rollup merge of #35370 - razielgn:updated-e0306-to-new-format, r=jonathandturner
Updated E0306 to new format. Part of #35233. Fixes #35315. r? @jonathandturner
This commit is contained in:
commit
b722358860
src
librustc_const_eval
test/compile-fail
@ -1337,10 +1337,13 @@ pub fn eval_length<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
Ok(val as usize)
|
||||
},
|
||||
Ok(const_val) => {
|
||||
span_err!(tcx.sess, count_expr.span, E0306,
|
||||
"expected usize for {}, found {}",
|
||||
reason,
|
||||
const_val.description());
|
||||
struct_span_err!(tcx.sess, count_expr.span, E0306,
|
||||
"expected `usize` for {}, found {}",
|
||||
reason,
|
||||
const_val.description())
|
||||
.span_label(count_expr.span, &format!("expected `usize`"))
|
||||
.emit();
|
||||
|
||||
Err(ErrorReported)
|
||||
}
|
||||
Err(err) => {
|
||||
|
@ -8,9 +8,17 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
const A: [u32; "hello"] = []; //~ ERROR E0306
|
||||
const B: [u32; true] = []; //~ ERROR E0306
|
||||
const C: [u32; 0.0] = []; //~ ERROR E0306
|
||||
const A: [u32; "hello"] = [];
|
||||
//~^ ERROR expected `usize` for array length, found string literal [E0306]
|
||||
//~| NOTE expected `usize`
|
||||
|
||||
const B: [u32; true] = [];
|
||||
//~^ ERROR expected `usize` for array length, found boolean [E0306]
|
||||
//~| NOTE expected `usize`
|
||||
|
||||
const C: [u32; 0.0] = [];
|
||||
//~^ ERROR expected `usize` for array length, found float [E0306]
|
||||
//~| NOTE expected `usize`
|
||||
|
||||
fn main() {
|
||||
}
|
||||
|
@ -25,17 +25,35 @@ const X3: usize = -42 && -39; //~ ERROR E0080
|
||||
const ARR3: [i32; X3] = [99; 6]; //~ NOTE: for array length here
|
||||
|
||||
const Y: usize = 42.0 == 42.0;
|
||||
const ARRR: [i32; Y] = [99; 1]; //~ ERROR: expected usize for array length
|
||||
const ARRR: [i32; Y] = [99; 1];
|
||||
//~^ ERROR: expected `usize` for array length, found boolean [E0306]
|
||||
//~| NOTE expected `usize`
|
||||
|
||||
const Y1: usize = 42.0 >= 42.0;
|
||||
const ARRR1: [i32; Y] = [99; 1]; //~ ERROR: expected usize for array length
|
||||
const ARRR1: [i32; Y] = [99; 1];
|
||||
//~^ ERROR: expected `usize` for array length, found boolean [E0306]
|
||||
//~| NOTE expected `usize`
|
||||
|
||||
const Y2: usize = 42.0 <= 42.0;
|
||||
const ARRR2: [i32; Y] = [99; 1]; //~ ERROR: expected usize for array length
|
||||
const ARRR2: [i32; Y] = [99; 1];
|
||||
//~^ ERROR: expected `usize` for array length, found boolean [E0306]
|
||||
//~| NOTE expected `usize`
|
||||
|
||||
const Y3: usize = 42.0 > 42.0;
|
||||
const ARRR3: [i32; Y] = [99; 0]; //~ ERROR: expected usize for array length
|
||||
const ARRR3: [i32; Y] = [99; 0];
|
||||
//~^ ERROR: expected `usize` for array length, found boolean [E0306]
|
||||
//~| NOTE expected `usize`
|
||||
|
||||
const Y4: usize = 42.0 < 42.0;
|
||||
const ARRR4: [i32; Y] = [99; 0]; //~ ERROR: expected usize for array length
|
||||
const ARRR4: [i32; Y] = [99; 0];
|
||||
//~^ ERROR: expected `usize` for array length, found boolean [E0306]
|
||||
//~| NOTE expected `usize`
|
||||
|
||||
const Y5: usize = 42.0 != 42.0;
|
||||
const ARRR5: [i32; Y] = [99; 0]; //~ ERROR: expected usize for array length
|
||||
const ARRR5: [i32; Y] = [99; 0];
|
||||
//~^ ERROR: expected `usize` for array length, found boolean [E0306]
|
||||
//~| NOTE expected `usize`
|
||||
|
||||
|
||||
fn main() {
|
||||
let _ = ARR;
|
||||
|
@ -16,5 +16,6 @@ fn main() {
|
||||
//~| expected type `usize`
|
||||
//~| found type `S`
|
||||
//~| expected usize, found struct `S`
|
||||
//~| ERROR expected usize for repeat count, found struct
|
||||
//~| ERROR expected `usize` for repeat count, found struct [E0306]
|
||||
//~| expected `usize`
|
||||
}
|
||||
|
@ -20,23 +20,27 @@ fn main() {
|
||||
//~| expected type `usize`
|
||||
//~| found type `()`
|
||||
//~| expected usize, found ()
|
||||
//~| ERROR expected usize for repeat count, found tuple [E0306]
|
||||
//~| ERROR expected `usize` for repeat count, found tuple [E0306]
|
||||
//~| expected `usize`
|
||||
let c = [0; true];
|
||||
//~^ ERROR mismatched types
|
||||
//~| expected usize, found bool
|
||||
//~| ERROR expected usize for repeat count, found boolean [E0306]
|
||||
//~| ERROR expected `usize` for repeat count, found boolean [E0306]
|
||||
//~| expected `usize`
|
||||
let d = [0; 0.5];
|
||||
//~^ ERROR mismatched types
|
||||
//~| expected type `usize`
|
||||
//~| found type `{float}`
|
||||
//~| expected usize, found floating-point variable
|
||||
//~| ERROR expected usize for repeat count, found float [E0306]
|
||||
//~| ERROR expected `usize` for repeat count, found float [E0306]
|
||||
//~| expected `usize`
|
||||
let e = [0; "foo"];
|
||||
//~^ ERROR mismatched types
|
||||
//~| expected type `usize`
|
||||
//~| found type `&'static str`
|
||||
//~| expected usize, found &-ptr
|
||||
//~| ERROR expected usize for repeat count, found string literal [E0306]
|
||||
//~| ERROR expected `usize` for repeat count, found string literal [E0306]
|
||||
//~| expected `usize`
|
||||
let f = [0; -4_isize];
|
||||
//~^ ERROR constant evaluation error
|
||||
//~| expected usize, found isize
|
||||
@ -55,5 +59,6 @@ fn main() {
|
||||
//~| expected type `usize`
|
||||
//~| found type `main::G`
|
||||
//~| expected usize, found struct `main::G`
|
||||
//~| ERROR expected usize for repeat count, found struct [E0306]
|
||||
//~| ERROR expected `usize` for repeat count, found struct [E0306]
|
||||
//~| expected `usize`
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user