Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not trigger redundant_pub_crate in external macros #13952

Merged
merged 1 commit into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions clippy_lints/src/redundant_pub_crate.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::source::HasSession;
use rustc_errors::Applicability;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::{Item, ItemKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty;
use rustc_session::impl_lint_pass;
use rustc_span::def_id::CRATE_DEF_ID;
Expand Down Expand Up @@ -49,6 +51,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate {
&& !cx.effective_visibilities.is_exported(item.owner_id.def_id)
&& self.is_exported.last() == Some(&false)
&& is_not_macro_export(item)
&& !in_external_macro(cx.sess(), item.span)
{
let span = item.span.with_hi(item.ident.span.hi());
let descr = cx.tcx.def_kind(item.owner_id).descr(item.owner_id.to_def_id());
Expand Down
7 changes: 7 additions & 0 deletions tests/ui/redundant_pub_crate.fixed
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@aux-build:proc_macros.rs
#![allow(dead_code)]
#![warn(clippy::redundant_pub_crate)]

Expand Down Expand Up @@ -113,4 +114,10 @@ mod issue_8732 {
pub(crate) use some_macro; // ok: macro exports are exempt
}

proc_macros::external! {
mod priv_mod {
pub(crate) fn dummy() {}
}
}

fn main() {}
7 changes: 7 additions & 0 deletions tests/ui/redundant_pub_crate.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@aux-build:proc_macros.rs
#![allow(dead_code)]
#![warn(clippy::redundant_pub_crate)]

Expand Down Expand Up @@ -113,4 +114,10 @@ mod issue_8732 {
pub(crate) use some_macro; // ok: macro exports are exempt
}

proc_macros::external! {
mod priv_mod {
pub(crate) fn dummy() {}
}
}

fn main() {}
32 changes: 16 additions & 16 deletions tests/ui/redundant_pub_crate.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: pub(crate) function inside private module
--> tests/ui/redundant_pub_crate.rs:6:5
--> tests/ui/redundant_pub_crate.rs:7:5
|
LL | pub(crate) fn g() {} // private due to m1
| ----------^^^^^
Expand All @@ -10,119 +10,119 @@ LL | pub(crate) fn g() {} // private due to m1
= help: to override `-D warnings` add `#[allow(clippy::redundant_pub_crate)]`

error: pub(crate) function inside private module
--> tests/ui/redundant_pub_crate.rs:11:9
--> tests/ui/redundant_pub_crate.rs:12:9
|
LL | pub(crate) fn g() {} // private due to m1_1 and m1
| ----------^^^^^
| |
| help: consider using: `pub`

error: pub(crate) module inside private module
--> tests/ui/redundant_pub_crate.rs:15:5
--> tests/ui/redundant_pub_crate.rs:16:5
|
LL | pub(crate) mod m1_2 {
| ----------^^^^^^^^^
| |
| help: consider using: `pub`

error: pub(crate) function inside private module
--> tests/ui/redundant_pub_crate.rs:18:9
--> tests/ui/redundant_pub_crate.rs:19:9
|
LL | pub(crate) fn g() {} // private due to m1_2 and m1
| ----------^^^^^
| |
| help: consider using: `pub`

error: pub(crate) function inside private module
--> tests/ui/redundant_pub_crate.rs:24:9
--> tests/ui/redundant_pub_crate.rs:25:9
|
LL | pub(crate) fn g() {} // private due to m1
| ----------^^^^^
| |
| help: consider using: `pub`

error: pub(crate) function inside private module
--> tests/ui/redundant_pub_crate.rs:31:5
--> tests/ui/redundant_pub_crate.rs:32:5
|
LL | pub(crate) fn g() {} // already crate visible due to m2
| ----------^^^^^
| |
| help: consider using: `pub`

error: pub(crate) function inside private module
--> tests/ui/redundant_pub_crate.rs:36:9
--> tests/ui/redundant_pub_crate.rs:37:9
|
LL | pub(crate) fn g() {} // private due to m2_1
| ----------^^^^^
| |
| help: consider using: `pub`

error: pub(crate) module inside private module
--> tests/ui/redundant_pub_crate.rs:40:5
--> tests/ui/redundant_pub_crate.rs:41:5
|
LL | pub(crate) mod m2_2 {
| ----------^^^^^^^^^
| |
| help: consider using: `pub`

error: pub(crate) function inside private module
--> tests/ui/redundant_pub_crate.rs:43:9
--> tests/ui/redundant_pub_crate.rs:44:9
|
LL | pub(crate) fn g() {} // already crate visible due to m2_2 and m2
| ----------^^^^^
| |
| help: consider using: `pub`

error: pub(crate) function inside private module
--> tests/ui/redundant_pub_crate.rs:49:9
--> tests/ui/redundant_pub_crate.rs:50:9
|
LL | pub(crate) fn g() {} // already crate visible due to m2
| ----------^^^^^
| |
| help: consider using: `pub`

error: pub(crate) function inside private module
--> tests/ui/redundant_pub_crate.rs:61:9
--> tests/ui/redundant_pub_crate.rs:62:9
|
LL | pub(crate) fn g() {} // private due to m3_1
| ----------^^^^^
| |
| help: consider using: `pub`

error: pub(crate) function inside private module
--> tests/ui/redundant_pub_crate.rs:68:9
--> tests/ui/redundant_pub_crate.rs:69:9
|
LL | pub(crate) fn g() {} // already crate visible due to m3_2
| ----------^^^^^
| |
| help: consider using: `pub`

error: pub(crate) function inside private module
--> tests/ui/redundant_pub_crate.rs:81:5
--> tests/ui/redundant_pub_crate.rs:82:5
|
LL | pub(crate) fn g() {} // private: not re-exported by `pub use m4::*`
| ----------^^^^^
| |
| help: consider using: `pub`

error: pub(crate) function inside private module
--> tests/ui/redundant_pub_crate.rs:86:9
--> tests/ui/redundant_pub_crate.rs:87:9
|
LL | pub(crate) fn g() {} // private due to m4_1
| ----------^^^^^
| |
| help: consider using: `pub`

error: pub(crate) module inside private module
--> tests/ui/redundant_pub_crate.rs:90:5
--> tests/ui/redundant_pub_crate.rs:91:5
|
LL | pub(crate) mod m4_2 {
| ----------^^^^^^^^^
| |
| help: consider using: `pub`

error: pub(crate) function inside private module
--> tests/ui/redundant_pub_crate.rs:93:9
--> tests/ui/redundant_pub_crate.rs:94:9
|
LL | pub(crate) fn g() {} // private due to m4_2
| ----------^^^^^
Expand Down
Loading