Skip to content

Commit 245a474

Browse files
committed
Inline ConstError into TypeError
1 parent cf1a719 commit 245a474

File tree

5 files changed

+10
-53
lines changed

5 files changed

+10
-53
lines changed

src/librustc/infer/combine.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use crate::hir::def_id::DefId;
3434
use crate::mir::interpret::ConstValue;
3535
use crate::ty::{IntType, UintType};
3636
use crate::ty::{self, Ty, TyCtxt, InferConst, LazyConst};
37-
use crate::ty::error::{ConstError, TypeError};
37+
use crate::ty::error::TypeError;
3838
use crate::ty::relate::{self, Relate, RelateResult, TypeRelation};
3939
use crate::ty::subst::SubstsRef;
4040
use crate::traits::{Obligation, PredicateObligations};
@@ -627,9 +627,7 @@ pub fn const_unification_error<'tcx>(
627627
a_is_expected: bool,
628628
(a, b): (&'tcx LazyConst<'tcx>, &'tcx LazyConst<'tcx>),
629629
) -> TypeError<'tcx> {
630-
TypeError::ConstError(
631-
ConstError::Mismatch(ty::relate::expected_found_bool(a_is_expected, &a, &b))
632-
)
630+
TypeError::ConstMismatch(ty::relate::expected_found_bool(a_is_expected, &a, &b))
633631
}
634632

635633
fn int_unification_error<'tcx>(a_is_expected: bool, v: (ty::IntVarValue, ty::IntVarValue))

src/librustc/ty/_match.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::ty::{self, Ty, TyCtxt, InferConst};
2-
use crate::ty::error::{TypeError, ConstError};
2+
use crate::ty::error::TypeError;
33
use crate::ty::relate::{self, Relate, TypeRelation, RelateResult};
44
use crate::mir::interpret::ConstValue;
55

@@ -96,9 +96,7 @@ impl<'a, 'gcx, 'tcx> TypeRelation<'a, 'gcx, 'tcx> for Match<'a, 'gcx, 'tcx> {
9696
}
9797

9898
(ConstValue::Infer(_), _) | (_, ConstValue::Infer(_)) => {
99-
return Err(TypeError::ConstError(
100-
ConstError::Mismatch(relate::expected_found(self, &a, &b))
101-
));
99+
return Err(TypeError::ConstMismatch(relate::expected_found(self, &a, &b)));
102100
}
103101

104102
_ => {}

src/librustc/ty/error.rs

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,7 @@ pub enum TypeError<'tcx> {
4545
ProjectionBoundsLength(ExpectedFound<usize>),
4646
ExistentialMismatch(ExpectedFound<&'tcx ty::List<ty::ExistentialPredicate<'tcx>>>),
4747

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>>),
48+
ConstMismatch(ExpectedFound<&'tcx ty::LazyConst<'tcx>>),
5549
}
5650

5751
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Debug, Copy)]
@@ -171,19 +165,7 @@ impl<'tcx> fmt::Display for TypeError<'tcx> {
171165
report_maybe_different(f, &format!("trait `{}`", values.expected),
172166
&format!("trait `{}`", values.found))
173167
}
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) => {
168+
ConstMismatch(ref values) => {
187169
write!(f, "expected `{:?}`, found `{:?}`", values.expected, values.found)
188170
}
189171
}

src/librustc/ty/relate.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -626,9 +626,7 @@ where
626626
);
627627
}
628628
_ => {
629-
Err(TypeError::ConstError(
630-
ConstError::Mismatch(expected_found(relation, &a, &b))
631-
))
629+
Err(TypeError::ConstMismatch(expected_found(relation, &a, &b)))
632630
}
633631
}
634632
}
@@ -642,9 +640,7 @@ where
642640
Ok(tcx.mk_lazy_const(ty::LazyConst::Unevaluated(*a_def_id, substs)))
643641
}
644642
_ => {
645-
Err(TypeError::ConstError(
646-
ConstError::Mismatch(expected_found(relation, &a, &b))
647-
))
643+
Err(TypeError::ConstMismatch(expected_found(relation, &a, &b)))
648644
}
649645
}
650646
}

src/librustc/ty/structural_impls.rs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -738,22 +738,11 @@ impl<'a, 'tcx> Lift<'tcx> for ty::error::TypeError<'a> {
738738
ProjectionBoundsLength(x) => ProjectionBoundsLength(x),
739739
Sorts(ref x) => return tcx.lift(x).map(Sorts),
740740
ExistentialMismatch(ref x) => return tcx.lift(x).map(ExistentialMismatch),
741-
ConstError(ref x) => return tcx.lift(x).map(ConstError),
741+
ConstMismatch(ref x) => return tcx.lift(x).map(ConstMismatch),
742742
})
743743
}
744744
}
745745

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-
757746
impl<'a, 'tcx> Lift<'tcx> for ty::InstanceDef<'a> {
758747
type Lifted = ty::InstanceDef<'tcx>;
759748
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
@@ -1332,13 +1321,7 @@ EnumTypeFoldableImpl! {
13321321
(ty::error::TypeError::ProjectionBoundsLength)(x),
13331322
(ty::error::TypeError::Sorts)(x),
13341323
(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),
1324+
(ty::error::TypeError::ConstMismatch)(x),
13421325
}
13431326
}
13441327

0 commit comments

Comments
 (0)