Double check the lowered predicates in type_param_predicates
This commit is contained in:
parent
697eda5f9a
commit
81dba0755e
1 changed files with 24 additions and 7 deletions
|
@ -652,7 +652,7 @@ pub(super) fn implied_predicates_with_filter<'tcx>(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure when elaborating supertraits, probing for associated types, etc.,
|
// Make sure when elaborating supertraits, probing for associated types, etc.,
|
||||||
// we really truly are elaborating clauses that have `Self` as their self type.
|
// we really truly are elaborating clauses that have `ty` as their self type.
|
||||||
// This is very important since downstream code relies on this being correct.
|
// This is very important since downstream code relies on this being correct.
|
||||||
pub(super) fn assert_only_contains_predicates_from<'tcx>(
|
pub(super) fn assert_only_contains_predicates_from<'tcx>(
|
||||||
filter: PredicateFilter,
|
filter: PredicateFilter,
|
||||||
|
@ -794,8 +794,6 @@ pub(super) fn type_param_predicates<'tcx>(
|
||||||
None => {}
|
None => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
use rustc_hir::*;
|
|
||||||
|
|
||||||
// In the HIR, bounds can derive from two places. Either
|
// In the HIR, bounds can derive from two places. Either
|
||||||
// written inline like `<T: Foo>` or in a where-clause like
|
// written inline like `<T: Foo>` or in a where-clause like
|
||||||
// `where T: Foo`.
|
// `where T: Foo`.
|
||||||
|
@ -827,7 +825,7 @@ pub(super) fn type_param_predicates<'tcx>(
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Node::Item(item) = hir_node
|
if let Node::Item(item) = hir_node
|
||||||
&& let ItemKind::Trait(..) = item.kind
|
&& let hir::ItemKind::Trait(..) = item.kind
|
||||||
// Implied `Self: Trait` and supertrait bounds.
|
// Implied `Self: Trait` and supertrait bounds.
|
||||||
&& param_id == item_hir_id
|
&& param_id == item_hir_id
|
||||||
{
|
{
|
||||||
|
@ -842,9 +840,28 @@ pub(super) fn type_param_predicates<'tcx>(
|
||||||
PredicateFilter::SelfTraitThatDefines(assoc_name),
|
PredicateFilter::SelfTraitThatDefines(assoc_name),
|
||||||
));
|
));
|
||||||
|
|
||||||
ty::EarlyBinder::bind(
|
let bounds =
|
||||||
tcx.arena.alloc_from_iter(result.skip_binder().iter().copied().chain(extra_predicates)),
|
&*tcx.arena.alloc_from_iter(result.skip_binder().iter().copied().chain(extra_predicates));
|
||||||
)
|
|
||||||
|
// Double check that the bounds *only* contain `SelfTy: Trait` preds.
|
||||||
|
let self_ty = match tcx.def_kind(def_id) {
|
||||||
|
DefKind::TyParam => Ty::new_param(
|
||||||
|
tcx,
|
||||||
|
tcx.generics_of(item_def_id)
|
||||||
|
.param_def_id_to_index(tcx, def_id.to_def_id())
|
||||||
|
.expect("expected generic param to be owned by item"),
|
||||||
|
tcx.item_name(def_id.to_def_id()),
|
||||||
|
),
|
||||||
|
DefKind::Trait | DefKind::TraitAlias => tcx.types.self_param,
|
||||||
|
_ => unreachable!(),
|
||||||
|
};
|
||||||
|
assert_only_contains_predicates_from(
|
||||||
|
PredicateFilter::SelfTraitThatDefines(assoc_name),
|
||||||
|
bounds,
|
||||||
|
self_ty,
|
||||||
|
);
|
||||||
|
|
||||||
|
ty::EarlyBinder::bind(bounds)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> ItemCtxt<'tcx> {
|
impl<'tcx> ItemCtxt<'tcx> {
|
||||||
|
|
Loading…
Add table
Reference in a new issue