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

+7-29
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

+11-18
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

+1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+3-3
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

+2-2
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

+1-1
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>()

library/core/tests/array.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ fn array_default_impl_avoids_leaks_on_panic() {
263263
use core::sync::atomic::{AtomicUsize, Ordering::Relaxed};
264264
static COUNTER: AtomicUsize = AtomicUsize::new(0);
265265
#[derive(Debug)]
266-
struct Bomb(usize);
266+
struct Bomb(#[allow(dead_code)] usize);
267267

268268
impl Default for Bomb {
269269
fn default() -> Bomb {

library/core/tests/atomic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ fn ptr_bitops() {
188188
#[cfg(any(not(target_arch = "arm"), target_os = "linux"))] // Missing intrinsic in compiler-builtins
189189
fn ptr_bitops_tagging() {
190190
#[repr(align(16))]
191-
struct Tagme(u128);
191+
struct Tagme(#[allow(dead_code)] u128);
192192

193193
let tagme = Tagme(1000);
194194
let ptr = &tagme as *const Tagme as *mut Tagme;

library/core/tests/intrinsics.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use core::intrinsics::assume;
44
#[test]
55
fn test_typeid_sized_types() {
66
struct X;
7-
struct Y(u32);
7+
struct Y(#[allow(dead_code)] u32);
88

99
assert_eq!(TypeId::of::<X>(), TypeId::of::<X>());
1010
assert_eq!(TypeId::of::<Y>(), TypeId::of::<Y>());
@@ -14,8 +14,8 @@ fn test_typeid_sized_types() {
1414
#[test]
1515
fn test_typeid_unsized_types() {
1616
trait Z {}
17-
struct X(str);
18-
struct Y(dyn Z + 'static);
17+
struct X(#[allow(dead_code)] str);
18+
struct Y(#[allow(dead_code)] dyn Z + 'static);
1919

2020
assert_eq!(TypeId::of::<X>(), TypeId::of::<X>());
2121
assert_eq!(TypeId::of::<Y>(), TypeId::of::<Y>());

library/core/tests/ptr.rs

+19-19
Original file line numberDiff line numberDiff line change
@@ -451,34 +451,34 @@ fn align_offset_various_strides() {
451451
for ptr in 1usize..4 * align {
452452
unsafe {
453453
#[repr(packed)]
454-
struct A3(u16, u8);
454+
struct A3(#[allow(dead_code)] u16, #[allow(dead_code)] u8);
455455
x |= test_stride::<A3>(ptr::invalid::<A3>(ptr), align);
456456

457-
struct A4(u32);
457+
struct A4(#[allow(dead_code)] u32);
458458
x |= test_stride::<A4>(ptr::invalid::<A4>(ptr), align);
459459

460460
#[repr(packed)]
461-
struct A5(u32, u8);
461+
struct A5(#[allow(dead_code)] u32, #[allow(dead_code)] u8);
462462
x |= test_stride::<A5>(ptr::invalid::<A5>(ptr), align);
463463

464464
#[repr(packed)]
465-
struct A6(u32, u16);
465+
struct A6(#[allow(dead_code)] u32, #[allow(dead_code)] u16);
466466
x |= test_stride::<A6>(ptr::invalid::<A6>(ptr), align);
467467

468468
#[repr(packed)]
469-
struct A7(u32, u16, u8);
469+
struct A7(#[allow(dead_code)] u32, #[allow(dead_code)] u16, #[allow(dead_code)] u8);
470470
x |= test_stride::<A7>(ptr::invalid::<A7>(ptr), align);
471471

472472
#[repr(packed)]
473-
struct A8(u32, u32);
473+
struct A8(#[allow(dead_code)] u32, #[allow(dead_code)] u32);
474474
x |= test_stride::<A8>(ptr::invalid::<A8>(ptr), align);
475475

476476
#[repr(packed)]
477-
struct A9(u32, u32, u8);
477+
struct A9(#[allow(dead_code)] u32, #[allow(dead_code)] u32, #[allow(dead_code)] u8);
478478
x |= test_stride::<A9>(ptr::invalid::<A9>(ptr), align);
479479

480480
#[repr(packed)]
481-
struct A10(u32, u32, u16);
481+
struct A10(#[allow(dead_code)] u32, #[allow(dead_code)] u32, #[allow(dead_code)] u16);
482482
x |= test_stride::<A10>(ptr::invalid::<A10>(ptr), align);
483483

484484
x |= test_stride::<u32>(ptr::invalid::<u32>(ptr), align);
@@ -517,34 +517,34 @@ fn align_offset_various_strides_const() {
517517
while ptr < 4 * align {
518518
unsafe {
519519
#[repr(packed)]
520-
struct A3(u16, u8);
520+
struct A3(#[allow(dead_code)] u16, #[allow(dead_code)] u8);
521521
test_stride::<A3>(ptr::invalid::<A3>(ptr), ptr, align);
522522

523-
struct A4(u32);
523+
struct A4(#[allow(dead_code)] u32);
524524
test_stride::<A4>(ptr::invalid::<A4>(ptr), ptr, align);
525525

526526
#[repr(packed)]
527-
struct A5(u32, u8);
527+
struct A5(#[allow(dead_code)] u32, #[allow(dead_code)] u8);
528528
test_stride::<A5>(ptr::invalid::<A5>(ptr), ptr, align);
529529

530530
#[repr(packed)]
531-
struct A6(u32, u16);
531+
struct A6(#[allow(dead_code)] u32, #[allow(dead_code)] u16);
532532
test_stride::<A6>(ptr::invalid::<A6>(ptr), ptr, align);
533533

534534
#[repr(packed)]
535-
struct A7(u32, u16, u8);
535+
struct A7(#[allow(dead_code)] u32, #[allow(dead_code)] u16, #[allow(dead_code)] u8);
536536
test_stride::<A7>(ptr::invalid::<A7>(ptr), ptr, align);
537537

538538
#[repr(packed)]
539-
struct A8(u32, u32);
539+
struct A8(#[allow(dead_code)] u32, #[allow(dead_code)] u32);
540540
test_stride::<A8>(ptr::invalid::<A8>(ptr), ptr, align);
541541

542542
#[repr(packed)]
543-
struct A9(u32, u32, u8);
543+
struct A9(#[allow(dead_code)] u32, #[allow(dead_code)] u32, #[allow(dead_code)] u8);
544544
test_stride::<A9>(ptr::invalid::<A9>(ptr), ptr, align);
545545

546546
#[repr(packed)]
547-
struct A10(u32, u32, u16);
547+
struct A10(#[allow(dead_code)] u32, #[allow(dead_code)] u32, #[allow(dead_code)] u16);
548548
test_stride::<A10>(ptr::invalid::<A10>(ptr), ptr, align);
549549

550550
test_stride::<u32>(ptr::invalid::<u32>(ptr), ptr, align);
@@ -672,7 +672,7 @@ fn align_offset_issue_103361() {
672672
const SIZE: usize = 1 << 30;
673673
#[cfg(target_pointer_width = "16")]
674674
const SIZE: usize = 1 << 13;
675-
struct HugeSize([u8; SIZE - 1]);
675+
struct HugeSize(#[allow(dead_code)] [u8; SIZE - 1]);
676676
let _ = ptr::invalid::<HugeSize>(SIZE).align_offset(SIZE);
677677
}
678678

@@ -684,7 +684,7 @@ fn align_offset_issue_103361_const() {
684684
const SIZE: usize = 1 << 30;
685685
#[cfg(target_pointer_width = "16")]
686686
const SIZE: usize = 1 << 13;
687-
struct HugeSize([u8; SIZE - 1]);
687+
struct HugeSize(#[allow(dead_code)] [u8; SIZE - 1]);
688688

689689
const {
690690
assert!(ptr::invalid::<HugeSize>(SIZE - 1).align_offset(SIZE) == SIZE - 1);
@@ -834,7 +834,7 @@ fn ptr_metadata_bounds() {
834834
fn dyn_metadata() {
835835
#[derive(Debug)]
836836
#[repr(align(32))]
837-
struct Something([u8; 47]);
837+
struct Something(#[allow(dead_code)] [u8; 47]);
838838

839839
let value = Something([0; 47]);
840840
let trait_object: &dyn Debug = &value;

library/core/tests/slice.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2110,9 +2110,9 @@ fn test_align_to_zst() {
21102110
#[test]
21112111
fn test_align_to_non_trivial() {
21122112
#[repr(align(8))]
2113-
struct U64(u64, u64);
2113+
struct U64(#[allow(dead_code)] u64, #[allow(dead_code)] u64);
21142114
#[repr(align(8))]
2115-
struct U64U64U32(u64, u64, u32);
2115+
struct U64U64U32(#[allow(dead_code)] u64, #[allow(dead_code)] u64, #[allow(dead_code)] u32);
21162116
let data = [
21172117
U64(1, 2),
21182118
U64(3, 4),
@@ -2197,7 +2197,7 @@ fn test_slice_partition_dedup_multiple_ident() {
21972197
#[test]
21982198
fn test_slice_partition_dedup_partialeq() {
21992199
#[derive(Debug)]
2200-
struct Foo(i32, i32);
2200+
struct Foo(i32, #[allow(dead_code)] i32);
22012201

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

library/std/src/collections/hash/set/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ fn test_replace() {
352352
use crate::hash;
353353

354354
#[derive(Debug)]
355-
struct Foo(&'static str, i32);
355+
struct Foo(&'static str, #[allow(dead_code)] i32);
356356

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

tests/codegen-units/item-collection/generic-drop-glue.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ enum EnumNoDrop<T1, T2> {
3434
}
3535

3636

37-
struct NonGenericNoDrop(#[allow(unused_tuple_struct_fields)] i32);
37+
struct NonGenericNoDrop(#[allow(dead_code)] i32);
3838

39-
struct NonGenericWithDrop(#[allow(unused_tuple_struct_fields)] i32);
39+
struct NonGenericWithDrop(#[allow(dead_code)] i32);
4040
//~ MONO_ITEM fn std::ptr::drop_in_place::<NonGenericWithDrop> - shim(Some(NonGenericWithDrop)) @@ generic_drop_glue-cgu.0[Internal]
4141

4242
impl Drop for NonGenericWithDrop {

0 commit comments

Comments
 (0)