Don't emit "value assigned to ... is never read" for each instance? #67548
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
D-verbose
Diagnostics: Too much output caused by a single piece of incorrect code.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Scrolling through warnings when compiling projects during the early development stages can be a bit of a chore, but there's not much the compiler can do about it as it doesn't know whether you just haven't gotten around to something or if you forgot about it. I typically add
#![allow(unused_code)]
and#![allow(dead_code)]
to new projects and take them out when the codebase nears completion of v1, but it occurs to me that there's no real value in emitting repeated warnings for unused assignments of the same variable.e.g.
There are different heuristics here depending on how important it is to generate all warnings in advance, including
This means code like
continues to emit two warnings as they are two different variables being unread, but this wouldn't emit two warnings:
as we are deduplicating by variable and not by unread write so only the first assignment will generate the warning, which is probably ok since addressing that error by adding either of
or
will go back to generating the warning for the other instance of unused write.
The above would continue to generate two warnings, but the following would generate only one:
as no value was overwritten at any point and a single read would suffice to address both instances of unused writes.
Personally, I think the latter is overkill and might slow things down and increase memory usage in the compiler without much benefit. The former is both fast and easy (with no allocations and predetermined memory consumption based off the size of the bloom filter).
The text was updated successfully, but these errors were encountered: