dead_code false positive introduced in rustc 1.78.0-nightly (8ace7ea1f 2024-02-07) #120770
Description
opened on Feb 8, 2024
#![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