Skip to content

False error: unknown x86 target feature: avx2 when passed to is_x86_feature_detected! as a literal instead of tt. #128586

Open
@vcfxb

Description

@vcfxb

Minimal reproduction:

macro_rules! x86_feature_detect {
    ($name:ident -> $feature:literal) => {
        #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
        thread_local! {
            pub static $name: core::cell::LazyCell<bool> = core::cell::LazyCell::new(|| is_x86_feature_detected!($feature));
        }

    };
}

x86_feature_detect!(SUPPORTS_AVX -> "avx2");

playground permalink

"avx2" is a feature for x86 documented at https://doc.rust-lang.org/std/macro.is_x86_feature_detected.html

The error:

   Compiling playground v0.0.1 (/playground)
error: unknown x86 target feature: avx2
  --> src/lib.rs:11:1
   |
11 | x86_feature_detect!(SUPPORTS_AVX -> "avx2");
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in the macro `is_x86_feature_detected` which comes from the expansion of the macro `x86_feature_detect` (in Nightly builds, run with -Z macro-backtrace for more info)

error: could not compile `playground` (lib) due to 1 previous error

This error is unclear -- and hard to reason about/diagnose since it comes from within a macro.

Based on the docs at https://doc.rust-lang.org/std/macro.is_x86_feature_detected.html,
I changed the type from literal to tt and it compiled as expected ("fixed" playground permalink).

This behavior appears consistent on stable and nightly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-target-featureArea: Enabling/disabling target features like AVX, Neon, etc.C-bugCategory: This is a bug.O-x86_64Target: x86-64 processors (like x86_64-*) (also known as amd64 and x64)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions