mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-01 20:47:36 +00:00
![]() Stabilize `#![feature(target_feature_11)]`
## Stabilization report
### Summary
Allows for safe functions to be marked with `#[target_feature]` attributes.
Functions marked with `#[target_feature]` are generally considered as unsafe functions: they are unsafe to call, cannot be assigned to safe function pointers, and don't implement the `Fn*` traits.
However, calling them from other `#[target_feature]` functions with a superset of features is safe.
```rust
// Demonstration function
#[target_feature(enable = "avx2")]
fn avx2() {}
fn foo() {
// Calling `avx2` here is unsafe, as we must ensure
// that AVX is available first.
unsafe {
avx2();
}
}
#[target_feature(enable = "avx2")]
fn bar() {
// Calling `avx2` here is safe.
avx2();
}
```
### Test cases
Tests for this feature can be found in [`src/test/ui/rfcs/rfc-2396-target_feature-11/`](
|
||
---|---|---|
.. | ||
back | ||
coverageinfo | ||
debuginfo | ||
mir | ||
traits | ||
base.rs | ||
codegen_attrs.rs | ||
common.rs | ||
errors.rs | ||
glue.rs | ||
lib.rs | ||
meth.rs | ||
mono_item.rs | ||
target_features.rs |