Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated E0306 to new format. #35370

Merged
merged 1 commit into from
Aug 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/librustc_const_eval/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
14 changes: 11 additions & 3 deletions src/test/compile-fail/E0306.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
}
30 changes: 24 additions & 6 deletions src/test/compile-fail/const-integer-bool-ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/test/compile-fail/issue-27008.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
}
15 changes: 10 additions & 5 deletions src/test/compile-fail/repeat_count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`
}