Skip to content

sym operands can not refer to generic parameters in recent nighty #96330

Closed
@yvt

Description

@yvt

I tried this code:

#![feature(asm_sym)]
#![feature(generic_const_exprs)]

trait Call {
    extern "C" fn call();
}

impl Call for () {
    extern "C" fn call() {}
}

fn call_in_asm<T: Call>() {
    unsafe {
        core::arch::asm!("call {}", sym T::call, clobber_abi("C"));
    }
}

fn main() {
    call_in_asm::<()>();
}

(Playground)

I expected to see this happen: Successful compilation or compilation failure with an adequate error message

Instead, this happened: Compilation error, sym operand marked with error: unconstrained generic constant

error: unconstrained generic constant
  --> src/main.rs:16:37
   |
16 |         core::arch::asm!("call {}", sym T::call, clobber_abi("C"));
   |                                     ^^^^^^^^^^^
   |
   = help: try adding a `where` bound using this expression: `where [(); sym T::call]:`

Meta

rustc --version --verbose:

rustc 1.62.0-nightly (de1bc0008 2022-04-21)
binary: rustc
commit-hash: de1bc0008be096cf7ed67b93402250d3b3e480d0
commit-date: 2022-04-21
host: aarch64-apple-darwin
release: 1.62.0-nightly
LLVM version: 14.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-inline-assemblyArea: Inline assembly (`asm!(…)`)C-bugCategory: This is a bug.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions