@@ -250,7 +250,12 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
250
250
&& let Some ( fn_sig) = fn_sig ( )
251
251
&& fn_sig. skip_binder ( ) . safety ( ) == hir:: Safety :: Safe
252
252
{
253
- if tcx. sess . target . is_like_wasm || tcx. sess . opts . actually_rustdoc {
253
+ if attr. meta_item_list ( ) . is_some_and ( |list| {
254
+ list. len ( ) == 1 && list[ 0 ] . ident ( ) . is_some_and ( |x| x. name == sym:: from_args)
255
+ } ) {
256
+ // #[target_feature(from_args)] can be applied to safe functions and safe
257
+ // trait methods.
258
+ } else if tcx. sess . target . is_like_wasm || tcx. sess . opts . actually_rustdoc {
254
259
// The `#[target_feature]` attribute is allowed on
255
260
// WebAssembly targets on all functions, including safe
256
261
// ones. Other targets require that `#[target_feature]` is
@@ -289,6 +294,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
289
294
attr,
290
295
supported_target_features,
291
296
& mut codegen_fn_attrs. target_features ,
297
+ Some ( & mut codegen_fn_attrs. target_features_from_args ) ,
292
298
) ;
293
299
}
294
300
sym:: linkage => {
@@ -599,7 +605,9 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
599
605
}
600
606
}
601
607
602
- if let Some ( sig) = fn_sig_outer ( ) {
608
+ if let Some ( sig) = fn_sig_outer ( )
609
+ && codegen_fn_attrs. target_features_from_args
610
+ {
603
611
let mut additional_tf = vec ! [ ] ;
604
612
for ty in sig. skip_binder ( ) . inputs ( ) . skip_binder ( ) {
605
613
extend_with_struct_target_features (
@@ -806,7 +814,7 @@ fn struct_target_features(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &[TargetFeatur
806
814
let mut features = vec ! [ ] ;
807
815
let supported_features = tcx. supported_target_features ( LOCAL_CRATE ) ;
808
816
for attr in tcx. get_attrs ( def_id, sym:: target_feature) {
809
- from_target_feature ( tcx, attr, supported_features, & mut features) ;
817
+ from_target_feature ( tcx, attr, supported_features, & mut features, None ) ;
810
818
}
811
819
tcx. arena . alloc_slice ( & features)
812
820
}
0 commit comments