]> git.lizzy.rs Git - rust.git/commitdiff
also print the expected type in the error message
authorOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Thu, 25 Feb 2016 10:12:18 +0000 (11:12 +0100)
committerOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Thu, 10 Mar 2016 11:50:13 +0000 (12:50 +0100)
src/librustc/middle/const_eval.rs
src/test/compile-fail/const-eval-overflow-3.rs
src/test/compile-fail/const-eval-overflow-4b.rs
src/test/compile-fail/issue-8761.rs
src/test/compile-fail/repeat_count.rs

index f4c5196d0cdb5145f7735b20d6308df90e67b29a..f56c42738e71e6f10edf6597d0d016f2f904e364 100644 (file)
@@ -465,7 +465,8 @@ pub enum ErrKind {
     Math(ConstMathErr),
 
     IntermediateUnsignedNegative,
-    InferredWrongType(ConstInt),
+    /// Expected, Got
+    TypeMismatch(String, ConstInt),
     BadType(ConstVal),
 }
 
@@ -528,7 +529,10 @@ pub fn description(&self) -> Cow<str> {
                                              number was encountered. This is most likely a bug in\
                                              the constant evaluator".into_cow(),
 
-            InferredWrongType(ref i) => format!("inferred wrong type for {}", i).into_cow(),
+            TypeMismatch(ref expected, ref got) => {
+                format!("mismatched types: expected `{}`, found `{}`",
+                        expected, got.description()).into_cow()
+            },
             BadType(ref i) => format!("value of wrong type: {:?}", i).into_cow(),
         }
     }
@@ -745,7 +749,7 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &TyCtxt<'tcx>,
 
         let val = match eval_const_expr_partial(tcx, &base, base_hint, fn_args) {
             Ok(val) => val,
-            Err(ConstEvalErr { kind: InferredWrongType(val), .. }) => {
+            Err(ConstEvalErr { kind: TypeMismatch(_, val), .. }) => {
                 // Something like `5i8 as usize` doesn't need a type hint for the base
                 // instead take the type hint from the inner value
                 let hint = match val.int_type() {
@@ -1085,8 +1089,8 @@ fn infer<'tcx>(
         (&ty::TyUint(_), Infer(_)) => Err(err(Math(ConstMathErr::NotInRange))),
         (&ty::TyUint(_), InferSigned(_)) => Err(err(IntermediateUnsignedNegative)),
 
-        (&ty::TyInt(_), i) |
-        (&ty::TyUint(_), i) => Err(err(InferredWrongType(i))),
+        (&ty::TyInt(ity), i) => Err(err(TypeMismatch(ity.to_string(), i))),
+        (&ty::TyUint(ity), i) => Err(err(TypeMismatch(ity.to_string(), i))),
 
         (&ty::TyEnum(ref adt, _), i) => {
             let hints = tcx.lookup_repr_hints(adt.did);
index 33fa4aae61151caa7f947426ab10b0511f3f3fe8..c90ae045f96b4aa0430e2b3c020f47d33caeba1a 100644 (file)
@@ -17,7 +17,7 @@
 // self-hosted and a cross-compiled setup; therefore resorting to
 // error-pattern for now.
 
-// error-pattern: expected constant integer for repeat count, but tried to add two integrals of
+// error-pattern: expected constant integer for repeat count, but attempted to add with overflow
 
 #![allow(unused_imports)]
 
index 68ef1b4775189439463fd4e9c2f96b1e625e3cd5..5aa93cf6383fe4c37e2209f3c33cb350e1ed2681 100644 (file)
@@ -21,7 +21,9 @@
 
 const A_I8_T
     : [u32; (i8::MAX as i8 + 1u8) as usize]
-    //~^ ERROR tried to add two integrals of different types [E0250]
+    //~^ ERROR mismatched types:
+    //~| expected `i8`,
+    //~| found `u8` [E0250]
     = [0; (i8::MAX as usize) + 1];
 
 fn main() {
index da8bd1dc28d981fb60def3d3b819c3b498dd6e02..1c98abce0304e149f092ea7e0a4137c0cac303d5 100644 (file)
 
 enum Foo {
     A = 1i64,
-    //~^ ERROR mismatched types: expected `isize` got `i64`
+    //~^ ERROR mismatched types:
+    //~| expected `isize`,
+    //~| found `i64` [E0080]
     B = 2u8
-    //~^ ERROR mismatched types: expected `isize` got `u8`
+    //~^ ERROR mismatched types:
+    //~| expected `isize`,
+    //~| found `u8` [E0080]
 }
 
 fn main() {}
index c0913be1354ca9cc21f1044ab226c0e68f99cd9e..10b722946a8a89f847c5af45081ee29e40f9470c 100644 (file)
@@ -43,13 +43,17 @@ fn main() {
     let f = [0; -4_isize];
     //~^ ERROR mismatched types
     //~| expected `usize`
-    //~| found `isize`
-    //~| ERROR expected positive integer for repeat count, found isize [E0306]
+    //~| found `isize` [E0308]
+    //~| ERROR mismatched types:
+    //~| expected `usize`,
+    //~| found `isize` [E0307]
     let f = [0_usize; -1_isize];
     //~^ ERROR mismatched types
     //~| expected `usize`
-    //~| found `isize`
-    //~| ERROR expected positive integer for repeat count, found isize [E0306]
+    //~| found `isize` [E0308]
+    //~| ERROR mismatched types
+    //~| expected `usize`
+    //~| found `isize` [E0307]
     struct G {
         g: (),
     }