FP: used_underscore_items
lints on debatably legitimate use-cases
#13478
Labels
C-bug
Category: Clippy is not doing the correct thing
I-false-positive
Issue: The lint was triggered on code it shouldn't have
Summary
I feel the new
used_underscore_items
lint is not universally applicable and would best live inrestriction
rather thanpedantic
, as there are sometimes legitimate use-cases for prefixing item names with a_
.Lint Name
used_underscore_items
Reproducer
As motivation, I'll give two examples where prefixing method names with
_
makes sense:First, as a way to reduce the impact of monomorphization on binary size for functions that have large bodies:
Second, as a way to introduce non-breaking changes when adding a new argument to a function. If we have the following initial code:
...and we want to add support for a second parameter without making breaking changes, we could transform it in the following way:
In both cases I feel that naming the private method with a prefixed underscore is a valid choice to make, in order to preserve the name and to not conflict with the public wrapper method. Granted, maybe this still means it should be a
pedantic
lint, but either way I feel these two cases qualify as false positives.Version
rustc 1.83.0-nightly (ed04567ba 2024-09-28)
binary: rustc
commit-hash: ed04567ba1d5956d1080fb8121caa005ce059e12
commit-date: 2024-09-28
host: x86_64-unknown-linux-gnu
release: 1.83.0-nightly
LLVM version: 19.1.0
Additional Labels
No response
The text was updated successfully, but these errors were encountered: