Skip to content

Commit a43598c

Browse files
committed
evaluation of generic const fns can run into trouble with inferring integrals
1 parent d2cc076 commit a43598c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/librustc_const_eval/eval.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ use syntax::attr::IntType;
4141
use std::borrow::Cow;
4242
use std::cmp::Ordering;
4343
use std::collections::hash_map::Entry::Vacant;
44+
use std::collections::BTreeMap;
4445

4546
use rustc_const_math::*;
4647

@@ -410,7 +411,8 @@ pub enum ErrKind {
410411
IntermediateUnsignedNegative,
411412
/// Expected, Got
412413
TypeMismatch(String, ConstInt),
413-
BadType(ConstVal),
414+
/// target type, got value
415+
BadType(String, ConstVal),
414416
ErroneousReferencedConstant(Box<ConstEvalErr>),
415417
CharCast(ConstInt),
416418
Aggregate(Vec<ConstEvalErr>),
@@ -472,7 +474,7 @@ impl ConstEvalErr {
472474
format!("mismatched types: expected `{}`, found `{}`",
473475
expected, got.description()).into_cow()
474476
},
475-
BadType(ref i) => format!("value of wrong type: {:?}", i).into_cow(),
477+
BadType(ref ty, ref i) => format!("expected `{}`, found `{:?}`", ty, i).into_cow(),
476478
ErroneousReferencedConstant(_) => "could not evaluate referenced constant".into_cow(),
477479
CharCast(ref got) => {
478480
format!("only `u8` can be cast as `char`, not `{}`", got.description()).into_cow()
@@ -1023,7 +1025,8 @@ fn infer<'a, 'tcx>(i: ConstInt,
10231025
let int_ty = tcx.enum_repr_type(hints.iter().next());
10241026
infer(i, tcx, &int_ty.to_ty(tcx).sty)
10251027
},
1026-
(_, i) => Err(BadType(ConstVal::Integral(i))),
1028+
(&ty::TyParam(_), i) => Ok(i),
1029+
(ty, i) => Err(BadType(ty.to_string(), ConstVal::Integral(i))),
10271030
}
10281031
}
10291032

0 commit comments

Comments
 (0)