needless_borrowed_reference for lambdas not immediately typed #11566
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
needless_borrowed_reference triggers when a lambda is passed to construct a struct, where the type-restriction is only enforced for an implementation. When the type-restriction is eager (like directly to a function), it doesn't appear to trigger. The lint is a false positive because when applying the lint's suggestion, the compiler does not backward-infer that the closure should be a tuple-reference rather than a tuple. The lifetime is specific to the struct and return-type, which can't be (easily) expressed in lambda typing, thus adding
: &(_,)
wont work. There are workarounds to properly type the lambda, but are inappropriate fixes.Lint Name
needless_borrowed_reference
Reproducer
I tried this code:
(playground)
I saw this happen:
I expected to see this happen:
Version
Additional Labels
No response
The text was updated successfully, but these errors were encountered: