rust/tests/ui/asm
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
..
aarch64
x86_64 Stabilize #![feature(target_feature_11)] 2023-02-01 08:53:02 +01:00
bad-arch.mirunsafeck.stderr
bad-arch.rs
bad-arch.thirunsafeck.stderr
bad-template.aarch64_mirunsafeck.stderr
bad-template.aarch64_thirunsafeck.stderr
bad-template.rs
bad-template.x86_64_mirunsafeck.stderr
bad-template.x86_64_thirunsafeck.stderr
generic-const.rs
inline-syntax.arm.stderr
inline-syntax.rs
inline-syntax.x86_64.stderr
issue-72570.rs Remove save-analysis. 2023-02-16 15:14:45 +11:00
issue-72570.stderr Remove save-analysis. 2023-02-16 15:14:45 +11:00
issue-85247.rs
issue-85247.rwpi.stderr
issue-87802.rs
issue-87802.stderr
issue-89305.rs
issue-89305.stderr
issue-92378.rs
issue-97490.rs
issue-99071.rs
issue-99071.stderr
issue-99122-2.rs
issue-99122.rs
issue-99122.stderr
may_unwind.rs
naked-functions-ffi.rs
naked-functions-ffi.stderr
naked-functions-unused.aarch64.stderr
naked-functions-unused.rs
naked-functions-unused.x86_64.stderr
naked-functions.rs
naked-functions.stderr
naked-invalid-attr.rs
naked-invalid-attr.stderr
named-asm-labels.rs
named-asm-labels.s
named-asm-labels.stderr
noreturn.rs
reg-conflict.rs
reg-conflict.stderr
type-check-1.rs
type-check-1.stderr
type-check-4.rs
type-check-4.stderr
unpretty-expanded.rs
unpretty-expanded.stdout