Fully fledged Clause type
This commit is contained in:
parent
fca56a8d2c
commit
21226eefb2
11 changed files with 155 additions and 96 deletions
|
@ -945,8 +945,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
|
||||
let mut trait_bounds = vec![];
|
||||
let mut projection_bounds = vec![];
|
||||
for (clause, span) in bounds.predicates() {
|
||||
let pred: ty::Predicate<'tcx> = clause.to_predicate(tcx);
|
||||
for (clause, span) in bounds.clauses() {
|
||||
let pred: ty::Predicate<'tcx> = clause.as_predicate();
|
||||
let bound_pred = pred.kind();
|
||||
match bound_pred.skip_binder() {
|
||||
ty::PredicateKind::Clause(clause) => match clause {
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
//! `ty` form from the HIR.
|
||||
|
||||
use rustc_hir::LangItem;
|
||||
use rustc_middle::ty::Binder;
|
||||
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt};
|
||||
use rustc_span::Span;
|
||||
|
||||
|
@ -24,62 +23,58 @@ use rustc_span::Span;
|
|||
/// include the self type (e.g., `trait_bounds`) but in others we do not
|
||||
#[derive(Default, PartialEq, Eq, Clone, Debug)]
|
||||
pub struct Bounds<'tcx> {
|
||||
pub predicates: Vec<(Binder<'tcx, ty::ClauseKind<'tcx>>, Span)>,
|
||||
pub clauses: Vec<(ty::Clause<'tcx>, Span)>,
|
||||
}
|
||||
|
||||
impl<'tcx> Bounds<'tcx> {
|
||||
pub fn push_region_bound(
|
||||
&mut self,
|
||||
_tcx: TyCtxt<'tcx>,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
region: ty::PolyTypeOutlivesPredicate<'tcx>,
|
||||
span: Span,
|
||||
) {
|
||||
self.predicates.push((region.map_bound(|p| ty::ClauseKind::TypeOutlives(p)), span));
|
||||
self.clauses
|
||||
.push((region.map_bound(|p| ty::ClauseKind::TypeOutlives(p)).to_predicate(tcx), span));
|
||||
}
|
||||
|
||||
pub fn push_trait_bound(
|
||||
&mut self,
|
||||
_tcx: TyCtxt<'tcx>,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
trait_ref: ty::PolyTraitRef<'tcx>,
|
||||
span: Span,
|
||||
constness: ty::BoundConstness,
|
||||
polarity: ty::ImplPolarity,
|
||||
) {
|
||||
self.predicates.push((
|
||||
trait_ref.map_bound(|trait_ref| {
|
||||
ty::ClauseKind::Trait(ty::TraitPredicate { trait_ref, constness, polarity })
|
||||
}),
|
||||
self.clauses.push((
|
||||
trait_ref
|
||||
.map_bound(|trait_ref| {
|
||||
ty::ClauseKind::Trait(ty::TraitPredicate { trait_ref, constness, polarity })
|
||||
})
|
||||
.to_predicate(tcx),
|
||||
span,
|
||||
));
|
||||
}
|
||||
|
||||
pub fn push_projection_bound(
|
||||
&mut self,
|
||||
_tcx: TyCtxt<'tcx>,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
projection: ty::PolyProjectionPredicate<'tcx>,
|
||||
span: Span,
|
||||
) {
|
||||
self.predicates.push((projection.map_bound(|proj| ty::ClauseKind::Projection(proj)), span));
|
||||
self.clauses.push((
|
||||
projection.map_bound(|proj| ty::ClauseKind::Projection(proj)).to_predicate(tcx),
|
||||
span,
|
||||
));
|
||||
}
|
||||
|
||||
pub fn push_sized(&mut self, tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span) {
|
||||
let sized_def_id = tcx.require_lang_item(LangItem::Sized, Some(span));
|
||||
let trait_ref = ty::TraitRef::new(tcx, sized_def_id, [ty]);
|
||||
// Preferable to put this obligation first, since we report better errors for sized ambiguity.
|
||||
self.predicates.insert(
|
||||
0,
|
||||
(
|
||||
ty::Binder::dummy(ty::ClauseKind::Trait(
|
||||
trait_ref.without_const().to_predicate(tcx),
|
||||
)),
|
||||
span,
|
||||
),
|
||||
);
|
||||
self.clauses.insert(0, (trait_ref.to_predicate(tcx), span));
|
||||
}
|
||||
|
||||
pub fn predicates(
|
||||
&self,
|
||||
) -> impl Iterator<Item = (Binder<'tcx, ty::ClauseKind<'tcx>>, Span)> + '_ {
|
||||
self.predicates.iter().cloned()
|
||||
pub fn clauses(&self) -> impl Iterator<Item = (ty::Clause<'tcx>, Span)> + '_ {
|
||||
self.clauses.iter().cloned()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ use crate::astconv::{AstConv, OnlySelfBounds};
|
|||
use rustc_hir as hir;
|
||||
use rustc_infer::traits::util;
|
||||
use rustc_middle::ty::subst::InternalSubsts;
|
||||
use rustc_middle::ty::ToPredicate;
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
use rustc_span::def_id::{DefId, LocalDefId};
|
||||
use rustc_span::Span;
|
||||
|
@ -49,8 +48,8 @@ fn associated_type_bounds<'tcx>(
|
|||
|
||||
let all_bounds = tcx.arena.alloc_from_iter(
|
||||
bounds
|
||||
.predicates()
|
||||
.map(|(clause, span)| (clause.to_predicate(tcx), span))
|
||||
.clauses()
|
||||
.map(|(clause, span)| (clause.as_predicate(), span))
|
||||
.chain(bounds_from_parent),
|
||||
);
|
||||
debug!(
|
||||
|
@ -80,9 +79,8 @@ 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.predicates().map(|(clause, span)| (clause.to_predicate(tcx), span)),
|
||||
)
|
||||
tcx.arena
|
||||
.alloc_from_iter(bounds.clauses().map(|(clause, span)| (clause.as_predicate(), span)))
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -126,8 +126,8 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
|
|||
predicates.extend(
|
||||
icx.astconv()
|
||||
.compute_bounds(tcx.types.self_param, self_bounds, OnlySelfBounds(false))
|
||||
.predicates()
|
||||
.map(|(clause, span)| (clause.to_predicate(tcx), span)),
|
||||
.clauses()
|
||||
.map(|(clause, span)| (clause.as_predicate(), span)),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -176,9 +176,8 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
|
|||
param.span,
|
||||
);
|
||||
trace!(?bounds);
|
||||
predicates.extend(
|
||||
bounds.predicates().map(|(clause, span)| (clause.to_predicate(tcx), span)),
|
||||
);
|
||||
predicates
|
||||
.extend(bounds.clauses().map(|(clause, span)| (clause.as_predicate(), span)));
|
||||
trace!(?predicates);
|
||||
}
|
||||
GenericParamKind::Const { .. } => {
|
||||
|
@ -237,9 +236,8 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
|
|||
bound_vars,
|
||||
OnlySelfBounds(false),
|
||||
);
|
||||
predicates.extend(
|
||||
bounds.predicates().map(|(clause, span)| (clause.to_predicate(tcx), span)),
|
||||
);
|
||||
predicates
|
||||
.extend(bounds.clauses().map(|(clause, span)| (clause.as_predicate(), span)));
|
||||
}
|
||||
|
||||
hir::WherePredicate::RegionPredicate(region_pred) => {
|
||||
|
@ -669,8 +667,8 @@ pub(super) fn implied_predicates_with_filter(
|
|||
// Combine the two lists to form the complete set of superbounds:
|
||||
let implied_bounds = &*tcx.arena.alloc_from_iter(
|
||||
superbounds
|
||||
.predicates()
|
||||
.map(|(clause, span)| (clause.to_predicate(tcx), span))
|
||||
.clauses()
|
||||
.map(|(clause, span)| (clause.as_predicate(), span))
|
||||
.chain(where_bounds_that_match),
|
||||
);
|
||||
debug!(?implied_bounds);
|
||||
|
@ -831,7 +829,7 @@ impl<'tcx> ItemCtxt<'tcx> {
|
|||
);
|
||||
}
|
||||
|
||||
bounds.predicates().map(|(clause, span)| (clause.to_predicate(self.tcx), span)).collect()
|
||||
bounds.clauses().map(|(clause, span)| (clause.as_predicate(), span)).collect()
|
||||
}
|
||||
|
||||
#[instrument(level = "trace", skip(self))]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue