Skip to content

Commit 2a5ee68

Browse files
committed
Auto merge of #8736 - Serial-ATA:issue-8732, r=xFrednet
Add macro export exemption to `redundant_pub_crate` changelog: Add macro export exemption to `redundant_pub_crate` closes #8732
2 parents cef882c + f20e890 commit 2a5ee68

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

clippy_lints/src/redundant_pub_crate.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
22
use rustc_errors::Applicability;
3+
use rustc_hir::def::{DefKind, Res};
34
use rustc_hir::{Item, ItemKind, VisibilityKind};
45
use rustc_lint::{LateContext, LateLintPass};
56
use rustc_session::{declare_tool_lint, impl_lint_pass};
7+
use rustc_span::hygiene::MacroKind;
68

79
declare_clippy_lint! {
810
/// ### What it does
@@ -41,8 +43,11 @@ impl_lint_pass!(RedundantPubCrate => [REDUNDANT_PUB_CRATE]);
4143

4244
impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate {
4345
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 {
4651
let span = item.span.with_hi(item.ident.span.hi());
4752
let descr = cx.tcx.def_kind(item.def_id).descr(item.def_id.to_def_id());
4853
span_lint_and_then(
@@ -73,3 +78,13 @@ impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate {
7378
}
7479
}
7580
}
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+
}

tests/ui/redundant_pub_crate.fixed

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,14 @@ mod m4 {
104104

105105
pub use m4::*;
106106

107+
mod issue_8732 {
108+
#[allow(unused_macros)]
109+
macro_rules! some_macro {
110+
() => {};
111+
}
112+
113+
#[allow(unused_imports)]
114+
pub(crate) use some_macro; // ok: macro exports are exempt
115+
}
116+
107117
fn main() {}

tests/ui/redundant_pub_crate.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,14 @@ mod m4 {
104104

105105
pub use m4::*;
106106

107+
mod issue_8732 {
108+
#[allow(unused_macros)]
109+
macro_rules! some_macro {
110+
() => {};
111+
}
112+
113+
#[allow(unused_imports)]
114+
pub(crate) use some_macro; // ok: macro exports are exempt
115+
}
116+
107117
fn main() {}

0 commit comments

Comments
 (0)