Auto merge of #132894 - frank-king:feature/where-refactor, r=cjgillot
Refactor `where` predicates, and reserve for attributes support Refactor `WherePredicate` to `WherePredicateKind`, and reserve for attributes support in `where` predicates. This is a part of #115590 and is split from #132388. r? petrochenkov
This commit is contained in:
commit
f2abf827c1
44 changed files with 394 additions and 408 deletions
|
@ -1100,7 +1100,7 @@ fn check_region_bounds_on_impl_item<'tcx>(
|
|||
// FIXME: we could potentially look at the impl's bounds to not point at bounds that
|
||||
// *are* present in the impl.
|
||||
for p in trait_generics.predicates {
|
||||
if let hir::WherePredicate::BoundPredicate(pred) = p {
|
||||
if let hir::WherePredicateKind::BoundPredicate(pred) = p.kind {
|
||||
for b in pred.bounds {
|
||||
if let hir::GenericBound::Outlives(lt) = b {
|
||||
bounds_span.push(lt.ident.span);
|
||||
|
@ -1113,7 +1113,7 @@ fn check_region_bounds_on_impl_item<'tcx>(
|
|||
{
|
||||
let mut impl_bounds = 0;
|
||||
for p in impl_generics.predicates {
|
||||
if let hir::WherePredicate::BoundPredicate(pred) = p {
|
||||
if let hir::WherePredicateKind::BoundPredicate(pred) = p.kind {
|
||||
for b in pred.bounds {
|
||||
if let hir::GenericBound::Outlives(_) = b {
|
||||
impl_bounds += 1;
|
||||
|
|
|
@ -1921,8 +1921,8 @@ fn check_variances_for_type_defn<'tcx>(
|
|||
hir_generics
|
||||
.predicates
|
||||
.iter()
|
||||
.filter_map(|predicate| match predicate {
|
||||
hir::WherePredicate::BoundPredicate(predicate) => {
|
||||
.filter_map(|predicate| match predicate.kind {
|
||||
hir::WherePredicateKind::BoundPredicate(predicate) => {
|
||||
match icx.lower_ty(predicate.bounded_ty).kind() {
|
||||
ty::Param(data) => Some(Parameter(data.index)),
|
||||
_ => None,
|
||||
|
@ -2202,8 +2202,8 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
|
|||
span = predicates
|
||||
.iter()
|
||||
// There seems to be no better way to find out which predicate we are in
|
||||
.find(|pred| pred.span().contains(obligation_span))
|
||||
.map(|pred| pred.span())
|
||||
.find(|pred| pred.span.contains(obligation_span))
|
||||
.map(|pred| pred.span)
|
||||
.unwrap_or(obligation_span);
|
||||
}
|
||||
|
||||
|
|
|
@ -238,11 +238,11 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
|
|||
trace!(?predicates);
|
||||
// Add inline `<T: Foo>` bounds and bounds in the where clause.
|
||||
for predicate in hir_generics.predicates {
|
||||
match predicate {
|
||||
hir::WherePredicate::BoundPredicate(bound_pred) => {
|
||||
match predicate.kind {
|
||||
hir::WherePredicateKind::BoundPredicate(bound_pred) => {
|
||||
let ty = icx.lowerer().lower_ty_maybe_return_type_notation(bound_pred.bounded_ty);
|
||||
|
||||
let bound_vars = tcx.late_bound_vars(bound_pred.hir_id);
|
||||
let bound_vars = tcx.late_bound_vars(predicate.hir_id);
|
||||
// Keep the type around in a dummy predicate, in case of no bounds.
|
||||
// That way, `where Ty:` is not a complete noop (see #53696) and `Ty`
|
||||
// is still checked for WF.
|
||||
|
@ -275,7 +275,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
|
|||
predicates.extend(bounds.clauses());
|
||||
}
|
||||
|
||||
hir::WherePredicate::RegionPredicate(region_pred) => {
|
||||
hir::WherePredicateKind::RegionPredicate(region_pred) => {
|
||||
let r1 = icx
|
||||
.lowerer()
|
||||
.lower_lifetime(region_pred.lifetime, RegionInferReason::RegionPredicate);
|
||||
|
@ -298,7 +298,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
|
|||
}))
|
||||
}
|
||||
|
||||
hir::WherePredicate::EqPredicate(..) => {
|
||||
hir::WherePredicateKind::EqPredicate(..) => {
|
||||
// FIXME(#20041)
|
||||
}
|
||||
}
|
||||
|
@ -881,7 +881,8 @@ impl<'tcx> ItemCtxt<'tcx> {
|
|||
let mut bounds = Bounds::default();
|
||||
|
||||
for predicate in hir_generics.predicates {
|
||||
let hir::WherePredicate::BoundPredicate(predicate) = predicate else {
|
||||
let hir_id = predicate.hir_id;
|
||||
let hir::WherePredicateKind::BoundPredicate(predicate) = predicate.kind else {
|
||||
continue;
|
||||
};
|
||||
|
||||
|
@ -901,7 +902,7 @@ impl<'tcx> ItemCtxt<'tcx> {
|
|||
|
||||
let bound_ty = self.lowerer().lower_ty_maybe_return_type_notation(predicate.bounded_ty);
|
||||
|
||||
let bound_vars = self.tcx.late_bound_vars(predicate.hir_id);
|
||||
let bound_vars = self.tcx.late_bound_vars(hir_id);
|
||||
self.lowerer().lower_bounds(
|
||||
bound_ty,
|
||||
predicate.bounds,
|
||||
|
@ -974,10 +975,10 @@ pub(super) fn const_conditions<'tcx>(
|
|||
let mut bounds = Bounds::default();
|
||||
|
||||
for pred in generics.predicates {
|
||||
match pred {
|
||||
hir::WherePredicate::BoundPredicate(bound_pred) => {
|
||||
match pred.kind {
|
||||
hir::WherePredicateKind::BoundPredicate(bound_pred) => {
|
||||
let ty = icx.lowerer().lower_ty_maybe_return_type_notation(bound_pred.bounded_ty);
|
||||
let bound_vars = tcx.late_bound_vars(bound_pred.hir_id);
|
||||
let bound_vars = tcx.late_bound_vars(pred.hir_id);
|
||||
icx.lowerer().lower_bounds(
|
||||
ty,
|
||||
bound_pred.bounds.iter(),
|
||||
|
|
|
@ -936,9 +936,9 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
|
|||
}
|
||||
|
||||
fn visit_where_predicate(&mut self, predicate: &'tcx hir::WherePredicate<'tcx>) {
|
||||
match predicate {
|
||||
&hir::WherePredicate::BoundPredicate(hir::WhereBoundPredicate {
|
||||
hir_id,
|
||||
let hir_id = predicate.hir_id;
|
||||
match predicate.kind {
|
||||
&hir::WherePredicateKind::BoundPredicate(hir::WhereBoundPredicate {
|
||||
bounded_ty,
|
||||
bounds,
|
||||
bound_generic_params,
|
||||
|
@ -979,7 +979,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
|
|||
walk_list!(this, visit_param_bound, bounds);
|
||||
})
|
||||
}
|
||||
&hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate {
|
||||
&hir::WherePredicateKind::RegionPredicate(hir::WhereRegionPredicate {
|
||||
lifetime,
|
||||
bounds,
|
||||
..
|
||||
|
@ -987,7 +987,9 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
|
|||
self.visit_lifetime(lifetime);
|
||||
walk_list!(self, visit_param_bound, bounds);
|
||||
}
|
||||
&hir::WherePredicate::EqPredicate(hir::WhereEqPredicate { lhs_ty, rhs_ty, .. }) => {
|
||||
&hir::WherePredicateKind::EqPredicate(hir::WhereEqPredicate {
|
||||
lhs_ty, rhs_ty, ..
|
||||
}) => {
|
||||
self.visit_ty(lhs_ty);
|
||||
self.visit_ty(rhs_ty);
|
||||
}
|
||||
|
@ -2073,7 +2075,8 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
|
|||
// bounds since we'll be emitting a hard error in HIR lowering, so this
|
||||
// is purely speculative.
|
||||
let one_bound = generics.predicates.iter().find_map(|predicate| {
|
||||
let hir::WherePredicate::BoundPredicate(predicate) = predicate else {
|
||||
let hir::WherePredicateKind::BoundPredicate(predicate) = predicate.kind
|
||||
else {
|
||||
return None;
|
||||
};
|
||||
let hir::TyKind::Path(hir::QPath::Resolved(None, bounded_path)) =
|
||||
|
|
|
@ -69,7 +69,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||
search_bounds(hir_bounds);
|
||||
if let Some((self_ty, where_clause)) = self_ty_where_predicates {
|
||||
for clause in where_clause {
|
||||
if let hir::WherePredicate::BoundPredicate(pred) = clause
|
||||
if let hir::WherePredicateKind::BoundPredicate(pred) = clause.kind
|
||||
&& pred.is_param_bound(self_ty.to_def_id())
|
||||
{
|
||||
search_bounds(pred.bounds);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue