@@ -9,11 +9,11 @@ use crate::{
9
9
SyntaxKind :: { ATTR , COMMENT , WHITESPACE } ,
10
10
SyntaxNode , SyntaxToken ,
11
11
algo:: { self , neighbor} ,
12
- ast:: { self , HasGenericArgs , HasGenericParams , edit:: IndentLevel , make} ,
12
+ ast:: { self , HasGenericParams , edit:: IndentLevel , make} ,
13
13
ted:: { self , Position } ,
14
14
} ;
15
15
16
- use super :: { GenericParam , HasArgList , HasName } ;
16
+ use super :: { GenericParam , HasName } ;
17
17
18
18
pub trait GenericParamsOwnerEdit : ast:: HasGenericParams {
19
19
fn get_or_create_generic_param_list ( & self ) -> ast:: GenericParamList ;
@@ -419,34 +419,6 @@ impl Removable for ast::TypeBoundList {
419
419
}
420
420
}
421
421
422
- impl ast:: PathSegment {
423
- pub fn get_or_create_generic_arg_list ( & self ) -> ast:: GenericArgList {
424
- if self . generic_arg_list ( ) . is_none ( ) {
425
- let arg_list = make:: generic_arg_list ( empty ( ) ) . clone_for_update ( ) ;
426
- ted:: append_child ( self . syntax ( ) , arg_list. syntax ( ) ) ;
427
- }
428
- self . generic_arg_list ( ) . unwrap ( )
429
- }
430
- }
431
-
432
- impl ast:: MethodCallExpr {
433
- pub fn get_or_create_generic_arg_list ( & self ) -> ast:: GenericArgList {
434
- if self . generic_arg_list ( ) . is_none ( ) {
435
- let generic_arg_list = make:: turbofish_generic_arg_list ( empty ( ) ) . clone_for_update ( ) ;
436
-
437
- if let Some ( arg_list) = self . arg_list ( ) {
438
- ted:: insert_raw (
439
- ted:: Position :: before ( arg_list. syntax ( ) ) ,
440
- generic_arg_list. syntax ( ) ,
441
- ) ;
442
- } else {
443
- ted:: append_child ( self . syntax ( ) , generic_arg_list. syntax ( ) ) ;
444
- }
445
- }
446
- self . generic_arg_list ( ) . unwrap ( )
447
- }
448
- }
449
-
450
422
impl Removable for ast:: UseTree {
451
423
fn remove ( & self ) {
452
424
for dir in [ Direction :: Next , Direction :: Prev ] {
@@ -677,106 +649,6 @@ impl ast::AssocItemList {
677
649
] ;
678
650
ted:: insert_all ( position, elements) ;
679
651
}
680
-
681
- /// Adds a new associated item at the start of the associated item list.
682
- ///
683
- /// Attention! This function does align the first line of `item` with respect to `self`,
684
- /// but it does _not_ change indentation of other lines (if any).
685
- pub fn add_item_at_start ( & self , item : ast:: AssocItem ) {
686
- match self . assoc_items ( ) . next ( ) {
687
- Some ( first_item) => {
688
- let indent = IndentLevel :: from_node ( first_item. syntax ( ) ) ;
689
- let before = Position :: before ( first_item. syntax ( ) ) ;
690
-
691
- ted:: insert_all (
692
- before,
693
- vec ! [
694
- item. syntax( ) . clone( ) . into( ) ,
695
- make:: tokens:: whitespace( & format!( "\n \n {indent}" ) ) . into( ) ,
696
- ] ,
697
- )
698
- }
699
- None => {
700
- let ( indent, position, whitespace) = match self . l_curly_token ( ) {
701
- Some ( l_curly) => {
702
- normalize_ws_between_braces ( self . syntax ( ) ) ;
703
- ( IndentLevel :: from_token ( & l_curly) + 1 , Position :: after ( & l_curly) , "\n " )
704
- }
705
- None => ( IndentLevel :: single ( ) , Position :: first_child_of ( self . syntax ( ) ) , "" ) ,
706
- } ;
707
-
708
- let mut elements = vec ! [ ] ;
709
-
710
- // Avoid pushing an empty whitespace token
711
- if !indent. is_zero ( ) || !whitespace. is_empty ( ) {
712
- elements. push ( make:: tokens:: whitespace ( & format ! ( "{whitespace}{indent}" ) ) . into ( ) )
713
- }
714
- elements. push ( item. syntax ( ) . clone ( ) . into ( ) ) ;
715
-
716
- ted:: insert_all ( position, elements)
717
- }
718
- } ;
719
- }
720
- }
721
-
722
- impl ast:: Fn {
723
- pub fn get_or_create_body ( & self ) -> ast:: BlockExpr {
724
- if self . body ( ) . is_none ( ) {
725
- let body = make:: ext:: empty_block_expr ( ) . clone_for_update ( ) ;
726
- match self . semicolon_token ( ) {
727
- Some ( semi) => {
728
- ted:: replace ( semi, body. syntax ( ) ) ;
729
- ted:: insert ( Position :: before ( body. syntax ) , make:: tokens:: single_space ( ) ) ;
730
- }
731
- None => ted:: append_child ( self . syntax ( ) , body. syntax ( ) ) ,
732
- }
733
- }
734
- self . body ( ) . unwrap ( )
735
- }
736
- }
737
-
738
- impl ast:: LetStmt {
739
- pub fn set_ty ( & self , ty : Option < ast:: Type > ) {
740
- match ty {
741
- None => {
742
- if let Some ( colon_token) = self . colon_token ( ) {
743
- ted:: remove ( colon_token) ;
744
- }
745
-
746
- if let Some ( existing_ty) = self . ty ( ) {
747
- if let Some ( sibling) = existing_ty. syntax ( ) . prev_sibling_or_token ( )
748
- && sibling. kind ( ) == SyntaxKind :: WHITESPACE
749
- {
750
- ted:: remove ( sibling) ;
751
- }
752
-
753
- ted:: remove ( existing_ty. syntax ( ) ) ;
754
- }
755
-
756
- // Remove any trailing ws
757
- if let Some ( last) = self . syntax ( ) . last_token ( ) . filter ( |it| it. kind ( ) == WHITESPACE )
758
- {
759
- last. detach ( ) ;
760
- }
761
- }
762
- Some ( new_ty) => {
763
- if self . colon_token ( ) . is_none ( ) {
764
- ted:: insert_raw (
765
- Position :: after (
766
- self . pat ( ) . expect ( "let stmt should have a pattern" ) . syntax ( ) ,
767
- ) ,
768
- make:: token ( T ! [ : ] ) ,
769
- ) ;
770
- }
771
-
772
- if let Some ( old_ty) = self . ty ( ) {
773
- ted:: replace ( old_ty. syntax ( ) , new_ty. syntax ( ) ) ;
774
- } else {
775
- ted:: insert ( Position :: after ( self . colon_token ( ) . unwrap ( ) ) , new_ty. syntax ( ) ) ;
776
- }
777
- }
778
- }
779
- }
780
652
}
781
653
782
654
impl ast:: RecordExprFieldList {
@@ -1091,35 +963,4 @@ mod tests {
1091
963
check ( "let a @ ()" , "let a" , None ) ;
1092
964
check ( "let a @ " , "let a" , None ) ;
1093
965
}
1094
-
1095
- #[ test]
1096
- fn test_let_stmt_set_ty ( ) {
1097
- #[ track_caller]
1098
- fn check ( before : & str , expected : & str , ty : Option < ast:: Type > ) {
1099
- let ty = ty. map ( |it| it. clone_for_update ( ) ) ;
1100
-
1101
- let let_stmt = ast_mut_from_text :: < ast:: LetStmt > ( & format ! ( "fn f() {{ {before} }}" ) ) ;
1102
- let_stmt. set_ty ( ty) ;
1103
-
1104
- let after = ast_mut_from_text :: < ast:: LetStmt > ( & format ! ( "fn f() {{ {expected} }}" ) ) ;
1105
- assert_eq ! ( let_stmt. to_string( ) , after. to_string( ) , "{let_stmt:#?}\n !=\n {after:#?}" ) ;
1106
- }
1107
-
1108
- // adding
1109
- check ( "let a;" , "let a: ();" , Some ( make:: ty_tuple ( [ ] ) ) ) ;
1110
- // no semicolon due to it being eaten during error recovery
1111
- check ( "let a:" , "let a: ()" , Some ( make:: ty_tuple ( [ ] ) ) ) ;
1112
-
1113
- // replacing
1114
- check ( "let a: u8;" , "let a: ();" , Some ( make:: ty_tuple ( [ ] ) ) ) ;
1115
- check ( "let a: u8 = 3;" , "let a: () = 3;" , Some ( make:: ty_tuple ( [ ] ) ) ) ;
1116
- check ( "let a: = 3;" , "let a: () = 3;" , Some ( make:: ty_tuple ( [ ] ) ) ) ;
1117
-
1118
- // removing
1119
- check ( "let a: u8;" , "let a;" , None ) ;
1120
- check ( "let a:;" , "let a;" , None ) ;
1121
-
1122
- check ( "let a: u8 = 3;" , "let a = 3;" , None ) ;
1123
- check ( "let a: = 3;" , "let a = 3;" , None ) ;
1124
- }
1125
966
}
0 commit comments