forked from rust-lang/rust-clippy
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Changes: ```` remove redundant import rustup rust-lang/rust#68404 rustup rust-lang/rust#69644 rustup rust-lang/rust#70344 Move verbose_file_reads to restriction move redundant_pub_crate to nursery readme: explain how to run only a single lint on a codebase Remove dependency on `matches` crate Move useless_transmute to nursery nursery group -> style Update for PR feedback Auto merge of rust-lang#5314 - ehuss:remove-git2, r=flip1995 Lint for `pub(crate)` items that are not crate visible due to the visibility of the module that contains them ```` Fixes #70456
- Loading branch information
1 parent
a3c73a9
commit 859b59e
Showing
40 changed files
with
513 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
use crate::utils::span_lint_and_then; | ||
use rustc_errors::Applicability; | ||
use rustc_hir::{Item, ItemKind, VisibilityKind}; | ||
use rustc_lint::{LateContext, LateLintPass}; | ||
use rustc_session::{declare_tool_lint, impl_lint_pass}; | ||
|
||
declare_clippy_lint! { | ||
/// **What it does:** Checks for items declared `pub(crate)` that are not crate visible because they | ||
/// are inside a private module. | ||
/// | ||
/// **Why is this bad?** Writing `pub(crate)` is misleading when it's redundant due to the parent | ||
/// module's visibility. | ||
/// | ||
/// **Known problems:** None. | ||
/// | ||
/// **Example:** | ||
/// | ||
/// ```rust | ||
/// mod internal { | ||
/// pub(crate) fn internal_fn() { } | ||
/// } | ||
/// ``` | ||
/// This function is not visible outside the module and it can be declared with `pub` or | ||
/// private visibility | ||
/// ```rust | ||
/// mod internal { | ||
/// pub fn internal_fn() { } | ||
/// } | ||
/// ``` | ||
pub REDUNDANT_PUB_CRATE, | ||
nursery, | ||
"Using `pub(crate)` visibility on items that are not crate visible due to the visibility of the module that contains them." | ||
} | ||
|
||
#[derive(Default)] | ||
pub struct RedundantPubCrate { | ||
is_exported: Vec<bool>, | ||
} | ||
|
||
impl_lint_pass!(RedundantPubCrate => [REDUNDANT_PUB_CRATE]); | ||
|
||
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() { | ||
let span = item.span.with_hi(item.ident.span.hi()); | ||
span_lint_and_then( | ||
cx, | ||
REDUNDANT_PUB_CRATE, | ||
span, | ||
&format!("pub(crate) {} inside private module", item.kind.descr()), | ||
|db| { | ||
db.span_suggestion( | ||
item.vis.span, | ||
"consider using", | ||
"pub".to_string(), | ||
Applicability::MachineApplicable, | ||
); | ||
}, | ||
) | ||
} | ||
} | ||
} | ||
|
||
if let ItemKind::Mod { .. } = item.kind { | ||
self.is_exported.push(cx.access_levels.is_exported(item.hir_id)); | ||
} | ||
} | ||
|
||
fn check_item_post(&mut self, _cx: &LateContext<'a, 'tcx>, item: &'tcx Item<'tcx>) { | ||
if let ItemKind::Mod { .. } = item.kind { | ||
self.is_exported.pop().expect("unbalanced check_item/check_item_post"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.