summaryrefslogtreecommitdiffstats
path: root/tests/mir-opt/simple_option_map_e2e.rs
blob: 2acd2a227b81f4efd58f76a42842093a8e045bd6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#[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,
    }
}

// EMIT_MIR simple_option_map_e2e.ezmap.PreCodegen.after.mir
pub fn ezmap(x: Option<i32>) -> Option<i32> {
    map(x, |n| n + 1)
}

fn main() {
    assert_eq!(None, ezmap(None));
}