-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
op_ref false positive with deref coercions when comparing #2597
Comments
Clippy on playpen is down. If memory serves right, isn't it also suggesting to deref the other side? |
The error message reported by clippy is:
|
We need to suggest a deref on the lhs here, too. |
From the playpen link, he is actually comparing
|
Dereferencing both sides works. We can probably figure this out by checking for autoref coercions |
I didn't know that was possible but what benefit does |
The advantage is one less temporary variable (the comparison operator internally takes a reference to its arguments). |
I just ran into this with https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=890234c7ce6d7ccde1d036ae41d782d4
|
I think I ran into this too pub fn example_problematic_lint(value: &String, rhs: &str) -> bool {
&**value < rhs
}
fn main() {
dbg!(example_problematic_lint(&"Hello".to_string(), "Worl"));
} Clippy output
|
This is probably fixed by #4878, but needs more tests, e.g. #2597 (comment). An improvement of this lint would still be to suggest a deref on both sides, when possible. |
Rustup Included rustups: - rust-lang/rust#66935 (syntax: Unify macro and attribute arguments in AST) - rust-lang/rust#66941 (Remove `ord` lang item) Fixes? #2597 changelog: none
I just ran into this with a newtype I defined:
Granted, I'll implement |
Perhaps related to #2042, but it seemed different enough to open a new issue.
With the following code: https://play.rust-lang.org/?gist=35d367db95cd56394d0bb9a05247b94c&version=nightly
Clippy complains that the reference should be removed, but removing the reference causes the code to stop compiling.
The text was updated successfully, but these errors were encountered: