@@ -64,6 +64,16 @@ impl Context<'_> {
6464type Supertraits = Punctuated < TypeParamBound , Token ! [ +] > ;
6565
6666pub fn expand ( input : & mut Item , is_local : bool ) {
67+ let inner_method_attrs = & [
68+ parse_quote ! ( #[ allow( clippy:: used_underscore_binding) ] ) ,
69+ parse_quote ! ( #[ allow( clippy:: type_repetition_in_bounds) ] ) ,
70+ ] ;
71+
72+ let trait_method_attrs = & [
73+ parse_quote ! ( #[ must_use] ) ,
74+ parse_quote ! ( #[ allow( clippy:: type_repetition_in_bounds) ] ) ,
75+ ] ;
76+
6777 match input {
6878 Item :: Trait ( input) => {
6979 let context = Context :: Trait {
@@ -79,13 +89,11 @@ pub fn expand(input: &mut Item, is_local: bool) {
7989 if let Some ( block) = block {
8090 has_self |= has_self_in_block ( block) ;
8191 transform_block ( sig, block) ;
82- method
83- . attrs
84- . push ( parse_quote ! ( #[ allow( clippy:: used_underscore_binding) ] ) ) ;
92+ method. attrs . extend_from_slice ( inner_method_attrs) ;
8593 }
8694 let has_default = method. default . is_some ( ) ;
8795 transform_sig ( context, sig, has_self, has_default, is_local) ;
88- method. attrs . push ( parse_quote ! ( # [ must_use ] ) ) ;
96+ method. attrs . extend_from_slice ( trait_method_attrs ) ;
8997 }
9098 }
9199 }
@@ -109,9 +117,7 @@ pub fn expand(input: &mut Item, is_local: bool) {
109117 let has_self = has_self_in_sig ( sig) || has_self_in_block ( block) ;
110118 transform_block ( sig, block) ;
111119 transform_sig ( context, sig, has_self, false , is_local) ;
112- method
113- . attrs
114- . push ( parse_quote ! ( #[ allow( clippy:: used_underscore_binding) ] ) ) ;
120+ method. attrs . extend_from_slice ( inner_method_attrs) ;
115121 }
116122 }
117123 }
@@ -192,13 +198,16 @@ fn transform_sig(
192198
193199 push_param ( & mut sig. generics , parse_quote_spanned ! ( default_span => ' async_trait) ) ;
194200
201+ let first_bound = where_clause_or_default ( & mut sig. generics . where_clause ) . predicates . first ( ) ;
202+ let bound_span = first_bound. map_or ( default_span, Spanned :: span) ;
203+
195204 if has_self {
196205 let bound: Ident = match sig. inputs . iter ( ) . next ( ) {
197206 Some ( FnArg :: Receiver ( Receiver {
198207 reference : Some ( _) ,
199208 mutability : None ,
200209 ..
201- } ) ) => parse_quote ! ( Sync ) ,
210+ } ) ) => parse_quote_spanned ! ( bound_span => Sync ) ,
202211 Some ( FnArg :: Typed ( arg) )
203212 if match ( arg. pat . as_ref ( ) , arg. ty . as_ref ( ) ) {
204213 ( Pat :: Ident ( pat) , Type :: Reference ( ty) ) => {
@@ -207,19 +216,21 @@ fn transform_sig(
207216 _ => false ,
208217 } =>
209218 {
210- parse_quote ! ( Sync )
219+ parse_quote_spanned ! ( bound_span => Sync )
211220 }
212- _ => parse_quote ! ( Send ) ,
221+ _ => parse_quote_spanned ! ( bound_span => Send ) ,
213222 } ;
223+
214224 let assume_bound = match context {
215225 Context :: Trait { supertraits, .. } => !has_default || has_bound ( supertraits, & bound) ,
216226 Context :: Impl { .. } => true ,
217227 } ;
228+
218229 let where_clause = where_clause_or_default ( & mut sig. generics . where_clause ) ;
219230 where_clause. predicates . push ( if assume_bound || is_local {
220- parse_quote_spanned ! ( where_clause . span ( ) => Self : ' async_trait)
231+ parse_quote_spanned ! ( bound_span => Self : ' async_trait)
221232 } else {
222- parse_quote_spanned ! ( where_clause . span ( ) => Self : :: core:: marker:: #bound + ' async_trait)
233+ parse_quote_spanned ! ( bound_span => Self : :: core:: marker:: #bound + ' async_trait)
223234 } ) ;
224235 }
225236
0 commit comments