11use crate :: {
22 AssistConfig ,
33 assist_context:: { AssistContext , Assists } ,
4- utils:: add_cfg_attrs_to,
54} ;
65use hir:: { HasCrate , Semantics } ;
76use ide_db:: {
@@ -13,8 +12,8 @@ use ide_db::{
1312use syntax:: {
1413 AstNode ,
1514 ast:: {
16- self , AssocItem , BlockExpr , GenericParam , HasGenericParams , HasName , HasTypeBounds ,
17- HasVisibility , edit_in_place:: Indent , make,
15+ self , AssocItem , BlockExpr , GenericParam , HasAttrs , HasGenericParams , HasName ,
16+ HasTypeBounds , HasVisibility , edit_in_place:: Indent , make,
1817 } ,
1918 syntax_editor:: Position ,
2019} ;
@@ -96,6 +95,7 @@ pub(crate) fn generate_blanket_trait_impl(
9695 }
9796
9897 let impl_ = make:: impl_trait (
98+ cfg_attrs ( & traitd) ,
9999 is_unsafe,
100100 traitd. generic_param_list ( ) ,
101101 trait_gen_args,
@@ -120,14 +120,11 @@ pub(crate) fn generate_blanket_trait_impl(
120120 continue ;
121121 }
122122 let f = todo_fn ( & method, ctx. config ) . clone_for_update ( ) ;
123- add_cfg_attrs_to ( & method, & f) ;
124123 f. indent ( 1 . into ( ) ) ;
125124 assoc_item_list. add_item ( AssocItem :: Fn ( f) ) ;
126125 }
127126 }
128127
129- add_cfg_attrs_to ( & traitd, & impl_) ;
130-
131128 impl_. indent ( indent) ;
132129
133130 edit. insert_all (
@@ -138,10 +135,10 @@ pub(crate) fn generate_blanket_trait_impl(
138135 ] ,
139136 ) ;
140137
141- if let Some ( cap) = ctx. config . snippet_cap {
142- if let Some ( self_ty) = impl_. self_ty ( ) {
143- builder . add_tabstop_before ( cap , self_ty ) ;
144- }
138+ if let Some ( cap) = ctx. config . snippet_cap
139+ && let Some ( self_ty) = impl_. self_ty ( )
140+ {
141+ builder . add_tabstop_before ( cap , self_ty ) ;
145142 }
146143
147144 builder. add_file_edits ( ctx. vfs_file_id ( ) , edit) ;
@@ -271,6 +268,7 @@ fn ty_bound_is(bound: &ast::TypeBound, s: &str) -> bool {
271268fn todo_fn ( f : & ast:: Fn , config : & AssistConfig ) -> ast:: Fn {
272269 let params = f. param_list ( ) . unwrap_or_else ( || make:: param_list ( None , None ) ) ;
273270 make:: fn_ (
271+ cfg_attrs ( f) ,
274272 f. visibility ( ) ,
275273 f. name ( ) . unwrap_or_else ( || make:: name ( "unnamed" ) ) ,
276274 f. generic_param_list ( ) ,
@@ -294,6 +292,10 @@ fn default_block(config: &AssistConfig) -> BlockExpr {
294292 make:: block_expr ( None , Some ( expr) )
295293}
296294
295+ fn cfg_attrs ( node : & impl HasAttrs ) -> impl Iterator < Item = ast:: Attr > {
296+ node. attrs ( ) . filter ( |attr| attr. as_simple_call ( ) . is_some_and ( |( name, _arg) | name == "cfg" ) )
297+ }
298+
297299#[ cfg( test) ]
298300mod test {
299301
0 commit comments