Skip to content

Commit 8b2f7e3

Browse files
committed
Auto merge of #104846 - spastorino:santa-clauses-make-goals-early-christmas-🎄, r=oli-obk
Branch Clause from Predicate r? `@oli-obk` This is part of what's proposed in rust-lang/compiler-team#531
2 parents 268d230 + 3f059a4 commit 8b2f7e3

10 files changed

+34
-35
lines changed

clippy_lints/src/dereference.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use rustc_lint::{LateContext, LateLintPass};
2525
use rustc_middle::mir::{Rvalue, StatementKind};
2626
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, AutoBorrowMutability};
2727
use rustc_middle::ty::{
28-
self, Binder, BoundVariableKind, EarlyBinder, FnSig, GenericArgKind, List, ParamTy, PredicateKind,
28+
self, Binder, BoundVariableKind, Clause, EarlyBinder, FnSig, GenericArgKind, List, ParamTy, PredicateKind,
2929
ProjectionPredicate, Ty, TyCtxt, TypeVisitable, TypeckResults,
3030
};
3131
use rustc_semver::RustcVersion;
@@ -1097,7 +1097,7 @@ fn needless_borrow_impl_arg_position<'tcx>(
10971097
let projection_predicates = predicates
10981098
.iter()
10991099
.filter_map(|predicate| {
1100-
if let PredicateKind::Projection(projection_predicate) = predicate.kind().skip_binder() {
1100+
if let PredicateKind::Clause(Clause::Projection(projection_predicate)) = predicate.kind().skip_binder() {
11011101
Some(projection_predicate)
11021102
} else {
11031103
None
@@ -1111,7 +1111,7 @@ fn needless_borrow_impl_arg_position<'tcx>(
11111111
if predicates
11121112
.iter()
11131113
.filter_map(|predicate| {
1114-
if let PredicateKind::Trait(trait_predicate) = predicate.kind().skip_binder()
1114+
if let PredicateKind::Clause(Clause::Trait(trait_predicate)) = predicate.kind().skip_binder()
11151115
&& trait_predicate.trait_ref.self_ty() == param_ty.to_ty(cx.tcx)
11161116
{
11171117
Some(trait_predicate.trait_ref.def_id)
@@ -1173,7 +1173,7 @@ fn needless_borrow_impl_arg_position<'tcx>(
11731173
}
11741174

11751175
predicates.iter().all(|predicate| {
1176-
if let PredicateKind::Trait(trait_predicate) = predicate.kind().skip_binder()
1176+
if let PredicateKind::Clause(Clause::Trait(trait_predicate)) = predicate.kind().skip_binder()
11771177
&& cx.tcx.is_diagnostic_item(sym::IntoIterator, trait_predicate.trait_ref.def_id)
11781178
&& let ty::Param(param_ty) = trait_predicate.self_ty().kind()
11791179
&& let GenericArgKind::Type(ty) = substs_with_referent_ty[param_ty.index as usize].unpack()

clippy_lints/src/derive.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_lint::{LateContext, LateLintPass};
1414
use rustc_middle::hir::nested_filter;
1515
use rustc_middle::traits::Reveal;
1616
use rustc_middle::ty::{
17-
self, Binder, BoundConstness, GenericParamDefKind, ImplPolarity, ParamEnv, PredicateKind, TraitPredicate, TraitRef,
17+
self, Binder, BoundConstness, Clause, GenericParamDefKind, ImplPolarity, ParamEnv, PredicateKind, TraitPredicate, TraitRef,
1818
Ty, TyCtxt,
1919
};
2020
use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -499,7 +499,7 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) ->
499499

500500
let ty_predicates = tcx.predicates_of(did).predicates;
501501
for (p, _) in ty_predicates {
502-
if let PredicateKind::Trait(p) = p.kind().skip_binder()
502+
if let PredicateKind::Clause(Clause::Trait(p)) = p.kind().skip_binder()
503503
&& p.trait_ref.def_id == eq_trait_id
504504
&& let ty::Param(self_ty) = p.trait_ref.self_ty().kind()
505505
&& p.constness == BoundConstness::NotConst
@@ -512,14 +512,14 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) ->
512512
ParamEnv::new(
513513
tcx.mk_predicates(ty_predicates.iter().map(|&(p, _)| p).chain(
514514
params.iter().filter(|&&(_, needs_eq)| needs_eq).map(|&(param, _)| {
515-
tcx.mk_predicate(Binder::dummy(PredicateKind::Trait(TraitPredicate {
515+
tcx.mk_predicate(Binder::dummy(PredicateKind::Clause(Clause::Trait(TraitPredicate {
516516
trait_ref: TraitRef::new(
517517
eq_trait_id,
518518
tcx.mk_substs(std::iter::once(tcx.mk_param_from_def(param))),
519519
),
520520
constness: BoundConstness::NotConst,
521521
polarity: ImplPolarity::Positive,
522-
})))
522+
}))))
523523
}),
524524
)),
525525
Reveal::UserFacing,

clippy_lints/src/future_not_send.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_hir::intravisit::FnKind;
44
use rustc_hir::{Body, FnDecl, HirId};
55
use rustc_infer::infer::TyCtxtInferExt;
66
use rustc_lint::{LateContext, LateLintPass};
7-
use rustc_middle::ty::{EarlyBinder, Opaque, PredicateKind::Trait};
7+
use rustc_middle::ty::{Clause, EarlyBinder, Opaque, PredicateKind};
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::TypeErrCtxtExt;
@@ -91,7 +91,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
9191
infcx
9292
.err_ctxt()
9393
.maybe_note_obligation_cause_for_async_await(db, &obligation);
94-
if let Trait(trait_pred) = obligation.predicate.kind().skip_binder() {
94+
if let PredicateKind::Clause(Clause::Trait(trait_pred)) = obligation.predicate.kind().skip_binder() {
9595
db.note(&format!(
9696
"`{}` doesn't implement `{}`",
9797
trait_pred.self_ty(),

clippy_lints/src/methods/unnecessary_to_owned.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_middle::mir::Mutability;
1717
use rustc_middle::ty::adjustment::{Adjust, Adjustment, OverloadedDeref};
1818
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, SubstsRef};
1919
use rustc_middle::ty::EarlyBinder;
20-
use rustc_middle::ty::{self, ParamTy, PredicateKind, ProjectionPredicate, TraitPredicate, Ty};
20+
use rustc_middle::ty::{self, Clause, ParamTy, PredicateKind, ProjectionPredicate, TraitPredicate, Ty};
2121
use rustc_semver::RustcVersion;
2222
use rustc_span::{sym, Symbol};
2323
use rustc_trait_selection::traits::{
@@ -341,12 +341,12 @@ fn get_input_traits_and_projections<'tcx>(
341341
let mut projection_predicates = Vec::new();
342342
for predicate in cx.tcx.param_env(callee_def_id).caller_bounds() {
343343
match predicate.kind().skip_binder() {
344-
PredicateKind::Trait(trait_predicate) => {
344+
PredicateKind::Clause(Clause::Trait(trait_predicate)) => {
345345
if trait_predicate.trait_ref.self_ty() == input {
346346
trait_predicates.push(trait_predicate);
347347
}
348348
}
349-
PredicateKind::Projection(projection_predicate) => {
349+
PredicateKind::Clause(Clause::Projection(projection_predicate)) => {
350350
if projection_predicate.projection_ty.self_ty() == input {
351351
projection_predicates.push(projection_predicate);
352352
}
@@ -403,7 +403,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
403403

404404
let mut trait_predicates = cx.tcx.param_env(callee_def_id)
405405
.caller_bounds().iter().filter(|predicate| {
406-
if let PredicateKind::Trait(trait_predicate) = predicate.kind().skip_binder()
406+
if let PredicateKind::Clause(Clause::Trait(trait_predicate)) = predicate.kind().skip_binder()
407407
&& trait_predicate.trait_ref.self_ty() == *param_ty {
408408
true
409409
} else {

clippy_lints/src/needless_pass_by_value.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
124124
.filter_map(|obligation| {
125125
// Note that we do not want to deal with qualified predicates here.
126126
match obligation.predicate.kind().no_bound_vars() {
127-
Some(ty::PredicateKind::Trait(pred)) if pred.def_id() != sized_trait => Some(pred),
127+
Some(ty::PredicateKind::Clause(ty::Clause::Trait(pred))) if pred.def_id() != sized_trait => Some(pred),
128128
_ => None,
129129
}
130130
})

clippy_lints/src/ptr.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_infer::infer::TyCtxtInferExt;
1919
use rustc_infer::traits::{Obligation, ObligationCause};
2020
use rustc_lint::{LateContext, LateLintPass};
2121
use rustc_middle::hir::nested_filter;
22-
use rustc_middle::ty::{self, Binder, ExistentialPredicate, List, PredicateKind, Ty};
22+
use rustc_middle::ty::{self, Binder, Clause, ExistentialPredicate, List, PredicateKind, Ty};
2323
use rustc_session::{declare_lint_pass, declare_tool_lint};
2424
use rustc_span::source_map::Span;
2525
use rustc_span::sym;
@@ -698,9 +698,8 @@ fn matches_preds<'tcx>(
698698
cx.tcx,
699699
ObligationCause::dummy(),
700700
cx.param_env,
701-
cx.tcx.mk_predicate(Binder::bind_with_vars(
702-
PredicateKind::Projection(p.with_self_ty(cx.tcx, ty)),
703-
List::empty(),
701+
cx.tcx.mk_predicate(Binder::dummy(
702+
PredicateKind::Clause(Clause::Projection(p.with_self_ty(cx.tcx, ty))),
704703
)),
705704
)),
706705
ExistentialPredicate::AutoTrait(p) => infcx

clippy_lints/src/unit_return_expecting_ord.rs

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

@@ -45,7 +45,7 @@ fn get_trait_predicates_for_trait_id<'tcx>(
4545
let mut preds = Vec::new();
4646
for (pred, _) in generics.predicates {
4747
if_chain! {
48-
if let PredicateKind::Trait(poly_trait_pred) = pred.kind().skip_binder();
48+
if let PredicateKind::Clause(Clause::Trait(poly_trait_pred)) = pred.kind().skip_binder();
4949
let trait_pred = cx.tcx.erase_late_bound_regions(pred.kind().rebind(poly_trait_pred));
5050
if let Some(trait_def_id) = trait_id;
5151
if trait_def_id == trait_pred.trait_ref.def_id;
@@ -63,7 +63,7 @@ fn get_projection_pred<'tcx>(
6363
trait_pred: TraitPredicate<'tcx>,
6464
) -> Option<ProjectionPredicate<'tcx>> {
6565
generics.predicates.iter().find_map(|(proj_pred, _)| {
66-
if let ty::PredicateKind::Projection(pred) = proj_pred.kind().skip_binder() {
66+
if let ty::PredicateKind::Clause(Clause::Projection(pred)) = proj_pred.kind().skip_binder() {
6767
let projection_pred = cx.tcx.erase_late_bound_regions(proj_pred.kind().rebind(pred));
6868
if projection_pred.projection_ty.substs == trait_pred.trait_ref.substs {
6969
return Some(projection_pred);

clippy_utils/src/eager_or_lazy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fn fn_eagerness(cx: &LateContext<'_>, fn_id: DefId, name: Symbol, have_one_arg:
7373
.flat_map(|v| v.fields.iter())
7474
.any(|x| matches!(cx.tcx.type_of(x.did).peel_refs().kind(), ty::Param(_)))
7575
&& all_predicates_of(cx.tcx, fn_id).all(|(pred, _)| match pred.kind().skip_binder() {
76-
PredicateKind::Trait(pred) => cx.tcx.trait_def(pred.trait_ref.def_id).is_marker,
76+
PredicateKind::Clause(ty::Clause::Trait(pred)) => cx.tcx.trait_def(pred.trait_ref.def_id).is_marker,
7777
_ => true,
7878
})
7979
&& subs.types().all(|x| matches!(x.peel_refs().kind(), ty::Param(_)))

clippy_utils/src/qualify_min_const_fn.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ pub fn is_min_const_fn<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, msrv: Option<
2525
let predicates = tcx.predicates_of(current);
2626
for (predicate, _) in predicates.predicates {
2727
match predicate.kind().skip_binder() {
28-
ty::PredicateKind::RegionOutlives(_)
29-
| ty::PredicateKind::TypeOutlives(_)
28+
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(_))
29+
| ty::PredicateKind::Clause(ty::Clause::TypeOutlives(_))
3030
| ty::PredicateKind::WellFormed(_)
31-
| ty::PredicateKind::Projection(_)
31+
| ty::PredicateKind::Clause(ty::Clause::Projection(_))
3232
| ty::PredicateKind::ConstEvaluatable(..)
3333
| ty::PredicateKind::ConstEquate(..)
34-
| ty::PredicateKind::Trait(..)
34+
| ty::PredicateKind::Clause(ty::Clause::Trait(..))
3535
| ty::PredicateKind::TypeWellFormedFromEnv(..) => continue,
3636
ty::PredicateKind::ObjectSafe(_) => panic!("object safe predicate on function: {predicate:#?}"),
3737
ty::PredicateKind::ClosureKind(..) => panic!("closure kind predicate on function: {predicate:#?}"),

clippy_utils/src/ty.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'
8181
match predicate.kind().skip_binder() {
8282
// For `impl Trait<U>`, it will register a predicate of `T: Trait<U>`, so we go through
8383
// and check substituions to find `U`.
84-
ty::PredicateKind::Trait(trait_predicate) => {
84+
ty::PredicateKind::Clause(ty::Clause::Trait(trait_predicate)) => {
8585
if trait_predicate
8686
.trait_ref
8787
.substs
@@ -94,7 +94,7 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'
9494
},
9595
// For `impl Trait<Assoc=U>`, it will register a predicate of `<T as Trait>::Assoc = U`,
9696
// so we check the term for `U`.
97-
ty::PredicateKind::Projection(projection_predicate) => {
97+
ty::PredicateKind::Clause(ty::Clause::Projection(projection_predicate)) => {
9898
if let ty::TermKind::Ty(ty) = projection_predicate.term.unpack() {
9999
if contains_ty_adt_constructor_opaque(cx, ty, needle) {
100100
return true;
@@ -239,7 +239,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
239239
ty::Tuple(substs) => substs.iter().any(|ty| is_must_use_ty(cx, ty)),
240240
ty::Opaque(def_id, _) => {
241241
for (predicate, _) in cx.tcx.explicit_item_bounds(*def_id) {
242-
if let ty::PredicateKind::Trait(trait_predicate) = predicate.kind().skip_binder() {
242+
if let ty::PredicateKind::Clause(ty::Clause::Trait(trait_predicate)) = predicate.kind().skip_binder() {
243243
if cx.tcx.has_attr(trait_predicate.trait_ref.def_id, sym::must_use) {
244244
return true;
245245
}
@@ -658,7 +658,7 @@ fn sig_from_bounds<'tcx>(
658658

659659
for pred in predicates {
660660
match pred.kind().skip_binder() {
661-
PredicateKind::Trait(p)
661+
PredicateKind::Clause(ty::Clause::Trait(p))
662662
if (lang_items.fn_trait() == Some(p.def_id())
663663
|| lang_items.fn_mut_trait() == Some(p.def_id())
664664
|| lang_items.fn_once_trait() == Some(p.def_id()))
@@ -671,7 +671,7 @@ fn sig_from_bounds<'tcx>(
671671
}
672672
inputs = Some(i);
673673
},
674-
PredicateKind::Projection(p)
674+
PredicateKind::Clause(ty::Clause::Projection(p))
675675
if Some(p.projection_ty.item_def_id) == lang_items.fn_once_output()
676676
&& p.projection_ty.self_ty() == ty =>
677677
{
@@ -699,7 +699,7 @@ fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: ProjectionTy<'tcx>) -> O
699699
.subst_iter_copied(cx.tcx, ty.substs)
700700
{
701701
match pred.kind().skip_binder() {
702-
PredicateKind::Trait(p)
702+
PredicateKind::Clause(ty::Clause::Trait(p))
703703
if (lang_items.fn_trait() == Some(p.def_id())
704704
|| lang_items.fn_mut_trait() == Some(p.def_id())
705705
|| lang_items.fn_once_trait() == Some(p.def_id())) =>
@@ -712,7 +712,7 @@ fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: ProjectionTy<'tcx>) -> O
712712
}
713713
inputs = Some(i);
714714
},
715-
PredicateKind::Projection(p) if Some(p.projection_ty.item_def_id) == lang_items.fn_once_output() => {
715+
PredicateKind::Clause(ty::Clause::Projection(p)) if Some(p.projection_ty.item_def_id) == lang_items.fn_once_output() => {
716716
if output.is_some() {
717717
// Multiple different fn trait impls. Is this even allowed?
718718
return None;
@@ -887,7 +887,7 @@ pub fn ty_is_fn_once_param<'tcx>(tcx: TyCtxt<'_>, ty: Ty<'tcx>, predicates: &'tc
887887
predicates
888888
.iter()
889889
.try_fold(false, |found, p| {
890-
if let PredicateKind::Trait(p) = p.kind().skip_binder()
890+
if let PredicateKind::Clause(ty::Clause::Trait(p)) = p.kind().skip_binder()
891891
&& let ty::Param(self_ty) = p.trait_ref.self_ty().kind()
892892
&& ty.index == self_ty.index
893893
{

0 commit comments

Comments
 (0)