@@ -250,7 +250,12 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
250250 && let Some ( fn_sig) = fn_sig ( )
251251 && fn_sig. skip_binder ( ) . safety ( ) == hir:: Safety :: Safe
252252 {
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 {
254259 // The `#[target_feature]` attribute is allowed on
255260 // WebAssembly targets on all functions, including safe
256261 // ones. Other targets require that `#[target_feature]` is
@@ -289,6 +294,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
289294 attr,
290295 supported_target_features,
291296 & mut codegen_fn_attrs. target_features ,
297+ Some ( & mut codegen_fn_attrs. target_features_from_args ) ,
292298 ) ;
293299 }
294300 sym:: linkage => {
@@ -599,7 +605,9 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
599605 }
600606 }
601607
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+ {
603611 let mut additional_tf = vec ! [ ] ;
604612 for ty in sig. skip_binder ( ) . inputs ( ) . skip_binder ( ) {
605613 extend_with_struct_target_features (
@@ -806,7 +814,7 @@ fn struct_target_features(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &[TargetFeatur
806814 let mut features = vec ! [ ] ;
807815 let supported_features = tcx. supported_target_features ( LOCAL_CRATE ) ;
808816 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 ) ;
810818 }
811819 tcx. arena . alloc_slice ( & features)
812820}
0 commit comments