Skip to content

Commit

Permalink
Remove unused error variants and const eval types
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Mar 8, 2018
1 parent ef995bd commit 4f65261
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 88 deletions.
16 changes: 0 additions & 16 deletions src/librustc/ich/impls_ty.rs
Expand Up @@ -353,10 +353,6 @@ for ::middle::const_val::ConstVal<'gcx> {
}
}

impl_stable_hash_for!(struct ::middle::const_val::ByteArray<'tcx> {
data
});

impl_stable_hash_for!(enum mir::interpret::Value {
ByVal(v),
ByValPair(a, b),
Expand Down Expand Up @@ -454,16 +450,7 @@ for ::middle::const_val::ErrKind<'gcx> {
mem::discriminant(self).hash_stable(hcx, hasher);

match *self {
CannotCast |
MissingStructField |
NonConstPath |
ExpectedConstTuple |
ExpectedConstStruct |
IndexedNonVec |
IndexNotUsize |
MiscBinaryOp |
MiscCatchAll |
IndexOpFeatureGated |
TypeckError |
CheckMatchError => {
// nothing to do
Expand All @@ -481,9 +468,6 @@ for ::middle::const_val::ErrKind<'gcx> {
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),
}
}
Expand Down
42 changes: 2 additions & 40 deletions src/librustc/middle/const_val.rs
Expand Up @@ -16,7 +16,6 @@ use mir::interpret::{Value, PrimVal};
use errors::DiagnosticBuilder;

use graphviz::IntoCow;
use serialize;
use syntax_pos::Span;

use std::borrow::Cow;
Expand All @@ -29,13 +28,6 @@ pub enum ConstVal<'tcx> {
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 {
Expand Down Expand Up @@ -64,26 +56,14 @@ pub struct ConstEvalErr<'tcx> {

#[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>),
Expand Down Expand Up @@ -131,28 +111,17 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'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
Expand All @@ -166,15 +135,8 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> {
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
}

Expand Down
20 changes: 0 additions & 20 deletions src/librustc/ty/codec.rs
Expand Up @@ -17,7 +17,6 @@
// 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;
Expand Down Expand Up @@ -240,17 +239,6 @@ pub fn decode_existential_predicate_slice<'a, 'tcx, D>(decoder: &mut D)
.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>
Expand Down Expand Up @@ -278,7 +266,6 @@ macro_rules! implement_ty_decoder {
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;

Expand Down Expand Up @@ -377,13 +364,6 @@ macro_rules! implement_ty_decoder {
}
}

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> {
Expand Down
12 changes: 0 additions & 12 deletions src/librustc/ty/structural_impls.rs
Expand Up @@ -703,26 +703,14 @@ impl<'a, 'tcx> Lift<'tcx> for const_val::ErrKind<'a> {
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,
Expand Down

0 comments on commit 4f65261

Please sign in to comment.