Created
January 10, 2020 08:49
-
-
Save Aaron1011/575aac86c92fba2ec6ede6c638119743 to your computer and use it in GitHub Desktop.
Never-type fallback bug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(never_type)] | |
//#![feature(never_type_fallback)] | |
fn get_type<T>(_: T) -> &'static str { | |
std::any::type_name::<T>() | |
} | |
fn unconstrained_return<T>() -> Result<T, String> { | |
Err("Hi".to_string()) | |
} | |
fn foo() { | |
let a = || { | |
match unconstrained_return::<_>() { | |
Ok(x) => x, // `x` has type `_`, which is unconstrained | |
Err(s) => panic!(s), // … except for unifying with the type of `panic!()` | |
// so that both `match` arms have the same type. | |
// Therefore `_` resolves to `!` and we "return" an `Ok(!)` value. | |
} | |
}; | |
let cast: &dyn FnOnce() -> _ = &a; | |
println!("Return type: {:?}", get_type(cast)); | |
} | |
fn main() { | |
foo() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment