Skip to content

Commit e477105

Browse files
committed
Auto merge of rust-lang#80679 - jackh726:predicate-kind-take2, r=lcnr
Remove PredicateKind and instead only use Binder<PredicateAtom> Originally brought up in rust-lang#76814 (comment) r? `@lcnr`
2 parents 7449dc9 + e73b8dc commit e477105

File tree

6 files changed

+24
-26
lines changed

6 files changed

+24
-26
lines changed

clippy_lints/src/future_not_send.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_hir::{Body, FnDecl, HirId};
44
use rustc_infer::infer::TyCtxtInferExt;
55
use rustc_lint::{LateContext, LateLintPass};
66
use rustc_middle::ty::subst::Subst;
7-
use rustc_middle::ty::{Opaque, PredicateAtom::Trait};
7+
use rustc_middle::ty::{Opaque, PredicateKind::Trait};
88
use rustc_session::{declare_lint_pass, declare_tool_lint};
99
use rustc_span::{sym, Span};
1010
use rustc_trait_selection::traits::error_reporting::suggestions::InferCtxtExt;
@@ -97,7 +97,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
9797
&obligation,
9898
);
9999
if let Trait(trait_pred, _) =
100-
obligation.predicate.skip_binders()
100+
obligation.predicate.kind().skip_binder()
101101
{
102102
db.note(&format!(
103103
"`{}` doesn't implement `{}`",

clippy_lints/src/methods/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1697,7 +1697,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
16971697
if let ty::Opaque(def_id, _) = *ret_ty.kind() {
16981698
// one of the associated types must be Self
16991699
for &(predicate, _span) in cx.tcx.explicit_item_bounds(def_id) {
1700-
if let ty::PredicateAtom::Projection(projection_predicate) = predicate.skip_binders() {
1700+
if let ty::PredicateKind::Projection(projection_predicate) = predicate.kind().skip_binder() {
17011701
// walk the associated type and check for Self
17021702
if contains_ty(projection_predicate.ty, self_ty) {
17031703
return;

clippy_lints/src/needless_pass_by_value.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,11 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
115115
.filter(|p| !p.is_global())
116116
.filter_map(|obligation| {
117117
// Note that we do not want to deal with qualified predicates here.
118-
if let ty::PredicateKind::Atom(ty::PredicateAtom::Trait(pred, _)) = obligation.predicate.kind() {
119-
if pred.def_id() == sized_trait {
120-
return None;
121-
}
122-
Some(pred)
123-
} else {
124-
None
118+
match obligation.predicate.kind().no_bound_vars() {
119+
Some(ty::PredicateKind::Trait(pred, _)) if pred.def_id() != sized_trait => {
120+
Some(pred)
121+
},
122+
_ => None,
125123
}
126124
})
127125
.collect::<Vec<_>>();

clippy_lints/src/unit_return_expecting_ord.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_hir::def_id::DefId;
44
use rustc_hir::{Expr, ExprKind, StmtKind};
55
use rustc_lint::{LateContext, LateLintPass};
66
use rustc_middle::ty;
7-
use rustc_middle::ty::{GenericPredicates, PredicateAtom, ProjectionPredicate, TraitPredicate};
7+
use rustc_middle::ty::{GenericPredicates, PredicateKind, ProjectionPredicate, TraitPredicate};
88
use rustc_session::{declare_lint_pass, declare_tool_lint};
99
use rustc_span::{BytePos, Span};
1010

@@ -42,7 +42,7 @@ fn get_trait_predicates_for_trait_id<'tcx>(
4242
let mut preds = Vec::new();
4343
for (pred, _) in generics.predicates {
4444
if_chain! {
45-
if let PredicateAtom::Trait(poly_trait_pred, _) = pred.skip_binders();
45+
if let PredicateKind::Trait(poly_trait_pred, _) = pred.kind().skip_binder();
4646
let trait_pred = cx.tcx.erase_late_bound_regions(ty::Binder::bind(poly_trait_pred));
4747
if let Some(trait_def_id) = trait_id;
4848
if trait_def_id == trait_pred.trait_ref.def_id;
@@ -60,7 +60,7 @@ fn get_projection_pred<'tcx>(
6060
pred: TraitPredicate<'tcx>,
6161
) -> Option<ProjectionPredicate<'tcx>> {
6262
generics.predicates.iter().find_map(|(proj_pred, _)| {
63-
if let ty::PredicateAtom::Projection(proj_pred) = proj_pred.skip_binders() {
63+
if let ty::PredicateKind::Projection(proj_pred) = proj_pred.kind().skip_binder() {
6464
let projection_pred = cx.tcx.erase_late_bound_regions(ty::Binder::bind(proj_pred));
6565
if projection_pred.projection_ty.substs == pred.trait_ref.substs {
6666
return Some(projection_pred);

clippy_lints/src/utils/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1470,7 +1470,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
14701470
ty::Tuple(ref substs) => substs.types().any(|ty| is_must_use_ty(cx, ty)),
14711471
ty::Opaque(ref def_id, _) => {
14721472
for (predicate, _) in cx.tcx.explicit_item_bounds(*def_id) {
1473-
if let ty::PredicateAtom::Trait(trait_predicate, _) = predicate.skip_binders() {
1473+
if let ty::PredicateKind::Trait(trait_predicate, _) = predicate.kind().skip_binder() {
14741474
if must_use_attr(&cx.tcx.get_attrs(trait_predicate.trait_ref.def_id)).is_some() {
14751475
return true;
14761476
}

clippy_lints/src/utils/qualify_min_const_fn.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>) -> McfResult {
1919
loop {
2020
let predicates = tcx.predicates_of(current);
2121
for (predicate, _) in predicates.predicates {
22-
match predicate.skip_binders() {
23-
ty::PredicateAtom::RegionOutlives(_)
24-
| ty::PredicateAtom::TypeOutlives(_)
25-
| ty::PredicateAtom::WellFormed(_)
26-
| ty::PredicateAtom::Projection(_)
27-
| ty::PredicateAtom::ConstEvaluatable(..)
28-
| ty::PredicateAtom::ConstEquate(..)
29-
| ty::PredicateAtom::TypeWellFormedFromEnv(..) => continue,
30-
ty::PredicateAtom::ObjectSafe(_) => panic!("object safe predicate on function: {:#?}", predicate),
31-
ty::PredicateAtom::ClosureKind(..) => panic!("closure kind predicate on function: {:#?}", predicate),
32-
ty::PredicateAtom::Subtype(_) => panic!("subtype predicate on function: {:#?}", predicate),
33-
ty::PredicateAtom::Trait(pred, _) => {
22+
match predicate.kind().skip_binder() {
23+
ty::PredicateKind::RegionOutlives(_)
24+
| ty::PredicateKind::TypeOutlives(_)
25+
| ty::PredicateKind::WellFormed(_)
26+
| ty::PredicateKind::Projection(_)
27+
| ty::PredicateKind::ConstEvaluatable(..)
28+
| ty::PredicateKind::ConstEquate(..)
29+
| ty::PredicateKind::TypeWellFormedFromEnv(..) => continue,
30+
ty::PredicateKind::ObjectSafe(_) => panic!("object safe predicate on function: {:#?}", predicate),
31+
ty::PredicateKind::ClosureKind(..) => panic!("closure kind predicate on function: {:#?}", predicate),
32+
ty::PredicateKind::Subtype(_) => panic!("subtype predicate on function: {:#?}", predicate),
33+
ty::PredicateKind::Trait(pred, _) => {
3434
if Some(pred.def_id()) == tcx.lang_items().sized_trait() {
3535
continue;
3636
}

0 commit comments

Comments
 (0)