Skip to content

Commit

Permalink
Rollup merge of rust-lang#35370 - razielgn:updated-e0306-to-new-forma…
Browse files Browse the repository at this point in the history
…t, r=jonathandturner

Updated E0306 to new format.

Part of rust-lang#35233.
Fixes rust-lang#35315.

r? @jonathandturner
  • Loading branch information
Jonathan Turner authored Aug 5, 2016
2 parents 320e3dc + b7468fa commit 3dd50b5
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 19 deletions.
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`
}

0 comments on commit 3dd50b5

Please sign in to comment.