mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-16 21:15:18 +03:00
Rename unused_pub_items_in_binary to dead_code_pub_in_binary
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
CONST_EVALUATABLE_UNCHECKED,
|
||||
CONST_ITEM_MUTATION,
|
||||
DEAD_CODE,
|
||||
DEAD_CODE_PUB_IN_BINARY,
|
||||
DEPENDENCY_ON_UNIT_NEVER_TYPE_FALLBACK,
|
||||
DEPRECATED,
|
||||
DEPRECATED_IN_FUTURE,
|
||||
@@ -148,7 +149,6 @@
|
||||
UNUSED_MACROS,
|
||||
UNUSED_MACRO_RULES,
|
||||
UNUSED_MUT,
|
||||
UNUSED_PUB_ITEMS_IN_BINARY,
|
||||
UNUSED_QUALIFICATIONS,
|
||||
UNUSED_UNSAFE,
|
||||
UNUSED_VARIABLES,
|
||||
@@ -791,13 +791,13 @@
|
||||
}
|
||||
|
||||
declare_lint! {
|
||||
/// The `unused_pub_items_in_binary` lint detects unused `pub` items in
|
||||
/// The `dead_code_pub_in_binary` lint detects unused `pub` items in
|
||||
/// executable crates.
|
||||
///
|
||||
/// ### Example
|
||||
///
|
||||
/// ```rust
|
||||
/// #![deny(unused_pub_items_in_binary)]
|
||||
/// #![deny(dead_code_pub_in_binary)]
|
||||
///
|
||||
/// pub fn unused_pub_fn() {}
|
||||
///
|
||||
@@ -815,7 +815,7 @@
|
||||
/// 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,
|
||||
pub DEAD_CODE_PUB_IN_BINARY,
|
||||
Allow,
|
||||
"detect public items in executable crates that are never used",
|
||||
crate_level_only
|
||||
|
||||
@@ -14,7 +14,7 @@ pub struct DeadCodeLivenessSnapshot {
|
||||
/// 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`.
|
||||
/// and is used for lint `dead_code_pub_in_binary`.
|
||||
/// `final_result` is the final liveness snapshot used for lint `dead_code`.
|
||||
#[derive(Clone, Debug, StableHash)]
|
||||
pub struct DeadCodeLivenessSummary {
|
||||
|
||||
@@ -1530,12 +1530,11 @@ fn check_unused_attribute(&self, hir_id: HirId, attr: &Attribute, style: Option<
|
||||
&& attr.has_any_name(&[sym::allow, sym::warn, sym::deny, sym::forbid, sym::expect])
|
||||
&& let Some(meta) = attr.meta_item_list()
|
||||
&& meta.iter().any(|meta| {
|
||||
meta.meta_item()
|
||||
.is_some_and(|item| item.path == sym::unused_pub_items_in_binary)
|
||||
meta.meta_item().is_some_and(|item| item.path == sym::dead_code_pub_in_binary)
|
||||
})
|
||||
&& !self.tcx.crate_types().contains(&CrateType::Executable)
|
||||
{
|
||||
errors::UnusedNote::NoEffectUnusedPubItemsInBinary
|
||||
errors::UnusedNote::NoEffectDeadCodePubInBinary
|
||||
} else if attr.has_name(sym::default_method_body_is_const) {
|
||||
errors::UnusedNote::DefaultMethodBodyConst
|
||||
} else {
|
||||
|
||||
@@ -21,12 +21,12 @@
|
||||
use rustc_middle::ty::{self, AssocTag, TyCtxt};
|
||||
use rustc_middle::{bug, span_bug};
|
||||
use rustc_session::config::CrateType;
|
||||
use rustc_session::lint::builtin::{DEAD_CODE, UNUSED_PUB_ITEMS_IN_BINARY};
|
||||
use rustc_session::lint::builtin::{DEAD_CODE, DEAD_CODE_PUB_IN_BINARY};
|
||||
use rustc_session::lint::{self, Lint, LintExpectationId};
|
||||
use rustc_span::{Symbol, kw};
|
||||
|
||||
use crate::errors::{
|
||||
ChangeFields, IgnoredDerivedImpls, MultipleDeadCodes, ParentInfo, UnusedPubItemsInBinaryNote,
|
||||
ChangeFields, DeadCodePubInBinaryNote, IgnoredDerivedImpls, MultipleDeadCodes, ParentInfo,
|
||||
UselessAssignment,
|
||||
};
|
||||
|
||||
@@ -1088,11 +1088,8 @@ fn def_lint_level(&self, id: LocalDefId) -> (lint::Level, Option<LintExpectation
|
||||
(level.level, level.lint_id)
|
||||
}
|
||||
|
||||
fn unused_pub_items_in_binary_note(&self) -> Option<UnusedPubItemsInBinaryNote> {
|
||||
self.target_lint
|
||||
.name
|
||||
.eq(UNUSED_PUB_ITEMS_IN_BINARY.name)
|
||||
.then_some(UnusedPubItemsInBinaryNote)
|
||||
fn dead_code_pub_in_binary_note(&self) -> Option<DeadCodePubInBinaryNote> {
|
||||
self.target_lint.name.eq(DEAD_CODE_PUB_IN_BINARY.name).then_some(DeadCodePubInBinaryNote)
|
||||
}
|
||||
|
||||
// # Panics
|
||||
@@ -1206,7 +1203,7 @@ fn lint_at_single_level(
|
||||
descr,
|
||||
participle,
|
||||
name_list,
|
||||
unused_pub_items_in_binary_note: self.unused_pub_items_in_binary_note(),
|
||||
dead_code_pub_in_binary_note: self.dead_code_pub_in_binary_note(),
|
||||
change_fields_suggestion: fields_suggestion,
|
||||
parent_info,
|
||||
ignored_derived_impls,
|
||||
@@ -1243,7 +1240,7 @@ fn lint_at_single_level(
|
||||
descr,
|
||||
participle,
|
||||
name_list,
|
||||
unused_pub_items_in_binary_note: self.unused_pub_items_in_binary_note(),
|
||||
dead_code_pub_in_binary_note: self.dead_code_pub_in_binary_note(),
|
||||
parent_info,
|
||||
ignored_derived_impls,
|
||||
enum_variants_with_same_name,
|
||||
@@ -1333,9 +1330,9 @@ fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalModDefId) {
|
||||
&& !pre_deferred_seeding.live_symbols.contains(&def_id)
|
||||
};
|
||||
|
||||
lint_dead_code_or_unused_pub_items_in_binary(
|
||||
lint_dead_codes(
|
||||
tcx,
|
||||
UNUSED_PUB_ITEMS_IN_BINARY,
|
||||
DEAD_CODE_PUB_IN_BINARY,
|
||||
module,
|
||||
&pre_deferred_seeding.live_symbols,
|
||||
&pre_deferred_seeding.ignored_derived_traits,
|
||||
@@ -1346,7 +1343,7 @@ fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalModDefId) {
|
||||
);
|
||||
}
|
||||
|
||||
lint_dead_code_or_unused_pub_items_in_binary(
|
||||
lint_dead_codes(
|
||||
tcx,
|
||||
DEAD_CODE,
|
||||
module,
|
||||
@@ -1357,7 +1354,7 @@ fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalModDefId) {
|
||||
);
|
||||
}
|
||||
|
||||
fn lint_dead_code_or_unused_pub_items_in_binary<'tcx>(
|
||||
fn lint_dead_codes<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
target_lint: &'static Lint,
|
||||
module: LocalModDefId,
|
||||
|
||||
@@ -298,8 +298,8 @@ pub(crate) enum UnusedNote {
|
||||
"the `linker_messages` and `linker_info` lints can only be controlled at the root of a crate that needs to be linked"
|
||||
)]
|
||||
LinkerMessagesBinaryCrateOnly,
|
||||
#[note("the `unused_pub_items_in_binary` lint has no effect in library crates")]
|
||||
NoEffectUnusedPubItemsInBinary,
|
||||
#[note("the `dead_code_pub_in_binary` lint has no effect in library crates")]
|
||||
NoEffectDeadCodePubInBinary,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
@@ -922,7 +922,7 @@ pub(crate) enum MultipleDeadCodes<'tcx> {
|
||||
participle: &'tcx str,
|
||||
name_list: DiagSymbolList,
|
||||
#[subdiagnostic]
|
||||
unused_pub_items_in_binary_note: Option<UnusedPubItemsInBinaryNote>,
|
||||
dead_code_pub_in_binary_note: Option<DeadCodePubInBinaryNote>,
|
||||
#[subdiagnostic]
|
||||
// only on DeadCodes since it's never a problem for tuple struct fields
|
||||
enum_variants_with_same_name: Vec<EnumVariantSameName<'tcx>>,
|
||||
@@ -947,7 +947,7 @@ pub(crate) enum MultipleDeadCodes<'tcx> {
|
||||
participle: &'tcx str,
|
||||
name_list: DiagSymbolList,
|
||||
#[subdiagnostic]
|
||||
unused_pub_items_in_binary_note: Option<UnusedPubItemsInBinaryNote>,
|
||||
dead_code_pub_in_binary_note: Option<DeadCodePubInBinaryNote>,
|
||||
#[subdiagnostic]
|
||||
change_fields_suggestion: ChangeFields,
|
||||
#[subdiagnostic]
|
||||
@@ -961,7 +961,7 @@ pub(crate) enum MultipleDeadCodes<'tcx> {
|
||||
#[note(
|
||||
"in libraries, `pub` items can be used by dependent crates; in binaries, they cannot, so this `pub` item is unused"
|
||||
)]
|
||||
pub(crate) struct UnusedPubItemsInBinaryNote;
|
||||
pub(crate) struct DeadCodePubInBinaryNote;
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
#[note(
|
||||
|
||||
@@ -753,6 +753,7 @@
|
||||
d32,
|
||||
dbg_macro,
|
||||
dead_code,
|
||||
dead_code_pub_in_binary,
|
||||
dealloc,
|
||||
debug,
|
||||
debug_assert_eq_macro,
|
||||
@@ -2192,7 +2193,6 @@
|
||||
unstable_removed,
|
||||
untagged_unions,
|
||||
unused_imports,
|
||||
unused_pub_items_in_binary,
|
||||
unwind,
|
||||
unwind_attributes,
|
||||
unwind_safe_trait,
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
#![deny(dead_code)]
|
||||
#![deny(unused_pub_items_in_binary)]
|
||||
#![deny(dead_code_pub_in_binary)]
|
||||
|
||||
pub fn g() {} //~ ERROR function `g` is never used
|
||||
|
||||
+2
-2
@@ -8,8 +8,8 @@ LL | pub fn g() {}
|
||||
note: the lint level is defined here
|
||||
--> $DIR/allow-dead-code-transitive.rs:2:9
|
||||
|
|
||||
LL | #![deny(unused_pub_items_in_binary)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL | #![deny(dead_code_pub_in_binary)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
#![deny(dead_code)]
|
||||
#![allow(unused_pub_items_in_binary)]
|
||||
#![allow(dead_code_pub_in_binary)]
|
||||
|
||||
pub fn unused_pub_fn() {
|
||||
helper();
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
#![deny(dead_code)]
|
||||
#![deny(unused_pub_items_in_binary)]
|
||||
#![deny(dead_code_pub_in_binary)]
|
||||
|
||||
pub fn unused_pub_fn() {} //~ ERROR function `unused_pub_fn` is never used
|
||||
|
||||
+2
-2
@@ -8,8 +8,8 @@ LL | pub fn unused_pub_fn() {}
|
||||
note: the lint level is defined here
|
||||
--> $DIR/basic.rs:2:9
|
||||
|
|
||||
LL | #![deny(unused_pub_items_in_binary)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL | #![deny(dead_code_pub_in_binary)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: function `unused_priv_fn` is never used
|
||||
--> $DIR/basic.rs:8:4
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
#![deny(unused_pub_items_in_binary)]
|
||||
#![deny(dead_code_pub_in_binary)]
|
||||
#![allow(dead_code)]
|
||||
|
||||
pub fn unused_pub_fn() {} //~ ERROR function `unused_pub_fn` is never used
|
||||
+2
-2
@@ -8,8 +8,8 @@ LL | pub fn unused_pub_fn() {}
|
||||
note: the lint level is defined here
|
||||
--> $DIR/deny-lint.rs:1:9
|
||||
|
|
||||
LL | #![deny(unused_pub_items_in_binary)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL | #![deny(dead_code_pub_in_binary)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
#![allow(dead_code)]
|
||||
#![deny(unused_pub_items_in_binary)]
|
||||
#![deny(dead_code_pub_in_binary)]
|
||||
|
||||
pub fn unused_pub_fn() {} //~ ERROR function `unused_pub_fn` is never used
|
||||
fn unused_priv_fn() {}
|
||||
+2
-2
@@ -8,8 +8,8 @@ LL | pub fn unused_pub_fn() {}
|
||||
note: the lint level is defined here
|
||||
--> $DIR/interaction-allow-dead-code.rs:2:9
|
||||
|
|
||||
LL | #![deny(unused_pub_items_in_binary)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL | #![deny(dead_code_pub_in_binary)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
#![allow(unused_pub_items_in_binary)]
|
||||
#![allow(dead_code_pub_in_binary)]
|
||||
#![deny(dead_code)]
|
||||
|
||||
pub fn unused_pub_fn() {}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
#![deny(dead_code)]
|
||||
#![deny(unused_pub_items_in_binary)]
|
||||
#![deny(dead_code_pub_in_binary)]
|
||||
//~^ WARN unused attribute
|
||||
|
||||
#![crate_type = "lib"]
|
||||
+3
-3
@@ -1,10 +1,10 @@
|
||||
warning: unused attribute
|
||||
--> $DIR/library.rs:2:1
|
||||
|
|
||||
LL | #![deny(unused_pub_items_in_binary)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute
|
||||
LL | #![deny(dead_code_pub_in_binary)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute
|
||||
|
|
||||
= note: the `unused_pub_items_in_binary` lint has no effect in library crates
|
||||
= note: the `dead_code_pub_in_binary` lint has no effect in library crates
|
||||
= note: requested on the command line with `-W unused-attributes`
|
||||
|
||||
error: function `unused_priv_fn` is never used
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
#![deny(dead_code)]
|
||||
#![deny(unused_pub_items_in_binary)]
|
||||
#![deny(dead_code_pub_in_binary)]
|
||||
|
||||
#[no_mangle]
|
||||
pub fn pub_fn_no_mangle() {}
|
||||
+2
-2
@@ -8,8 +8,8 @@ LL | pub fn unused_pub_fn() {}
|
||||
note: the lint level is defined here
|
||||
--> $DIR/no-mangle-items.rs:2:9
|
||||
|
|
||||
LL | #![deny(unused_pub_items_in_binary)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL | #![deny(dead_code_pub_in_binary)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: function `unused_priv_fn` is never used
|
||||
--> $DIR/no-mangle-items.rs:12:4
|
||||
Reference in New Issue
Block a user