diff --git a/src/librustc/ty/error.rs b/src/librustc/ty/error.rs index 74d0a29bcff..5e3718b73bf 100644 --- a/src/librustc/ty/error.rs +++ b/src/librustc/ty/error.rs @@ -44,6 +44,14 @@ pub enum TypeError<'tcx> { ProjectionMismatched(ExpectedFound), ProjectionBoundsLength(ExpectedFound), ExistentialMismatch(ExpectedFound<&'tcx ty::List>>), + + 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) + } } } } diff --git a/src/librustc/ty/structural_impls.rs b/src/librustc/ty/structural_impls.rs index 9aaff33e933..548339ee687 100644 --- a/src/librustc/ty/structural_impls.rs +++ b/src/librustc/ty/structural_impls.rs @@ -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 { + 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 { @@ -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), } }