borrow_deref_ref
suggestion breaks code
#11346
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
When there is a method (not a freestanding function) that takes
self: &mut &Self
(or simply&mut self
whenSelf
is&T
) and such a method is called on an immutable variable of the&Self
type, a reborrow is required so that a mutable reference to the copy of the original reference is taken.The problem is that clippy flags such a reborrow as needless, when in reality, when removed, it causes a compilation error because it is not possible to take a mutable reference to an immutable variable.
Lint Name
borrow_deref_ref
Reproducer
This is the most minimal example I managed to write that reproduces the problem:
Note that if we remove the need to use the dot operator, the lint doesn't show up:
Additional Labels
@rustbot label +I-suggestion-causes-error
The text was updated successfully, but these errors were encountered: