Skip to content

Commit 9bbbf60

Browse files
committedAug 5, 2022
Auto merge of rust-lang#95977 - FabianWolff:issue-92790-dead-tuple, r=estebank
Warn about dead tuple struct fields Continuation of rust-lang#92972. Fixes rust-lang#92790. The language team has already commented on this in rust-lang#92972 (comment); I have incorporated their requests here. Specifically, there is now a new allow-by-default `unused_tuple_struct_fields` lint (name bikesheddable), and fields of unit type are ignored (rust-lang#92972 (comment)), so error messages look like this: ``` error: field is never read: `1` --> $DIR/tuple-struct-field.rs:6:21 | LL | struct Wrapper(i32, [u8; LEN], String); | ^^^^^^^^^ | help: change the field to unit type to suppress this warning while preserving the field numbering | LL | struct Wrapper(i32, (), String); | ~~ ``` r? `@joshtriplett`
2 parents cdfd675 + e3c7e04 commit 9bbbf60

File tree

168 files changed

+451
-246
lines changed

Some content is hidden

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

168 files changed

+451
-246
lines changed
 

‎compiler/rustc_apfloat/src/ppc.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub type DoubleDouble = DoubleFloat<ieee::Double>;
3030
// FIXME: Implement all operations in DoubleDouble, and delete these
3131
// semantics.
3232
// FIXME(eddyb) This shouldn't need to be `pub`, it's only used in bounds.
33-
pub struct FallbackS<F>(F);
33+
pub struct FallbackS<F>(#[allow(unused)] F);
3434
type Fallback<F> = ieee::IeeeFloat<FallbackS<F>>;
3535
impl<F: Float> ieee::Semantics for FallbackS<F> {
3636
// Forbid any conversion to/from bits.
@@ -45,7 +45,7 @@ impl<F: Float> ieee::Semantics for FallbackS<F> {
4545
// truncate the mantissa. The result of that second conversion
4646
// may be inexact, but should never underflow.
4747
// FIXME(eddyb) This shouldn't need to be `pub`, it's only used in bounds.
48-
pub struct FallbackExtendedS<F>(F);
48+
pub struct FallbackExtendedS<F>(#[allow(unused)] F);
4949
type FallbackExtended<F> = ieee::IeeeFloat<FallbackExtendedS<F>>;
5050
impl<F: Float> ieee::Semantics for FallbackExtendedS<F> {
5151
// Forbid any conversion to/from bits.

‎compiler/rustc_lint_defs/src/builtin.rs‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,32 @@ declare_lint! {
630630
"detects attributes that were not used by the compiler"
631631
}
632632

633+
declare_lint! {
634+
/// The `unused_tuple_struct_fields` lint detects fields of tuple structs
635+
/// that are never read.
636+
///
637+
/// ### Example
638+
///
639+
/// ```
640+
/// #[warn(unused_tuple_struct_fields)]
641+
/// struct S(i32, i32, i32);
642+
/// let s = S(1, 2, 3);
643+
/// let _ = (s.0, s.2);
644+
/// ```
645+
///
646+
/// {{produces}}
647+
///
648+
/// ### Explanation
649+
///
650+
/// Tuple struct fields that are never read anywhere may indicate a
651+
/// mistake or unfinished code. To silence this warning, consider
652+
/// removing the unused field(s) or, to preserve the numbering of the
653+
/// remaining fields, change the unused field(s) to have unit type.
654+
pub UNUSED_TUPLE_STRUCT_FIELDS,
655+
Allow,
656+
"detects tuple struct fields that are never read"
657+
}
658+
633659
declare_lint! {
634660
/// The `unreachable_code` lint detects unreachable code paths.
635661
///
@@ -3281,6 +3307,7 @@ declare_lint_pass! {
32813307
UNSUPPORTED_CALLING_CONVENTIONS,
32823308
BREAK_WITH_LABEL_AND_LOOP,
32833309
UNUSED_ATTRIBUTES,
3310+
UNUSED_TUPLE_STRUCT_FIELDS,
32843311
NON_EXHAUSTIVE_OMITTED_PATTERNS,
32853312
TEXT_DIRECTION_CODEPOINT_IN_COMMENT,
32863313
DEREF_INTO_DYN_SUPERTRAIT,

0 commit comments

Comments
 (0)