Introduce PredicateKind::Clause
This commit is contained in:
parent
42cc8e8f4e
commit
974e2837bb
75 changed files with 568 additions and 407 deletions
|
@ -1638,19 +1638,20 @@ declare_lint_pass!(
|
|||
impl<'tcx> LateLintPass<'tcx> for TrivialConstraints {
|
||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
|
||||
use rustc_middle::ty::visit::TypeVisitable;
|
||||
use rustc_middle::ty::Clause;
|
||||
use rustc_middle::ty::PredicateKind::*;
|
||||
|
||||
if cx.tcx.features().trivial_bounds {
|
||||
let predicates = cx.tcx.predicates_of(item.owner_id);
|
||||
for &(predicate, span) in predicates.predicates {
|
||||
let predicate_kind_name = match predicate.kind().skip_binder() {
|
||||
Trait(..) => "trait",
|
||||
TypeOutlives(..) |
|
||||
RegionOutlives(..) => "lifetime",
|
||||
Clause(Clause::Trait(..)) => "trait",
|
||||
Clause(Clause::TypeOutlives(..)) |
|
||||
Clause(Clause::RegionOutlives(..)) => "lifetime",
|
||||
|
||||
// Ignore projections, as they can only be global
|
||||
// if the trait bound is global
|
||||
Projection(..) |
|
||||
Clause(Clause::Projection(..)) |
|
||||
// Ignore bounds that a user can't type
|
||||
WellFormed(..) |
|
||||
ObjectSafe(..) |
|
||||
|
@ -2051,7 +2052,10 @@ impl ExplicitOutlivesRequirements {
|
|||
inferred_outlives
|
||||
.iter()
|
||||
.filter_map(|(pred, _)| match pred.kind().skip_binder() {
|
||||
ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(a, b)) => match *a {
|
||||
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(ty::OutlivesPredicate(
|
||||
a,
|
||||
b,
|
||||
))) => match *a {
|
||||
ty::ReEarlyBound(ebr) if ebr.def_id == def_id => Some(b),
|
||||
_ => None,
|
||||
},
|
||||
|
@ -2067,9 +2071,10 @@ impl ExplicitOutlivesRequirements {
|
|||
inferred_outlives
|
||||
.iter()
|
||||
.filter_map(|(pred, _)| match pred.kind().skip_binder() {
|
||||
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(a, b)) => {
|
||||
a.is_param(index).then_some(b)
|
||||
}
|
||||
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(ty::OutlivesPredicate(
|
||||
a,
|
||||
b,
|
||||
))) => a.is_param(index).then_some(b),
|
||||
_ => None,
|
||||
})
|
||||
.collect()
|
||||
|
|
|
@ -74,7 +74,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
|
|||
// Liberate bound regions in the predicate since we
|
||||
// don't actually care about lifetimes in this check.
|
||||
let predicate = cx.tcx.liberate_late_bound_regions(def_id, pred.kind());
|
||||
let ty::PredicateKind::Projection(proj) = predicate else {
|
||||
let ty::PredicateKind::Clause(ty::Clause::Projection(proj)) = predicate else {
|
||||
continue;
|
||||
};
|
||||
// Only check types, since those are the only things that may
|
||||
|
@ -116,12 +116,13 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
|
|||
// If it's a trait bound and an opaque that doesn't satisfy it,
|
||||
// then we can emit a suggestion to add the bound.
|
||||
let add_bound = match (proj_term.kind(), assoc_pred.kind().skip_binder()) {
|
||||
(ty::Opaque(def_id, _), ty::PredicateKind::Trait(trait_pred)) => {
|
||||
Some(AddBound {
|
||||
suggest_span: cx.tcx.def_span(*def_id).shrink_to_hi(),
|
||||
trait_ref: trait_pred.print_modifiers_and_trait_path(),
|
||||
})
|
||||
}
|
||||
(
|
||||
ty::Opaque(def_id, _),
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred)),
|
||||
) => Some(AddBound {
|
||||
suggest_span: cx.tcx.def_span(*def_id).shrink_to_hi(),
|
||||
trait_ref: trait_pred.print_modifiers_and_trait_path(),
|
||||
}),
|
||||
_ => None,
|
||||
};
|
||||
cx.emit_spanned_lint(
|
||||
|
|
|
@ -87,11 +87,12 @@ declare_lint_pass!(
|
|||
|
||||
impl<'tcx> LateLintPass<'tcx> for DropTraitConstraints {
|
||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
|
||||
use rustc_middle::ty::Clause;
|
||||
use rustc_middle::ty::PredicateKind::*;
|
||||
|
||||
let predicates = cx.tcx.explicit_predicates_of(item.owner_id);
|
||||
for &(predicate, span) in predicates.predicates {
|
||||
let Trait(trait_predicate) = predicate.kind().skip_binder() else {
|
||||
let Clause(Clause::Trait(trait_predicate)) = predicate.kind().skip_binder() else {
|
||||
continue
|
||||
};
|
||||
let def_id = trait_predicate.trait_ref.def_id;
|
||||
|
|
|
@ -258,8 +258,9 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
|
|||
)
|
||||
.filter_map(|obligation| {
|
||||
// We only look at the `DefId`, so it is safe to skip the binder here.
|
||||
if let ty::PredicateKind::Trait(ref poly_trait_predicate) =
|
||||
obligation.predicate.kind().skip_binder()
|
||||
if let ty::PredicateKind::Clause(ty::Clause::Trait(
|
||||
ref poly_trait_predicate,
|
||||
)) = obligation.predicate.kind().skip_binder()
|
||||
{
|
||||
let def_id = poly_trait_predicate.trait_ref.def_id;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue