Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0ee2b06

Browse files
committedNov 29, 2023
Merge unused_tuple_struct_fields into dead_code
This implicitly upgrades the lint from `allow` to `warn` and places it into the `unused` lint group.
1 parent abe34e9 commit 0ee2b06

File tree

178 files changed

+262
-290
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

178 files changed

+262
-290
lines changed
 

‎compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -569,8 +569,13 @@ declare_lint! {
569569
/// Dead code may signal a mistake or unfinished code. To silence the
570570
/// warning for individual items, prefix the name with an underscore such
571571
/// as `_foo`. If it was intended to expose the item outside of the crate,
572-
/// consider adding a visibility modifier like `pub`. Otherwise consider
573-
/// removing the unused code.
572+
/// consider adding a visibility modifier like `pub`.
573+
///
574+
/// To preserve the numbering of tuple structs with unused fields,
575+
/// change the unused fields to have unit type or use
576+
/// `PhantomData`.
577+
///
578+
/// Otherwise consider removing the unused code.
574579
pub DEAD_CODE,
575580
Warn,
576581
"detect unused, unexported items"
@@ -604,32 +609,6 @@ declare_lint! {
604609
"detects attributes that were not used by the compiler"
605610
}
606611

607-
declare_lint! {
608-
/// The `unused_tuple_struct_fields` lint detects fields of tuple structs
609-
/// that are never read.
610-
///
611-
/// ### Example
612-
///
613-
/// ```rust
614-
/// #[warn(unused_tuple_struct_fields)]
615-
/// struct S(i32, i32, i32);
616-
/// let s = S(1, 2, 3);
617-
/// let _ = (s.0, s.2);
618-
/// ```
619-
///
620-
/// {{produces}}
621-
///
622-
/// ### Explanation
623-
///
624-
/// Tuple struct fields that are never read anywhere may indicate a
625-
/// mistake or unfinished code. To silence this warning, consider
626-
/// removing the unused field(s) or, to preserve the numbering of the
627-
/// remaining fields, change the unused field(s) to have unit type.
628-
pub UNUSED_TUPLE_STRUCT_FIELDS,
629-
Allow,
630-
"detects tuple struct fields that are never read"
631-
}
632-
633612
declare_lint! {
634613
/// The `unreachable_code` lint detects unreachable code paths.
635614
///
@@ -3466,7 +3445,6 @@ declare_lint_pass! {
34663445
UNUSED_MACROS,
34673446
UNUSED_MUT,
34683447
UNUSED_QUALIFICATIONS,
3469-
UNUSED_TUPLE_STRUCT_FIELDS,
34703448
UNUSED_UNSAFE,
34713449
UNUSED_VARIABLES,
34723450
USELESS_DEPRECATED,

‎compiler/rustc_passes/src/dead.rs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -835,12 +835,6 @@ impl<'tcx> DeadVisitor<'tcx> {
835835
let multiple = num > 6;
836836
let name_list = names.into();
837837

838-
let lint = if is_positional {
839-
lint::builtin::UNUSED_TUPLE_STRUCT_FIELDS
840-
} else {
841-
lint::builtin::DEAD_CODE
842-
};
843-
844838
let parent_info = if let Some(parent_item) = parent_item {
845839
let parent_descr = tcx.def_descr(parent_item.to_def_id());
846840
let span = if let DefKind::Impl { .. } = tcx.def_kind(parent_item) {
@@ -893,7 +887,12 @@ impl<'tcx> DeadVisitor<'tcx> {
893887
}
894888
};
895889

896-
self.tcx.emit_spanned_lint(lint, first_hir_id, MultiSpan::from_spans(spans), diag);
890+
self.tcx.emit_spanned_lint(
891+
lint::builtin::DEAD_CODE,
892+
first_hir_id,
893+
MultiSpan::from_spans(spans),
894+
diag,
895+
);
897896
}
898897

899898
fn warn_multiple(
@@ -1013,17 +1012,11 @@ fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalModDefId) {
10131012
if let ShouldWarnAboutField::Yes(is_pos) =
10141013
visitor.should_warn_about_field(field)
10151014
{
1016-
let level = tcx
1017-
.lint_level_at_node(
1018-
if is_pos {
1019-
is_positional = true;
1020-
lint::builtin::UNUSED_TUPLE_STRUCT_FIELDS
1021-
} else {
1022-
lint::builtin::DEAD_CODE
1023-
},
1024-
hir_id,
1025-
)
1026-
.0;
1015+
if is_pos {
1016+
is_positional = true;
1017+
}
1018+
1019+
let level = tcx.lint_level_at_node(lint::builtin::DEAD_CODE, hir_id).0;
10271020
Some(DeadItem { def_id, name: field.name, level })
10281021
} else {
10291022
None

0 commit comments

Comments
 (0)
Please sign in to comment.