Skip to content

Commit 16acf7d

Browse files
committed
use check_path instead of check_expr
1 parent 157e797 commit 16acf7d

File tree

1 file changed

+27
-49
lines changed

1 file changed

+27
-49
lines changed

src/librustc/lint/internal.rs

Lines changed: 27 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Some lints that are only useful in the compiler or crates that use compiler internals, such as
22
//! Clippy.
33
4-
use crate::hir::{Expr, ExprKind, PatKind, Path, QPath, Ty, TyKind};
4+
use crate::hir::{HirId, Path, QPath, Ty, TyKind};
55
use crate::lint::{
66
EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintArray, LintContext, LintPass,
77
};
@@ -81,56 +81,34 @@ impl LintPass for TyKindUsage {
8181
}
8282

8383
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TyKindUsage {
84-
fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &'tcx Expr) {
85-
let qpaths = match &expr.node {
86-
ExprKind::Match(_, arms, _) => {
87-
let mut qpaths = vec![];
88-
for arm in arms {
89-
for pat in &arm.pats {
90-
match &pat.node {
91-
PatKind::Path(qpath) | PatKind::TupleStruct(qpath, ..) => {
92-
qpaths.push(qpath)
93-
}
94-
_ => (),
95-
}
96-
}
97-
}
98-
qpaths
99-
}
100-
ExprKind::Path(qpath) => vec![qpath],
101-
_ => vec![],
102-
};
103-
for qpath in qpaths {
104-
if let QPath::Resolved(_, path) = qpath {
105-
let segments_iter = path.segments.iter().rev().skip(1).rev();
84+
fn check_path(&mut self, cx: &LateContext<'_, '_>, path: &'tcx Path, _: HirId) {
85+
let segments_iter = path.segments.iter().rev().skip(1).rev();
10686

107-
if let Some(last) = segments_iter.clone().last() {
108-
if last.ident.as_str() == "TyKind" {
109-
let path = Path {
110-
span: path.span.with_hi(last.ident.span.hi()),
111-
def: path.def,
112-
segments: segments_iter.cloned().collect(),
113-
};
87+
if let Some(last) = segments_iter.clone().last() {
88+
if last.ident.as_str() == "TyKind" {
89+
let path = Path {
90+
span: path.span.with_hi(last.ident.span.hi()),
91+
def: path.def,
92+
segments: segments_iter.cloned().collect(),
93+
};
11494

115-
if let Some(def) = last.def {
116-
if def
117-
.def_id()
118-
.match_path(cx.tcx, &["rustc", "ty", "sty", "TyKind"])
119-
{
120-
cx.struct_span_lint(
121-
USAGE_OF_TY_TYKIND,
122-
path.span,
123-
"usage of `ty::TyKind::<kind>`",
124-
)
125-
.span_suggestion(
126-
path.span,
127-
"try using ty::<kind> directly",
128-
"ty".to_string(),
129-
Applicability::MaybeIncorrect, // ty maybe needs an import
130-
)
131-
.emit();
132-
}
133-
}
95+
if let Some(def) = last.def {
96+
if def
97+
.def_id()
98+
.match_path(cx.tcx, &["rustc", "ty", "sty", "TyKind"])
99+
{
100+
cx.struct_span_lint(
101+
USAGE_OF_TY_TYKIND,
102+
path.span,
103+
"usage of `ty::TyKind::<kind>`",
104+
)
105+
.span_suggestion(
106+
path.span,
107+
"try using ty::<kind> directly",
108+
"ty".to_string(),
109+
Applicability::MaybeIncorrect, // ty maybe needs an import
110+
)
111+
.emit();
134112
}
135113
}
136114
}

0 commit comments

Comments
 (0)