-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Most dead code warnings don't work inside const _ #101532
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.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.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_codeL-false-negativeLint: False negative (should have fired but didn't).Lint: False negative (should have fired but didn't).L-unused_variablesLint: unused_variablesLint: unused_variablesT-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.
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.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.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_codeL-false-negativeLint: False negative (should have fired but didn't).Lint: False negative (should have fired but didn't).L-unused_variablesLint: unused_variablesLint: unused_variablesT-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.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Given the following code:
The current output is:
Ideally the output should look like:
What's surprising is that adding
pubchanges the output to the expected one, even thoughpubdoesn't make any meaning onconst _: ():It's also interesting that the logic matches what happens with functions. For example, in:
the function
fooitself and also only the variableaare reported as unused, while the rest of the items don't get a warning:However, once
foois made public, all the items get warnings:Either way,
const _should have different treatment due to being anonymous, but it's still a bit surprising that onlyletvariables get inside bothconst _andfn foo.