Skip to content

Commit 2254727

Browse files
varkoryodaldevoid
andcommitted
Add ConstError
Co-Authored-By: Gabriel Smith <[email protected]>
1 parent cafa10d commit 2254727

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/librustc/ty/error.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ pub enum TypeError<'tcx> {
4444
ProjectionMismatched(ExpectedFound<DefId>),
4545
ProjectionBoundsLength(ExpectedFound<usize>),
4646
ExistentialMismatch(ExpectedFound<&'tcx ty::List<ty::ExistentialPredicate<'tcx>>>),
47+
48+
ConstError(ConstError<'tcx>),
49+
}
50+
51+
// Data structure used in const unification
52+
#[derive(Clone, Debug)]
53+
pub enum ConstError<'tcx> {
54+
Mismatch(ExpectedFound<&'tcx ty::LazyConst<'tcx>>),
4755
}
4856

4957
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Debug, Copy)]
@@ -163,6 +171,21 @@ impl<'tcx> fmt::Display for TypeError<'tcx> {
163171
report_maybe_different(f, &format!("trait `{}`", values.expected),
164172
&format!("trait `{}`", values.found))
165173
}
174+
ConstError(ref err) => {
175+
write!(f, "{}", err)
176+
}
177+
}
178+
}
179+
}
180+
181+
impl<'tcx> fmt::Display for ConstError<'tcx> {
182+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
183+
use self::ConstError::*;
184+
185+
match *self {
186+
Mismatch(ref values) => {
187+
write!(f, "expected `{:?}`, found `{:?}`", values.expected, values.found)
188+
}
166189
}
167190
}
168191
}

src/librustc/ty/structural_impls.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,11 +737,23 @@ impl<'a, 'tcx> Lift<'tcx> for ty::error::TypeError<'a> {
737737
ProjectionMismatched(x) => ProjectionMismatched(x),
738738
ProjectionBoundsLength(x) => ProjectionBoundsLength(x),
739739
Sorts(ref x) => return tcx.lift(x).map(Sorts),
740-
ExistentialMismatch(ref x) => return tcx.lift(x).map(ExistentialMismatch)
740+
ExistentialMismatch(ref x) => return tcx.lift(x).map(ExistentialMismatch),
741+
ConstError(ref x) => return tcx.lift(x).map(ConstError),
741742
})
742743
}
743744
}
744745

746+
impl<'a, 'tcx> Lift<'tcx> for ty::error::ConstError<'a> {
747+
type Lifted = ty::error::ConstError<'tcx>;
748+
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
749+
use ty::error::ConstError::*;
750+
751+
match *self {
752+
Mismatch(ref x) => return tcx.lift(x).map(Mismatch),
753+
}
754+
}
755+
}
756+
745757
impl<'a, 'tcx> Lift<'tcx> for ty::InstanceDef<'a> {
746758
type Lifted = ty::InstanceDef<'tcx>;
747759
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
@@ -1320,6 +1332,13 @@ EnumTypeFoldableImpl! {
13201332
(ty::error::TypeError::ProjectionBoundsLength)(x),
13211333
(ty::error::TypeError::Sorts)(x),
13221334
(ty::error::TypeError::ExistentialMismatch)(x),
1335+
(ty::error::TypeError::ConstError)(x),
1336+
}
1337+
}
1338+
1339+
EnumTypeFoldableImpl! {
1340+
impl<'tcx> TypeFoldable<'tcx> for ty::error::ConstError<'tcx> {
1341+
(ty::error::ConstError::Mismatch)(x),
13231342
}
13241343
}
13251344

0 commit comments

Comments
 (0)