Suggests removed "unused" mut when not actually able to be removed #11199
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
I-suggestion-causes-error
Issue: The suggestions provided by this Lint cause an ICE/error when applied
Summary
Clippy will suggest that
mut
be removed from function references if it is not used, even if the mutability cannot be removed because of function type requirements.Lint Name
clippy::needless_pass_by_ref_mut
Reproducer
The codebase this occurs in is rather complicated, so I reduced it to a simple test case which reproduces the same false positive.
Here we have a fixed object
Action
which expects a specific type for its function pointer. However, while most implementers need for full mutable access, some do not, which then triggers the following Clippy lint:However, this is incorrect, as the
mut
cannot actually be removed, as this will change the function signature, causing a compiler error. That is, if I change line 20 tofn action_bar(ctx: &Context)
, then I get:Because there is a legitimate type incompatibility reason why
mut
cannot be removed here, Clippy should not be recommending its removal.Version
Additional Labels
@rustbot label +I-suggestion-causes-error
The text was updated successfully, but these errors were encountered: