summaryrefslogtreecommitdiffstats
path: root/tests/codegen-units/item-collection/generic-functions.rs
blob: f790cd0dadd7a07d1c899f495430bc37674e453b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// compile-flags:-Zprint-mono-items=eager -Zinline-mir=no

#![deny(dead_code)]
#![feature(start)]

fn foo1<T1>(a: T1) -> (T1, u32) {
    (a, 1)
}

fn foo2<T1, T2>(a: T1, b: T2) -> (T1, T2) {
    (a, b)
}

fn foo3<T1, T2, T3>(a: T1, b: T2, c: T3) -> (T1, T2, T3) {
    (a, b, c)
}

// This function should be instantiated even if no used
//~ MONO_ITEM fn lifetime_only
pub fn lifetime_only<'a>(a: &'a u32) -> &'a u32 {
    a
}

//~ MONO_ITEM fn start
#[start]
fn start(_: isize, _: *const *const u8) -> isize {
    //~ MONO_ITEM fn foo1::<i32>
    let _ = foo1(2i32);
    //~ MONO_ITEM fn foo1::<i64>
    let _ = foo1(2i64);
    //~ MONO_ITEM fn foo1::<&str>
    let _ = foo1("abc");
    //~ MONO_ITEM fn foo1::<char>
    let _ = foo1('v');

    //~ MONO_ITEM fn foo2::<i32, i32>
    let _ = foo2(2i32, 2i32);
    //~ MONO_ITEM fn foo2::<i64, &str>
    let _ = foo2(2i64, "abc");
    //~ MONO_ITEM fn foo2::<&str, usize>
    let _ = foo2("a", 2usize);
    //~ MONO_ITEM fn foo2::<char, ()>
    let _ = foo2('v', ());

    //~ MONO_ITEM fn foo3::<i32, i32, i32>
    let _ = foo3(2i32, 2i32, 2i32);
    //~ MONO_ITEM fn foo3::<i64, &str, char>
    let _ = foo3(2i64, "abc", 'c');
    //~ MONO_ITEM fn foo3::<i16, &str, usize>
    let _ = foo3(0i16, "a", 2usize);
    //~ MONO_ITEM fn foo3::<char, (), ()>
    let _ = foo3('v', (), ());

    0
}