Skip to content

dead_code false positive introduced in rustc 1.78.0-nightly (8ace7ea1f 2024-02-07)  #120770

@tamird

Description

#![deny(warnings)]

#[repr(u8)]
#[derive(Copy, Clone, Debug)]
pub enum RecordField {
    Target = 1,
    Level,
    Module,
    File,
    Line,
    NumArgs,
}

unsafe trait Pod {}

#[repr(transparent)]
struct RecordFieldWrapper(RecordField);

unsafe impl Pod for RecordFieldWrapper {}

fn try_read<T: Pod>(buf: &[u8]) -> T {
    unsafe { std::ptr::read_unaligned(buf.as_ptr() as *const T) }
}

pub fn foo(buf: &[u8]) -> RecordField {
    let RecordFieldWrapper(tag) = try_read(buf);
    tag
}

This code compiles on stable (and nightlies before 2024-02-07) but now produces:

error: struct `RecordFieldWrapper` is never constructed
  --> aya-log/src/lib.rs:79:8
   |
79 | struct RecordFieldWrapper(RecordField);
   |        ^^^^^^^^^^^^^^^^^^
   |
   = note: `RecordFieldWrapper` has a derived impl for the trait `Clone`, but this is intentionally ignored during dead code analysis
   = note: `-D dead-code` implied by `-D warnings`
   = help: to override `-D warnings` add `#[allow(dead_code)]`

NOTE: playground's nightly is not new enough
playground

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.C-discussionCategory: Discussion or questions that doesn't represent real issues.L-dead_codeLint: dead_codeP-lowLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions