@@ -2588,30 +2588,22 @@ fn simd_ffi_feature_check(
25882588 }
25892589}
25902590
2591- fn simd_ffi_check < ' tcx > (
2592- tcx : TyCtxt < ' tcx > ,
2593- def_id : DefId ,
2594- ast_ty : & hir:: Ty < ' _ > ,
2595- ty : Ty < ' tcx > ,
2596- ) {
2591+ fn simd_ffi_check < ' tcx > ( tcx : TyCtxt < ' tcx > , def_id : DefId , ast_ty : & hir:: Ty < ' _ > , ty : Ty < ' tcx > ) {
25972592 if !ty. is_simd ( ) {
25982593 return ;
25992594 }
26002595
26012596 // The use of SIMD types in FFI is feature-gated:
26022597 if !tcx. features ( ) . simd_ffi {
26032598 let snip = tcx
2604- . sess
2605- . source_map ( )
2606- . span_to_snippet ( ast_ty. span )
2607- . map_or_else ( |_| String :: new ( ) , |s| format ! ( "{}" , s) ) ;
2599+ . sess
2600+ . source_map ( )
2601+ . span_to_snippet ( ast_ty. span )
2602+ . map_or_else ( |_| String :: new ( ) , |s| format ! ( "{}" , s) ) ;
26082603 tcx. sess
26092604 . struct_span_err (
26102605 ast_ty. span ,
2611- & format ! (
2612- "use of SIMD type `{}` in FFI is unstable" ,
2613- snip
2614- ) ,
2606+ & format ! ( "use of SIMD type `{}` in FFI is unstable" , snip) ,
26152607 )
26162608 . help ( "add `#![feature(simd_ffi)]` to the crate attributes to enable" )
26172609 . emit ( ) ;
@@ -2646,12 +2638,14 @@ fn simd_ffi_check<'tcx>(
26462638 let target: & str = & tcx. sess . target . arch ;
26472639
26482640 for f in features {
2649- if let Err ( v) = simd_ffi_feature_check ( target, simd_len, simd_elem_width, f. to_ident_string ( ) ) {
2641+ if let Err ( v) =
2642+ simd_ffi_feature_check ( target, simd_len, simd_elem_width, f. to_ident_string ( ) )
2643+ {
26502644 let type_str = tcx
2651- . sess
2652- . source_map ( )
2653- . span_to_snippet ( ast_ty. span )
2654- . map_or_else ( |_| String :: new ( ) , |s| format ! ( "{}" , s) ) ;
2645+ . sess
2646+ . source_map ( )
2647+ . span_to_snippet ( ast_ty. span )
2648+ . map_or_else ( |_| String :: new ( ) , |s| format ! ( "{}" , s) ) ;
26552649 let msg = if let Some ( f) = v {
26562650 format ! (
26572651 "use of SIMD type `{}` in FFI requires `#[target_feature(enable = \" {}\" )]`" ,
@@ -2952,7 +2946,10 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
29522946 codegen_fn_attrs. export_name = Some ( s) ;
29532947 }
29542948 } else if tcx. sess . check_name ( attr, sym:: target_feature) {
2955- if !tcx. is_closure ( id) && tcx. fn_sig ( id) . unsafety ( ) == hir:: Unsafety :: Normal {
2949+ if !tcx. is_closure ( id)
2950+ && !tcx. is_foreign_item ( id)
2951+ && tcx. fn_sig ( id) . unsafety ( ) == hir:: Unsafety :: Normal
2952+ {
29562953 if tcx. sess . target . is_like_wasm || tcx. sess . opts . actually_rustdoc {
29572954 // The `#[target_feature]` attribute is allowed on
29582955 // WebAssembly targets on all functions, including safe
0 commit comments