@@ -267,7 +267,12 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
267
267
&& let Some ( fn_sig) = fn_sig ( )
268
268
&& fn_sig. skip_binder ( ) . safety ( ) == hir:: Safety :: Safe
269
269
{
270
- if tcx. sess . target . is_like_wasm || tcx. sess . opts . actually_rustdoc {
270
+ if attr. meta_item_list ( ) . is_some_and ( |list| {
271
+ list. len ( ) == 1 && list[ 0 ] . ident ( ) . is_some_and ( |x| x. name == sym:: from_args)
272
+ } ) {
273
+ // #[target_feature(from_args)] can be applied to safe functions and safe
274
+ // trait methods.
275
+ } else if tcx. sess . target . is_like_wasm || tcx. sess . opts . actually_rustdoc {
271
276
// The `#[target_feature]` attribute is allowed on
272
277
// WebAssembly targets on all functions, including safe
273
278
// ones. Other targets require that `#[target_feature]` is
@@ -306,6 +311,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
306
311
attr,
307
312
supported_target_features,
308
313
& mut codegen_fn_attrs. target_features ,
314
+ Some ( & mut codegen_fn_attrs. target_features_from_args ) ,
309
315
) ;
310
316
}
311
317
sym:: linkage => {
@@ -616,7 +622,9 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
616
622
}
617
623
}
618
624
619
- if let Some ( sig) = fn_sig_outer ( ) {
625
+ if let Some ( sig) = fn_sig_outer ( )
626
+ && codegen_fn_attrs. target_features_from_args
627
+ {
620
628
let mut additional_tf = vec ! [ ] ;
621
629
for ty in sig. skip_binder ( ) . inputs ( ) . skip_binder ( ) {
622
630
extend_with_struct_target_features (
@@ -785,7 +793,7 @@ fn struct_target_features(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &[TargetFeatur
785
793
let mut features = vec ! [ ] ;
786
794
let supported_features = tcx. supported_target_features ( LOCAL_CRATE ) ;
787
795
for attr in tcx. get_attrs ( def_id, sym:: target_feature) {
788
- from_target_feature ( tcx, attr, supported_features, & mut features) ;
796
+ from_target_feature ( tcx, attr, supported_features, & mut features, None ) ;
789
797
}
790
798
tcx. arena . alloc_slice ( & features)
791
799
}
0 commit comments