Refactor where
predicates, and reserve for attributes support
This commit is contained in:
parent
67a8c64259
commit
161221da9e
44 changed files with 394 additions and 408 deletions
|
@ -1407,7 +1407,7 @@ declare_lint_pass!(TypeAliasBounds => [TYPE_ALIAS_BOUNDS]);
|
|||
impl TypeAliasBounds {
|
||||
pub(crate) fn affects_object_lifetime_defaults(pred: &hir::WherePredicate<'_>) -> bool {
|
||||
// Bounds of the form `T: 'a` with `T` type param affect object lifetime defaults.
|
||||
if let hir::WherePredicate::BoundPredicate(pred) = pred
|
||||
if let hir::WherePredicateKind::BoundPredicate(pred) = pred.kind
|
||||
&& pred.bounds.iter().any(|bound| matches!(bound, hir::GenericBound::Outlives(_)))
|
||||
&& pred.bound_generic_params.is_empty() // indeed, even if absent from the RHS
|
||||
&& pred.bounded_ty.as_generic_param().is_some()
|
||||
|
@ -1451,11 +1451,11 @@ impl<'tcx> LateLintPass<'tcx> for TypeAliasBounds {
|
|||
let mut inline_sugg = Vec::new();
|
||||
|
||||
for p in generics.predicates {
|
||||
let span = p.span();
|
||||
if p.in_where_clause() {
|
||||
let span = p.span;
|
||||
if p.kind.in_where_clause() {
|
||||
where_spans.push(span);
|
||||
} else {
|
||||
for b in p.bounds() {
|
||||
for b in p.kind.bounds() {
|
||||
inline_spans.push(b.span());
|
||||
}
|
||||
inline_sugg.push((span, String::new()));
|
||||
|
@ -2071,7 +2071,7 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
|
|||
let num_where_predicates = hir_generics
|
||||
.predicates
|
||||
.iter()
|
||||
.filter(|predicate| predicate.in_where_clause())
|
||||
.filter(|predicate| predicate.kind.in_where_clause())
|
||||
.count();
|
||||
|
||||
let mut bound_count = 0;
|
||||
|
@ -2080,8 +2080,8 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
|
|||
let mut dropped_where_predicate_count = 0;
|
||||
for (i, where_predicate) in hir_generics.predicates.iter().enumerate() {
|
||||
let (relevant_lifetimes, bounds, predicate_span, in_where_clause) =
|
||||
match where_predicate {
|
||||
hir::WherePredicate::RegionPredicate(predicate) => {
|
||||
match where_predicate.kind {
|
||||
hir::WherePredicateKind::RegionPredicate(predicate) => {
|
||||
if let Some(ResolvedArg::EarlyBound(region_def_id)) =
|
||||
cx.tcx.named_bound_var(predicate.lifetime.hir_id)
|
||||
{
|
||||
|
@ -2090,21 +2090,21 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
|
|||
cx.tcx,
|
||||
// don't warn if the inferred span actually came from the predicate we're looking at
|
||||
// this happens if the type is recursively defined
|
||||
inferred_outlives
|
||||
.iter()
|
||||
.filter(|(_, span)| !predicate.span.contains(*span)),
|
||||
inferred_outlives.iter().filter(|(_, span)| {
|
||||
!where_predicate.span.contains(*span)
|
||||
}),
|
||||
item.owner_id.def_id,
|
||||
region_def_id,
|
||||
),
|
||||
&predicate.bounds,
|
||||
predicate.span,
|
||||
where_predicate.span,
|
||||
predicate.in_where_clause,
|
||||
)
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
hir::WherePredicate::BoundPredicate(predicate) => {
|
||||
hir::WherePredicateKind::BoundPredicate(predicate) => {
|
||||
// FIXME we can also infer bounds on associated types,
|
||||
// and should check for them here.
|
||||
match predicate.bounded_ty.kind {
|
||||
|
@ -2118,12 +2118,12 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
|
|||
// don't warn if the inferred span actually came from the predicate we're looking at
|
||||
// this happens if the type is recursively defined
|
||||
inferred_outlives.iter().filter(|(_, span)| {
|
||||
!predicate.span.contains(*span)
|
||||
!where_predicate.span.contains(*span)
|
||||
}),
|
||||
index,
|
||||
),
|
||||
&predicate.bounds,
|
||||
predicate.span,
|
||||
where_predicate.span,
|
||||
predicate.origin == PredicateOrigin::WhereClause,
|
||||
)
|
||||
}
|
||||
|
@ -2161,7 +2161,7 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
|
|||
} else if i + 1 < num_where_predicates {
|
||||
// If all the bounds on a predicate were inferable and there are
|
||||
// further predicates, we want to eat the trailing comma.
|
||||
let next_predicate_span = hir_generics.predicates[i + 1].span();
|
||||
let next_predicate_span = hir_generics.predicates[i + 1].span;
|
||||
if next_predicate_span.from_expansion() {
|
||||
where_lint_spans.push(predicate_span);
|
||||
} else {
|
||||
|
|
|
@ -300,7 +300,7 @@ impl<'a> LintDiagnostic<'a, ()> for BuiltinTypeAliasBounds<'_> {
|
|||
let affect_object_lifetime_defaults = self
|
||||
.preds
|
||||
.iter()
|
||||
.filter(|pred| pred.in_where_clause() == self.in_where_clause)
|
||||
.filter(|pred| pred.kind.in_where_clause() == self.in_where_clause)
|
||||
.any(|pred| TypeAliasBounds::affects_object_lifetime_defaults(pred));
|
||||
|
||||
// If there are any shorthand assoc tys, then the bounds can't be removed automatically.
|
||||
|
|
|
@ -1304,12 +1304,12 @@ impl EarlyLintPass for UnusedParens {
|
|||
}
|
||||
|
||||
fn enter_where_predicate(&mut self, _: &EarlyContext<'_>, pred: &ast::WherePredicate) {
|
||||
use rustc_ast::{WhereBoundPredicate, WherePredicate};
|
||||
if let WherePredicate::BoundPredicate(WhereBoundPredicate {
|
||||
use rustc_ast::{WhereBoundPredicate, WherePredicateKind};
|
||||
if let WherePredicateKind::BoundPredicate(WhereBoundPredicate {
|
||||
bounded_ty,
|
||||
bound_generic_params,
|
||||
..
|
||||
}) = pred
|
||||
}) = &pred.kind
|
||||
&& let ast::TyKind::Paren(_) = &bounded_ty.kind
|
||||
&& bound_generic_params.is_empty()
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue