@@ -3,7 +3,7 @@ use crate::errors;
33/// Ideally, this code would be in libtest but for efficiency and error messages it lives here.
44use crate :: util:: { check_builtin_macro_attribute, warn_on_duplicate_attribute} ;
55use rustc_ast:: ptr:: P ;
6- use rustc_ast:: { self as ast, attr} ;
6+ use rustc_ast:: { self as ast, attr, GenericParamKind } ;
77use rustc_ast_pretty:: pprust;
88use rustc_errors:: Applicability ;
99use rustc_expand:: base:: * ;
@@ -550,24 +550,21 @@ fn has_test_signature(cx: &ExtCtxt<'_>, i: &ast::Item) -> bool {
550550 return false ;
551551 }
552552
553- match ( has_output, has_should_panic_attr) {
554- ( true , true ) => {
555- sd. span_err ( i. span , "functions using `#[should_panic]` must return `()`" ) ;
556- false
557- }
558- ( true , false ) => {
559- if !generics. params . is_empty ( ) {
560- sd. span_err (
561- i. span ,
562- "functions used as tests must have signature fn() -> ()" ,
563- ) ;
564- false
565- } else {
566- true
567- }
568- }
569- ( false , _) => true ,
553+ if has_should_panic_attr && has_output {
554+ sd. span_err ( i. span , "functions using `#[should_panic]` must return `()`" ) ;
555+ return false ;
570556 }
557+
558+ if generics. params . iter ( ) . any ( |param| !matches ! ( param. kind, GenericParamKind :: Lifetime ) )
559+ {
560+ sd. span_err (
561+ i. span ,
562+ "functions used as tests can not have any non-lifetime generic parameters" ,
563+ ) ;
564+ return false ;
565+ }
566+
567+ true
571568 }
572569 _ => {
573570 // should be unreachable because `is_test_fn_item` should catch all non-fn items
0 commit comments