Skip to content

Commit 7006f05

Browse files
calebzulawskiveluca93
authored andcommitted
Stabilize target_feature_11
1 parent f6cb952 commit 7006f05

38 files changed

+261
-158
lines changed

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,9 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
249249
{
250250
if tcx.sess.target.is_like_wasm || tcx.sess.opts.actually_rustdoc {
251251
// The `#[target_feature]` attribute is allowed on
252-
// WebAssembly targets on all functions, including safe
253-
// ones. Other targets require that `#[target_feature]` is
254-
// only applied to unsafe functions (pending the
255-
// `target_feature_11` feature) because on most targets
252+
// WebAssembly targets on all functions. Prior to stabilizing
253+
// the `target_feature_11` feature, `#[target_feature]` was
254+
// only permitted on safe functions because on most targets
256255
// execution of instructions that are not supported is
257256
// considered undefined behavior. For WebAssembly which is a
258257
// 100% safe target at execution time it's not possible to
@@ -266,17 +265,10 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
266265
// if a target is documenting some wasm-specific code then
267266
// it's not spuriously denied.
268267
//
269-
// This exception needs to be kept in sync with allowing
270-
// `#[target_feature]` on `main` and `start`.
271-
} else if !tcx.features().target_feature_11() {
272-
feature_err(
273-
&tcx.sess,
274-
sym::target_feature_11,
275-
attr.span,
276-
"`#[target_feature(..)]` can only be applied to `unsafe` functions",
277-
)
278-
.with_span_label(tcx.def_span(did), "not an `unsafe` function")
279-
.emit();
268+
// Now that `#[target_feature]` is permitted on safe functions,
269+
// this exception must still exist for allowing the attribute on
270+
// `main`, `start`, and other functions that are not usually
271+
// allowed.
280272
} else {
281273
check_target_feature_trait_unsafe(tcx, did, attr.span);
282274
}
@@ -584,10 +576,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
584576
// its parent function, which effectively inherits the features anyway. Boxing this closure
585577
// would result in this closure being compiled without the inherited target features, but this
586578
// is probably a poor usage of `#[inline(always)]` and easily avoided by not using the attribute.
587-
if tcx.features().target_feature_11()
588-
&& tcx.is_closure_like(did.to_def_id())
589-
&& codegen_fn_attrs.inline != InlineAttr::Always
590-
{
579+
if tcx.is_closure_like(did.to_def_id()) && codegen_fn_attrs.inline != InlineAttr::Always {
591580
let owner_id = tcx.parent(did.to_def_id());
592581
if tcx.def_kind(owner_id).has_codegen_attrs() {
593582
codegen_fn_attrs

compiler/rustc_feature/src/accepted.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,8 @@ declare_features! (
385385
(accepted, struct_variant, "1.0.0", None),
386386
/// Allows `#[target_feature(...)]`.
387387
(accepted, target_feature, "1.27.0", None),
388+
/// Allows the use of `#[target_feature]` on safe functions.
389+
(accepted, target_feature_11, "CURRENT_RUSTC_VERSION", Some(69098)),
388390
/// Allows `fn main()` with return types which implements `Termination` (RFC 1937).
389391
(accepted, termination_trait, "1.26.0", Some(43301)),
390392
/// Allows `#[test]` functions where the return type implements `Termination` (RFC 1937).

compiler/rustc_feature/src/unstable.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,8 +610,6 @@ declare_features! (
610610
(unstable, strict_provenance_lints, "1.61.0", Some(130351)),
611611
/// Allows string patterns to dereference values to match them.
612612
(unstable, string_deref_patterns, "1.67.0", Some(87121)),
613-
/// Allows the use of `#[target_feature]` on safe functions.
614-
(unstable, target_feature_11, "1.45.0", Some(69098)),
615613
/// Allows using `#[thread_local]` on `static` items.
616614
(unstable, thread_local, "1.0.0", Some(29594)),
617615
/// Allows defining `trait X = A + B;` alias items.

library/core/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@
187187
#![feature(staged_api)]
188188
#![feature(stmt_expr_attributes)]
189189
#![feature(strict_provenance_lints)]
190-
#![feature(target_feature_11)]
191190
#![feature(trait_alias)]
192191
#![feature(transparent_unions)]
193192
#![feature(try_blocks)]

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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
//@ edition: 2021
22
//@ only-x86_64
33

4-
#![feature(async_closure, target_feature_11)]
5-
// `target_feature_11` just to test safe functions w/ target features.
4+
#![feature(async_closure)]
65

7-
use std::pin::Pin;
86
use std::future::Future;
7+
use std::pin::Pin;
98

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

1314
fn test(f: impl AsyncFn()) {}
1415

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error[E0277]: the trait bound `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:17:10
33
|
44
LL | test(target_feature);
55
| ---- ^^^^^^^^^^^^^^ the trait `AsyncFn()` is not implemented for fn item `fn() -> Pin<Box<(dyn Future<Output = ()> + 'static)>> {target_feature}`
66
| |
77
| required by a bound introduced by this call
88
|
99
note: required by a bound in `test`
10-
--> $DIR/fn-exception-target-features.rs:13:17
10+
--> $DIR/fn-exception-target-features.rs:14:17
1111
|
1212
LL | fn test(f: impl AsyncFn()) {}
1313
| ^^^^^^^^^ required by this bound in `test`

0 commit comments

Comments
 (0)