mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +00:00
![]() Stabilize target_feature_11 # Stabilization report This is an updated version of https://github.com/rust-lang/rust/pull/116114, which is itself a redo of https://github.com/rust-lang/rust/pull/99767. Most of this commit and report were copied from those PRs. Thanks ```@LeSeulArtichaut``` and ```@calebzulawski!``` ## 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 *generally* 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(); } ``` Moreover, once https://github.com/rust-lang/rust/pull/135504 is merged, they can be converted to safe function pointers in a context in which calling them is safe: ```rust // Demonstration function #[target_feature(enable = "avx2")] fn avx2() {} fn foo() -> fn() { // Converting `avx2` to fn() is a compilation error here. avx2 } #[target_feature(enable = "avx2")] fn bar() -> fn() { // `avx2` coerces to fn() here avx2 } ``` See the section "Closures" below for justification of this behaviour. ## Test cases Tests for this feature can be found in [`tests/ui/target_feature/`]( |
||
---|---|---|
.. | ||
auxiliary | ||
ambiguous-arg.rs | ||
ambiguous-arg.stderr | ||
arg-mismatch.rs | ||
arg-mismatch.stderr | ||
async-fn-mut-for-async-fn.rs | ||
async-fn-once-for-async-fn.rs | ||
async-future-out-must-be-sized.rs | ||
async-future-out-must-be-sized.stderr | ||
await-inference-guidance.rs | ||
body-check-on-non-fnmut.rs | ||
box-deref-in-debuginfo.rs | ||
brand.rs | ||
call-once-deduction.rs | ||
captures.rs | ||
captures.run.stdout | ||
clone-closure.rs | ||
clone-closure.run.stdout | ||
closure-shim-borrowck-error.rs | ||
closure-shim-borrowck-error.stderr | ||
constrained-but-no-upvars-yet.rs | ||
debuginfo-by-move-body.rs | ||
def-path.rs | ||
def-path.stderr | ||
different-projection-lengths-for-different-upvars.rs | ||
dont-ice-when-body-tainted-by-errors.rs | ||
dont-ice-when-body-tainted-by-errors.stderr | ||
drop.rs | ||
drop.run.stdout | ||
fn-exception-target-features.rs | ||
fn-exception-target-features.stderr | ||
fn-exception.rs | ||
fn-exception.stderr | ||
force-move-due-to-actually-fnonce.rs | ||
force-move-due-to-inferred-kind.rs | ||
foreign.rs | ||
higher-ranked-return.rs | ||
higher-ranked-return.stderr | ||
higher-ranked.rs | ||
implements-fnmut.rs | ||
inline-body.rs | ||
is-fn.rs | ||
is-not-fn.current.stderr | ||
is-not-fn.next.stderr | ||
is-not-fn.rs | ||
lint-closure-returning-async-block.rs | ||
lint-closure-returning-async-block.stderr | ||
mac-body.rs | ||
mangle.rs | ||
moro-example.rs | ||
move-consuming-capture.rs | ||
move-consuming-capture.stderr | ||
move-is-async-fn.rs | ||
move-out-of-ref.rs | ||
move-out-of-ref.stderr | ||
mut-ref-reborrow.rs | ||
mutate.rs | ||
no-borrow-from-env.rs | ||
non-copy-arg-does-not-force-inner-move.rs | ||
not-clone-closure.rs | ||
not-clone-closure.stderr | ||
not-fn.rs | ||
not-fn.stderr | ||
not-lending.rs | ||
not-lending.stderr | ||
once.rs | ||
overlapping-projs.rs | ||
overlapping-projs.run.stdout | ||
post-mono-higher-ranked-hang-2.rs | ||
post-mono-higher-ranked-hang-2.stderr | ||
post-mono-higher-ranked-hang.rs | ||
post-mono-higher-ranked-hang.stderr | ||
precise-captures.call_once.run.stdout | ||
precise-captures.call.run.stdout | ||
precise-captures.force_once.run.stdout | ||
precise-captures.rs | ||
pretty-async-fn-opaque.rs | ||
pretty-async-fn-opaque.stderr | ||
refd.rs | ||
return-type-mismatch.rs | ||
return-type-mismatch.stderr | ||
sig-from-bare-fn.rs | ||
signature-deduction.rs | ||
signature-inference-from-two-part-bound.rs | ||
tainted-body-2.rs | ||
tainted-body-2.stderr | ||
tainted-body.rs | ||
tainted-body.stderr | ||
truncated-fields-when-imm.rs | ||
validate-synthetic-body.rs | ||
without-precise-captures-we-are-powerless.rs | ||
without-precise-captures-we-are-powerless.stderr | ||
wrong-fn-kind.rs | ||
wrong-fn-kind.stderr |