Fix const conditions for RPITITs
This commit is contained in:
parent
52890e8215
commit
4977640c79
5 changed files with 254 additions and 28 deletions
|
@ -371,10 +371,9 @@ pub(super) fn explicit_item_bounds_with_filter(
|
|||
associated_type_bounds(tcx, def_id, opaque_ty.bounds, opaque_ty.span, filter);
|
||||
return ty::EarlyBinder::bind(bounds);
|
||||
}
|
||||
Some(ty::ImplTraitInTraitData::Impl { .. }) => span_bug!(
|
||||
tcx.def_span(def_id),
|
||||
"item bounds for RPITIT in impl to be fed on def-id creation"
|
||||
),
|
||||
Some(ty::ImplTraitInTraitData::Impl { .. }) => {
|
||||
span_bug!(tcx.def_span(def_id), "RPITIT in impl should not have item bounds")
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
|
||||
|
|
|
@ -957,6 +957,15 @@ pub(super) fn const_conditions<'tcx>(
|
|||
bug!("const_conditions invoked for item that is not conditionally const: {def_id:?}");
|
||||
}
|
||||
|
||||
match tcx.opt_rpitit_info(def_id.to_def_id()) {
|
||||
// RPITITs inherit const conditions of their parent fn
|
||||
Some(
|
||||
ty::ImplTraitInTraitData::Impl { fn_def_id }
|
||||
| ty::ImplTraitInTraitData::Trait { fn_def_id, .. },
|
||||
) => return tcx.const_conditions(fn_def_id),
|
||||
None => {}
|
||||
}
|
||||
|
||||
let (generics, trait_def_id_and_supertraits, has_parent) = match tcx.hir_node_by_def_id(def_id)
|
||||
{
|
||||
Node::Item(item) => match item.kind {
|
||||
|
@ -1060,19 +1069,29 @@ pub(super) fn explicit_implied_const_bounds<'tcx>(
|
|||
bug!("const_conditions invoked for item that is not conditionally const: {def_id:?}");
|
||||
}
|
||||
|
||||
let bounds = match tcx.hir_node_by_def_id(def_id) {
|
||||
Node::Item(hir::Item { kind: hir::ItemKind::Trait(..), .. }) => {
|
||||
implied_predicates_with_filter(
|
||||
tcx,
|
||||
def_id.to_def_id(),
|
||||
PredicateFilter::SelfConstIfConst,
|
||||
)
|
||||
}
|
||||
Node::TraitItem(hir::TraitItem { kind: hir::TraitItemKind::Type(..), .. })
|
||||
| Node::OpaqueTy(_) => {
|
||||
let bounds = match tcx.opt_rpitit_info(def_id.to_def_id()) {
|
||||
// RPITIT's bounds are the same as opaque type bounds, but with
|
||||
// a projection self type.
|
||||
Some(ty::ImplTraitInTraitData::Trait { .. }) => {
|
||||
explicit_item_bounds_with_filter(tcx, def_id, PredicateFilter::ConstIfConst)
|
||||
}
|
||||
_ => bug!("explicit_implied_const_bounds called on wrong item: {def_id:?}"),
|
||||
Some(ty::ImplTraitInTraitData::Impl { .. }) => {
|
||||
span_bug!(tcx.def_span(def_id), "RPITIT in impl should not have item bounds")
|
||||
}
|
||||
None => match tcx.hir_node_by_def_id(def_id) {
|
||||
Node::Item(hir::Item { kind: hir::ItemKind::Trait(..), .. }) => {
|
||||
implied_predicates_with_filter(
|
||||
tcx,
|
||||
def_id.to_def_id(),
|
||||
PredicateFilter::SelfConstIfConst,
|
||||
)
|
||||
}
|
||||
Node::TraitItem(hir::TraitItem { kind: hir::TraitItemKind::Type(..), .. })
|
||||
| Node::OpaqueTy(_) => {
|
||||
explicit_item_bounds_with_filter(tcx, def_id, PredicateFilter::ConstIfConst)
|
||||
}
|
||||
_ => bug!("explicit_implied_const_bounds called on wrong item: {def_id:?}"),
|
||||
},
|
||||
};
|
||||
|
||||
bounds.map_bound(|bounds| {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue