rust-lang / rust-lang/rust

Call to fn with target_feature that's enabled program-wide cites a very generic error code

Open
#158,241 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics I-lang-nominated P-lang-drag-1 T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
// https://rust.godbolt.org/z/evxnYch3z

// When building for x86_64:

pub fn movemask(a: core::arch::x86_64::__m128i) -> i32 {
    core::arch::x86_64::_mm_movemask_epi8(a)
}
Current output
error[E0133]: call to function `_mm_movemask_epi8` with `#[target_feature]` is unsafe and requires unsafe block
 --> <source>:3:5
  |
3 |     core::arch::x86_64::_mm_movemask_epi8(a)
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call to function with `#[target_feature]`
  |
  = help: in order for the call to be safe, the context requires the following additional target feature: sse2
  = note: the sse2 target feature being enabled in the build configuration does not remove the requirement to list it in `#[target_feature]`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0133`.
Desired output
A different error number that would provide a design justification for why a target feature being enable in the build configuration does not remove the requirement to list it in `#[target_feature]`.
Rationale and extra context

E0133 is a very generic "Unsafe code was used outside of an unsafe block." explanation.

Considering how disappointing it is that even after Rust 1.87, unsafe can't be elided for architecture-specific intrinsics that are available in the target (notably sse2 when targeting x86 or x86_64 and neon when targeting aarch64), expected a different error number that would provide a design justification for why a target feature being enable in the build configuration does not remove the requirement to list it in #[target_feature].

Other cases

Rust Version
rustc 1.98.0-nightly (91fe22da8 2026-06-21)

(Don't know how to get something more precise from Compiler Explorer.)
Anything else?

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the x86_64 example and reading the existing E0133 diagnostic, including its target_feature help and note. Trace how this call is classified and how the diagnostic is selected; done means the case receives a distinct error code or explanation that justifies requiring #[target_feature] even when the feature is enabled in the build configuration.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.