Inline ConstError into TypeError
This commit is contained in:
parent
cf1a719c19
commit
245a474ab7
@ -34,7 +34,7 @@ use crate::hir::def_id::DefId;
|
||||
use crate::mir::interpret::ConstValue;
|
||||
use crate::ty::{IntType, UintType};
|
||||
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::subst::SubstsRef;
|
||||
use crate::traits::{Obligation, PredicateObligations};
|
||||
@ -627,9 +627,7 @@ pub fn const_unification_error<'tcx>(
|
||||
a_is_expected: bool,
|
||||
(a, b): (&'tcx LazyConst<'tcx>, &'tcx LazyConst<'tcx>),
|
||||
) -> TypeError<'tcx> {
|
||||
TypeError::ConstError(
|
||||
ConstError::Mismatch(ty::relate::expected_found_bool(a_is_expected, &a, &b))
|
||||
)
|
||||
TypeError::ConstMismatch(ty::relate::expected_found_bool(a_is_expected, &a, &b))
|
||||
}
|
||||
|
||||
fn int_unification_error<'tcx>(a_is_expected: bool, v: (ty::IntVarValue, ty::IntVarValue))
|
||||
|
@ -1,5 +1,5 @@
|
||||
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::mir::interpret::ConstValue;
|
||||
|
||||
@ -96,9 +96,7 @@ impl<'a, 'gcx, 'tcx> TypeRelation<'a, 'gcx, 'tcx> for Match<'a, 'gcx, 'tcx> {
|
||||
}
|
||||
|
||||
(ConstValue::Infer(_), _) | (_, ConstValue::Infer(_)) => {
|
||||
return Err(TypeError::ConstError(
|
||||
ConstError::Mismatch(relate::expected_found(self, &a, &b))
|
||||
));
|
||||
return Err(TypeError::ConstMismatch(relate::expected_found(self, &a, &b)));
|
||||
}
|
||||
|
||||
_ => {}
|
||||
|
@ -45,13 +45,7 @@ pub enum TypeError<'tcx> {
|
||||
ProjectionBoundsLength(ExpectedFound<usize>),
|
||||
ExistentialMismatch(ExpectedFound<&'tcx ty::List<ty::ExistentialPredicate<'tcx>>>),
|
||||
|
||||
ConstError(ConstError<'tcx>),
|
||||
}
|
||||
|
||||
// Data structure used in const unification
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum ConstError<'tcx> {
|
||||
Mismatch(ExpectedFound<&'tcx ty::LazyConst<'tcx>>),
|
||||
ConstMismatch(ExpectedFound<&'tcx ty::LazyConst<'tcx>>),
|
||||
}
|
||||
|
||||
#[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),
|
||||
&format!("trait `{}`", values.found))
|
||||
}
|
||||
ConstError(ref err) => {
|
||||
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) => {
|
||||
ConstMismatch(ref values) => {
|
||||
write!(f, "expected `{:?}`, found `{:?}`", values.expected, values.found)
|
||||
}
|
||||
}
|
||||
|
@ -626,9 +626,7 @@ where
|
||||
);
|
||||
}
|
||||
_ => {
|
||||
Err(TypeError::ConstError(
|
||||
ConstError::Mismatch(expected_found(relation, &a, &b))
|
||||
))
|
||||
Err(TypeError::ConstMismatch(expected_found(relation, &a, &b)))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -642,9 +640,7 @@ where
|
||||
Ok(tcx.mk_lazy_const(ty::LazyConst::Unevaluated(*a_def_id, substs)))
|
||||
}
|
||||
_ => {
|
||||
Err(TypeError::ConstError(
|
||||
ConstError::Mismatch(expected_found(relation, &a, &b))
|
||||
))
|
||||
Err(TypeError::ConstMismatch(expected_found(relation, &a, &b)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -738,22 +738,11 @@ impl<'a, 'tcx> Lift<'tcx> for ty::error::TypeError<'a> {
|
||||
ProjectionBoundsLength(x) => ProjectionBoundsLength(x),
|
||||
Sorts(ref x) => return tcx.lift(x).map(Sorts),
|
||||
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> {
|
||||
type Lifted = ty::InstanceDef<'tcx>;
|
||||
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::Sorts)(x),
|
||||
(ty::error::TypeError::ExistentialMismatch)(x),
|
||||
(ty::error::TypeError::ConstError)(x),
|
||||
}
|
||||
}
|
||||
|
||||
EnumTypeFoldableImpl! {
|
||||
impl<'tcx> TypeFoldable<'tcx> for ty::error::ConstError<'tcx> {
|
||||
(ty::error::ConstError::Mismatch)(x),
|
||||
(ty::error::TypeError::ConstMismatch)(x),
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user