Migrate predicates_of and caller_bounds to Clause
This commit is contained in:
parent
36fb58e433
commit
fbdef58414
77 changed files with 478 additions and 705 deletions
|
@ -220,7 +220,7 @@ fn compare_method_predicate_entailment<'tcx>(
|
|||
// the new hybrid bounds we computed.
|
||||
let normalize_cause = traits::ObligationCause::misc(impl_m_span, impl_m_def_id);
|
||||
let param_env = ty::ParamEnv::new(
|
||||
tcx.mk_predicates(&hybrid_preds.predicates),
|
||||
tcx.mk_clauses(&hybrid_preds.predicates),
|
||||
Reveal::UserFacing,
|
||||
hir::Constness::NotConst,
|
||||
);
|
||||
|
@ -1835,7 +1835,7 @@ fn compare_type_predicate_entailment<'tcx>(
|
|||
let impl_ty_span = tcx.def_span(impl_ty_def_id);
|
||||
let normalize_cause = traits::ObligationCause::misc(impl_ty_span, impl_ty_def_id);
|
||||
let param_env = ty::ParamEnv::new(
|
||||
tcx.mk_predicates(&hybrid_preds.predicates),
|
||||
tcx.mk_clauses(&hybrid_preds.predicates),
|
||||
Reveal::UserFacing,
|
||||
hir::Constness::NotConst,
|
||||
);
|
||||
|
@ -2011,7 +2011,7 @@ pub(super) fn check_type_bounds<'tcx>(
|
|||
.to_predicate(tcx),
|
||||
),
|
||||
};
|
||||
ty::ParamEnv::new(tcx.mk_predicates(&predicates), Reveal::UserFacing, param_env.constness())
|
||||
ty::ParamEnv::new(tcx.mk_clauses(&predicates), Reveal::UserFacing, param_env.constness())
|
||||
};
|
||||
debug!(?normalize_param_env);
|
||||
|
||||
|
|
|
@ -296,7 +296,7 @@ fn default_body_is_unstable(
|
|||
/// Re-sugar `ty::GenericPredicates` in a way suitable to be used in structured suggestions.
|
||||
fn bounds_from_generic_predicates<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
predicates: impl IntoIterator<Item = (ty::Predicate<'tcx>, Span)>,
|
||||
predicates: impl IntoIterator<Item = (ty::Clause<'tcx>, Span)>,
|
||||
) -> (String, String) {
|
||||
let mut types: FxHashMap<Ty<'tcx>, Vec<DefId>> = FxHashMap::default();
|
||||
let mut projections = vec![];
|
||||
|
@ -304,7 +304,7 @@ fn bounds_from_generic_predicates<'tcx>(
|
|||
debug!("predicate {:?}", predicate);
|
||||
let bound_predicate = predicate.kind();
|
||||
match bound_predicate.skip_binder() {
|
||||
ty::PredicateKind::Clause(ty::ClauseKind::Trait(trait_predicate)) => {
|
||||
ty::ClauseKind::Trait(trait_predicate) => {
|
||||
let entry = types.entry(trait_predicate.self_ty()).or_default();
|
||||
let def_id = trait_predicate.def_id();
|
||||
if Some(def_id) != tcx.lang_items().sized_trait() {
|
||||
|
@ -313,7 +313,7 @@ fn bounds_from_generic_predicates<'tcx>(
|
|||
entry.push(trait_predicate.def_id());
|
||||
}
|
||||
}
|
||||
ty::PredicateKind::Clause(ty::ClauseKind::Projection(projection_pred)) => {
|
||||
ty::ClauseKind::Projection(projection_pred) => {
|
||||
projections.push(bound_predicate.rebind(projection_pred));
|
||||
}
|
||||
_ => {}
|
||||
|
@ -362,7 +362,7 @@ fn fn_sig_suggestion<'tcx>(
|
|||
tcx: TyCtxt<'tcx>,
|
||||
sig: ty::FnSig<'tcx>,
|
||||
ident: Ident,
|
||||
predicates: impl IntoIterator<Item = (ty::Predicate<'tcx>, Span)>,
|
||||
predicates: impl IntoIterator<Item = (ty::Clause<'tcx>, Span)>,
|
||||
assoc: ty::AssocItem,
|
||||
) -> String {
|
||||
let args = sig
|
||||
|
|
|
@ -15,7 +15,7 @@ use rustc_middle::mir::ConstraintCategory;
|
|||
use rustc_middle::query::Providers;
|
||||
use rustc_middle::ty::trait_def::TraitSpecializationKind;
|
||||
use rustc_middle::ty::{
|
||||
self, AdtKind, GenericParamDefKind, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable,
|
||||
self, AdtKind, GenericParamDefKind, ToPredicate, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable,
|
||||
TypeVisitable, TypeVisitableExt, TypeVisitor,
|
||||
};
|
||||
use rustc_middle::ty::{GenericArgKind, InternalSubsts};
|
||||
|
@ -322,7 +322,7 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, associated_items: &[hir::TraitItemRe
|
|||
// Gather the bounds with which all other items inside of this trait constrain the GAT.
|
||||
// This is calculated by taking the intersection of the bounds that each item
|
||||
// constrains the GAT with individually.
|
||||
let mut new_required_bounds: Option<FxHashSet<ty::Predicate<'_>>> = None;
|
||||
let mut new_required_bounds: Option<FxHashSet<ty::Clause<'_>>> = None;
|
||||
for item in associated_items {
|
||||
let item_def_id = item.id.owner_id;
|
||||
// Skip our own GAT, since it does not constrain itself at all.
|
||||
|
@ -419,9 +419,17 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, associated_items: &[hir::TraitItemRe
|
|||
let mut unsatisfied_bounds: Vec<_> = required_bounds
|
||||
.into_iter()
|
||||
.filter(|clause| match clause.kind().skip_binder() {
|
||||
ty::PredicateKind::Clause(ty::ClauseKind::RegionOutlives(
|
||||
ty::OutlivesPredicate(a, b),
|
||||
)) => !region_known_to_outlive(
|
||||
ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(a, b)) => {
|
||||
!region_known_to_outlive(
|
||||
tcx,
|
||||
gat_def_id.def_id,
|
||||
param_env,
|
||||
&FxIndexSet::default(),
|
||||
a,
|
||||
b,
|
||||
)
|
||||
}
|
||||
ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate(a, b)) => !ty_known_to_outlive(
|
||||
tcx,
|
||||
gat_def_id.def_id,
|
||||
param_env,
|
||||
|
@ -429,18 +437,7 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, associated_items: &[hir::TraitItemRe
|
|||
a,
|
||||
b,
|
||||
),
|
||||
ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate(
|
||||
a,
|
||||
b,
|
||||
))) => !ty_known_to_outlive(
|
||||
tcx,
|
||||
gat_def_id.def_id,
|
||||
param_env,
|
||||
&FxIndexSet::default(),
|
||||
a,
|
||||
b,
|
||||
),
|
||||
_ => bug!("Unexpected PredicateKind"),
|
||||
_ => bug!("Unexpected ClauseKind"),
|
||||
})
|
||||
.map(|clause| clause.to_string())
|
||||
.collect();
|
||||
|
@ -488,7 +485,7 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, associated_items: &[hir::TraitItemRe
|
|||
fn augment_param_env<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
new_predicates: Option<&FxHashSet<ty::Predicate<'tcx>>>,
|
||||
new_predicates: Option<&FxHashSet<ty::Clause<'tcx>>>,
|
||||
) -> ty::ParamEnv<'tcx> {
|
||||
let Some(new_predicates) = new_predicates else {
|
||||
return param_env;
|
||||
|
@ -498,7 +495,7 @@ fn augment_param_env<'tcx>(
|
|||
return param_env;
|
||||
}
|
||||
|
||||
let bounds = tcx.mk_predicates_from_iter(
|
||||
let bounds = tcx.mk_clauses_from_iter(
|
||||
param_env.caller_bounds().iter().chain(new_predicates.iter().cloned()),
|
||||
);
|
||||
// FIXME(compiler-errors): Perhaps there is a case where we need to normalize this
|
||||
|
@ -524,7 +521,7 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
|
|||
wf_tys: &FxIndexSet<Ty<'tcx>>,
|
||||
gat_def_id: LocalDefId,
|
||||
gat_generics: &'tcx ty::Generics,
|
||||
) -> Option<FxHashSet<ty::Predicate<'tcx>>> {
|
||||
) -> Option<FxHashSet<ty::Clause<'tcx>>> {
|
||||
// The bounds we that we would require from `to_check`
|
||||
let mut bounds = FxHashSet::default();
|
||||
|
||||
|
@ -573,11 +570,10 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
|
|||
);
|
||||
// The predicate we expect to see. (In our example,
|
||||
// `Self: 'me`.)
|
||||
let clause = ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(
|
||||
ty::OutlivesPredicate(ty_param, region_param),
|
||||
));
|
||||
let clause = tcx.mk_predicate(ty::Binder::dummy(clause));
|
||||
bounds.insert(clause);
|
||||
bounds.insert(
|
||||
ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate(ty_param, region_param))
|
||||
.to_predicate(tcx),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -622,11 +618,13 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
|
|||
},
|
||||
);
|
||||
// The predicate we expect to see.
|
||||
let clause = ty::PredicateKind::Clause(ty::ClauseKind::RegionOutlives(
|
||||
ty::OutlivesPredicate(region_a_param, region_b_param),
|
||||
));
|
||||
let clause = tcx.mk_predicate(ty::Binder::dummy(clause));
|
||||
bounds.insert(clause);
|
||||
bounds.insert(
|
||||
ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(
|
||||
region_a_param,
|
||||
region_b_param,
|
||||
))
|
||||
.to_predicate(tcx),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1406,7 +1404,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
|
|||
infcx,
|
||||
wfcx.param_env.without_const(),
|
||||
wfcx.body_def_id,
|
||||
p,
|
||||
p.as_predicate(),
|
||||
sp,
|
||||
)
|
||||
});
|
||||
|
@ -1875,9 +1873,7 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
|
|||
// We lower empty bounds like `Vec<dyn Copy>:` as
|
||||
// `WellFormed(Vec<dyn Copy>)`, which will later get checked by
|
||||
// regular WF checking
|
||||
if let ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(..)) =
|
||||
pred.kind().skip_binder()
|
||||
{
|
||||
if let ty::ClauseKind::WellFormed(..) = pred.kind().skip_binder() {
|
||||
continue;
|
||||
}
|
||||
// Match the existing behavior.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue