-
-
Notifications
You must be signed in to change notification settings - Fork 15.4k
False positive dead code warning #102190
Copy link
Copy link
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.A-proc-macrosArea: Procedural macrosArea: Procedural macrosC-bugCategory: This is a bug.Category: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.L-dead_codeLint: dead_codeLint: dead_codeT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.A-proc-macrosArea: Procedural macrosArea: Procedural macrosC-bugCategory: This is a bug.Category: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.L-dead_codeLint: dead_codeLint: dead_codeT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
When code is generated via a proc macro there is a case which creates a false positive for the dead code warning.
Proc macro (src/lib.rs):
Test (tests/all.rs):
The current output is:
The generated code for all four functions are identical (except the name, obviusly), tested with
cargo expand.One is reported as dead code, though no report should be given since
#[allow(dead_code)]is used.On 1.63.0 this is not a warning, but with 1.65.0-beta.1 it is.
I'm aware that this is a very special case and I don't mind if it doesn't get fixed but I thought I'll report it anyway.
For a quick copy-and-paste run here the Cargo.toml:
(I don't know how to setup play.rust-lang.org to create a proc-macro and a real test, thats why it's missing.)