Add ConstError

Co-Authored-By: Gabriel Smith <yodaldevoid@users.noreply.github.com>
This commit is contained in:
varkor 2019-03-08 01:13:38 +00:00
parent cafa10d96e
commit 2254727480
2 changed files with 43 additions and 1 deletions

View File

@ -44,6 +44,14 @@ pub enum TypeError<'tcx> {
ProjectionMismatched(ExpectedFound<DefId>),
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>>),
}
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Debug, Copy)]
@ -163,6 +171,21 @@ 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) => {
write!(f, "expected `{:?}`, found `{:?}`", values.expected, values.found)
}
}
}
}

View File

@ -737,11 +737,23 @@ impl<'a, 'tcx> Lift<'tcx> for ty::error::TypeError<'a> {
ProjectionMismatched(x) => ProjectionMismatched(x),
ProjectionBoundsLength(x) => ProjectionBoundsLength(x),
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),
})
}
}
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> {
@ -1320,6 +1332,13 @@ 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),
}
}