-
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 #2042
Comments
That is so weird. I think this is rather a rustc bug... I'll investigate |
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 If you add a reference, instead yoou get u16: Add<&'a $0>
u8: Into<$0> And on the first bound, only the |
For reference, error[E0283]: type annotations needed
--> /tmp/t.rs:5:25
|
5 | let x = word + byte.into();
| - ^^^^
| |
| type must be known at this point
|
= note: multiple `impl`s satisfying `u16: std::ops::Add<_>` found in the `core` crate:
- impl std::ops::Add for u16;
- impl std::ops::Add<&u16> for u16;
help: try using a fully qualified path to specify the expected types
|
5 | let x = word + <u8 as std::convert::Into<T>>::into(byte);
| ++++++++++++++++++++++++++++++++++++ ~ |
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.
The text was updated successfully, but these errors were encountered: