// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use self::ConstVal::*;
-use self::ConstAggregate::*;
pub use rustc_const_math::ConstInt;
use hir;
}
impl<'tcx> ConstVal<'tcx> {
- pub fn description(&self) -> &'static str {
- match *self {
- Float(f) => f.description(),
- Integral(i) => i.description(),
- Str(_) => "string literal",
- ByteStr(_) => "byte string literal",
- Bool(_) => "boolean",
- Char(..) => "char",
- Variant(_) => "enum variant",
- Aggregate(Struct(_)) => "struct",
- Aggregate(Tuple(_)) => "tuple",
- Function(..) => "function definition",
- Aggregate(Array(..)) => "array",
- Aggregate(Repeat(..)) => "repeat",
- }
- }
-
pub fn to_const_int(&self) -> Option<ConstInt> {
match *self {
ConstVal::Integral(i) => Some(i),
pub enum ErrKind<'tcx> {
CannotCast,
MissingStructField,
- NegateOn(ConstVal<'tcx>),
- NotOn(ConstVal<'tcx>),
NonConstPath,
UnimplementedConstVal(&'static str),
match self.kind {
CannotCast => simple!("can't cast this type"),
- NegateOn(ref const_val) => simple!("negate on {}", const_val.description()),
- NotOn(ref const_val) => simple!("not on {}", const_val.description()),
-
MissingStructField => simple!("nonexistent struct field"),
NonConstPath => simple!("non-constant path in constant expression"),
UnimplementedConstVal(what) =>
mk_const(match cx.eval(inner)?.val {
Float(f) => Float(-f),
Integral(i) => Integral(math!(e, -i)),
- const_val => signal!(e, NegateOn(const_val)),
+ _ => signal!(e, TypeckError)
})
}
hir::ExprUnary(hir::UnNot, ref inner) => {
mk_const(match cx.eval(inner)?.val {
Integral(i) => Integral(math!(e, !i)),
Bool(b) => Bool(!b),
- const_val => signal!(e, NotOn(const_val)),
+ _ => signal!(e, TypeckError)
})
}
hir::ExprUnary(hir::UnDeref, _) => signal!(e, UnimplementedConstVal("deref operation")),
Some(result) => Ok(result),
None => {
// FIXME: can this ever be reached?
- span_err!(tcx.sess, span, E0298,
- "type mismatch comparing {} and {}",
- a.description(),
- b.description());
+ tcx.sess.delay_span_bug(span,
+ &format!("type mismatch comparing {:?} and {:?}", a, b));
Err(ErrorReported)
}
}