Skip to content

Commit 3c4facb

Browse files
author
Nick Hamann
committed
Add long diagnostics for E0249 and E0250
1 parent ed1bc68 commit 3c4facb

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

src/librustc_typeck/astconv.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1603,7 +1603,8 @@ pub fn ast_ty_to_ty<'tcx>(this: &AstConv<'tcx>,
16031603
Some(i as usize)),
16041604
_ => {
16051605
span_err!(tcx.sess, ast_ty.span, E0249,
1606-
"expected constant expr for array length");
1606+
"expected constant integer expression \
1607+
for array length");
16071608
this.tcx().types.err
16081609
}
16091610
}

src/librustc_typeck/diagnostics.rs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,38 @@ struct Foo { x: bool }
260260
261261
struct Bar<S, T> { x: Foo<S, T> }
262262
```
263+
"##,
264+
265+
E0249: r##"
266+
This error indicates a constant expression for the array length was found, but
267+
it was not an integer (signed or unsigned) expression.
268+
269+
Some examples of code that produces this error are:
270+
271+
```
272+
const A: [u32; "hello"] = []; // error
273+
const B: [u32; true] = []; // error
274+
const C: [u32; 0.0] = []; // error
275+
"##,
276+
277+
E0250: r##"
278+
This means there was an error while evaluating the expression for the length of
279+
a fixed-size array type.
280+
281+
Some examples of code that produces this error are:
282+
283+
```
284+
// divide by zero in the length expression
285+
const A: [u32; 1/0] = [];
286+
287+
// Rust currently will not evaluate the function `foo` at compile time
288+
fn foo() -> usize { 12 }
289+
const B: [u32; foo()] = [];
290+
291+
// it is an error to try to add `u8` and `f64`
292+
use std::{f64, u8};
293+
const C: [u32; u8::MAX + f64::EPSILON] = [];
294+
```
263295
"##
264296

265297
}
@@ -403,8 +435,6 @@ register_diagnostics! {
403435
E0246, // illegal recursive type
404436
E0247, // found module name used as a type
405437
E0248, // found value name used as a type
406-
E0249, // expected constant expr for array length
407-
E0250, // expected constant expr for array length
408438
E0318, // can't create default impls for traits outside their crates
409439
E0319, // trait impls for defaulted traits allowed just for structs/enums
410440
E0320, // recursive overflow during dropck

0 commit comments

Comments
 (0)