about summary refs log tree commit diff
path: root/tests/ui/asm/naked-asm-mono-sym-fn.rs
blob: 948c290c0b4fb41163c4f22b1f17254f0b6c9ba3 (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
// Regression test for <https://github.com/rust-lang/rust/issues/140373>.
// Test that we're properly monomorphizing sym args in naked asm blocks
// that point to associated items.

//@ edition: 2021
//@ needs-asm-support
//@ only-x86_64
//@ build-pass

trait Tr {
    extern "C" fn t();
}

enum E<const C: usize> {}

impl<const C: usize> Tr for E<C> {
    extern "C" fn t() {
        println!("Const generic: {}", C);
    }
}

#[unsafe(naked)]
extern "C" fn foo<U: Tr>() {
    core::arch::naked_asm!(
        "push rax",
        "call {fn}",
        "pop rax",
        "ret",
        fn = sym <U as Tr>::t,
    );
}

fn main() {
    foo::<E<42>>();
}