From b7468fa1896e4fc4bec0bea4fecc241ab8295129 Mon Sep 17 00:00:00 2001 From: Federico Ravasio Date: Fri, 5 Aug 2016 16:54:05 +0200 Subject: [PATCH] Updated E0306 to new format. --- src/librustc_const_eval/eval.rs | 11 ++++--- src/test/compile-fail/E0306.rs | 14 +++++++-- .../compile-fail/const-integer-bool-ops.rs | 30 +++++++++++++++---- src/test/compile-fail/issue-27008.rs | 3 +- src/test/compile-fail/repeat_count.rs | 15 ++++++---- 5 files changed, 54 insertions(+), 19 deletions(-) diff --git a/src/librustc_const_eval/eval.rs b/src/librustc_const_eval/eval.rs index d424b57c93841..43d9725baaf00 100644 --- a/src/librustc_const_eval/eval.rs +++ b/src/librustc_const_eval/eval.rs @@ -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) => { diff --git a/src/test/compile-fail/E0306.rs b/src/test/compile-fail/E0306.rs index 61cc8902036ec..9ffaef7472b78 100644 --- a/src/test/compile-fail/E0306.rs +++ b/src/test/compile-fail/E0306.rs @@ -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() { } diff --git a/src/test/compile-fail/const-integer-bool-ops.rs b/src/test/compile-fail/const-integer-bool-ops.rs index 5dadd892f8352..398dc2f22150c 100644 --- a/src/test/compile-fail/const-integer-bool-ops.rs +++ b/src/test/compile-fail/const-integer-bool-ops.rs @@ -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; diff --git a/src/test/compile-fail/issue-27008.rs b/src/test/compile-fail/issue-27008.rs index ee6ec52761266..e89bff025e006 100644 --- a/src/test/compile-fail/issue-27008.rs +++ b/src/test/compile-fail/issue-27008.rs @@ -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` } diff --git a/src/test/compile-fail/repeat_count.rs b/src/test/compile-fail/repeat_count.rs index 1758b28a32482..555dd0f0c3945 100644 --- a/src/test/compile-fail/repeat_count.rs +++ b/src/test/compile-fail/repeat_count.rs @@ -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` }