rust/library/core/src
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
array
async_iter
cell
char
convert Remove from_fn lang item 2023-02-26 09:15:54 +00:00
ffi Document that CStr::as_ptr returns a type alias 2023-02-16 14:22:08 +00:00
fmt
future
hash
intrinsics
iter Rollup merge of #107890 - obeis:mapping-to-unit, r=cjgillot 2023-02-26 00:46:25 +01:00
macros
mem
net Add tracking issue 2023-02-26 13:50:10 +01:00
num Require literals for some (u)int_impl! parameters 2023-02-22 23:26:22 -08:00
ops Constify RangeBounds, RangeX::contains and RangeX::is_empty. 2023-02-15 15:50:54 +01:00
panic
prelude
ptr
slice Optimize break patterns 2023-02-22 16:02:35 +00:00
str
sync
task
unicode
any.rs
arch.rs
ascii.rs
asserting.rs
bool.rs
borrow.rs
cell.rs
clone.rs
cmp.rs Constify RangeBounds, RangeX::contains and RangeX::is_empty. 2023-02-15 15:50:54 +01:00
default.rs
error.md
error.rs
hint.rs clarify correctness of black_box 2023-02-15 16:22:08 +00:00
internal_macros.rs
intrinsics.rs
lib.rs Auto merge of #99767 - LeSeulArtichaut:stable-target-feature-11, r=estebank 2023-02-28 01:14:56 +00:00
marker.rs
option.rs
panic.rs
panicking.rs
pin.rs
primitive_docs.rs
primitive.rs
result.rs "Basic usage" is redundant for there is just one example 2023-02-16 19:49:31 +02:00
time.rs
tuple.rs
unit.rs