Skip to content

Commit 09c49cc

Browse files
committed
clippy
1 parent 4d4c3ab commit 09c49cc

File tree

4 files changed

+17
-23
lines changed

4 files changed

+17
-23
lines changed

src/tools/clippy/clippy_lints/src/future_not_send.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc_hir::intravisit::FnKind;
33
use rustc_hir::{Body, FnDecl, HirId};
44
use rustc_infer::infer::TyCtxtInferExt;
55
use rustc_lint::{LateContext, LateLintPass};
6-
use rustc_middle::ty::{Opaque, PredicateKind::Trait, ToPolyTraitRef};
6+
use rustc_middle::ty::{Opaque, PredicateKind::Trait};
77
use rustc_session::{declare_lint_pass, declare_tool_lint};
88
use rustc_span::{sym, Span};
99
use rustc_trait_selection::traits::error_reporting::suggestions::InferCtxtExt;
@@ -91,12 +91,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for FutureNotSend {
9191
cx.tcx.infer_ctxt().enter(|infcx| {
9292
for FulfillmentError { obligation, .. } in send_errors {
9393
infcx.maybe_note_obligation_cause_for_async_await(db, &obligation);
94-
if let Trait(trait_pred, _) = obligation.predicate.kind() {
95-
let trait_ref = trait_pred.to_poly_trait_ref();
96-
db.note(&*format!(
94+
if let Trait(trait_pred, _) = obligation.predicate.ignore_qualifiers().skip_binder().kind() {
95+
db.note(&format!(
9796
"`{}` doesn't implement `{}`",
98-
trait_ref.skip_binder().self_ty(),
99-
trait_ref.print_only_trait_path(),
97+
trait_pred.self_ty(),
98+
trait_pred.trait_ref.print_only_trait_path(),
10099
));
101100
}
102101
}

src/tools/clippy/clippy_lints/src/methods/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,13 +1558,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
15581558
// if return type is impl trait, check the associated types
15591559
if let ty::Opaque(def_id, _) = ret_ty.kind {
15601560
// one of the associated types must be Self
1561-
for predicate in cx.tcx.predicates_of(def_id).predicates {
1562-
if let ty::PredicateKind::Projection(poly_projection_predicate) = predicate.0.kind() {
1563-
let binder = poly_projection_predicate.ty();
1564-
let associated_type = binder.skip_binder();
1565-
1561+
for &(predicate, _span) in cx.tcx.predicates_of(def_id).predicates {
1562+
if let ty::PredicateKind::Projection(projection_predicate) = predicate.ignore_qualifiers().skip_binder().kind() {
15661563
// walk the associated type and check for Self
1567-
if contains_self_ty(associated_type) {
1564+
if contains_self_ty(projection_predicate.ty) {
15681565
return;
15691566
}
15701567
}

src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
114114
let preds = traits::elaborate_predicates(cx.tcx, cx.param_env.caller_bounds.iter())
115115
.filter(|p| !p.is_global())
116116
.filter_map(|obligation| {
117-
if let ty::PredicateKind::Trait(poly_trait_ref, _) = obligation.predicate.kind() {
118-
if poly_trait_ref.def_id() == sized_trait || poly_trait_ref.skip_binder().has_escaping_bound_vars()
119-
{
117+
// Note that we do not want to deal with qualified predicates here.
118+
if let ty::PredicateKind::Trait(pred, _) = obligation.predicate.kind() {
119+
if pred.def_id() == sized_trait {
120120
return None;
121121
}
122-
Some(poly_trait_ref)
122+
Some(pred)
123123
} else {
124124
None
125125
}
@@ -158,29 +158,27 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
158158
}
159159
}
160160

161-
//
162161
// * Exclude a type that is specifically bounded by `Borrow`.
163162
// * Exclude a type whose reference also fulfills its bound. (e.g., `std::convert::AsRef`,
164163
// `serde::Serialize`)
165164
let (implements_borrow_trait, all_borrowable_trait) = {
166165
let preds = preds
167166
.iter()
168-
.filter(|t| t.skip_binder().self_ty() == ty)
167+
.filter(|t| t.self_ty() == ty)
169168
.collect::<Vec<_>>();
170169

171170
(
172171
preds.iter().any(|t| t.def_id() == borrow_trait),
173172
!preds.is_empty() && {
174173
let ty_empty_region = cx.tcx.mk_imm_ref(cx.tcx.lifetimes.re_root_empty, ty);
175174
preds.iter().all(|t| {
176-
let ty_params = &t
177-
.skip_binder()
175+
let ty_params = t
178176
.trait_ref
179177
.substs
180178
.iter()
181179
.skip(1)
182180
.collect::<Vec<_>>();
183-
implements_trait(cx, ty_empty_region, t.def_id(), ty_params)
181+
implements_trait(cx, ty_empty_region, t.def_id(), &ty_params)
184182
})
185183
},
186184
)

src/tools/clippy/clippy_lints/src/utils/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,8 +1290,8 @@ pub fn is_must_use_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>) -> boo
12901290
ty::Tuple(ref substs) => substs.types().any(|ty| is_must_use_ty(cx, ty)),
12911291
ty::Opaque(ref def_id, _) => {
12921292
for (predicate, _) in cx.tcx.predicates_of(*def_id).predicates {
1293-
if let ty::PredicateKind::Trait(ref poly_trait_predicate, _) = predicate.kind() {
1294-
if must_use_attr(&cx.tcx.get_attrs(poly_trait_predicate.skip_binder().trait_ref.def_id)).is_some() {
1293+
if let ty::PredicateKind::Trait(trait_predicate, _) = predicate.ignore_qualifiers().skip_binder().kind() {
1294+
if must_use_attr(&cx.tcx.get_attrs(trait_predicate.trait_ref.def_id)).is_some() {
12951295
return true;
12961296
}
12971297
}

0 commit comments

Comments
 (0)