Skip to content

Type inference failure (partial hints?) #15960

@Earnestly

Description

@Earnestly

A small issue with hints and type inference, I don't fully grok what's going on so here is some code to better explain what I'm seeing:

fn main() {
    let f: int = std::rand::random() % 100i;
    // Or
    // let f: int = (std::rand::random() % 100i) * 20i;
}    
inf.rs:2:18: 2:37 error: the type of this value must be known in this context
inf.rs:2     let f: int = std::rand::random() % 100i;
                          ^~~~~~~~~~~~~~~~~~~
error: aborting due to previous error

However with:

fn main() {
    let f: int = 100i % std::rand::random(); // works but obviously incorrect
}    

rand::random<int>() is successfully deduced.

Why might this be the case?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions