Skip to content

Commit 2ad4d6a

Browse files
committed
rustup: update for the new Ty::walk interface.
1 parent 89e14d2 commit 2ad4d6a

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

clippy_lints/src/let_underscore.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use if_chain::if_chain;
22
use rustc_hir::{Local, PatKind};
33
use rustc_lint::{LateContext, LateLintPass};
44
use rustc_middle::lint::in_external_macro;
5+
use rustc_middle::ty::subst::GenericArgKind;
56
use rustc_session::{declare_lint_pass, declare_tool_lint};
67

78
use crate::utils::{is_must_use_func_call, is_must_use_ty, match_type, paths, span_lint_and_help};
@@ -75,8 +76,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnderscore {
7576
if let PatKind::Wild = local.pat.kind;
7677
if let Some(ref init) = local.init;
7778
then {
78-
let check_ty = |ty| SYNC_GUARD_PATHS.iter().any(|path| match_type(cx, ty, path));
79-
if cx.tables.expr_ty(init).walk().any(check_ty) {
79+
let init_ty = cx.tables.expr_ty(init);
80+
let contains_sync_guard = init_ty.walk().any(|inner| match inner.unpack() {
81+
GenericArgKind::Type(inner_ty) => SYNC_GUARD_PATHS.iter().any(|path| match_type(cx, inner_ty, path)),
82+
83+
GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => false,
84+
});
85+
if contains_sync_guard {
8086
span_lint_and_help(
8187
cx,
8288
LET_UNDERSCORE_LOCK,

clippy_lints/src/methods/mod.rs

+16-9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rustc_hir::intravisit::{self, Visitor};
1515
use rustc_lint::{LateContext, LateLintPass, Lint, LintContext};
1616
use rustc_middle::hir::map::Map;
1717
use rustc_middle::lint::in_external_macro;
18+
use rustc_middle::ty::subst::GenericArgKind;
1819
use rustc_middle::ty::{self, Predicate, Ty};
1920
use rustc_session::{declare_lint_pass, declare_tool_lint};
2021
use rustc_span::source_map::Span;
@@ -1407,7 +1408,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
14071408
let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id);
14081409
let item = cx.tcx.hir().expect_item(parent);
14091410
let def_id = cx.tcx.hir().local_def_id(item.hir_id);
1410-
let ty = cx.tcx.type_of(def_id);
1411+
let self_ty = cx.tcx.type_of(def_id);
14111412
if_chain! {
14121413
if let hir::ImplItemKind::Fn(ref sig, id) = impl_item.kind;
14131414
if let Some(first_arg) = iter_input_pats(&sig.decl, cx.tcx.hir().body(id)).next();
@@ -1429,7 +1430,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
14291430
if name == method_name &&
14301431
sig.decl.inputs.len() == n_args &&
14311432
out_type.matches(cx, &sig.decl.output) &&
1432-
self_kind.matches(cx, ty, first_arg_ty) {
1433+
self_kind.matches(cx, self_ty, first_arg_ty) {
14331434
span_lint(cx, SHOULD_IMPLEMENT_TRAIT, impl_item.span, &format!(
14341435
"defining a method called `{}` on this type; consider implementing \
14351436
the `{}` trait or choosing a less ambiguous name", name, trait_name));
@@ -1441,7 +1442,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
14411442
.iter()
14421443
.find(|(ref conv, _)| conv.check(&name))
14431444
{
1444-
if !self_kinds.iter().any(|k| k.matches(cx, ty, first_arg_ty)) {
1445+
if !self_kinds.iter().any(|k| k.matches(cx, self_ty, first_arg_ty)) {
14451446
let lint = if item.vis.node.is_pub() {
14461447
WRONG_PUB_SELF_CONVENTION
14471448
} else {
@@ -1471,8 +1472,16 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
14711472
if let hir::ImplItemKind::Fn(_, _) = impl_item.kind {
14721473
let ret_ty = return_ty(cx, impl_item.hir_id);
14731474

1475+
let contains_self_ty = |ty: Ty<'tcx>| {
1476+
ty.walk().any(|inner| match inner.unpack() {
1477+
GenericArgKind::Type(inner_ty) => same_tys(cx, self_ty, inner_ty),
1478+
1479+
GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => false,
1480+
})
1481+
};
1482+
14741483
// walk the return type and check for Self (this does not check associated types)
1475-
if ret_ty.walk().any(|inner_type| same_tys(cx, ty, inner_type)) {
1484+
if contains_self_ty(ret_ty) {
14761485
return;
14771486
}
14781487

@@ -1486,18 +1495,16 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
14861495
let associated_type = binder.skip_binder();
14871496

14881497
// walk the associated type and check for Self
1489-
for inner_type in associated_type.walk() {
1490-
if same_tys(cx, ty, inner_type) {
1491-
return;
1492-
}
1498+
if contains_self_ty(associated_type) {
1499+
return;
14931500
}
14941501
},
14951502
(_, _) => {},
14961503
}
14971504
}
14981505
}
14991506

1500-
if name == "new" && !same_tys(cx, ret_ty, ty) {
1507+
if name == "new" && !same_tys(cx, ret_ty, self_ty) {
15011508
span_lint(
15021509
cx,
15031510
NEW_RET_NO_SELF,

0 commit comments

Comments
 (0)