rust/library
bors b583ede652 Auto merge of #99767 - LeSeulArtichaut:stable-target-feature-11, r=estebank
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/`](b67ba9ba20/src/test/ui/rfcs/rfc-2396-target_feature-11/).

### Edge cases

- https://github.com/rust-lang/rust/issues/73631

Closures defined inside functions marked with `#[target_feature]` inherit the target features of their parent function. They can still be assigned to safe function pointers and implement the appropriate `Fn*` traits.

```rust
#[target_feature(enable = "avx2")]
fn qux() {
    let my_closure = || avx2(); // this call to `avx2` is safe
    let f: fn() = my_closure;
}
```

This means that in order to call a function with `#[target_feature]`, you must show that the target-feature is available while the function executes *and* for as long as whatever may escape from that function lives.

### Documentation

- Reference: https://github.com/rust-lang/reference/pull/1181

---
cc tracking issue #69098
r? `@ghost`
2023-02-28 01:14:56 +00:00
..
alloc Disambiguate comments 2023-02-26 03:13:56 +01:00
backtrace@07872f28cd Update backtrace 2022-09-02 16:09:58 -04:00
core Auto merge of #99767 - LeSeulArtichaut:stable-target-feature-11, r=estebank 2023-02-28 01:14:56 +00:00
panic_abort Replace libstd, libcore, liballoc in line comments. 2022-12-30 14:00:42 +01:00
panic_unwind Replace libstd, libcore, liballoc in docs. 2022-12-30 14:00:40 +01:00
portable-simd Remove unnecessary &format! 2023-01-21 22:06:42 -05:00
proc_macro Auto merge of #105671 - lukas-code:depreciate-char, r=scottmcm 2023-02-12 11:09:06 +00:00
profiler_builtins Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rtstartup Remove custom frame info registration on i686-pc-windows-gnu 2022-08-23 16:12:58 +08:00
rustc-std-workspace-alloc Replace libstd, libcore, liballoc in line comments. 2022-12-30 14:00:42 +01:00
rustc-std-workspace-core
rustc-std-workspace-std
std Rollup merge of #107110 - strega-nil:mbtwc-wctmb, r=ChrisDenton 2023-02-27 18:48:48 +01:00
stdarch@a0c30f3e3c update stdarch 2022-12-29 11:22:13 +01:00
test test: drop unused deps 2023-02-24 20:45:00 +03:00
unwind Replace libstd, libcore, liballoc in line comments. 2022-12-30 14:00:42 +01:00