-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Lint unused pub items in binary crates #149509
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
e651309
cc41061
f12e960
64d40ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -146,6 +146,7 @@ declare_lint_pass! { | |||||
| UNUSED_MACROS, | ||||||
| UNUSED_MACRO_RULES, | ||||||
| UNUSED_MUT, | ||||||
| UNUSED_PUB_ITEMS_IN_BINARY, | ||||||
| UNUSED_QUALIFICATIONS, | ||||||
| UNUSED_UNSAFE, | ||||||
| UNUSED_VARIABLES, | ||||||
|
|
@@ -782,6 +783,37 @@ declare_lint! { | |||||
| "detect unused, unexported items" | ||||||
| } | ||||||
|
|
||||||
| declare_lint! { | ||||||
| /// The `unused_pub_items_in_binary` lint detects unused `pub` items in | ||||||
| /// executable crates. | ||||||
| /// | ||||||
| /// ### Example | ||||||
| /// | ||||||
| /// ```rust | ||||||
| /// #![deny(unused_pub_items_in_binary)] | ||||||
| /// | ||||||
| /// pub fn unused_pub_fn() {} | ||||||
| /// | ||||||
| /// fn main() {} | ||||||
| /// ``` | ||||||
| /// | ||||||
| /// {{produces}} | ||||||
| /// | ||||||
| /// ### Explanation | ||||||
| /// | ||||||
| /// In executable crates, `pub` items are often implementation details | ||||||
| /// rather than part of an external API. This lint helps find those items | ||||||
| /// when they are never used. | ||||||
| /// | ||||||
| /// This lint only applies to executable crates. In library crates, public | ||||||
| /// items are considered part of the crate's API and are not reported by | ||||||
| /// this lint. | ||||||
| pub UNUSED_PUB_ITEMS_IN_BINARY, | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
In keeping with the RFC 0344 guidance, I might call this
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assuming this is something like “ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The name "unused pub" makes me think the |
||||||
| Allow, | ||||||
| "detect public items in executable crates that are never used", | ||||||
| crate_level_only | ||||||
| } | ||||||
|
|
||||||
| declare_lint! { | ||||||
| /// The `unused_attributes` lint detects attributes that were not used by | ||||||
| /// the compiler. | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| use rustc_data_structures::fx::FxIndexSet; | ||
| use rustc_hir::def_id::{DefId, LocalDefIdMap, LocalDefIdSet}; | ||
| use rustc_macros::HashStable; | ||
|
|
||
| /// A single snapshot of dead-code liveness analysis state. | ||
| #[derive(Clone, Debug, HashStable)] | ||
| pub struct DeadCodeLivenessSnapshot { | ||
| pub live_symbols: LocalDefIdSet, | ||
| /// Maps each ADT to derived traits (for example `Debug` and `Clone`) that should be ignored | ||
| /// when checking for dead code diagnostics. | ||
| pub ignored_derived_traits: LocalDefIdMap<FxIndexSet<DefId>>, | ||
| } | ||
|
|
||
| /// Dead-code liveness data for both analysis phases. | ||
| /// | ||
| /// `pre_deferred_seeding` is computed before reachable-public and `#[allow(dead_code)]` seeding, | ||
| /// and is used for lint `unused_pub_items_in_binary`. | ||
| /// `final_result` is the final liveness snapshot used for lint `dead_code`. | ||
| #[derive(Clone, Debug, HashStable)] | ||
| pub struct DeadCodeLivenessSummary { | ||
| pub pre_deferred_seeding: DeadCodeLivenessSnapshot, | ||
| pub final_result: DeadCodeLivenessSnapshot, | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.