You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I expected to see this happen: This code compiles successfully.
Instead, this happened:
Compiling playground v0.0.1 (/playground)
error[E0277]: the trait bound `u32: std::convert::From<i32>` is not satisfied
--> src/main.rs:24:51
|
24 | let builder = Builder::default().per_page(25).page(25);
| ^^^^ the trait `std::convert::From<i32>` is not implemented for `u32`
|
= help: the following implementations were found:
<u32 as std::convert::From<bool>>
<u32 as std::convert::From<char>>
<u32 as std::convert::From<std::net::Ipv4Addr>>
<u32 as std::convert::From<std::num::NonZeroU32>>
and 2 others
= note: required because of the requirements on the impl of `std::convert::Into<u32>` for `i32`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground`.
To learn more, run the command again with —verbose.
This is because there is only one impl Into<u8> for X that applies when X is an integer type variable, which is the blanket From impl, which then calls the reflective impl<T> From<T> for T impl, so the compiler knows that the type has to be u8.
u32 has impls of From<u16> and From<u8>, in addition to the reflective From<u32> impl, so the compiler doesn't know which integer type to use.
It's different from #39255 since this issue doesn't rely on the i32 fallback, instead running into multiple applicable impls, but I believe both are expected behavior, so closing.
This might be a duplicate of #39255, I'm not sure. But it's not clear why the type is correctly inferred for
u8
but isn't foru32
.I tried this code:
I expected to see this happen: This code compiles successfully.
Instead, this happened:
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: