diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs index 92c7e66a0eb85..0fdb5b8c2a48e 100644 --- a/clippy_lints/src/future_not_send.rs +++ b/clippy_lints/src/future_not_send.rs @@ -3,7 +3,7 @@ use rustc_hir::intravisit::FnKind; use rustc_hir::{Body, FnDecl, HirId}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{Opaque, PredicateKind::Trait, ToPolyTraitRef}; +use rustc_middle::ty::{Opaque, PredicateAtom::Trait}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{sym, Span}; use rustc_trait_selection::traits::error_reporting::suggestions::InferCtxtExt; @@ -91,12 +91,11 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { cx.tcx.infer_ctxt().enter(|infcx| { for FulfillmentError { obligation, .. } in send_errors { infcx.maybe_note_obligation_cause_for_async_await(db, &obligation); - if let Trait(trait_pred, _) = obligation.predicate.kind() { - let trait_ref = trait_pred.to_poly_trait_ref(); - db.note(&*format!( + if let Trait(trait_pred, _) = obligation.predicate.skip_binders() { + db.note(&format!( "`{}` doesn't implement `{}`", - trait_ref.skip_binder().self_ty(), - trait_ref.print_only_trait_path(), + trait_pred.self_ty(), + trait_pred.trait_ref.print_only_trait_path(), )); } } diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 97cc58023f55e..2c70183d87666 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -1558,13 +1558,10 @@ impl<'tcx> LateLintPass<'tcx> for Methods { // if return type is impl trait, check the associated types if let ty::Opaque(def_id, _) = ret_ty.kind { // one of the associated types must be Self - for predicate in cx.tcx.predicates_of(def_id).predicates { - if let ty::PredicateKind::Projection(poly_projection_predicate) = predicate.0.kind() { - let binder = poly_projection_predicate.ty(); - let associated_type = binder.skip_binder(); - + for &(predicate, _span) in cx.tcx.predicates_of(def_id).predicates { + if let ty::PredicateAtom::Projection(projection_predicate) = predicate.skip_binders() { // walk the associated type and check for Self - if contains_self_ty(associated_type) { + if contains_self_ty(projection_predicate.ty) { return; } } diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 8118cb32cf28e..8263f5eda330f 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -113,12 +113,12 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { let preds = traits::elaborate_predicates(cx.tcx, cx.param_env.caller_bounds().iter()) .filter(|p| !p.is_global()) .filter_map(|obligation| { - if let ty::PredicateKind::Trait(poly_trait_ref, _) = obligation.predicate.kind() { - if poly_trait_ref.def_id() == sized_trait || poly_trait_ref.skip_binder().has_escaping_bound_vars() - { + // Note that we do not want to deal with qualified predicates here. + if let ty::PredicateKind::Atom(ty::PredicateAtom::Trait(pred, _)) = obligation.predicate.kind() { + if pred.def_id() == sized_trait { return None; } - Some(poly_trait_ref) + Some(pred) } else { None } @@ -163,18 +163,15 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { // * Exclude a type whose reference also fulfills its bound. (e.g., `std::convert::AsRef`, // `serde::Serialize`) let (implements_borrow_trait, all_borrowable_trait) = { - let preds = preds - .iter() - .filter(|t| t.skip_binder().self_ty() == ty) - .collect::>(); + let preds = preds.iter().filter(|t| t.self_ty() == ty).collect::>(); ( preds.iter().any(|t| t.def_id() == borrow_trait), !preds.is_empty() && { let ty_empty_region = cx.tcx.mk_imm_ref(cx.tcx.lifetimes.re_root_empty, ty); preds.iter().all(|t| { - let ty_params = &t.skip_binder().trait_ref.substs.iter().skip(1).collect::>(); - implements_trait(cx, ty_empty_region, t.def_id(), ty_params) + let ty_params = t.trait_ref.substs.iter().skip(1).collect::>(); + implements_trait(cx, ty_empty_region, t.def_id(), &ty_params) }) }, ) diff --git a/clippy_lints/src/unit_return_expecting_ord.rs b/clippy_lints/src/unit_return_expecting_ord.rs index ac6f3d125bb42..679aaec9fcd6c 100644 --- a/clippy_lints/src/unit_return_expecting_ord.rs +++ b/clippy_lints/src/unit_return_expecting_ord.rs @@ -4,7 +4,7 @@ use rustc_hir::def_id::DefId; use rustc_hir::{Expr, ExprKind, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; -use rustc_middle::ty::{GenericPredicates, PredicateKind, ProjectionPredicate, TraitPredicate}; +use rustc_middle::ty::{GenericPredicates, PredicateAtom, ProjectionPredicate, TraitPredicate}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{BytePos, Span}; @@ -42,8 +42,8 @@ fn get_trait_predicates_for_trait_id<'tcx>( let mut preds = Vec::new(); for (pred, _) in generics.predicates { if_chain! { - if let PredicateKind::Trait(poly_trait_pred, _) = pred.kind(); - let trait_pred = cx.tcx.erase_late_bound_regions(&poly_trait_pred); + if let PredicateAtom::Trait(poly_trait_pred, _) = pred.skip_binders(); + let trait_pred = cx.tcx.erase_late_bound_regions(&ty::Binder::bind(poly_trait_pred)); if let Some(trait_def_id) = trait_id; if trait_def_id == trait_pred.trait_ref.def_id; then { @@ -60,8 +60,8 @@ fn get_projection_pred<'tcx>( pred: TraitPredicate<'tcx>, ) -> Option> { generics.predicates.iter().find_map(|(proj_pred, _)| { - if let PredicateKind::Projection(proj_pred) = proj_pred.kind() { - let projection_pred = cx.tcx.erase_late_bound_regions(proj_pred); + if let ty::PredicateAtom::Projection(proj_pred) = proj_pred.skip_binders() { + let projection_pred = cx.tcx.erase_late_bound_regions(&ty::Binder::bind(proj_pred)); if projection_pred.projection_ty.substs == pred.trait_ref.substs { return Some(projection_pred); } diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index a4bee1c278059..655b1133cf74f 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -1263,8 +1263,8 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { ty::Tuple(ref substs) => substs.types().any(|ty| is_must_use_ty(cx, ty)), ty::Opaque(ref def_id, _) => { for (predicate, _) in cx.tcx.predicates_of(*def_id).predicates { - if let ty::PredicateKind::Trait(ref poly_trait_predicate, _) = predicate.kind() { - if must_use_attr(&cx.tcx.get_attrs(poly_trait_predicate.skip_binder().trait_ref.def_id)).is_some() { + if let ty::PredicateAtom::Trait(trait_predicate, _) = predicate.skip_binders() { + if must_use_attr(&cx.tcx.get_attrs(trait_predicate.trait_ref.def_id)).is_some() { return true; } }