Skip to content
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

cmp_owned provides a confusing suggestion #8103

Open
Volker-Weissmann opened this issue Dec 9, 2021 · 1 comment · May be fixed by #14247
Open

cmp_owned provides a confusing suggestion #8103

Volker-Weissmann opened this issue Dec 9, 2021 · 1 comment · May be fixed by #14247
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages

Comments

@Volker-Weissmann
Copy link

Volker-Weissmann commented Dec 9, 2021

Description

Example:

let my_string = String::from("hello");
let eq = my_string == "hello".to_owned();

Why does clippy suggest changing "hello".to_owned() into *"hello" instead of "hello"?

This created confusion for beginners because dereferencing a string literal isn't something you normally do.

Version

rustc 1.58.0-nightly (4961b107f 2021-11-04)
binary: rustc
commit-hash: 4961b107f204e15b26961eab0685df6be3ab03c6
commit-date: 2021-11-04
host: x86_64-unknown-linux-gnu
release: 1.58.0-nightly
LLVM version: 13.0.0

Additional Labels

@rustbot label +C-enhancement

@rustbot rustbot added the C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages label Dec 9, 2021
@BartMassey
Copy link

In addition, would suggest an addition to the lint description to point out that comparison operators are implicitly by-reference; this is part of the confusion with *"hello" I think.

@giraffate giraffate changed the title Clippy suggests cmp_owned provides a confusing suggestion Dec 10, 2021
@lapla-cogito lapla-cogito linked a pull request Feb 18, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants