Skip to content

Commit 9e75cbe

Browse files
committed
introduce new TypeError variant: ConstMismatchTooGeneric
1 parent 390bb34 commit 9e75cbe

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

compiler/rustc_middle/src/ty/error.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ pub enum TypeError<'tcx> {
6767
),
6868
ObjectUnsafeCoercion(DefId),
6969
ConstMismatch(ExpectedFound<&'tcx ty::Const<'tcx>>),
70+
ConstMismatchTooGeneric(ExpectedFound<&'tcx ty::Const<'tcx>>, Option<String>),
7071

7172
IntrinsicCast,
7273
/// Safe `#[target_feature]` functions are not assignable to safe function pointers.
@@ -201,6 +202,12 @@ impl<'tcx> fmt::Display for TypeError<'tcx> {
201202
ConstMismatch(ref values) => {
202203
write!(f, "expected `{}`, found `{}`", values.expected, values.found)
203204
}
205+
ConstMismatchTooGeneric(ref values, ref suggestion) => match suggestion {
206+
Some(sugg) => {
207+
write!(f, "expected `{}`, found `{}`", values.expected, sugg)
208+
}
209+
None => write!(f, "expected `{}`, found `{}`", values.expected, values.found),
210+
},
204211
IntrinsicCast => write!(f, "cannot coerce intrinsics to function pointers"),
205212
TargetFeatureCast(_) => write!(
206213
f,
@@ -233,6 +240,7 @@ impl<'tcx> TypeError<'tcx> {
233240
| ProjectionMismatched(_)
234241
| ExistentialMismatch(_)
235242
| ConstMismatch(_)
243+
| ConstMismatchTooGeneric(_, _)
236244
| IntrinsicCast
237245
| ObjectUnsafeCoercion(_) => true,
238246
}

compiler/rustc_middle/src/ty/structural_impls.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,9 @@ impl<'a, 'tcx> Lift<'tcx> for ty::error::TypeError<'a> {
625625
Sorts(x) => return tcx.lift(x).map(Sorts),
626626
ExistentialMismatch(x) => return tcx.lift(x).map(ExistentialMismatch),
627627
ConstMismatch(x) => return tcx.lift(x).map(ConstMismatch),
628+
ConstMismatchTooGeneric(x, s) => {
629+
return tcx.lift(x).map(|x| ConstMismatchTooGeneric(x, s));
630+
}
628631
IntrinsicCast => IntrinsicCast,
629632
TargetFeatureCast(x) => TargetFeatureCast(x),
630633
ObjectUnsafeCoercion(x) => return tcx.lift(x).map(ObjectUnsafeCoercion),

0 commit comments

Comments
 (0)