Skip to content

Commit e116866

Browse files
committed
Implement unused_pub_items_in_binary lint
1 parent 8b86f48 commit e116866

18 files changed

Lines changed: 429 additions & 93 deletions

compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ declare_lint_pass! {
145145
UNUSED_MACROS,
146146
UNUSED_MACRO_RULES,
147147
UNUSED_MUT,
148+
UNUSED_PUB_ITEMS_IN_BINARY,
148149
UNUSED_QUALIFICATIONS,
149150
UNUSED_UNSAFE,
150151
UNUSED_VARIABLES,
@@ -781,6 +782,29 @@ declare_lint! {
781782
"detect unused, unexported items"
782783
}
783784

785+
declare_lint! {
786+
/// The `unused_pub_items_in_binary` lint detects public items in executable
787+
/// crates that are not used.
788+
///
789+
/// ### Example
790+
///
791+
/// ```rust
792+
/// pub fn helper() {}
793+
/// ```
794+
///
795+
/// {{produces}}
796+
///
797+
/// ### Explanation
798+
///
799+
/// In executable crates, `pub` items are often not part of a public API.
800+
/// This lint helps detect such items when they are never used within the
801+
/// crate.
802+
pub UNUSED_PUB_ITEMS_IN_BINARY,
803+
Allow,
804+
"detect public items in executable crates that are never used",
805+
crate_level_only
806+
}
807+
784808
declare_lint! {
785809
/// The `unused_attributes` lint detects attributes that were not used by
786810
/// the compiler.

compiler/rustc_middle/src/queries.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,10 +1190,16 @@ rustc_queries! {
11901190
cache_on_disk_if { tcx.is_typeck_child(key.to_def_id()) }
11911191
}
11921192

1193-
/// Return the live symbols in the crate for dead code check.
1193+
/// Return the live symbols in the crate for dead code checks.
11941194
///
1195-
/// The second return value maps from ADTs to ignored derived traits (e.g. Debug and Clone).
1195+
/// The return values are:
1196+
/// - phase-1 live symbols (before reachable-public dead-code seeding)
1197+
/// - final live symbols for dead-code
1198+
/// - unused reachable public symbols in executable crates
1199+
/// - a map from ADTs to ignored derived traits (e.g. Debug and Clone)
11961200
query live_symbols_and_ignored_derived_traits(_: ()) -> &'tcx Result<(
1201+
LocalDefIdSet,
1202+
LocalDefIdSet,
11971203
LocalDefIdSet,
11981204
LocalDefIdMap<FxIndexSet<DefId>>,
11991205
), ErrorGuaranteed> {

0 commit comments

Comments
 (0)