|
1 | 1 | use clippy_utils::diagnostics::span_lint_and_then; |
2 | 2 | use rustc_errors::Applicability; |
| 3 | +use rustc_hir::def::{DefKind, Res}; |
3 | 4 | use rustc_hir::{Item, ItemKind, VisibilityKind}; |
4 | 5 | use rustc_lint::{LateContext, LateLintPass}; |
5 | 6 | use rustc_session::{declare_tool_lint, impl_lint_pass}; |
| 7 | +use rustc_span::hygiene::MacroKind; |
6 | 8 |
|
7 | 9 | declare_clippy_lint! { |
8 | 10 | /// ### What it does |
@@ -41,8 +43,11 @@ impl_lint_pass!(RedundantPubCrate => [REDUNDANT_PUB_CRATE]); |
41 | 43 |
|
42 | 44 | impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate { |
43 | 45 | fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) { |
44 | | - if let VisibilityKind::Crate { .. } = item.vis.node { |
45 | | - if !cx.access_levels.is_exported(item.def_id) && self.is_exported.last() == Some(&false) { |
| 46 | + if_chain! { |
| 47 | + if let VisibilityKind::Crate { .. } = item.vis.node; |
| 48 | + if !cx.access_levels.is_exported(item.def_id) && self.is_exported.last() == Some(&false); |
| 49 | + if is_not_macro_export(item); |
| 50 | + then { |
46 | 51 | let span = item.span.with_hi(item.ident.span.hi()); |
47 | 52 | let descr = cx.tcx.def_kind(item.def_id).descr(item.def_id.to_def_id()); |
48 | 53 | span_lint_and_then( |
@@ -73,3 +78,13 @@ impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate { |
73 | 78 | } |
74 | 79 | } |
75 | 80 | } |
| 81 | + |
| 82 | +fn is_not_macro_export<'tcx>(item: &'tcx Item<'tcx>) -> bool { |
| 83 | + if let ItemKind::Use(path, _) = item.kind { |
| 84 | + if let Res::Def(DefKind::Macro(MacroKind::Bang), _) = path.res { |
| 85 | + return false; |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + true |
| 90 | +} |
0 commit comments