Migrate item_bounds to ty::Clause
This commit is contained in:
parent
2efe091705
commit
46a650f4e0
37 changed files with 232 additions and 152 deletions
|
@ -409,9 +409,7 @@ fn fn_sig_suggestion<'tcx>(
|
|||
output = if let ty::Alias(_, alias_ty) = *output.kind() {
|
||||
tcx.explicit_item_bounds(alias_ty.def_id)
|
||||
.subst_iter_copied(tcx, alias_ty.substs)
|
||||
.find_map(|(bound, _)| {
|
||||
bound.to_opt_poly_projection_pred()?.no_bound_vars()?.term.ty()
|
||||
})
|
||||
.find_map(|(bound, _)| bound.as_projection_clause()?.no_bound_vars()?.term.ty())
|
||||
.unwrap_or_else(|| {
|
||||
span_bug!(
|
||||
ident.span,
|
||||
|
|
|
@ -1086,7 +1086,7 @@ fn check_associated_type_bounds(wfcx: &WfCheckingCtxt<'_, '_>, item: ty::AssocIt
|
|||
wfcx.infcx,
|
||||
wfcx.param_env,
|
||||
wfcx.body_def_id,
|
||||
normalized_bound,
|
||||
normalized_bound.as_predicate(),
|
||||
bound_span,
|
||||
)
|
||||
});
|
||||
|
@ -1562,7 +1562,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInTraitFinder<'_, 'tcx> {
|
|||
self.wfcx.infcx,
|
||||
self.wfcx.param_env,
|
||||
self.wfcx.body_def_id,
|
||||
bound,
|
||||
bound.as_predicate(),
|
||||
bound_span,
|
||||
));
|
||||
// Set the debruijn index back to innermost here, since we already eagerly
|
||||
|
|
|
@ -19,7 +19,7 @@ fn associated_type_bounds<'tcx>(
|
|||
assoc_item_def_id: LocalDefId,
|
||||
ast_bounds: &'tcx [hir::GenericBound<'tcx>],
|
||||
span: Span,
|
||||
) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
|
||||
) -> &'tcx [(ty::Clause<'tcx>, Span)] {
|
||||
let item_ty = tcx.mk_projection(
|
||||
assoc_item_def_id.to_def_id(),
|
||||
InternalSubsts::identity_for_item(tcx, assoc_item_def_id),
|
||||
|
@ -33,8 +33,11 @@ fn associated_type_bounds<'tcx>(
|
|||
let trait_def_id = tcx.local_parent(assoc_item_def_id);
|
||||
let trait_predicates = tcx.trait_explicit_predicates_and_bounds(trait_def_id);
|
||||
|
||||
let bounds_from_parent = trait_predicates.predicates.iter().copied().filter(|(pred, _)| {
|
||||
match pred.kind().skip_binder() {
|
||||
let bounds_from_parent = trait_predicates
|
||||
.predicates
|
||||
.iter()
|
||||
.copied()
|
||||
.filter(|(pred, _)| match pred.kind().skip_binder() {
|
||||
ty::PredicateKind::Clause(ty::ClauseKind::Trait(tr)) => tr.self_ty() == item_ty,
|
||||
ty::PredicateKind::Clause(ty::ClauseKind::Projection(proj)) => {
|
||||
proj.projection_ty.self_ty() == item_ty
|
||||
|
@ -43,15 +46,10 @@ fn associated_type_bounds<'tcx>(
|
|||
outlives.0 == item_ty
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
});
|
||||
})
|
||||
.map(|(pred, span)| (pred.as_clause().unwrap(), span));
|
||||
|
||||
let all_bounds = tcx.arena.alloc_from_iter(
|
||||
bounds
|
||||
.clauses()
|
||||
.map(|(clause, span)| (clause.as_predicate(), span))
|
||||
.chain(bounds_from_parent),
|
||||
);
|
||||
let all_bounds = tcx.arena.alloc_from_iter(bounds.clauses().chain(bounds_from_parent));
|
||||
debug!(
|
||||
"associated_type_bounds({}) = {:?}",
|
||||
tcx.def_path_str(assoc_item_def_id.to_def_id()),
|
||||
|
@ -71,7 +69,7 @@ fn opaque_type_bounds<'tcx>(
|
|||
ast_bounds: &'tcx [hir::GenericBound<'tcx>],
|
||||
item_ty: Ty<'tcx>,
|
||||
span: Span,
|
||||
) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
|
||||
) -> &'tcx [(ty::Clause<'tcx>, Span)] {
|
||||
ty::print::with_no_queries!({
|
||||
let icx = ItemCtxt::new(tcx, opaque_def_id);
|
||||
let mut bounds = icx.astconv().compute_bounds(item_ty, ast_bounds, OnlySelfBounds(false));
|
||||
|
@ -79,15 +77,14 @@ fn opaque_type_bounds<'tcx>(
|
|||
icx.astconv().add_implicitly_sized(&mut bounds, item_ty, ast_bounds, None, span);
|
||||
debug!(?bounds);
|
||||
|
||||
tcx.arena
|
||||
.alloc_from_iter(bounds.clauses().map(|(clause, span)| (clause.as_predicate(), span)))
|
||||
tcx.arena.alloc_from_iter(bounds.clauses())
|
||||
})
|
||||
}
|
||||
|
||||
pub(super) fn explicit_item_bounds(
|
||||
tcx: TyCtxt<'_>,
|
||||
def_id: LocalDefId,
|
||||
) -> ty::EarlyBinder<&'_ [(ty::Predicate<'_>, Span)]> {
|
||||
) -> ty::EarlyBinder<&'_ [(ty::Clause<'_>, Span)]> {
|
||||
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.
|
||||
|
@ -139,11 +136,8 @@ pub(super) fn explicit_item_bounds(
|
|||
pub(super) fn item_bounds(
|
||||
tcx: TyCtxt<'_>,
|
||||
def_id: DefId,
|
||||
) -> ty::EarlyBinder<&'_ ty::List<ty::Predicate<'_>>> {
|
||||
) -> ty::EarlyBinder<&'_ ty::List<ty::Clause<'_>>> {
|
||||
tcx.explicit_item_bounds(def_id).map_bound(|bounds| {
|
||||
tcx.mk_predicates_from_iter(util::elaborate(
|
||||
tcx,
|
||||
bounds.iter().map(|&(bound, _span)| bound),
|
||||
))
|
||||
tcx.mk_clauses_from_iter(util::elaborate(tcx, bounds.iter().map(|&(bound, _span)| bound)))
|
||||
})
|
||||
}
|
||||
|
|
|
@ -162,28 +162,25 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
|
|||
// which thus mentions `'a` and should thus accept hidden types that borrow 'a
|
||||
// instead of requiring an additional `+ 'a`.
|
||||
match pred.kind().skip_binder() {
|
||||
ty::PredicateKind::Clause(ty::ClauseKind::Trait(ty::TraitPredicate {
|
||||
ty::ClauseKind::Trait(ty::TraitPredicate {
|
||||
trait_ref: ty::TraitRef { def_id: _, substs, .. },
|
||||
constness: _,
|
||||
polarity: _,
|
||||
})) => {
|
||||
}) => {
|
||||
for subst in &substs[1..] {
|
||||
subst.visit_with(&mut collector);
|
||||
}
|
||||
}
|
||||
ty::PredicateKind::Clause(ty::ClauseKind::Projection(ty::ProjectionPredicate {
|
||||
ty::ClauseKind::Projection(ty::ProjectionPredicate {
|
||||
projection_ty: ty::AliasTy { substs, .. },
|
||||
term,
|
||||
})) => {
|
||||
}) => {
|
||||
for subst in &substs[1..] {
|
||||
subst.visit_with(&mut collector);
|
||||
}
|
||||
term.visit_with(&mut collector);
|
||||
}
|
||||
ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate(
|
||||
_,
|
||||
region,
|
||||
))) => {
|
||||
ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate(_, region)) => {
|
||||
region.visit_with(&mut collector);
|
||||
}
|
||||
_ => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue