2023-10-16 12:36:39 -05:00
|
|
|
// skip-filecheck
|
2023-04-23 04:38:37 -05:00
|
|
|
// compile-flags: -O -C debuginfo=0 -Zmir-opt-level=2
|
|
|
|
// only-64bit
|
|
|
|
|
2023-01-02 00:01:29 -06:00
|
|
|
#[inline(always)]
|
|
|
|
fn map<T, U, F>(slf: Option<T>, f: F) -> Option<U>
|
|
|
|
where
|
|
|
|
F: FnOnce(T) -> U,
|
|
|
|
{
|
|
|
|
match slf {
|
|
|
|
Some(x) => Some(f(x)),
|
|
|
|
None => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-23 04:38:37 -05:00
|
|
|
// EMIT_MIR simple_option_map.ezmap.PreCodegen.after.mir
|
2023-01-02 00:01:29 -06:00
|
|
|
pub fn ezmap(x: Option<i32>) -> Option<i32> {
|
|
|
|
map(x, |n| n + 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
assert_eq!(None, ezmap(None));
|
|
|
|
}
|