Skip to content

Commit 54994b2

Browse files
committed
Fix the primary span of redundant_pub_crate when flagging nameless items
1 parent d28d234 commit 54994b2

File tree

4 files changed

+37
-8
lines changed

4 files changed

+37
-8
lines changed

clippy_lints/src/redundant_pub_crate.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,10 @@ impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate {
5252
&& is_not_macro_export(item)
5353
&& !item.span.in_external_macro(cx.sess().source_map())
5454
{
55-
// FIXME: `DUMMY_SP` isn't right here, because it causes the
56-
// resulting span to begin at the start of the file.
57-
let span = item.span.with_hi(
58-
item.kind
59-
.ident()
60-
.map_or(rustc_span::DUMMY_SP.hi(), |ident| ident.span.hi()),
61-
);
55+
let span = item
56+
.kind
57+
.ident()
58+
.map_or(item.span, |ident| item.span.with_hi(ident.span.hi()));
6259
let descr = cx.tcx.def_kind(item.owner_id).descr(item.owner_id.to_def_id());
6360
span_lint_and_then(
6461
cx,

tests/ui/redundant_pub_crate.fixed

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ mod m4 {
131131
}
132132
}
133133

134+
mod m5 {
135+
pub mod m5_1 {}
136+
// Test that the primary span isn't butchered for item kinds that don't have an ident.
137+
pub use m5_1::*; //~ redundant_pub_crate
138+
#[rustfmt::skip]
139+
pub use m5_1::{*}; //~ redundant_pub_crate
140+
}
141+
134142
pub use m4::*;
135143

136144
mod issue_8732 {

tests/ui/redundant_pub_crate.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ mod m4 {
131131
}
132132
}
133133

134+
mod m5 {
135+
pub mod m5_1 {}
136+
// Test that the primary span isn't butchered for item kinds that don't have an ident.
137+
pub(crate) use m5_1::*; //~ redundant_pub_crate
138+
#[rustfmt::skip]
139+
pub(crate) use m5_1::{*}; //~ redundant_pub_crate
140+
}
141+
134142
pub use m4::*;
135143

136144
mod issue_8732 {

tests/ui/redundant_pub_crate.stderr

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,5 +129,21 @@ LL | pub(crate) fn g() {} // private due to m4_2
129129
| |
130130
| help: consider using: `pub`
131131

132-
error: aborting due to 16 previous errors
132+
error: pub(crate) import inside private module
133+
--> tests/ui/redundant_pub_crate.rs:137:5
134+
|
135+
LL | pub(crate) use m5_1::*;
136+
| ----------^^^^^^^^^^^^^
137+
| |
138+
| help: consider using: `pub`
139+
140+
error: pub(crate) import inside private module
141+
--> tests/ui/redundant_pub_crate.rs:139:27
142+
|
143+
LL | pub(crate) use m5_1::{*};
144+
| ---------- ^
145+
| |
146+
| help: consider using: `pub`
147+
148+
error: aborting due to 18 previous errors
133149

0 commit comments

Comments
 (0)