use abstract consts when unifying ConstKind::Unevaluated
This commit is contained in:
parent
d327fa112b
commit
c3a772f55f
8 changed files with 96 additions and 10 deletions
|
@ -263,6 +263,16 @@ rustc_queries! {
|
|||
}
|
||||
}
|
||||
|
||||
query try_unify_abstract_consts(key: (
|
||||
(ty::WithOptConstParam<DefId>, SubstsRef<'tcx>),
|
||||
(ty::WithOptConstParam<DefId>, SubstsRef<'tcx>)
|
||||
)) -> bool {
|
||||
desc {
|
||||
|tcx| "trying to unify the generic constants {} and {}",
|
||||
tcx.def_path_str(key.0.0.did), tcx.def_path_str(key.1.0.did)
|
||||
}
|
||||
}
|
||||
|
||||
query mir_drops_elaborated_and_const_checked(
|
||||
key: ty::WithOptConstParam<LocalDefId>
|
||||
) -> &'tcx Steal<mir::Body<'tcx>> {
|
||||
|
|
|
@ -193,6 +193,22 @@ impl<'tcx> Key for (DefId, SubstsRef<'tcx>) {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Key
|
||||
for (
|
||||
(ty::WithOptConstParam<DefId>, SubstsRef<'tcx>),
|
||||
(ty::WithOptConstParam<DefId>, SubstsRef<'tcx>),
|
||||
)
|
||||
{
|
||||
type CacheSelector = DefaultCacheSelector;
|
||||
|
||||
fn query_crate(&self) -> CrateNum {
|
||||
(self.0).0.did.krate
|
||||
}
|
||||
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||
(self.0).0.did.default_span(tcx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Key for (LocalDefId, DefId, SubstsRef<'tcx>) {
|
||||
type CacheSelector = DefaultCacheSelector;
|
||||
|
||||
|
|
|
@ -576,7 +576,20 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
|
|||
new_val.map(ty::ConstKind::Value)
|
||||
}
|
||||
|
||||
// FIXME(const_generics): this is wrong, as it is a projection
|
||||
(
|
||||
ty::ConstKind::Unevaluated(a_def, a_substs, None),
|
||||
ty::ConstKind::Unevaluated(b_def, b_substs, None),
|
||||
) if tcx.features().const_evaluatable_checked => {
|
||||
if tcx.try_unify_abstract_consts(((a_def, a_substs), (b_def, b_substs))) {
|
||||
Ok(a.val)
|
||||
} else {
|
||||
Err(TypeError::ConstMismatch(expected_found(relation, a, b)))
|
||||
}
|
||||
}
|
||||
|
||||
// While this is slightly incorrect, it shouldn't matter for `min_const_generics`
|
||||
// and is the better alternative to waiting until `const_evaluatable_checked` can
|
||||
// be stabilized.
|
||||
(
|
||||
ty::ConstKind::Unevaluated(a_def, a_substs, a_promoted),
|
||||
ty::ConstKind::Unevaluated(b_def, b_substs, b_promoted),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue