Skip to content

Commit 1947a2d

Browse files
committed
Remove unused fn new(); add help string
1 parent e43890e commit 1947a2d

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

clippy_lints/src/redundant_pub_crate.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::span_lint;
1+
use crate::utils::span_lint_and_help;
22
use rustc_hir::{Item, ItemKind, VisibilityKind};
33
use rustc_lint::{LateContext, LateLintPass};
44
use rustc_session::{declare_tool_lint, impl_lint_pass};
@@ -38,24 +38,17 @@ pub struct RedundantPubCrate {
3838

3939
impl_lint_pass!(RedundantPubCrate => [REDUNDANT_PUB_CRATE]);
4040

41-
impl RedundantPubCrate {
42-
pub fn new() -> Self {
43-
Self {
44-
is_exported: Vec::new(),
45-
}
46-
}
47-
}
48-
4941
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RedundantPubCrate {
5042
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item<'tcx>) {
5143
if let VisibilityKind::Crate { .. } = item.vis.node {
5244
if !cx.access_levels.is_exported(item.hir_id) {
5345
if let Some(false) = self.is_exported.last() {
54-
span_lint(
46+
span_lint_and_help(
5547
cx,
5648
REDUNDANT_PUB_CRATE,
5749
item.span,
5850
&format!("pub(crate) {} inside private module", item.kind.descr()),
51+
"consider using `pub` instead of `pub(crate)`",
5952
)
6053
}
6154
}

tests/ui/redundant_pub_crate.stderr

+31
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ LL | pub(crate) fn g() {} // private due to m1
55
| ^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: `-D clippy::redundant-pub-crate` implied by `-D warnings`
8+
= help: consider using `pub` instead of `pub(crate)`
89

910
error: pub(crate) function inside private module
1011
--> $DIR/redundant_pub_crate.rs:10:9
1112
|
1213
LL | pub(crate) fn g() {} // private due to m1_1 and m1
1314
| ^^^^^^^^^^^^^^^^^^^^
15+
|
16+
= help: consider using `pub` instead of `pub(crate)`
1417

1518
error: pub(crate) module inside private module
1619
--> $DIR/redundant_pub_crate.rs:14:5
@@ -22,30 +25,40 @@ LL | | pub(crate) fn g() {} // private due to m1_2 and m1
2225
LL | | pub fn h() {}
2326
LL | | }
2427
| |_____^
28+
|
29+
= help: consider using `pub` instead of `pub(crate)`
2530

2631
error: pub(crate) function inside private module
2732
--> $DIR/redundant_pub_crate.rs:17:9
2833
|
2934
LL | pub(crate) fn g() {} // private due to m1_2 and m1
3035
| ^^^^^^^^^^^^^^^^^^^^
36+
|
37+
= help: consider using `pub` instead of `pub(crate)`
3138

3239
error: pub(crate) function inside private module
3340
--> $DIR/redundant_pub_crate.rs:23:9
3441
|
3542
LL | pub(crate) fn g() {} // private due to m1
3643
| ^^^^^^^^^^^^^^^^^^^^
44+
|
45+
= help: consider using `pub` instead of `pub(crate)`
3746

3847
error: pub(crate) function inside private module
3948
--> $DIR/redundant_pub_crate.rs:30:5
4049
|
4150
LL | pub(crate) fn g() {} // already crate visible due to m2
4251
| ^^^^^^^^^^^^^^^^^^^^
52+
|
53+
= help: consider using `pub` instead of `pub(crate)`
4354

4455
error: pub(crate) function inside private module
4556
--> $DIR/redundant_pub_crate.rs:35:9
4657
|
4758
LL | pub(crate) fn g() {} // private due to m2_1
4859
| ^^^^^^^^^^^^^^^^^^^^
60+
|
61+
= help: consider using `pub` instead of `pub(crate)`
4962

5063
error: pub(crate) module inside private module
5164
--> $DIR/redundant_pub_crate.rs:39:5
@@ -57,42 +70,56 @@ LL | | pub(crate) fn g() {} // already crate visible due to m2_2 and m2
5770
LL | | pub fn h() {}
5871
LL | | }
5972
| |_____^
73+
|
74+
= help: consider using `pub` instead of `pub(crate)`
6075

6176
error: pub(crate) function inside private module
6277
--> $DIR/redundant_pub_crate.rs:42:9
6378
|
6479
LL | pub(crate) fn g() {} // already crate visible due to m2_2 and m2
6580
| ^^^^^^^^^^^^^^^^^^^^
81+
|
82+
= help: consider using `pub` instead of `pub(crate)`
6683

6784
error: pub(crate) function inside private module
6885
--> $DIR/redundant_pub_crate.rs:48:9
6986
|
7087
LL | pub(crate) fn g() {} // already crate visible due to m2
7188
| ^^^^^^^^^^^^^^^^^^^^
89+
|
90+
= help: consider using `pub` instead of `pub(crate)`
7291

7392
error: pub(crate) function inside private module
7493
--> $DIR/redundant_pub_crate.rs:60:9
7594
|
7695
LL | pub(crate) fn g() {} // private due to m3_1
7796
| ^^^^^^^^^^^^^^^^^^^^
97+
|
98+
= help: consider using `pub` instead of `pub(crate)`
7899

79100
error: pub(crate) function inside private module
80101
--> $DIR/redundant_pub_crate.rs:67:9
81102
|
82103
LL | pub(crate) fn g() {} // already crate visible due to m3_2
83104
| ^^^^^^^^^^^^^^^^^^^^
105+
|
106+
= help: consider using `pub` instead of `pub(crate)`
84107

85108
error: pub(crate) function inside private module
86109
--> $DIR/redundant_pub_crate.rs:80:5
87110
|
88111
LL | pub(crate) fn g() {} // private: not re-exported by `pub use m4::*`
89112
| ^^^^^^^^^^^^^^^^^^^^
113+
|
114+
= help: consider using `pub` instead of `pub(crate)`
90115

91116
error: pub(crate) function inside private module
92117
--> $DIR/redundant_pub_crate.rs:85:9
93118
|
94119
LL | pub(crate) fn g() {} // private due to m4_1
95120
| ^^^^^^^^^^^^^^^^^^^^
121+
|
122+
= help: consider using `pub` instead of `pub(crate)`
96123

97124
error: pub(crate) module inside private module
98125
--> $DIR/redundant_pub_crate.rs:89:5
@@ -104,12 +131,16 @@ LL | | pub(crate) fn g() {} // private due to m4_2
104131
LL | | pub fn h() {}
105132
LL | | }
106133
| |_____^
134+
|
135+
= help: consider using `pub` instead of `pub(crate)`
107136

108137
error: pub(crate) function inside private module
109138
--> $DIR/redundant_pub_crate.rs:92:9
110139
|
111140
LL | pub(crate) fn g() {} // private due to m4_2
112141
| ^^^^^^^^^^^^^^^^^^^^
142+
|
143+
= help: consider using `pub` instead of `pub(crate)`
113144

114145
error: aborting due to 16 previous errors
115146

0 commit comments

Comments
 (0)