Skip to content

Commit b7468fa

Browse files
committed
Updated E0306 to new format.
1 parent 41fe4b7 commit b7468fa

File tree

5 files changed

+54
-19
lines changed

5 files changed

+54
-19
lines changed

src/librustc_const_eval/eval.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -1337,10 +1337,13 @@ pub fn eval_length<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
13371337
Ok(val as usize)
13381338
},
13391339
Ok(const_val) => {
1340-
span_err!(tcx.sess, count_expr.span, E0306,
1341-
"expected usize for {}, found {}",
1342-
reason,
1343-
const_val.description());
1340+
struct_span_err!(tcx.sess, count_expr.span, E0306,
1341+
"expected `usize` for {}, found {}",
1342+
reason,
1343+
const_val.description())
1344+
.span_label(count_expr.span, &format!("expected `usize`"))
1345+
.emit();
1346+
13441347
Err(ErrorReported)
13451348
}
13461349
Err(err) => {

src/test/compile-fail/E0306.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,17 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
const A: [u32; "hello"] = []; //~ ERROR E0306
12-
const B: [u32; true] = []; //~ ERROR E0306
13-
const C: [u32; 0.0] = []; //~ ERROR E0306
11+
const A: [u32; "hello"] = [];
12+
//~^ ERROR expected `usize` for array length, found string literal [E0306]
13+
//~| NOTE expected `usize`
14+
15+
const B: [u32; true] = [];
16+
//~^ ERROR expected `usize` for array length, found boolean [E0306]
17+
//~| NOTE expected `usize`
18+
19+
const C: [u32; 0.0] = [];
20+
//~^ ERROR expected `usize` for array length, found float [E0306]
21+
//~| NOTE expected `usize`
1422

1523
fn main() {
1624
}

src/test/compile-fail/const-integer-bool-ops.rs

+24-6
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,35 @@ const X3: usize = -42 && -39; //~ ERROR E0080
2525
const ARR3: [i32; X3] = [99; 6]; //~ NOTE: for array length here
2626

2727
const Y: usize = 42.0 == 42.0;
28-
const ARRR: [i32; Y] = [99; 1]; //~ ERROR: expected usize for array length
28+
const ARRR: [i32; Y] = [99; 1];
29+
//~^ ERROR: expected `usize` for array length, found boolean [E0306]
30+
//~| NOTE expected `usize`
31+
2932
const Y1: usize = 42.0 >= 42.0;
30-
const ARRR1: [i32; Y] = [99; 1]; //~ ERROR: expected usize for array length
33+
const ARRR1: [i32; Y] = [99; 1];
34+
//~^ ERROR: expected `usize` for array length, found boolean [E0306]
35+
//~| NOTE expected `usize`
36+
3137
const Y2: usize = 42.0 <= 42.0;
32-
const ARRR2: [i32; Y] = [99; 1]; //~ ERROR: expected usize for array length
38+
const ARRR2: [i32; Y] = [99; 1];
39+
//~^ ERROR: expected `usize` for array length, found boolean [E0306]
40+
//~| NOTE expected `usize`
41+
3342
const Y3: usize = 42.0 > 42.0;
34-
const ARRR3: [i32; Y] = [99; 0]; //~ ERROR: expected usize for array length
43+
const ARRR3: [i32; Y] = [99; 0];
44+
//~^ ERROR: expected `usize` for array length, found boolean [E0306]
45+
//~| NOTE expected `usize`
46+
3547
const Y4: usize = 42.0 < 42.0;
36-
const ARRR4: [i32; Y] = [99; 0]; //~ ERROR: expected usize for array length
48+
const ARRR4: [i32; Y] = [99; 0];
49+
//~^ ERROR: expected `usize` for array length, found boolean [E0306]
50+
//~| NOTE expected `usize`
51+
3752
const Y5: usize = 42.0 != 42.0;
38-
const ARRR5: [i32; Y] = [99; 0]; //~ ERROR: expected usize for array length
53+
const ARRR5: [i32; Y] = [99; 0];
54+
//~^ ERROR: expected `usize` for array length, found boolean [E0306]
55+
//~| NOTE expected `usize`
56+
3957

4058
fn main() {
4159
let _ = ARR;

src/test/compile-fail/issue-27008.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ fn main() {
1616
//~| expected type `usize`
1717
//~| found type `S`
1818
//~| expected usize, found struct `S`
19-
//~| ERROR expected usize for repeat count, found struct
19+
//~| ERROR expected `usize` for repeat count, found struct [E0306]
20+
//~| expected `usize`
2021
}

src/test/compile-fail/repeat_count.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,27 @@ fn main() {
2020
//~| expected type `usize`
2121
//~| found type `()`
2222
//~| expected usize, found ()
23-
//~| ERROR expected usize for repeat count, found tuple [E0306]
23+
//~| ERROR expected `usize` for repeat count, found tuple [E0306]
24+
//~| expected `usize`
2425
let c = [0; true];
2526
//~^ ERROR mismatched types
2627
//~| expected usize, found bool
27-
//~| ERROR expected usize for repeat count, found boolean [E0306]
28+
//~| ERROR expected `usize` for repeat count, found boolean [E0306]
29+
//~| expected `usize`
2830
let d = [0; 0.5];
2931
//~^ ERROR mismatched types
3032
//~| expected type `usize`
3133
//~| found type `{float}`
3234
//~| expected usize, found floating-point variable
33-
//~| ERROR expected usize for repeat count, found float [E0306]
35+
//~| ERROR expected `usize` for repeat count, found float [E0306]
36+
//~| expected `usize`
3437
let e = [0; "foo"];
3538
//~^ ERROR mismatched types
3639
//~| expected type `usize`
3740
//~| found type `&'static str`
3841
//~| expected usize, found &-ptr
39-
//~| ERROR expected usize for repeat count, found string literal [E0306]
42+
//~| ERROR expected `usize` for repeat count, found string literal [E0306]
43+
//~| expected `usize`
4044
let f = [0; -4_isize];
4145
//~^ ERROR constant evaluation error
4246
//~| expected usize, found isize
@@ -55,5 +59,6 @@ fn main() {
5559
//~| expected type `usize`
5660
//~| found type `main::G`
5761
//~| expected usize, found struct `main::G`
58-
//~| ERROR expected usize for repeat count, found struct [E0306]
62+
//~| ERROR expected `usize` for repeat count, found struct [E0306]
63+
//~| expected `usize`
5964
}

0 commit comments

Comments
 (0)