-
Notifications
You must be signed in to change notification settings - Fork 1.7k
unnecessary_to_owned
doesn't take type changes into account
#9351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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
Comments
This comment was marked as off-topic.
This comment was marked as off-topic.
@rustbot claim |
bors
added a commit
that referenced
this issue
Sep 4, 2022
Fix `unnecessary_to_owned` false positive Fixes #9351. Note that this commit reworks that fix for #9317. The change is to check that the type implements `AsRef<str>` before regarding `to_string` as an equivalent of `to_owned`. This was suggested by Jarcho in the #9317 issue comments. The benefit of this is that it moves some complexity out of `check_other_call_arg` and simplifies the module as a whole. changelog: FP: [`unnecessary_to_owned`]: No longer lints, if type change would cause errors in the caller function
kraktus
pushed a commit
to kraktus/rust-clippy
that referenced
this issue
Sep 5, 2022
Fixes rust-lang#9351. Note that this commit reworks that fix for rust-lang#9317. The change is to check that the type implements `AsRef<str>` before regarding `to_string` as an equivalent of `to_owned`. This was suggested by Jarcho in the rust-lang#9317 issue comments. The benefit of this is that it moves some complexity out of `check_other_call_arg` and simplifies the module as a whole.
kartva
pushed a commit
to kartva/rust-clippy
that referenced
this issue
Sep 6, 2022
Fixes rust-lang#9351. Note that this commit reworks that fix for rust-lang#9317. The change is to check that the type implements `AsRef<str>` before regarding `to_string` as an equivalent of `to_owned`. This was suggested by Jarcho in the rust-lang#9317 issue comments. The benefit of this is that it moves some complexity out of `check_other_call_arg` and simplifies the module as a whole.
kartva
pushed a commit
to kartva/rust-clippy
that referenced
this issue
Sep 7, 2022
Fixes rust-lang#9351. Note that this commit reworks that fix for rust-lang#9317. The change is to check that the type implements `AsRef<str>` before regarding `to_string` as an equivalent of `to_owned`. This was suggested by Jarcho in the rust-lang#9317 issue comments. The benefit of this is that it moves some complexity out of `check_other_call_arg` and simplifies the module as a whole.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Uh oh!
There was an error while loading. Please reload this page.
Summary
unnecessary_to_owned
suggests changing the type of an input but doesn't check if this type is used in other places. This can lead to suggestions that won't compile due to mismatched type errors.Lint Name
unnecessary_to_owned
Reproducer
I tried this code:
I saw this happen:
Applying the suggestion results in this error
Playground
I expected to see this happen:
No warning.
Version
Additional Labels
@rustbot +label I-suggestion-causes-error
The text was updated successfully, but these errors were encountered: