@@ -29,6 +29,20 @@ pub fn simd_test(_: TokenStream, item: TokenStream) -> TokenStream {
2929 . filter ( |attr| !attr. path ( ) . is_ident ( "simd_test" ) )
3030 . collect ( ) ;
3131
32+ // If this is a `#[should_panic]` test, run it with the fallback so it actually panics
33+ let should_panic_attr = input_fn
34+ . attrs
35+ . iter ( )
36+ . find ( |attr| attr. path ( ) . is_ident ( "should_panic" ) ) ;
37+ let panic_else = if should_panic_attr. is_some ( ) {
38+ quote ! {
39+ let fallback = fearless_simd:: Fallback :: new( ) ;
40+ #input_fn_name( fallback) ;
41+ }
42+ } else {
43+ quote ! { }
44+ } ;
45+
3246 let fallback_snippet = quote ! {
3347 #( #test_attrs) *
3448 #[ test]
@@ -47,6 +61,9 @@ pub fn simd_test(_: TokenStream, item: TokenStream) -> TokenStream {
4761 // target features aren't supported. This is not ideal, since it may mislead you into thinking tests have passed
4862 // when they haven't even been run, but some CI runners don't support all target features and we don't want failures
4963 // as a result of that.
64+ //
65+ // However, for #[should_panic] tests, we need to panic if features aren't available to avoid
66+ // "test did not panic as expected" failures.
5067
5168 let neon_snippet = quote ! {
5269 #[ cfg( target_arch = "aarch64" ) ]
@@ -56,6 +73,8 @@ pub fn simd_test(_: TokenStream, item: TokenStream) -> TokenStream {
5673 if std:: arch:: is_aarch64_feature_detected!( "neon" ) {
5774 let neon = unsafe { fearless_simd:: aarch64:: Neon :: new_unchecked( ) } ;
5875 #input_fn_name( neon) ;
76+ } else {
77+ #panic_else
5978 }
6079 }
6180 } ;
@@ -68,6 +87,8 @@ pub fn simd_test(_: TokenStream, item: TokenStream) -> TokenStream {
6887 if std:: arch:: is_x86_feature_detected!( "sse4.2" ) {
6988 let sse4 = unsafe { fearless_simd:: x86:: Sse4_2 :: new_unchecked( ) } ;
7089 #input_fn_name( sse4) ;
90+ } else {
91+ #panic_else
7192 }
7293 }
7394 } ;
@@ -82,6 +103,8 @@ pub fn simd_test(_: TokenStream, item: TokenStream) -> TokenStream {
82103 {
83104 let avx2 = unsafe { fearless_simd:: x86:: Avx2 :: new_unchecked( ) } ;
84105 #input_fn_name( avx2) ;
106+ } else {
107+ #panic_else
85108 }
86109 }
87110 } ;
0 commit comments