Skip to content

Commit

Permalink
Remove unused fn new(); add help string
Browse files Browse the repository at this point in the history
  • Loading branch information
1tgr committed Mar 16, 2020
1 parent e43890e commit 1947a2d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
13 changes: 3 additions & 10 deletions clippy_lints/src/redundant_pub_crate.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::utils::span_lint;
use crate::utils::span_lint_and_help;
use rustc_hir::{Item, ItemKind, VisibilityKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_tool_lint, impl_lint_pass};
Expand Down Expand Up @@ -38,24 +38,17 @@ pub struct RedundantPubCrate {

impl_lint_pass!(RedundantPubCrate => [REDUNDANT_PUB_CRATE]);

impl RedundantPubCrate {
pub fn new() -> Self {
Self {
is_exported: Vec::new(),
}
}
}

impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RedundantPubCrate {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item<'tcx>) {
if let VisibilityKind::Crate { .. } = item.vis.node {
if !cx.access_levels.is_exported(item.hir_id) {
if let Some(false) = self.is_exported.last() {
span_lint(
span_lint_and_help(
cx,
REDUNDANT_PUB_CRATE,
item.span,
&format!("pub(crate) {} inside private module", item.kind.descr()),
"consider using `pub` instead of `pub(crate)`",
)
}
}
Expand Down
31 changes: 31 additions & 0 deletions tests/ui/redundant_pub_crate.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ LL | pub(crate) fn g() {} // private due to m1
| ^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::redundant-pub-crate` implied by `-D warnings`
= help: consider using `pub` instead of `pub(crate)`

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

error: aborting due to 16 previous errors

0 comments on commit 1947a2d

Please sign in to comment.