add asm_cfg: #[cfg(...)] within asm! by folkertdev · Pull Request #140367 · rust-lang/rust (original) (raw)

I'm still struggling with getting this to work. I think this should work, but it expands to an Expr::Block, which is not a string, and hence rejected.

#[unsafe(naked)] extern "C" fn with_cfg_match() -> u64 { core::arch::naked_asm!( cfg_match!{{ unix => {"mov rax, 5"} _ => {"mov rax, 10"} }}, "ret", ) }

using this instead

        cfg_match!{{
            unix => "mov rax, 5",
            _ => "mov rax, 10",
        }},

does not parse,

error: expected identifier, found reserved identifier `_`
  --> src/main.rs:10:9
   |
10 | /         cfg_match!{{
11 | |             unix => "mov rax, 5",
12 | |             _ => "mov rax, 10",
13 | |         }},
   | |__________^ expected identifier, found reserved identifier

So, am I still using this macro wrong?