@@ -15,7 +15,6 @@ use ide_db::{
1515 syntax_helpers:: { node_ext:: preorder_expr, prettify_macro_expansion} ,
1616} ;
1717use itertools:: Itertools ;
18- use stdx:: format_to;
1918use syntax:: {
2019 AstNode , AstToken , Direction , NodeOrToken , SourceFile ,
2120 SyntaxKind :: * ,
@@ -530,102 +529,6 @@ fn has_any_fn(imp: &ast::Impl, names: &[String]) -> bool {
530529 false
531530}
532531
533- /// Find the end of the `impl` block for the given `ast::Impl`.
534- //
535- // FIXME: this partially overlaps with `find_struct_impl`
536- pub ( crate ) fn find_impl_block_end ( impl_def : ast:: Impl , buf : & mut String ) -> Option < TextSize > {
537- buf. push ( '\n' ) ;
538- let end = impl_def
539- . assoc_item_list ( )
540- . and_then ( |it| it. r_curly_token ( ) ) ?
541- . prev_sibling_or_token ( ) ?
542- . text_range ( )
543- . end ( ) ;
544- Some ( end)
545- }
546-
547- /// Generates the surrounding `impl Type { <code> }` including type and lifetime
548- /// parameters.
549- // FIXME: migrate remaining uses to `generate_impl`
550- pub ( crate ) fn generate_impl_text ( adt : & ast:: Adt , code : & str ) -> String {
551- generate_impl_text_inner ( adt, None , true , code)
552- }
553-
554- fn generate_impl_text_inner (
555- adt : & ast:: Adt ,
556- trait_text : Option < & str > ,
557- trait_is_transitive : bool ,
558- code : & str ,
559- ) -> String {
560- // Ensure lifetime params are before type & const params
561- let generic_params = adt. generic_param_list ( ) . map ( |generic_params| {
562- let lifetime_params =
563- generic_params. lifetime_params ( ) . map ( ast:: GenericParam :: LifetimeParam ) ;
564- let ty_or_const_params = generic_params. type_or_const_params ( ) . filter_map ( |param| {
565- let param = match param {
566- ast:: TypeOrConstParam :: Type ( param) => {
567- // remove defaults since they can't be specified in impls
568- let mut bounds =
569- param. type_bound_list ( ) . map_or_else ( Vec :: new, |it| it. bounds ( ) . collect ( ) ) ;
570- if let Some ( trait_) = trait_text {
571- // Add the current trait to `bounds` if the trait is transitive,
572- // meaning `impl<T> Trait for U<T>` requires `T: Trait`.
573- if trait_is_transitive {
574- bounds. push ( make:: type_bound_text ( trait_) ) ;
575- }
576- } ;
577- // `{ty_param}: {bounds}`
578- let param = make:: type_param ( param. name ( ) ?, make:: type_bound_list ( bounds) ) ;
579- ast:: GenericParam :: TypeParam ( param)
580- }
581- ast:: TypeOrConstParam :: Const ( param) => {
582- // remove defaults since they can't be specified in impls
583- let param = make:: const_param ( param. name ( ) ?, param. ty ( ) ?) ;
584- ast:: GenericParam :: ConstParam ( param)
585- }
586- } ;
587- Some ( param)
588- } ) ;
589-
590- make:: generic_param_list ( itertools:: chain ( lifetime_params, ty_or_const_params) )
591- } ) ;
592-
593- // FIXME: use syntax::make & mutable AST apis instead
594- // `trait_text` and `code` can't be opaque blobs of text
595- let mut buf = String :: with_capacity ( code. len ( ) ) ;
596-
597- // Copy any cfg attrs from the original adt
598- buf. push_str ( "\n \n " ) ;
599- let cfg_attrs = adt. attrs ( ) . filter ( |attr| matches ! ( attr. meta( ) , Some ( ast:: Meta :: CfgMeta ( _) ) ) ) ;
600- cfg_attrs. for_each ( |attr| buf. push_str ( & format ! ( "{attr}\n " ) ) ) ;
601-
602- // `impl{generic_params} {trait_text} for {name}{generic_params.to_generic_args()}`
603- buf. push_str ( "impl" ) ;
604- if let Some ( generic_params) = & generic_params {
605- format_to ! ( buf, "{generic_params}" ) ;
606- }
607- buf. push ( ' ' ) ;
608- if let Some ( trait_text) = trait_text {
609- buf. push_str ( trait_text) ;
610- buf. push_str ( " for " ) ;
611- }
612- buf. push_str ( & adt. name ( ) . unwrap ( ) . text ( ) ) ;
613- if let Some ( generic_params) = generic_params {
614- format_to ! ( buf, "{}" , generic_params. to_generic_args( ) ) ;
615- }
616-
617- match adt. where_clause ( ) {
618- Some ( where_clause) => {
619- format_to ! ( buf, "\n {where_clause}\n {{\n {code}\n }}" ) ;
620- }
621- None => {
622- format_to ! ( buf, " {{\n {code}\n }}" ) ;
623- }
624- }
625-
626- buf
627- }
628-
629532/// Generates the corresponding `impl Type {}` including type and lifetime
630533/// parameters.
631534pub ( crate ) fn generate_impl_with_item (
@@ -917,28 +820,6 @@ fn generic_param_associated_bounds_with_factory(
917820 trait_where_clause. peek ( ) . is_some ( ) . then ( || make. where_clause ( trait_where_clause) )
918821}
919822
920- pub ( crate ) fn add_method_to_adt (
921- builder : & mut SourceChangeBuilder ,
922- adt : & ast:: Adt ,
923- impl_def : Option < ast:: Impl > ,
924- method : & str ,
925- ) {
926- let mut buf = String :: with_capacity ( method. len ( ) + 2 ) ;
927- if impl_def. is_some ( ) {
928- buf. push ( '\n' ) ;
929- }
930- buf. push_str ( method) ;
931-
932- let start_offset = impl_def
933- . and_then ( |impl_def| find_impl_block_end ( impl_def, & mut buf) )
934- . unwrap_or_else ( || {
935- buf = generate_impl_text ( adt, & buf) ;
936- adt. syntax ( ) . text_range ( ) . end ( )
937- } ) ;
938-
939- builder. insert ( start_offset, buf) ;
940- }
941-
942823#[ derive( Debug ) ]
943824pub ( crate ) struct ReferenceConversion < ' db > {
944825 conversion : ReferenceConversionType ,
0 commit comments