@@ -267,7 +267,12 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
267267 && let Some ( fn_sig) = fn_sig ( )
268268 && fn_sig. skip_binder ( ) . safety ( ) == hir:: Safety :: Safe
269269 {
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 {
271276 // The `#[target_feature]` attribute is allowed on
272277 // WebAssembly targets on all functions, including safe
273278 // ones. Other targets require that `#[target_feature]` is
@@ -306,6 +311,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
306311 attr,
307312 supported_target_features,
308313 & mut codegen_fn_attrs. target_features ,
314+ Some ( & mut codegen_fn_attrs. target_features_from_args ) ,
309315 ) ;
310316 }
311317 sym:: linkage => {
@@ -616,7 +622,9 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
616622 }
617623 }
618624
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+ {
620628 let mut additional_tf = vec ! [ ] ;
621629 for ty in sig. skip_binder ( ) . inputs ( ) . skip_binder ( ) {
622630 extend_with_struct_target_features (
@@ -785,7 +793,7 @@ fn struct_target_features(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &[TargetFeatur
785793 let mut features = vec ! [ ] ;
786794 let supported_features = tcx. supported_target_features ( LOCAL_CRATE ) ;
787795 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 ) ;
789797 }
790798 tcx. arena . alloc_slice ( & features)
791799}
0 commit comments