False `error: unknown x86 target feature: avx2` when passed to `is_x86_feature_detected!` as a `literal` instead of `tt`.
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
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");
"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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the minimal macro example from the issue, comparing the $feature:literal and $feature:tt forms in the linked Playground. Read the is_x86_feature_detected! macro expansion and verify that the documented x86 feature such as avx2 produces an accurate result or diagnostic when passed through the wrapper macro.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100