-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Generic Type can't inference properly #119469
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
Comments
The library num-traits-0.2.17 only impl #[cfg(not(has_int_to_from_bytes))]
impl FromBytes for i32 {
type Bytes = [u8; 4];
#[inline]
fn from_be_bytes(bytes: &Self::Bytes) -> Self {
Self::from_be(<Self as FromBytes>::from_ne_bytes(bytes))
}
#[inline]
fn from_le_bytes(bytes: &Self::Bytes) -> Self {
Self::from_le(<Self as FromBytes>::from_ne_bytes(bytes))
}
#[inline]
fn from_ne_bytes(bytes: &Self::Bytes) -> Self {
unsafe { transmute(*bytes) }
}
} So Rust should be able to know the const Generic types |
Could you format your code using triple ticks? It helps reading your code a lot easier. Like this:
For more details see https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax That said |
So based on my observation, when I simply use
It looks like Rust knows But for the function I think when Rust fails to infer a generics, all generics that follow will fail, and that shouldn't happen. |
The problem with this attempt is that you can't specify just one single generic argument, you need to specify all of them. This doesn't mean the compiler can't infer the other ones given the first, just that the language requires you to specify all of them. Think for example if you instead wanted to specify what is Having to specify all the generic arguments doesn't mean you can't have the compiler infer some of them. You can in fact just use the inferred type |
Ok, that makes sense now, I though that Rust takes the generic argument based on the based on the generic arguments order in the function signature. Thank you! |
After try with
|
Example Code:
Error message:
|
Closing as works as intended / duplicate of the closed issue #41718 and the RFCs rust-lang/rfcs#1196 and rust-lang/rfcs#2176. If you disagree with my assessment I can of course reopen this issue. |
for example:
Rust can do type inference for save_compressed correctly without any generic type hinting. But for load_compressed_slice, we have to pass all Generic type.
The text was updated successfully, but these errors were encountered: