rust/compiler
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
..
rustc Add a new rustc_driver dylib to rexport rustc_driver_impl 2023-02-02 07:34:41 +01:00
rustc_abi Unify validity checks into a single query 2023-02-23 18:42:36 +00:00
rustc_apfloat
rustc_arena
rustc_ast Use ThinVec in a few more AST types. 2023-02-21 11:51:56 +11:00
rustc_ast_lowering Add ErrorGuaranteed to HIR ExprKind::Err 2023-02-25 19:46:36 +00:00
rustc_ast_passes avoid &str to String conversions 2023-02-27 14:27:13 +09:00
rustc_ast_pretty Use ThinVec in various AST types. 2023-02-21 11:51:56 +11:00
rustc_attr errors: generate typed identifiers in each crate 2023-02-22 09:15:53 +00:00
rustc_baked_icu_data update ICU4X to 1.1.0 2023-02-04 22:28:59 +01:00
rustc_borrowck Auto merge of #108487 - cjgillot:no-typeck-mir, r=oli-obk 2023-02-27 21:48:10 +00:00
rustc_builtin_macros Replace parse_[sth]_expr with parse_expr_[sth] function names 2023-02-24 05:12:03 +01:00
rustc_codegen_cranelift Rollup merge of #108364 - Nilstrieb:validity-checks-refactor, r=compiler-errors 2023-02-27 06:11:52 +01:00
rustc_codegen_gcc Use List::empty() instead of mk_substs(&[]). 2023-02-24 07:33:02 +11:00
rustc_codegen_llvm Use List::empty() instead of mk_substs(&[]). 2023-02-24 07:33:02 +11:00
rustc_codegen_ssa Auto merge of #99767 - LeSeulArtichaut:stable-target-feature-11, r=estebank 2023-02-28 01:14:56 +00:00
rustc_const_eval Auto merge of #108487 - cjgillot:no-typeck-mir, r=oli-obk 2023-02-27 21:48:10 +00:00
rustc_data_structures Upgrade ena to 0.14.1. 2023-02-24 08:53:27 +11:00
rustc_driver Remove unneeded extern crate 2023-02-02 07:47:39 +01:00
rustc_driver_impl refactor: statically guarantee that current error codes are documented 2023-02-26 20:12:36 +13:00
rustc_error_codes refactor: statically guarantee that current error codes are documented 2023-02-26 20:12:36 +13:00
rustc_error_messages Handle selecting the default locale better 2023-02-23 01:14:10 +01:00
rustc_errors Rollup merge of #108482 - Ezrashaw:force-error-docs, r=GuillaumeGomez 2023-02-26 12:05:00 +01:00
rustc_expand make "proc macro panicked" translatable 2023-02-24 23:37:10 +02:00
rustc_feature Auto merge of #99767 - LeSeulArtichaut:stable-target-feature-11, r=estebank 2023-02-28 01:14:56 +00:00
rustc_fs_util
rustc_graphviz Fix uninlined_format_args for some compiler crates 2023-01-05 19:01:12 +01:00
rustc_hir Rollup merge of #108484 - Nilstrieb:˂DiagnosticItem˂FromFn˃ as From˂˂LangItemFromFn˃˃˃꞉꞉from, r=cjgillot 2023-02-26 12:05:01 +01:00
rustc_hir_analysis Rollup merge of #108363 - cjgillot:unused-crate, r=WaffleLapkin 2023-02-27 18:48:49 +01:00
rustc_hir_pretty Add ErrorGuaranteed to HIR ExprKind::Err 2023-02-25 19:46:36 +00:00
rustc_hir_typeck Auto merge of #108487 - cjgillot:no-typeck-mir, r=oli-obk 2023-02-27 21:48:10 +00:00
rustc_incremental errors: generate typed identifiers in each crate 2023-02-22 09:15:53 +00:00
rustc_index Fix IndexVec::drain_enumerated 2023-01-19 15:25:33 +00:00
rustc_infer Don't trigger ICE for ReError when the other region is empty. 2023-02-26 20:47:18 -06:00
rustc_interface Rollup merge of #107675 - jsgf:link-directives, r=davidtwco 2023-02-25 11:53:09 -08:00
rustc_lexer Update lexer lifetime test 2023-02-14 23:25:01 +08:00
rustc_lint Rollup merge of #108363 - cjgillot:unused-crate, r=WaffleLapkin 2023-02-27 18:48:49 +01:00
rustc_lint_defs Rollup merge of #108363 - cjgillot:unused-crate, r=WaffleLapkin 2023-02-27 18:48:49 +01:00
rustc_llvm Add kernel-address sanitizer support for freestanding targets 2023-02-14 20:54:25 -05:00
rustc_log Rollup merge of #107895 - matthiaskrgr:cl, r=compiler-errors 2023-02-11 17:18:44 +01:00
rustc_macros Emit the enum discriminant separately for the Encodable macro 2023-02-25 01:04:56 +01:00
rustc_metadata Rollup merge of #107675 - jsgf:link-directives, r=davidtwco 2023-02-25 11:53:09 -08:00
rustc_middle Auto merge of #108487 - cjgillot:no-typeck-mir, r=oli-obk 2023-02-27 21:48:10 +00:00
rustc_mir_build Auto merge of #108487 - cjgillot:no-typeck-mir, r=oli-obk 2023-02-27 21:48:10 +00:00
rustc_mir_dataflow Auto merge of #108250 - nnethercote:rename-interner-funcs, r=compiler-errors 2023-02-25 13:55:26 +00:00
rustc_mir_transform Rollup merge of #108364 - Nilstrieb:validity-checks-refactor, r=compiler-errors 2023-02-27 06:11:52 +01:00
rustc_monomorphize Rename many interner functions. 2023-02-24 07:32:24 +11:00
rustc_parse Rollup merge of #108477 - y21:replace-semi-with-comma-sugg, r=compiler-errors 2023-02-27 06:11:53 +01:00
rustc_parse_format Replace some thens with some then_somes 2023-02-16 15:26:03 +00:00
rustc_passes Rollup merge of #108486 - cjgillot:owner-ditem, r=Nilstrieb 2023-02-27 06:11:53 +01:00
rustc_plugin_impl errors: generate typed identifiers in each crate 2023-02-22 09:15:53 +00:00
rustc_privacy Auto merge of #108324 - notriddle:notriddle/assoc-fn-method, r=compiler-errors,davidtwco,estebank,oli-obk 2023-02-23 00:19:12 +00:00
rustc_query_impl Move ensure_sufficient_stack to try_execute_query callers 2023-02-25 06:11:01 +01:00
rustc_query_system Don't inline try_execute_query 2023-02-25 06:11:02 +01:00
rustc_resolve Rollup merge of #108533 - notriddle:notriddle/resolver-def-descr, r=compiler-errors 2023-02-27 18:48:51 +01:00
rustc_serialize Emit the enum discriminant separately for the Encodable macro 2023-02-25 01:04:56 +01:00
rustc_session Rollup merge of #107675 - jsgf:link-directives, r=davidtwco 2023-02-25 11:53:09 -08:00
rustc_smir
rustc_span Rollup merge of #108484 - Nilstrieb:˂DiagnosticItem˂FromFn˃ as From˂˂LangItemFromFn˃˃˃꞉꞉from, r=cjgillot 2023-02-26 12:05:01 +01:00
rustc_symbol_mangling Rename many interner functions. 2023-02-24 07:32:24 +11:00
rustc_target Auto merge of #106476 - keith:ks/add-sanitizer-support-for-modern-ios-platforms, r=badboy 2023-02-18 05:58:41 +00:00
rustc_trait_selection Rollup merge of #108319 - compiler-errors:dont-project-to-specializable-rpitits, r=lcnr 2023-02-27 06:11:51 +01:00
rustc_traits Add mk_canonical_var_infos_from_iter. 2023-02-24 07:33:02 +11:00
rustc_transmute Remove type-traversal trait aliases 2023-02-22 17:04:58 +00:00
rustc_ty_utils Rename many interner functions. 2023-02-24 07:32:24 +11:00
rustc_type_ir make first component of dyn* use pointer layout+type, and adjust DynStar comment 2023-02-18 19:24:55 +00:00