Skip to content
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

Type inference fails in unpredictable ways #33449

Closed
notriddle opened this issue May 6, 2016 · 4 comments
Closed

Type inference fails in unpredictable ways #33449

notriddle opened this issue May 6, 2016 · 4 comments
Labels
A-inference Area: Type inference C-bug Category: This is a bug.

Comments

@notriddle
Copy link
Contributor

This works

#![allow(unused)]

fn f<F>() -> Result<Option<F>, ()> {
    panic!()
}

fn g<G>() -> Option<G> {
    f().unwrap().unwrap()
}

This does not:

#![allow(unused)]

fn f<F>() -> Result<Option<F>, ()> {
    panic!()
}

fn g<G>() -> Option<G> where Option<G>: Sized { // <--
    f().unwrap().unwrap()
}
@jonas-schievink
Copy link
Contributor

Might be related to #24066 (explained in more detail in this comment)

@dtolnay
Copy link
Member

dtolnay commented May 7, 2016

Thanks for filing this! Came up in serde-rs/serde#305.

@arielb1
Copy link
Contributor

arielb1 commented May 7, 2016

workaround: explicitly specify type parameters rather than leaving them to inference:

#![allow(unused)]

fn f<F>() -> Result<Option<F>, ()> {
    panic!()
}

fn g<G>() -> Option<G> where Option<G>: Sized {
    f::<Option<G>>().unwrap().unwrap()
}

fn main() {}

@Mark-Simulacrum Mark-Simulacrum added the A-inference Area: Type inference label Jun 23, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 25, 2017
@bstrie
Copy link
Contributor

bstrie commented Feb 21, 2020

Triage: the given code works when tested on Rust 1.41. Closing.

@bstrie bstrie closed this as completed Feb 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inference Area: Type inference C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

6 participants