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

op_ref false positive #2042

Open
euclio opened this issue Sep 11, 2017 · 2 comments
Open

op_ref false positive #2042

euclio opened this issue Sep 11, 2017 · 2 comments
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

Comments

@euclio
Copy link
Contributor

euclio commented Sep 11, 2017

With the following code: https://play.rust-lang.org/?gist=1aa5789d7082019e91bac7b093304ad5&version=stable

Clippy suggests removing the reference, but without the reference the Rust compiler complains that type annotations are needed.

I would expect the lint to not fire in this case.

@oli-obk
Copy link
Contributor

oli-obk commented Sep 11, 2017

That is so weird. I think this is rather a rustc bug... I'll investigate

@arielb1
Copy link

arielb1 commented Sep 12, 2017

That's a trait-system issue. Operator overloading does succeed in this case. Without the autoref, you get these trait bounds:

u16: Add<$0>
u8: Into<$0>

Because the compiler only considers each trait bound alone, it can't see that the only solution is $0 = u16.

If you add a reference, instead yoou get

u16: Add<&'a $0>
u8: Into<$0>

And on the first bound, only the impl Add<&u16> for u16 impl matches, which allows a solution.

@oli-obk oli-obk added the C-bug Category: Clippy is not doing the correct thing label Apr 2, 2018
@phansch phansch added the I-false-positive Issue: The lint was triggered on code it shouldn't have label Dec 21, 2020
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
Projects
None yet
Development

No branches or pull requests

4 participants