also print the expected type in the error message
This commit is contained in:
parent
54b15c7160
commit
bba1596c71
@ -465,7 +465,8 @@ pub enum ErrKind {
|
||||
Math(ConstMathErr),
|
||||
|
||||
IntermediateUnsignedNegative,
|
||||
InferredWrongType(ConstInt),
|
||||
/// Expected, Got
|
||||
TypeMismatch(String, ConstInt),
|
||||
BadType(ConstVal),
|
||||
}
|
||||
|
||||
@ -528,7 +529,10 @@ impl ConstEvalErr {
|
||||
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);
|
||||
|
@ -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)]
|
||||
|
||||
|
@ -21,7 +21,9 @@ use std::{u8, u16, u32, u64, usize};
|
||||
|
||||
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() {
|
||||
|
@ -10,9 +10,13 @@
|
||||
|
||||
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() {}
|
||||
|
@ -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: (),
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user