Inconsistent handling of to_string() removal suggestion between field and method access #13726
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
I have 2 values to pass to a function. The first is borrowed (indirectly) from a field in the second, and the function needs a mutable reference of the second. So I am making a copy (
to_string()
) of the first, to avoid the conflicting borrows. But clippy suggests removingto_string()
, which would result in a compiler error.However, this suggestion only happens if the field is borrowed via a method. If done directly with the field instead of an accessor method, clippy does not make the (invalid) suggestion.
Lint Name
unnecessary_to_owned
Reproducer
Here is a complete example:
The first call to
use_it
(using the field directly) does NOT result in a warning. But the second call results in:And the third call to
use_it
with the suggested change (commented out) would result in a compiler error because of the conflicting borrows.Version
Additional Labels
@rustbot label +I-suggestion-causes-error
The text was updated successfully, but these errors were encountered: