Skip to content

Type inference for closure gets confused without trivial help #27828

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

Closed
frankmcsherry opened this issue Aug 14, 2015 · 3 comments
Closed

Type inference for closure gets confused without trivial help #27828

frankmcsherry opened this issue Aug 14, 2015 · 3 comments
Labels
A-closures Area: Closures (`|…| { … }`) A-type-system Area: Type system

Comments

@frankmcsherry
Copy link
Contributor

The following falls over at the moment, but works with the commented version of the closure:

fn main() {
    let f = |&x| x as u64;         // <-- doesn't work
    // let f = |&x: &_| x as u64;  // <-- does work
    test_me0(&f);
    test_me1(&f);
}

fn test_me0<F: Fn(&u32) -> u64>(func: &F) -> u64 { func(&0) }
fn test_me1<F: Fn(&u32) -> u64>(func: &F) -> u64 { func(&1) }

@eddyb's thinking is that a &x pattern may not result in a &T type hint, same for &mut x. His thinking was that way back when &x would also match &mut which is no longer possible, but attempts to get playbot to verify this for us in public did not go as planned.

In any case, it was there determined that &x: _ and &x: &_ should be identical, and that this is not expected. :)

@frankmcsherry frankmcsherry changed the title Type inference for closure get confused without trivial help Type inference for closure gets confused without trivial help Aug 14, 2015
@steveklabnik steveklabnik added A-closures Area: Closures (`|…| { … }`) A-type-system Area: Type system labels Aug 17, 2015
@steveklabnik
Copy link
Member

#27828 is basically the same issue, and has a bunch more examples, so I'm going to close this one. I've left a note over there that this example matters too, thanks!

@frankmcsherry
Copy link
Contributor Author

You've referenced this issue, not another one. Meant #12679 maybe?

@steveklabnik
Copy link
Member

Yes, sorry :( copy-paste error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-closures Area: Closures (`|…| { … }`) A-type-system Area: Type system
Projects
None yet
Development

No branches or pull requests

2 participants