Skip to content

Generic Type can't inference properly #119469

@Jianqoq

Description

@Jianqoq

for example:

pub fn save_compressed<'a,T: CommonBounds + ToBytes<Bytes = [u8; N]>,const N: usize, const M: usize>(file_name: &'a str, tensors: [(&'a str, T); M])

pub fn load_compressed<T: CommonBounds + FromBytes<Bytes = [u8; N]>,const N: usize,const M: usize>(file_name: String, queries: [(&str, &[Slice]); M])

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.

let a: i32 = 1;

save_compressed("file", [
    ("a", a.clone()),
    ("b", a.clone()),
]);

let _ = load_compressed::<i32>("file".to_string(), [
    ("b", &[Slice::Full(..)]),
])?;
12  |     let _ = load_compressed::<i32>("file".to_string(), [
    |             ^^^^^^^^^^^^^^^^^^^^^   --- supplied 1 generic argument
    |             |
    |             expected 3 generic arguments

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-inferenceArea: Type inferenceC-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions