Skip to content

Commit 0ee2b06

Browse files
committed
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

library/alloc/src/boxed.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
//! Creating a recursive data structure:
2525
//!
2626
//! ```
27+
//! ##[allow(dead_code)]
2728
//! #[derive(Debug)]
2829
//! enum List<T> {
2930
//! Cons(T, Box<List<T>>),

library/alloc/src/boxed/thin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ struct WithHeader<H>(NonNull<u8>, PhantomData<H>);
171171
/// An opaque representation of `WithHeader<H>` to avoid the
172172
/// projection invariance of `<T as Pointee>::Metadata`.
173173
#[repr(transparent)]
174-
#[allow(unused_tuple_struct_fields)] // Field only used through `WithHeader` type above.
174+
#[allow(dead_code)] // Field only used through `WithHeader` type above.
175175
struct WithOpaqueHeader(NonNull<u8>);
176176

177177
impl WithOpaqueHeader {

library/alloc/src/collections/btree/set/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ fn test_extend_ref() {
527527
#[test]
528528
fn test_recovery() {
529529
#[derive(Debug)]
530-
struct Foo(&'static str, i32);
530+
struct Foo(&'static str, #[allow(dead_code)] i32);
531531

532532
impl PartialEq for Foo {
533533
fn eq(&self, other: &Self) -> bool {

library/alloc/src/collections/vec_deque/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,7 @@ fn test_clone_from() {
10851085
fn test_vec_deque_truncate_drop() {
10861086
static mut DROPS: u32 = 0;
10871087
#[derive(Clone)]
1088-
struct Elem(i32);
1088+
struct Elem(#[allow(dead_code)] i32);
10891089
impl Drop for Elem {
10901090
fn drop(&mut self) {
10911091
unsafe {

library/alloc/tests/autotraits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
fn require_sync<T: Sync>(_: T) {}
22
fn require_send_sync<T: Send + Sync>(_: T) {}
33

4-
struct NotSend(*const ());
4+
struct NotSend(#[allow(dead_code)] *const ());
55
unsafe impl Sync for NotSend {}
66

77
#[test]

library/alloc/tests/vec.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ fn test_cmp() {
549549
#[test]
550550
fn test_vec_truncate_drop() {
551551
static mut DROPS: u32 = 0;
552-
struct Elem(i32);
552+
struct Elem(#[allow(dead_code)] i32);
553553
impl Drop for Elem {
554554
fn drop(&mut self) {
555555
unsafe {
@@ -1091,7 +1091,7 @@ fn test_into_iter_advance_by() {
10911091

10921092
#[test]
10931093
fn test_into_iter_drop_allocator() {
1094-
struct ReferenceCountedAllocator<'a>(DropCounter<'a>);
1094+
struct ReferenceCountedAllocator<'a>(#[allow(dead_code)] DropCounter<'a>);
10951095

10961096
unsafe impl Allocator for ReferenceCountedAllocator<'_> {
10971097
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, core::alloc::AllocError> {
@@ -2401,7 +2401,7 @@ fn test_vec_dedup_multiple_ident() {
24012401
#[test]
24022402
fn test_vec_dedup_partialeq() {
24032403
#[derive(Debug)]
2404-
struct Foo(i32, i32);
2404+
struct Foo(i32, #[allow(dead_code)] i32);
24052405

24062406
impl PartialEq for Foo {
24072407
fn eq(&self, other: &Foo) -> bool {

library/core/benches/slice.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ fn binary_search_l3_worst_case(b: &mut Bencher) {
9191
}
9292

9393
#[derive(Clone)]
94-
struct Rgb(u8, u8, u8);
94+
struct Rgb(#[allow(dead_code)] u8, #[allow(dead_code)] u8, #[allow(dead_code)] u8);
9595

9696
impl Rgb {
9797
fn gen(i: usize) -> Self {
@@ -154,7 +154,7 @@ swap_with_slice!(swap_with_slice_5x_usize_3000, 3000, |i| [i; 5]);
154154
#[bench]
155155
fn fill_byte_sized(b: &mut Bencher) {
156156
#[derive(Copy, Clone)]
157-
struct NewType(u8);
157+
struct NewType(#[allow(dead_code)] u8);
158158

159159
let mut ary = [NewType(0); 1024];
160160

library/core/tests/any.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ fn any_unsized() {
122122
fn distinct_type_names() {
123123
// https://github.com/rust-lang/rust/issues/84666
124124

125-
struct Velocity(f32, f32);
125+
struct Velocity(#[allow(dead_code)] f32, #[allow(dead_code)] f32);
126126

127127
fn type_name_of_val<T>(_: T) -> &'static str {
128128
type_name::<T>()

0 commit comments

Comments
 (0)