From 4f65261c4396ed3d6611ff990c71e8b9e4cf4f11 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Fri, 26 Jan 2018 16:22:26 +0100 Subject: [PATCH] Remove unused error variants and const eval types --- src/librustc/ich/impls_ty.rs | 16 ----------- src/librustc/middle/const_val.rs | 42 ++--------------------------- src/librustc/ty/codec.rs | 20 -------------- src/librustc/ty/structural_impls.rs | 12 --------- 4 files changed, 2 insertions(+), 88 deletions(-) diff --git a/src/librustc/ich/impls_ty.rs b/src/librustc/ich/impls_ty.rs index 2dfb2d0bffc6c..72bc5af3b7e2d 100644 --- a/src/librustc/ich/impls_ty.rs +++ b/src/librustc/ich/impls_ty.rs @@ -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), @@ -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 @@ -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), } } diff --git a/src/librustc/middle/const_val.rs b/src/librustc/middle/const_val.rs index 5b18b7d5fd918..c987ed0ea5d3f 100644 --- a/src/librustc/middle/const_val.rs +++ b/src/librustc/middle/const_val.rs @@ -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; @@ -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 { match *self { @@ -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>), - TypeckError, CheckMatchError, Miri(::mir::interpret::EvalError<'tcx>), @@ -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 @@ -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 } diff --git a/src/librustc/ty/codec.rs b/src/librustc/ty/codec.rs index fbb14f39ade34..f98bc95356098 100644 --- a/src/librustc/ty/codec.rs +++ b/src/librustc/ty/codec.rs @@ -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; @@ -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, 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> @@ -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; @@ -377,13 +364,6 @@ macro_rules! implement_ty_decoder { } } - impl<$($typaram),*> SpecializedDecoder> - for $DecoderName<$($typaram),*> { - fn specialized_decode(&mut self) -> Result, 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> { diff --git a/src/librustc/ty/structural_impls.rs b/src/librustc/ty/structural_impls.rs index 9394a853920e5..4e1f3664d7f85 100644 --- a/src/librustc/ty/structural_impls.rs +++ b/src/librustc/ty/structural_impls.rs @@ -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,