mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-03 20:23:59 +00:00
rustup: update for the new Ty::walk interface.
This commit is contained in:
parent
89e14d201d
commit
2ad4d6a057
@ -2,6 +2,7 @@ use if_chain::if_chain;
|
|||||||
use rustc_hir::{Local, PatKind};
|
use rustc_hir::{Local, PatKind};
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_middle::lint::in_external_macro;
|
use rustc_middle::lint::in_external_macro;
|
||||||
|
use rustc_middle::ty::subst::GenericArgKind;
|
||||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||||
|
|
||||||
use crate::utils::{is_must_use_func_call, is_must_use_ty, match_type, paths, span_lint_and_help};
|
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 {
|
|||||||
if let PatKind::Wild = local.pat.kind;
|
if let PatKind::Wild = local.pat.kind;
|
||||||
if let Some(ref init) = local.init;
|
if let Some(ref init) = local.init;
|
||||||
then {
|
then {
|
||||||
let check_ty = |ty| SYNC_GUARD_PATHS.iter().any(|path| match_type(cx, ty, path));
|
let init_ty = cx.tables.expr_ty(init);
|
||||||
if cx.tables.expr_ty(init).walk().any(check_ty) {
|
let contains_sync_guard = init_ty.walk().any(|inner| match inner.unpack() {
|
||||||
|
GenericArgKind::Type(inner_ty) => SYNC_GUARD_PATHS.iter().any(|path| match_type(cx, inner_ty, path)),
|
||||||
|
|
||||||
|
GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => false,
|
||||||
|
});
|
||||||
|
if contains_sync_guard {
|
||||||
span_lint_and_help(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
LET_UNDERSCORE_LOCK,
|
LET_UNDERSCORE_LOCK,
|
||||||
|
@ -15,6 +15,7 @@ use rustc_hir::intravisit::{self, Visitor};
|
|||||||
use rustc_lint::{LateContext, LateLintPass, Lint, LintContext};
|
use rustc_lint::{LateContext, LateLintPass, Lint, LintContext};
|
||||||
use rustc_middle::hir::map::Map;
|
use rustc_middle::hir::map::Map;
|
||||||
use rustc_middle::lint::in_external_macro;
|
use rustc_middle::lint::in_external_macro;
|
||||||
|
use rustc_middle::ty::subst::GenericArgKind;
|
||||||
use rustc_middle::ty::{self, Predicate, Ty};
|
use rustc_middle::ty::{self, Predicate, Ty};
|
||||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||||
use rustc_span::source_map::Span;
|
use rustc_span::source_map::Span;
|
||||||
@ -1407,7 +1408,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
|
|||||||
let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id);
|
let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id);
|
||||||
let item = cx.tcx.hir().expect_item(parent);
|
let item = cx.tcx.hir().expect_item(parent);
|
||||||
let def_id = cx.tcx.hir().local_def_id(item.hir_id);
|
let def_id = cx.tcx.hir().local_def_id(item.hir_id);
|
||||||
let ty = cx.tcx.type_of(def_id);
|
let self_ty = cx.tcx.type_of(def_id);
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if let hir::ImplItemKind::Fn(ref sig, id) = impl_item.kind;
|
if let hir::ImplItemKind::Fn(ref sig, id) = impl_item.kind;
|
||||||
if let Some(first_arg) = iter_input_pats(&sig.decl, cx.tcx.hir().body(id)).next();
|
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 {
|
|||||||
if name == method_name &&
|
if name == method_name &&
|
||||||
sig.decl.inputs.len() == n_args &&
|
sig.decl.inputs.len() == n_args &&
|
||||||
out_type.matches(cx, &sig.decl.output) &&
|
out_type.matches(cx, &sig.decl.output) &&
|
||||||
self_kind.matches(cx, ty, first_arg_ty) {
|
self_kind.matches(cx, self_ty, first_arg_ty) {
|
||||||
span_lint(cx, SHOULD_IMPLEMENT_TRAIT, impl_item.span, &format!(
|
span_lint(cx, SHOULD_IMPLEMENT_TRAIT, impl_item.span, &format!(
|
||||||
"defining a method called `{}` on this type; consider implementing \
|
"defining a method called `{}` on this type; consider implementing \
|
||||||
the `{}` trait or choosing a less ambiguous name", name, trait_name));
|
the `{}` trait or choosing a less ambiguous name", name, trait_name));
|
||||||
@ -1441,7 +1442,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
|
|||||||
.iter()
|
.iter()
|
||||||
.find(|(ref conv, _)| conv.check(&name))
|
.find(|(ref conv, _)| conv.check(&name))
|
||||||
{
|
{
|
||||||
if !self_kinds.iter().any(|k| k.matches(cx, ty, first_arg_ty)) {
|
if !self_kinds.iter().any(|k| k.matches(cx, self_ty, first_arg_ty)) {
|
||||||
let lint = if item.vis.node.is_pub() {
|
let lint = if item.vis.node.is_pub() {
|
||||||
WRONG_PUB_SELF_CONVENTION
|
WRONG_PUB_SELF_CONVENTION
|
||||||
} else {
|
} else {
|
||||||
@ -1471,8 +1472,16 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
|
|||||||
if let hir::ImplItemKind::Fn(_, _) = impl_item.kind {
|
if let hir::ImplItemKind::Fn(_, _) = impl_item.kind {
|
||||||
let ret_ty = return_ty(cx, impl_item.hir_id);
|
let ret_ty = return_ty(cx, impl_item.hir_id);
|
||||||
|
|
||||||
|
let contains_self_ty = |ty: Ty<'tcx>| {
|
||||||
|
ty.walk().any(|inner| match inner.unpack() {
|
||||||
|
GenericArgKind::Type(inner_ty) => same_tys(cx, self_ty, inner_ty),
|
||||||
|
|
||||||
|
GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => false,
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
// walk the return type and check for Self (this does not check associated types)
|
// walk the return type and check for Self (this does not check associated types)
|
||||||
if ret_ty.walk().any(|inner_type| same_tys(cx, ty, inner_type)) {
|
if contains_self_ty(ret_ty) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1486,18 +1495,16 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
|
|||||||
let associated_type = binder.skip_binder();
|
let associated_type = binder.skip_binder();
|
||||||
|
|
||||||
// walk the associated type and check for Self
|
// walk the associated type and check for Self
|
||||||
for inner_type in associated_type.walk() {
|
if contains_self_ty(associated_type) {
|
||||||
if same_tys(cx, ty, inner_type) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
(_, _) => {},
|
(_, _) => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if name == "new" && !same_tys(cx, ret_ty, ty) {
|
if name == "new" && !same_tys(cx, ret_ty, self_ty) {
|
||||||
span_lint(
|
span_lint(
|
||||||
cx,
|
cx,
|
||||||
NEW_RET_NO_SELF,
|
NEW_RET_NO_SELF,
|
||||||
|
Loading…
Reference in New Issue
Block a user