|
9 | 9 |
|
10 | 10 |
|
11 | 11 | use crate::utils::{
|
12 |
| - match_qpath, match_type, paths, span_help_and_lint, span_lint, span_lint_and_sugg, walk_ptrs_ty, |
| 12 | + match_def_path, match_type, paths, span_help_and_lint, span_lint, span_lint_and_sugg, walk_ptrs_ty, |
13 | 13 | };
|
14 | 14 | use if_chain::if_chain;
|
15 | 15 | use crate::rustc::hir;
|
16 | 16 | use crate::rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
|
17 | 17 | use crate::rustc::hir::*;
|
| 18 | +use crate::rustc::hir::def::Def; |
18 | 19 | use crate::rustc::lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintArray, LintPass};
|
19 | 20 | use crate::rustc::{declare_tool_lint, lint_array};
|
20 | 21 | use crate::rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
@@ -160,15 +161,21 @@ impl LintPass for LintWithoutLintPass {
|
160 | 161 |
|
161 | 162 | impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass {
|
162 | 163 | fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
|
163 |
| - if let hir::ItemKind::Static(ref ty, MutImmutable, body_id) = item.node { |
164 |
| - if is_lint_ref_type(ty) { |
| 164 | + if let hir::ItemKind::Static(ref ty, MutImmutable, _) = item.node { |
| 165 | + if is_lint_ref_type(cx, ty) { |
165 | 166 | self.declared_lints.insert(item.name, item.span);
|
166 |
| - } else if is_lint_array_type(ty) && item.name == "ARRAY" { |
167 |
| - if let VisibilityKind::Inherited = item.vis.node { |
| 167 | + } |
| 168 | + } else if let hir::ItemKind::Impl(.., Some(ref trait_ref), _, ref impl_item_refs) = item.node { |
| 169 | + if_chain! { |
| 170 | + if let hir::TraitRef{path, ..} = trait_ref; |
| 171 | + if let Def::Trait(def_id) = path.def; |
| 172 | + if match_def_path(cx.tcx, def_id, &paths::LINT_PASS); |
| 173 | + then { |
168 | 174 | let mut collector = LintCollector {
|
169 | 175 | output: &mut self.registered_lints,
|
170 | 176 | cx,
|
171 | 177 | };
|
| 178 | + let body_id = cx.tcx.hir.body_owned_by(impl_item_refs[0].id.node_id); |
172 | 179 | collector.visit_expr(&cx.tcx.hir.body(body_id).value);
|
173 | 180 | }
|
174 | 181 | }
|
@@ -203,28 +210,22 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass {
|
203 | 210 | }
|
204 | 211 | }
|
205 | 212 |
|
206 |
| -fn is_lint_ref_type(ty: &Ty) -> bool { |
| 213 | +fn is_lint_ref_type<'tcx>(cx: &LateContext<'_, 'tcx>, ty: &Ty) -> bool { |
207 | 214 | if let TyKind::Rptr(
|
208 | 215 | _,
|
209 | 216 | MutTy {
|
210 | 217 | ty: ref inner,
|
211 | 218 | mutbl: MutImmutable,
|
212 | 219 | },
|
213 |
| - ) = ty.node |
214 |
| - { |
| 220 | + ) = ty.node { |
215 | 221 | if let TyKind::Path(ref path) = inner.node {
|
216 |
| - return match_qpath(path, &paths::LINT); |
| 222 | + if let Def::Struct(def_id) = cx.tables.qpath_def(path, inner.hir_id) { |
| 223 | + return match_def_path(cx.tcx, def_id, &paths::LINT); |
| 224 | + } |
217 | 225 | }
|
218 | 226 | }
|
219 |
| - false |
220 |
| -} |
221 | 227 |
|
222 |
| -fn is_lint_array_type(ty: &Ty) -> bool { |
223 |
| - if let TyKind::Path(ref path) = ty.node { |
224 |
| - match_qpath(path, &paths::LINT_ARRAY) |
225 |
| - } else { |
226 |
| - false |
227 |
| - } |
| 228 | + false |
228 | 229 | }
|
229 | 230 |
|
230 | 231 | struct LintCollector<'a, 'tcx: 'a> {
|
|
0 commit comments