Skip to main content

Module target_features

Module target_features 

Source
Expand description

Declares Rust’s target feature names for each target. Note that these are similar to but not always identical to LLVM’s feature names, and Rust adds some features that do not correspond to LLVM features at all.

The target features listed here can be used in #[target_feature] and #[cfg(target_feature)]. They also do not trigger any warnings when used with -Ctarget-feature.

Note that even unstable (and even entirely unlisted) features can be used with -Ctarget-feature on stable. Using a feature not on the list of Rust target features only emits a warning. Only cfg(target_feature) and #[target_feature] actually do any stability gating. cfg(target_feature) for unstable features just works on nightly without any feature gate. #[target_feature] requires a feature gate.

When adding features to the below lists check whether they’re named already elsewhere in rust e.g. in stdarch and whether the given name matches LLVM’s if it doesn’t, to_llvm_feature in llvm_util in rustc_codegen_llvm needs to be adapted. Additionally, if the feature is not available in older version of LLVM supported by the current rust, the same function must be updated to filter out these features to avoid triggering warnings.

Also note that all target features listed here must be purely additive: for target_feature 1.1 to be sound, we can never allow features like +soft-float (on x86) to be controlled on a per-function level, since we would then allow safe calls from functions with +soft-float to functions without that feature!

It is important for soundness to consider the interaction of target features and the function call ABI. For example, disabling the x87 feature on x86 changes how scalar floats are passed as arguments, so letting people toggle that feature would be unsound. To this end, the Target::abi_required_features function computes which target features must and must not be enabled for any given target, and individual features can also be marked as Forbidden. See https://github.com/rust-lang/rust/issues/116344 for some more context.

The one exception to features that change the ABI is features that enable larger vector registers. Those are permitted to be listed here. The *_FOR_CORRECT_VECTOR_ABI arrays store information about which target feature is ABI-required for which vector size; this is used to ensure that vectors can only be passed via extern "C" when the right feature is enabled. (For the “Rust” ABI we generally pass vectors by-ref exactly to avoid these issues.) Also see https://github.com/rust-lang/rust/issues/116558.

Stabilizing a target feature requires t-lang approval.

Structs§

FeatureConstraints

Enums§

Stability
Stability information for target features.

Constants§

AARCH64_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI 🔒
AARCH64_TIED_FEATURES 🔒
AMDGPU_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI 🔒
ARM_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI 🔒
BPF_FEATURES 🔒
CSKY_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI 🔒
HEXAGON_FEATURES 🔒
HEXAGON_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI 🔒
IBMZ_FEATURES 🔒
LOONGARCH_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI 🔒
MIPS_FEATURES 🔒
MIPS_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI 🔒
NVPTX_FEATURES 🔒
POWERPC_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI 🔒
RISCV_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI 🔒
RUSTC_SPECIFIC_FEATURES
Features that control behaviour of rustc, rather than the codegen. These exist globally and are not in the target-specific lists below.
S390X_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI 🔒
SPARC_FEATURES 🔒
SPARC_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI 🔒
WASM_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI 🔒
X86_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI 🔒
XTENSA_FEATURES 🔒

Statics§

AARCH64_FEATURES 🔒
ARM_FEATURES 🔒
AVR_FEATURES 🔒
CSKY_FEATURES 🔒
LOONGARCH_FEATURES 🔒
M68K_FEATURES 🔒
POWERPC_FEATURES 🔒
RISCV_FEATURES 🔒
WASM_FEATURES 🔒
X86_FEATURES 🔒

Functions§

all_rust_features
When rustdoc is running, provide a list of all known features so that all their respective primitives may be documented.

Type Aliases§

ImpliedFeatures 🔒
If feature A “implies” feature B, then: