Skip to content

Let pattern matching on tuple structs broken for double generic functions.  #11508

Closed
@nightpool

Description

@nightpool

The demo code from Closed01 doesn't compile.

use std::rand::{Closed01, random};

fn main() {
    let Closed01(val) = random::<Closed01<f32>>();
    println!("{} is a random number between 0 and 1!", val);
}

The compiler gives an error message of

error: mismatched types: expected `std::rand::Closed01<f32>` but found 
`std::rand::Closed01<BUG[0u]>` (expected f32 but found type parameter)

@huonw found a workaround by wrapping it in a function:
rust fn extract<T>(Closed01(x): Closed01<T>) -> T { x }

I'm not sure what exactly is going on here, but I'm guessing it has something to do with the double generic function <Closed01> and let pattern matching for tuple structs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions