@@ -9,6 +9,7 @@ use rustc_ast_pretty::pprust;
99use rustc_attr_parsing:: AttributeParser ;
1010use rustc_errors:: { Applicability , Diag , Level } ;
1111use rustc_expand:: base:: * ;
12+ use rustc_expand:: config:: attr_into_trace;
1213use rustc_hir:: Attribute ;
1314use rustc_hir:: attrs:: AttributeKind ;
1415use rustc_span:: { ErrorGuaranteed , Ident , RemapPathScopeComponents , Span , Symbol , sym} ;
@@ -113,7 +114,7 @@ pub(crate) fn expand_test_or_bench(
113114 item : Annotatable ,
114115 is_bench : bool ,
115116) -> Vec < Annotatable > {
116- let ( item, is_stmt) = match item {
117+ let ( mut item, is_stmt) = match item {
117118 Annotatable :: Item ( i) => ( i, false ) ,
118119 Annotatable :: Stmt ( box ast:: Stmt { kind : ast:: StmtKind :: Item ( i) , .. } ) => ( i, true ) ,
119120 other => {
@@ -136,6 +137,14 @@ pub(crate) fn expand_test_or_bench(
136137 return vec ! [ ] ;
137138 }
138139
140+ // Add a trace to the originating test function, so that we can
141+ // check if attributes that have `#[test]` or `#[bench]` as a requirement
142+ // actually are annotated with said attributes
143+ item. attrs . push ( attr_into_trace (
144+ cx. attr_word ( sym:: test_trace, cx. with_def_site_ctxt ( attr_sp) ) ,
145+ sym:: test_trace,
146+ ) ) ;
147+
139148 if let Some ( attr) = attr:: find_by_name ( & item. attrs , sym:: naked) {
140149 cx. dcx ( ) . emit_err ( errors:: NakedFunctionTestingAttribute {
141150 testing_span : attr_sp,
0 commit comments