]> git.lizzy.rs Git - rust.git/commitdiff
Add long diagnostics for E0249 and E0250
authorNick Hamann <nick@wabbo.org>
Sun, 10 May 2015 23:58:21 +0000 (18:58 -0500)
committerNick Hamann <nick@wabbo.org>
Mon, 11 May 2015 01:04:04 +0000 (20:04 -0500)
src/librustc_typeck/astconv.rs
src/librustc_typeck/diagnostics.rs

index 677254238c03498143cda5e658a8c1c22bb45b98..54ec1aace92112fe16a1109126004b15fdbacdc6 100644 (file)
@@ -1603,7 +1603,8 @@ pub fn ast_ty_to_ty<'tcx>(this: &AstConv<'tcx>,
                                         Some(i as usize)),
                         _ => {
                             span_err!(tcx.sess, ast_ty.span, E0249,
-                                      "expected constant expr for array length");
+                                      "expected constant integer expression \
+                                       for array length");
                             this.tcx().types.err
                         }
                     }
index 373be620736488014aa2c12e1ba8d432d182742b..ea872d1014425e9b6f0e31deef6f8d8a16d7f35d 100644 (file)
@@ -260,6 +260,38 @@ struct Foo { x: bool }
 
 struct Bar<S, T> { x: Foo<S, T> }
 ```
+"##,
+
+E0249: r##"
+This error indicates a constant expression for the array length was found, but
+it was not an integer (signed or unsigned) expression.
+
+Some examples of code that produces this error are:
+
+```
+const A: [u32; "hello"] = []; // error
+const B: [u32; true] = []; // error
+const C: [u32; 0.0] = []; // error
+"##,
+
+E0250: r##"
+This means there was an error while evaluating the expression for the length of
+a fixed-size array type.
+
+Some examples of code that produces this error are:
+
+```
+// divide by zero in the length expression
+const A: [u32; 1/0] = [];
+
+// Rust currently will not evaluate the function `foo` at compile time
+fn foo() -> usize { 12 }
+const B: [u32; foo()] = [];
+
+// it is an error to try to add `u8` and `f64`
+use std::{f64, u8};
+const C: [u32; u8::MAX + f64::EPSILON] = [];
+```
 "##
 
 }
@@ -403,8 +435,6 @@ struct Bar<S, T> { x: Foo<S, T> }
     E0246, // illegal recursive type
     E0247, // found module name used as a type
     E0248, // found value name used as a type
-    E0249, // expected constant expr for array length
-    E0250, // expected constant expr for array length
     E0318, // can't create default impls for traits outside their crates
     E0319, // trait impls for defaulted traits allowed just for structs/enums
     E0320, // recursive overflow during dropck