|
1 | 1 | //! Some lints that are only useful in the compiler or crates that use compiler internals, such as
|
2 | 2 | //! Clippy.
|
3 | 3 |
|
4 |
| -use crate::hir::{Expr, ExprKind, PatKind, Path, QPath, Ty, TyKind}; |
| 4 | +use crate::hir::{HirId, Path, QPath, Ty, TyKind}; |
5 | 5 | use crate::lint::{
|
6 | 6 | EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintArray, LintContext, LintPass,
|
7 | 7 | };
|
@@ -81,56 +81,34 @@ impl LintPass for TyKindUsage {
|
81 | 81 | }
|
82 | 82 |
|
83 | 83 | 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(); |
106 | 86 |
|
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 | + }; |
114 | 94 |
|
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(); |
134 | 112 | }
|
135 | 113 | }
|
136 | 114 | }
|
|
0 commit comments