Skip to content

Commit 44b2e6c

Browse files
calebzulawskiveluca93
authored andcommitted
Stabilize target_feature_11
1 parent ebcf860 commit 44b2e6c

34 files changed

+77
-165
lines changed

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

+8-19
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,9 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
260260
if safe_target_features {
261261
if tcx.sess.target.is_like_wasm || tcx.sess.opts.actually_rustdoc {
262262
// The `#[target_feature]` attribute is allowed on
263-
// WebAssembly targets on all functions, including safe
264-
// ones. Other targets require that `#[target_feature]` is
265-
// only applied to unsafe functions (pending the
266-
// `target_feature_11` feature) because on most targets
263+
// WebAssembly targets on all functions. Prior to stabilizing
264+
// the `target_feature_11` feature, `#[target_feature]` was
265+
// only permitted on unsafe functions because on most targets
267266
// execution of instructions that are not supported is
268267
// considered undefined behavior. For WebAssembly which is a
269268
// 100% safe target at execution time it's not possible to
@@ -277,17 +276,10 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
277276
// if a target is documenting some wasm-specific code then
278277
// it's not spuriously denied.
279278
//
280-
// This exception needs to be kept in sync with allowing
281-
// `#[target_feature]` on `main` and `start`.
282-
} else if !tcx.features().target_feature_11() {
283-
feature_err(
284-
&tcx.sess,
285-
sym::target_feature_11,
286-
attr.span,
287-
"`#[target_feature(..)]` can only be applied to `unsafe` functions",
288-
)
289-
.with_span_label(tcx.def_span(did), "not an `unsafe` function")
290-
.emit();
279+
// Now that `#[target_feature]` is permitted on safe functions,
280+
// this exception must still exist for allowing the attribute on
281+
// `main`, `start`, and other functions that are not usually
282+
// allowed.
291283
} else {
292284
check_target_feature_trait_unsafe(tcx, did, attr.span);
293285
}
@@ -616,10 +608,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
616608
// its parent function, which effectively inherits the features anyway. Boxing this closure
617609
// would result in this closure being compiled without the inherited target features, but this
618610
// is probably a poor usage of `#[inline(always)]` and easily avoided by not using the attribute.
619-
if tcx.features().target_feature_11()
620-
&& tcx.is_closure_like(did.to_def_id())
621-
&& !codegen_fn_attrs.inline.always()
622-
{
611+
if tcx.is_closure_like(did.to_def_id()) && codegen_fn_attrs.inline != InlineAttr::Always {
623612
let owner_id = tcx.parent(did.to_def_id());
624613
if tcx.def_kind(owner_id).has_codegen_attrs() {
625614
codegen_fn_attrs

compiler/rustc_feature/src/accepted.rs

+2
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,8 @@ declare_features! (
389389
(accepted, struct_variant, "1.0.0", None),
390390
/// Allows `#[target_feature(...)]`.
391391
(accepted, target_feature, "1.27.0", None),
392+
/// Allows the use of `#[target_feature]` on safe functions.
393+
(accepted, target_feature_11, "CURRENT_RUSTC_VERSION", Some(69098)),
392394
/// Allows `fn main()` with return types which implements `Termination` (RFC 1937).
393395
(accepted, termination_trait, "1.26.0", Some(43301)),
394396
/// Allows `#[test]` functions where the return type implements `Termination` (RFC 1937).

compiler/rustc_feature/src/unstable.rs

-2
Original file line numberDiff line numberDiff line change
@@ -618,8 +618,6 @@ declare_features! (
618618
(unstable, strict_provenance_lints, "1.61.0", Some(130351)),
619619
/// Allows string patterns to dereference values to match them.
620620
(unstable, string_deref_patterns, "1.67.0", Some(87121)),
621-
/// Allows the use of `#[target_feature]` on safe functions.
622-
(unstable, target_feature_11, "1.45.0", Some(69098)),
623621
/// Allows using `#[thread_local]` on `static` items.
624622
(unstable, thread_local, "1.0.0", Some(29594)),
625623
/// Allows defining `trait X = A + B;` alias items.

library/core/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@
190190
#![feature(staged_api)]
191191
#![feature(stmt_expr_attributes)]
192192
#![feature(strict_provenance_lints)]
193-
#![feature(target_feature_11)]
194193
#![feature(trait_alias)]
195194
#![feature(transparent_unions)]
196195
#![feature(try_blocks)]

tests/assembly/closure-inherit-target-feature.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// make sure the feature is not enabled at compile-time
55
//@ compile-flags: -C opt-level=3 -C target-feature=-sse4.1 -C llvm-args=-x86-asm-syntax=intel
66

7-
#![feature(target_feature_11)]
87
#![crate_type = "rlib"]
98

109
use std::arch::x86_64::{__m128, _mm_blend_ps};

tests/codegen/target-feature-inline-closure.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//@ compile-flags: -Copt-level=3 -Ctarget-cpu=x86-64
44

55
#![crate_type = "lib"]
6-
#![feature(target_feature_11)]
76

87
#[cfg(target_arch = "x86_64")]
98
use std::arch::x86_64::*;

tests/mir-opt/inline/inline_compatibility.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#![crate_type = "lib"]
66
#![feature(no_sanitize)]
7-
#![feature(target_feature_11)]
87
#![feature(c_variadic)]
98

109
#[inline]

tests/ui/asm/x86_64/issue-89875.rs

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
//@ needs-asm-support
33
//@ only-x86_64
44

5-
#![feature(target_feature_11)]
6-
75
use std::arch::asm;
86

97
#[target_feature(enable = "avx")]

tests/ui/async-await/async-closures/fn-exception-target-features.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
//@ edition: 2021
22
//@ only-x86_64
33

4-
#![feature(target_feature_11)]
5-
// `target_feature_11` just to test safe functions w/ target features.
6-
7-
use std::pin::Pin;
84
use std::future::Future;
5+
use std::pin::Pin;
96

107
#[target_feature(enable = "sse2")]
11-
fn target_feature() -> Pin<Box<dyn Future<Output = ()> + 'static>> { todo!() }
8+
fn target_feature() -> Pin<Box<dyn Future<Output = ()> + 'static>> {
9+
todo!()
10+
}
1211

1312
fn test(f: impl AsyncFn()) {}
1413

tests/ui/async-await/async-closures/fn-exception-target-features.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0277]: the trait bound `#[target_features] fn() -> Pin<Box<(dyn Future<Output = ()> + 'static)>> {target_feature}: AsyncFn()` is not satisfied
2-
--> $DIR/fn-exception-target-features.rs:16:10
2+
--> $DIR/fn-exception-target-features.rs:15:10
33
|
44
LL | test(target_feature);
55
| ---- ^^^^^^^^^^^^^^ unsatisfied trait bound
@@ -8,7 +8,7 @@ LL | test(target_feature);
88
|
99
= help: the trait `AsyncFn()` is not implemented for fn item `#[target_features] fn() -> Pin<Box<(dyn Future<Output = ()> + 'static)>> {target_feature}`
1010
note: required by a bound in `test`
11-
--> $DIR/fn-exception-target-features.rs:13:17
11+
--> $DIR/fn-exception-target-features.rs:12:17
1212
|
1313
LL | fn test(f: impl AsyncFn()) {}
1414
| ^^^^^^^^^ required by this bound in `test`

tests/ui/lang-items/start_lang_item_with_target_feature.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@ only-x86_64
22
//@ check-fail
33

4-
#![feature(lang_items, no_core, target_feature_11)]
4+
#![feature(lang_items, no_core)]
55
#![no_core]
66

77
#[lang = "copy"]

tests/ui/panic-handler/panic-handler-with-target-feature.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//@ compile-flags:-C panic=abort
22
//@ only-x86_64
33

4-
#![feature(target_feature_11)]
54
#![no_std]
65
#![no_main]
76

tests/ui/panic-handler/panic-handler-with-target-feature.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: `#[panic_handler]` function is not allowed to have `#[target_feature]`
2-
--> $DIR/panic-handler-with-target-feature.rs:11:1
2+
--> $DIR/panic-handler-with-target-feature.rs:10:1
33
|
44
LL | #[target_feature(enable = "avx2")]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

tests/ui/rfcs/rfc-2396-target_feature-11/check-pass.rs

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
//@ check-pass
1010
//@ only-x86_64
1111

12-
#![feature(target_feature_11)]
13-
1412
#[target_feature(enable = "sse2")]
1513
const fn sse2() {}
1614

tests/ui/rfcs/rfc-2396-target_feature-11/closures-inherit-target_feature.rs

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
//@ check-pass
44
//@ only-x86_64
55

6-
#![feature(target_feature_11)]
7-
86
#[target_feature(enable = "avx")]
97
fn also_use_avx() {
108
println!("Hello from AVX")

tests/ui/rfcs/rfc-2396-target_feature-11/feature-gate-target_feature_11.rs

-6
This file was deleted.

tests/ui/rfcs/rfc-2396-target_feature-11/feature-gate-target_feature_11.stderr

-15
This file was deleted.

tests/ui/rfcs/rfc-2396-target_feature-11/fn-ptr.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//@ only-x86_64
22

3-
#![feature(target_feature_11)]
4-
53
#[target_feature(enable = "avx")]
64
fn foo_avx() {}
75

tests/ui/rfcs/rfc-2396-target_feature-11/fn-ptr.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0308]: mismatched types
2-
--> $DIR/fn-ptr.rs:14:21
2+
--> $DIR/fn-ptr.rs:12:21
33
|
44
LL | #[target_feature(enable = "avx")]
55
| --------------------------------- `#[target_feature]` added here
@@ -14,7 +14,7 @@ LL | let foo: fn() = foo_avx;
1414
= note: functions with `#[target_feature]` can only be coerced to `unsafe` function pointers
1515

1616
error[E0308]: mismatched types
17-
--> $DIR/fn-ptr.rs:23:21
17+
--> $DIR/fn-ptr.rs:21:21
1818
|
1919
LL | #[target_feature(enable = "sse2")]
2020
| ---------------------------------- `#[target_feature]` added here

tests/ui/rfcs/rfc-2396-target_feature-11/fn-traits.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//@ only-x86_64
22

3-
#![feature(target_feature_11)]
4-
53
#[target_feature(enable = "avx")]
64
fn foo() {}
75

tests/ui/rfcs/rfc-2396-target_feature-11/fn-traits.stderr

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0277]: expected a `Fn()` closure, found `#[target_features] fn() {foo}`
2-
--> $DIR/fn-traits.rs:31:10
2+
--> $DIR/fn-traits.rs:29:10
33
|
44
LL | call(foo);
55
| ---- ^^^ expected an `Fn()` closure, found `#[target_features] fn() {foo}`
@@ -11,13 +11,13 @@ LL | call(foo);
1111
= note: `#[target_feature]` functions do not implement the `Fn` traits
1212
= note: try casting the function to a `fn` pointer or wrapping it in a closure
1313
note: required by a bound in `call`
14-
--> $DIR/fn-traits.rs:14:17
14+
--> $DIR/fn-traits.rs:12:17
1515
|
1616
LL | fn call(f: impl Fn()) {
1717
| ^^^^ required by this bound in `call`
1818

1919
error[E0277]: expected a `FnMut()` closure, found `#[target_features] fn() {foo}`
20-
--> $DIR/fn-traits.rs:32:14
20+
--> $DIR/fn-traits.rs:30:14
2121
|
2222
LL | call_mut(foo);
2323
| -------- ^^^ expected an `FnMut()` closure, found `#[target_features] fn() {foo}`
@@ -29,13 +29,13 @@ LL | call_mut(foo);
2929
= note: `#[target_feature]` functions do not implement the `Fn` traits
3030
= note: try casting the function to a `fn` pointer or wrapping it in a closure
3131
note: required by a bound in `call_mut`
32-
--> $DIR/fn-traits.rs:18:25
32+
--> $DIR/fn-traits.rs:16:25
3333
|
3434
LL | fn call_mut(mut f: impl FnMut()) {
3535
| ^^^^^^^ required by this bound in `call_mut`
3636

3737
error[E0277]: expected a `FnOnce()` closure, found `#[target_features] fn() {foo}`
38-
--> $DIR/fn-traits.rs:33:15
38+
--> $DIR/fn-traits.rs:31:15
3939
|
4040
LL | call_once(foo);
4141
| --------- ^^^ expected an `FnOnce()` closure, found `#[target_features] fn() {foo}`
@@ -47,13 +47,13 @@ LL | call_once(foo);
4747
= note: `#[target_feature]` functions do not implement the `Fn` traits
4848
= note: try casting the function to a `fn` pointer or wrapping it in a closure
4949
note: required by a bound in `call_once`
50-
--> $DIR/fn-traits.rs:22:22
50+
--> $DIR/fn-traits.rs:20:22
5151
|
5252
LL | fn call_once(f: impl FnOnce()) {
5353
| ^^^^^^^^ required by this bound in `call_once`
5454

5555
error[E0277]: expected a `FnOnce(i32)` closure, found `#[target_features] fn(i32) {bar}`
56-
--> $DIR/fn-traits.rs:34:19
56+
--> $DIR/fn-traits.rs:32:19
5757
|
5858
LL | call_once_i32(bar);
5959
| ------------- ^^^ expected an `FnOnce(i32)` closure, found `#[target_features] fn(i32) {bar}`
@@ -64,13 +64,13 @@ LL | call_once_i32(bar);
6464
= note: `#[target_feature]` functions do not implement the `Fn` traits
6565
= note: try casting the function to a `fn` pointer or wrapping it in a closure
6666
note: required by a bound in `call_once_i32`
67-
--> $DIR/fn-traits.rs:26:26
67+
--> $DIR/fn-traits.rs:24:26
6868
|
6969
LL | fn call_once_i32(f: impl FnOnce(i32)) {
7070
| ^^^^^^^^^^^ required by this bound in `call_once_i32`
7171

7272
error[E0277]: expected a `Fn()` closure, found `unsafe fn() {foo_unsafe}`
73-
--> $DIR/fn-traits.rs:36:10
73+
--> $DIR/fn-traits.rs:34:10
7474
|
7575
LL | call(foo_unsafe);
7676
| ---- ^^^^^^^^^^ call the function in a closure: `|| unsafe { /* code */ }`
@@ -83,13 +83,13 @@ LL | call(foo_unsafe);
8383
= note: `#[target_feature]` functions do not implement the `Fn` traits
8484
= note: try casting the function to a `fn` pointer or wrapping it in a closure
8585
note: required by a bound in `call`
86-
--> $DIR/fn-traits.rs:14:17
86+
--> $DIR/fn-traits.rs:12:17
8787
|
8888
LL | fn call(f: impl Fn()) {
8989
| ^^^^ required by this bound in `call`
9090

9191
error[E0277]: expected a `FnMut()` closure, found `unsafe fn() {foo_unsafe}`
92-
--> $DIR/fn-traits.rs:38:14
92+
--> $DIR/fn-traits.rs:36:14
9393
|
9494
LL | call_mut(foo_unsafe);
9595
| -------- ^^^^^^^^^^ call the function in a closure: `|| unsafe { /* code */ }`
@@ -102,13 +102,13 @@ LL | call_mut(foo_unsafe);
102102
= note: `#[target_feature]` functions do not implement the `Fn` traits
103103
= note: try casting the function to a `fn` pointer or wrapping it in a closure
104104
note: required by a bound in `call_mut`
105-
--> $DIR/fn-traits.rs:18:25
105+
--> $DIR/fn-traits.rs:16:25
106106
|
107107
LL | fn call_mut(mut f: impl FnMut()) {
108108
| ^^^^^^^ required by this bound in `call_mut`
109109

110110
error[E0277]: expected a `FnOnce()` closure, found `unsafe fn() {foo_unsafe}`
111-
--> $DIR/fn-traits.rs:40:15
111+
--> $DIR/fn-traits.rs:38:15
112112
|
113113
LL | call_once(foo_unsafe);
114114
| --------- ^^^^^^^^^^ call the function in a closure: `|| unsafe { /* code */ }`
@@ -121,7 +121,7 @@ LL | call_once(foo_unsafe);
121121
= note: `#[target_feature]` functions do not implement the `Fn` traits
122122
= note: try casting the function to a `fn` pointer or wrapping it in a closure
123123
note: required by a bound in `call_once`
124-
--> $DIR/fn-traits.rs:22:22
124+
--> $DIR/fn-traits.rs:20:22
125125
|
126126
LL | fn call_once(f: impl FnOnce()) {
127127
| ^^^^^^^^ required by this bound in `call_once`
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//@ only-x86_64
22

3-
#![feature(target_feature_11)]
4-
53
#[target_feature(enable = "avx2")]
64
fn main() {}
75
//~^ ERROR `main` function is not allowed to have `#[target_feature]`

tests/ui/rfcs/rfc-2396-target_feature-11/issue-108645-target-feature-on-main.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: `main` function is not allowed to have `#[target_feature]`
2-
--> $DIR/issue-108645-target-feature-on-main.rs:6:1
2+
--> $DIR/issue-108645-target-feature-on-main.rs:4:1
33
|
44
LL | fn main() {}
55
| ^^^^^^^^^ `main` function is not allowed to have `#[target_feature]`

tests/ui/rfcs/rfc-2396-target_feature-11/issue-108655-inline-always-closure.rs

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
//@ check-pass
44
//@ only-x86_64
55

6-
#![feature(target_feature_11)]
7-
86
#[target_feature(enable = "avx")]
97
pub unsafe fn test() {
108
({

tests/ui/rfcs/rfc-2396-target_feature-11/issue-99876.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//@ check-pass
22

3-
#![feature(target_feature_11)]
4-
53
struct S<T>(T)
64
where
75
[T; (|| {}, 1).1]: Copy;

tests/ui/rfcs/rfc-2396-target_feature-11/return-fn-ptr.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//@ only-x86_64
22
//@ run-pass
33

4-
#![feature(target_feature_11)]
5-
64
#[target_feature(enable = "sse2")]
75
fn foo() -> bool {
86
true

0 commit comments

Comments
 (0)