}
}
-impl_stable_hash_for!(struct ::middle::const_val::ByteArray<'tcx> {
- data
-});
-
impl_stable_hash_for!(enum mir::interpret::Value {
ByVal(v),
ByValPair(a, b),
mem::discriminant(self).hash_stable(hcx, hasher);
match *self {
- CannotCast |
- MissingStructField |
NonConstPath |
- ExpectedConstTuple |
- ExpectedConstStruct |
- IndexedNonVec |
- IndexNotUsize |
- MiscBinaryOp |
- MiscCatchAll |
- IndexOpFeatureGated |
TypeckError |
CheckMatchError => {
// nothing to do
LayoutError(ref layout_error) => {
layout_error.hash_stable(hcx, hasher);
}
- ErroneousReferencedConstant(ref const_val) => {
- const_val.hash_stable(hcx, hasher);
- }
Miri(ref err) => err.hash_stable(hcx, hasher),
}
}
use errors::DiagnosticBuilder;
use graphviz::IntoCow;
-use serialize;
use syntax_pos::Span;
use std::borrow::Cow;
Value(Value),
}
-#[derive(Copy, Clone, Debug, Hash, RustcEncodable, Eq, PartialEq)]
-pub struct ByteArray<'tcx> {
- pub data: &'tcx [u8],
-}
-
-impl<'tcx> serialize::UseSpecializedDecodable for ByteArray<'tcx> {}
-
impl<'tcx> ConstVal<'tcx> {
pub fn to_raw_bits(&self) -> Option<u128> {
match *self {
#[derive(Clone, Debug)]
pub enum ErrKind<'tcx> {
- CannotCast,
- MissingStructField,
NonConstPath,
UnimplementedConstVal(&'static str),
- ExpectedConstTuple,
- ExpectedConstStruct,
- IndexedNonVec,
- IndexNotUsize,
IndexOutOfBounds { len: u64, index: u64 },
- MiscBinaryOp,
- MiscCatchAll,
-
- IndexOpFeatureGated,
Math(ConstMathErr),
LayoutError(layout::LayoutError<'tcx>),
- ErroneousReferencedConstant(Box<ConstEvalErr<'tcx>>),
-
TypeckError,
CheckMatchError,
Miri(::mir::interpret::EvalError<'tcx>),
}
match self.kind {
- CannotCast => simple!("can't cast this type"),
- MissingStructField => simple!("nonexistent struct field"),
NonConstPath => simple!("non-constant path in constant expression"),
UnimplementedConstVal(what) =>
simple!("unimplemented constant expression: {}", what),
- ExpectedConstTuple => simple!("expected constant tuple"),
- ExpectedConstStruct => simple!("expected constant struct"),
- IndexedNonVec => simple!("indexing is only supported for arrays"),
- IndexNotUsize => simple!("indices must be of type `usize`"),
IndexOutOfBounds { len, index } => {
simple!("index out of bounds: the len is {} but the index is {}",
len, index)
}
- MiscBinaryOp => simple!("bad operands for binary"),
- MiscCatchAll => simple!("unsupported constant expr"),
- IndexOpFeatureGated => simple!("the index operation on const values is unstable"),
Math(ref err) => Simple(err.description().into_cow()),
LayoutError(ref err) => Simple(err.to_string().into_cow()),
- ErroneousReferencedConstant(_) => simple!("could not evaluate referenced constant"),
-
TypeckError => simple!("type-checking failed"),
CheckMatchError => simple!("match-checking failed"),
// FIXME: report a full backtrace
primary_kind: &str)
-> DiagnosticBuilder<'gcx>
{
- let mut err = self;
- while let &ConstEvalErr {
- kind: ErrKind::ErroneousReferencedConstant(box ref i_err), ..
- } = err {
- err = i_err;
- }
-
- let mut diag = struct_error(tcx, err.span, "constant evaluation error");
- err.note(tcx, primary_span, primary_kind, &mut diag);
+ let mut diag = struct_error(tcx, self.span, "constant evaluation error");
+ self.note(tcx, primary_span, primary_kind, &mut diag);
diag
}
// persisting to incr. comp. caches.
use hir::def_id::{DefId, CrateNum};
-use middle::const_val::ByteArray;
use rustc_data_structures::fx::FxHashMap;
use rustc_serialize::{Decodable, Decoder, Encoder, Encodable, opaque};
use std::hash::Hash;
.mk_existential_predicates((0..len).map(|_| Decodable::decode(decoder)))?)
}
-#[inline]
-pub fn decode_byte_array<'a, 'tcx, D>(decoder: &mut D)
- -> Result<ByteArray<'tcx>, D::Error>
- where D: TyDecoder<'a, 'tcx>,
- 'tcx: 'a,
-{
- Ok(ByteArray {
- data: decoder.tcx().alloc_byte_array(&Vec::decode(decoder)?)
- })
-}
-
#[inline]
pub fn decode_const<'a, 'tcx, D>(decoder: &mut D)
-> Result<&'tcx ty::Const<'tcx>, D::Error>
use $crate::ty::codec::*;
use $crate::ty::subst::Substs;
use $crate::hir::def_id::{CrateNum};
- use $crate::middle::const_val::ByteArray;
use rustc_serialize::{Decoder, SpecializedDecoder};
use std::borrow::Cow;
}
}
- impl<$($typaram),*> SpecializedDecoder<ByteArray<'tcx>>
- for $DecoderName<$($typaram),*> {
- fn specialized_decode(&mut self) -> Result<ByteArray<'tcx>, Self::Error> {
- decode_byte_array(self)
- }
- }
-
impl<$($typaram),*> SpecializedDecoder<&'tcx $crate::ty::Const<'tcx>>
for $DecoderName<$($typaram),*> {
fn specialized_decode(&mut self) -> Result<&'tcx ty::Const<'tcx>, Self::Error> {
use middle::const_val::ErrKind::*;
Some(match *self {
- CannotCast => CannotCast,
- MissingStructField => MissingStructField,
NonConstPath => NonConstPath,
UnimplementedConstVal(s) => UnimplementedConstVal(s),
- ExpectedConstTuple => ExpectedConstTuple,
- ExpectedConstStruct => ExpectedConstStruct,
- IndexedNonVec => IndexedNonVec,
- IndexNotUsize => IndexNotUsize,
IndexOutOfBounds { len, index } => IndexOutOfBounds { len, index },
- MiscBinaryOp => MiscBinaryOp,
- MiscCatchAll => MiscCatchAll,
- IndexOpFeatureGated => IndexOpFeatureGated,
Math(ref e) => Math(e.clone()),
LayoutError(ref e) => {
return tcx.lift(e).map(LayoutError)
}
- ErroneousReferencedConstant(ref e) => {
- return tcx.lift(e).map(ErroneousReferencedConstant)
- }
TypeckError => TypeckError,
CheckMatchError => CheckMatchError,