Inline ConstError into TypeError

This commit is contained in:
varkor 2019-03-12 19:27:06 +00:00
parent cf1a719c19
commit 245a474ab7
5 changed files with 10 additions and 53 deletions

View File

@ -34,7 +34,7 @@ use crate::hir::def_id::DefId;
use crate::mir::interpret::ConstValue; use crate::mir::interpret::ConstValue;
use crate::ty::{IntType, UintType}; use crate::ty::{IntType, UintType};
use crate::ty::{self, Ty, TyCtxt, InferConst, LazyConst}; use crate::ty::{self, Ty, TyCtxt, InferConst, LazyConst};
use crate::ty::error::{ConstError, TypeError}; use crate::ty::error::TypeError;
use crate::ty::relate::{self, Relate, RelateResult, TypeRelation}; use crate::ty::relate::{self, Relate, RelateResult, TypeRelation};
use crate::ty::subst::SubstsRef; use crate::ty::subst::SubstsRef;
use crate::traits::{Obligation, PredicateObligations}; use crate::traits::{Obligation, PredicateObligations};
@ -627,9 +627,7 @@ pub fn const_unification_error<'tcx>(
a_is_expected: bool, a_is_expected: bool,
(a, b): (&'tcx LazyConst<'tcx>, &'tcx LazyConst<'tcx>), (a, b): (&'tcx LazyConst<'tcx>, &'tcx LazyConst<'tcx>),
) -> TypeError<'tcx> { ) -> TypeError<'tcx> {
TypeError::ConstError( TypeError::ConstMismatch(ty::relate::expected_found_bool(a_is_expected, &a, &b))
ConstError::Mismatch(ty::relate::expected_found_bool(a_is_expected, &a, &b))
)
} }
fn int_unification_error<'tcx>(a_is_expected: bool, v: (ty::IntVarValue, ty::IntVarValue)) fn int_unification_error<'tcx>(a_is_expected: bool, v: (ty::IntVarValue, ty::IntVarValue))

View File

@ -1,5 +1,5 @@
use crate::ty::{self, Ty, TyCtxt, InferConst}; use crate::ty::{self, Ty, TyCtxt, InferConst};
use crate::ty::error::{TypeError, ConstError}; use crate::ty::error::TypeError;
use crate::ty::relate::{self, Relate, TypeRelation, RelateResult}; use crate::ty::relate::{self, Relate, TypeRelation, RelateResult};
use crate::mir::interpret::ConstValue; use crate::mir::interpret::ConstValue;
@ -96,9 +96,7 @@ impl<'a, 'gcx, 'tcx> TypeRelation<'a, 'gcx, 'tcx> for Match<'a, 'gcx, 'tcx> {
} }
(ConstValue::Infer(_), _) | (_, ConstValue::Infer(_)) => { (ConstValue::Infer(_), _) | (_, ConstValue::Infer(_)) => {
return Err(TypeError::ConstError( return Err(TypeError::ConstMismatch(relate::expected_found(self, &a, &b)));
ConstError::Mismatch(relate::expected_found(self, &a, &b))
));
} }
_ => {} _ => {}

View File

@ -45,13 +45,7 @@ pub enum TypeError<'tcx> {
ProjectionBoundsLength(ExpectedFound<usize>), ProjectionBoundsLength(ExpectedFound<usize>),
ExistentialMismatch(ExpectedFound<&'tcx ty::List<ty::ExistentialPredicate<'tcx>>>), ExistentialMismatch(ExpectedFound<&'tcx ty::List<ty::ExistentialPredicate<'tcx>>>),
ConstError(ConstError<'tcx>), ConstMismatch(ExpectedFound<&'tcx ty::LazyConst<'tcx>>),
}
// Data structure used in const unification
#[derive(Clone, Debug)]
pub enum ConstError<'tcx> {
Mismatch(ExpectedFound<&'tcx ty::LazyConst<'tcx>>),
} }
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Debug, Copy)] #[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Debug, Copy)]
@ -171,19 +165,7 @@ impl<'tcx> fmt::Display for TypeError<'tcx> {
report_maybe_different(f, &format!("trait `{}`", values.expected), report_maybe_different(f, &format!("trait `{}`", values.expected),
&format!("trait `{}`", values.found)) &format!("trait `{}`", values.found))
} }
ConstError(ref err) => { ConstMismatch(ref values) => {
write!(f, "{}", err)
}
}
}
}
impl<'tcx> fmt::Display for ConstError<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use self::ConstError::*;
match *self {
Mismatch(ref values) => {
write!(f, "expected `{:?}`, found `{:?}`", values.expected, values.found) write!(f, "expected `{:?}`, found `{:?}`", values.expected, values.found)
} }
} }

View File

@ -626,9 +626,7 @@ where
); );
} }
_ => { _ => {
Err(TypeError::ConstError( Err(TypeError::ConstMismatch(expected_found(relation, &a, &b)))
ConstError::Mismatch(expected_found(relation, &a, &b))
))
} }
} }
} }
@ -642,9 +640,7 @@ where
Ok(tcx.mk_lazy_const(ty::LazyConst::Unevaluated(*a_def_id, substs))) Ok(tcx.mk_lazy_const(ty::LazyConst::Unevaluated(*a_def_id, substs)))
} }
_ => { _ => {
Err(TypeError::ConstError( Err(TypeError::ConstMismatch(expected_found(relation, &a, &b)))
ConstError::Mismatch(expected_found(relation, &a, &b))
))
} }
} }
} }

View File

@ -738,22 +738,11 @@ impl<'a, 'tcx> Lift<'tcx> for ty::error::TypeError<'a> {
ProjectionBoundsLength(x) => ProjectionBoundsLength(x), ProjectionBoundsLength(x) => ProjectionBoundsLength(x),
Sorts(ref x) => return tcx.lift(x).map(Sorts), Sorts(ref x) => return tcx.lift(x).map(Sorts),
ExistentialMismatch(ref x) => return tcx.lift(x).map(ExistentialMismatch), ExistentialMismatch(ref x) => return tcx.lift(x).map(ExistentialMismatch),
ConstError(ref x) => return tcx.lift(x).map(ConstError), ConstMismatch(ref x) => return tcx.lift(x).map(ConstMismatch),
}) })
} }
} }
impl<'a, 'tcx> Lift<'tcx> for ty::error::ConstError<'a> {
type Lifted = ty::error::ConstError<'tcx>;
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
use ty::error::ConstError::*;
match *self {
Mismatch(ref x) => return tcx.lift(x).map(Mismatch),
}
}
}
impl<'a, 'tcx> Lift<'tcx> for ty::InstanceDef<'a> { impl<'a, 'tcx> Lift<'tcx> for ty::InstanceDef<'a> {
type Lifted = ty::InstanceDef<'tcx>; type Lifted = ty::InstanceDef<'tcx>;
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> { fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
@ -1332,13 +1321,7 @@ EnumTypeFoldableImpl! {
(ty::error::TypeError::ProjectionBoundsLength)(x), (ty::error::TypeError::ProjectionBoundsLength)(x),
(ty::error::TypeError::Sorts)(x), (ty::error::TypeError::Sorts)(x),
(ty::error::TypeError::ExistentialMismatch)(x), (ty::error::TypeError::ExistentialMismatch)(x),
(ty::error::TypeError::ConstError)(x), (ty::error::TypeError::ConstMismatch)(x),
}
}
EnumTypeFoldableImpl! {
impl<'tcx> TypeFoldable<'tcx> for ty::error::ConstError<'tcx> {
(ty::error::ConstError::Mismatch)(x),
} }
} }