about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeón Orell Valerian Liehr <me@fmease.dev>2025-04-01 18:20:41 +0200
committerLeón Orell Valerian Liehr <me@fmease.dev>2025-04-01 18:20:41 +0200
commit54994b2d4b89a8af8c5a04799e7fa224c7103ea6 (patch)
tree4c79606b31f279411d3666e05a0760b0f9418422
parentd28d2344d000aa96bef729cf408731f952f71fb0 (diff)
downloadrust-54994b2d4b89a8af8c5a04799e7fa224c7103ea6.tar.gz
rust-54994b2d4b89a8af8c5a04799e7fa224c7103ea6.zip
Fix the primary span of redundant_pub_crate when flagging nameless items
-rw-r--r--clippy_lints/src/redundant_pub_crate.rs11
-rw-r--r--tests/ui/redundant_pub_crate.fixed8
-rw-r--r--tests/ui/redundant_pub_crate.rs8
-rw-r--r--tests/ui/redundant_pub_crate.stderr18
4 files changed, 37 insertions, 8 deletions
diff --git a/clippy_lints/src/redundant_pub_crate.rs b/clippy_lints/src/redundant_pub_crate.rs
index f2fdac5a8af..7b381fac5f1 100644
--- a/clippy_lints/src/redundant_pub_crate.rs
+++ b/clippy_lints/src/redundant_pub_crate.rs
@@ -52,13 +52,10 @@ impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate {
             && is_not_macro_export(item)
             && !item.span.in_external_macro(cx.sess().source_map())
         {
-            // FIXME: `DUMMY_SP` isn't right here, because it causes the
-            // resulting span to begin at the start of the file.
-            let span = item.span.with_hi(
-                item.kind
-                    .ident()
-                    .map_or(rustc_span::DUMMY_SP.hi(), |ident| ident.span.hi()),
-            );
+            let span = item
+                .kind
+                .ident()
+                .map_or(item.span, |ident| item.span.with_hi(ident.span.hi()));
             let descr = cx.tcx.def_kind(item.owner_id).descr(item.owner_id.to_def_id());
             span_lint_and_then(
                 cx,
diff --git a/tests/ui/redundant_pub_crate.fixed b/tests/ui/redundant_pub_crate.fixed
index a6450123f4c..8a30fedede4 100644
--- a/tests/ui/redundant_pub_crate.fixed
+++ b/tests/ui/redundant_pub_crate.fixed
@@ -131,6 +131,14 @@ mod m4 {
     }
 }
 
+mod m5 {
+    pub mod m5_1 {}
+    // Test that the primary span isn't butchered for item kinds that don't have an ident.
+    pub use m5_1::*; //~ redundant_pub_crate
+    #[rustfmt::skip]
+    pub use m5_1::{*}; //~ redundant_pub_crate
+}
+
 pub use m4::*;
 
 mod issue_8732 {
diff --git a/tests/ui/redundant_pub_crate.rs b/tests/ui/redundant_pub_crate.rs
index 7415d34d50c..45ba13a63b2 100644
--- a/tests/ui/redundant_pub_crate.rs
+++ b/tests/ui/redundant_pub_crate.rs
@@ -131,6 +131,14 @@ mod m4 {
     }
 }
 
+mod m5 {
+    pub mod m5_1 {}
+    // Test that the primary span isn't butchered for item kinds that don't have an ident.
+    pub(crate) use m5_1::*; //~ redundant_pub_crate
+    #[rustfmt::skip]
+    pub(crate) use m5_1::{*}; //~ redundant_pub_crate
+}
+
 pub use m4::*;
 
 mod issue_8732 {
diff --git a/tests/ui/redundant_pub_crate.stderr b/tests/ui/redundant_pub_crate.stderr
index 95909ea8b06..4a47a321028 100644
--- a/tests/ui/redundant_pub_crate.stderr
+++ b/tests/ui/redundant_pub_crate.stderr
@@ -129,5 +129,21 @@ LL |         pub(crate) fn g() {} // private due to m4_2
    |         |
    |         help: consider using: `pub`
 
-error: aborting due to 16 previous errors
+error: pub(crate) import inside private module
+  --> tests/ui/redundant_pub_crate.rs:137:5
+   |
+LL |     pub(crate) use m5_1::*;
+   |     ----------^^^^^^^^^^^^^
+   |     |
+   |     help: consider using: `pub`
+
+error: pub(crate) import inside private module
+  --> tests/ui/redundant_pub_crate.rs:139:27
+   |
+LL |     pub(crate) use m5_1::{*};
+   |     ----------            ^
+   |     |
+   |     help: consider using: `pub`
+
+error: aborting due to 18 previous errors