@@ -297,7 +297,6 @@ impl<'a> FnInputCtx<'a> {
297297 let members = Member :: from_raw ( & self . config , MemberOrigin :: FnArg , members) ?;
298298
299299 let generics = self . generics ( ) ;
300-
301300 let mut adapted_fn_sig = self . adapted_fn ( ) ?. sig ;
302301
303302 if self . config . start_fn . name . is_none ( ) {
@@ -342,7 +341,7 @@ impl<'a> FnInputCtx<'a> {
342341 vis : finish_fn_vis. map ( SpannedKey :: into_value) ,
343342 unsafety : self . fn_item . norm . sig . unsafety ,
344343 asyncness : self . fn_item . norm . sig . asyncness ,
345- must_use : get_must_use_attribute ( & self . fn_item . norm . attrs ) ?,
344+ special_attrs : get_propagated_attrs ( & self . fn_item . norm . attrs ) ?,
346345 body : Box :: new ( finish_fn_body) ,
347346 output : self . fn_item . norm . sig . output ,
348347 attrs : finish_fn_docs,
@@ -486,26 +485,38 @@ fn merge_generic_params(
486485 . collect ( )
487486}
488487
489- fn get_must_use_attribute ( attrs : & [ syn:: Attribute ] ) -> Result < Option < syn:: Attribute > > {
488+ const PROPAGATED_ATTRIBUTES : & [ & str ] = & [ "must_use" , "track_caller" ] ;
489+
490+ fn get_propagated_attrs ( attrs : & [ syn:: Attribute ] ) -> Result < Vec < syn:: Attribute > > {
491+ PROPAGATED_ATTRIBUTES
492+ . iter ( )
493+ . copied ( )
494+ . filter_map ( |needle| find_propagated_attr ( attrs, needle) . transpose ( ) )
495+ . collect ( )
496+ }
497+
498+ fn find_propagated_attr ( attrs : & [ syn:: Attribute ] , needle : & str ) -> Result < Option < syn:: Attribute > > {
490499 let mut iter = attrs
491500 . iter ( )
492- . filter ( |attr| attr. meta . path ( ) . is_ident ( "must_use" ) ) ;
501+ . filter ( |attr| attr. meta . path ( ) . is_ident ( needle ) ) ;
493502
494503 let result = iter. next ( ) ;
495504
496505 if let Some ( second) = iter. next ( ) {
497506 bail ! (
498507 second,
499- "found multiple #[must_use], but bon only works with exactly one or zero."
508+ "found multiple #[{}], but bon only works with exactly one or zero." ,
509+ needle
500510 ) ;
501511 }
502512
503513 if let Some ( attr) = result {
504514 if let syn:: AttrStyle :: Inner ( _) = attr. style {
505515 bail ! (
506516 attr,
507- "#[must_use] attribute must be placed on the function itself, \
508- not inside it."
517+ "#[{}] attribute must be placed on the function itself, \
518+ not inside it.",
519+ needle
509520 ) ;
510521 }
511522 }
0 commit comments