File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -646,6 +646,47 @@ impl ast::MatchArmList {
646646 }
647647}
648648
649+ impl ast:: LetStmt {
650+ pub fn set_ty ( & self , ty : Option < ast:: Type > ) {
651+ match ty {
652+ None => {
653+ if let Some ( colon_token) = self . colon_token ( ) {
654+ ted:: remove ( colon_token) ;
655+ }
656+
657+ if let Some ( existing_ty) = self . ty ( ) {
658+ if let Some ( sibling) = existing_ty. syntax ( ) . prev_sibling_or_token ( ) {
659+ if sibling. kind ( ) == SyntaxKind :: WHITESPACE {
660+ ted:: remove ( sibling) ;
661+ }
662+ }
663+
664+ ted:: remove ( existing_ty. syntax ( ) ) ;
665+ }
666+ }
667+ Some ( new_ty) => {
668+ if self . colon_token ( ) . is_none ( ) {
669+ let mut to_insert: Vec < SyntaxElement > = vec ! [ ] ;
670+
671+ let position = match self . pat ( ) {
672+ Some ( pat) => Position :: after ( pat. syntax ( ) ) ,
673+ None => {
674+ to_insert. push ( make:: tokens:: single_space ( ) . into ( ) ) ;
675+ Position :: after ( self . let_token ( ) . unwrap ( ) )
676+ }
677+ } ;
678+
679+ to_insert. push ( make:: token ( T ! [ : ] ) . into ( ) ) ;
680+
681+ ted:: insert_all_raw ( position, to_insert) ;
682+ }
683+
684+ ted:: insert ( Position :: after ( self . colon_token ( ) . unwrap ( ) ) , new_ty. syntax ( ) ) ;
685+ }
686+ }
687+ }
688+ }
689+
649690impl ast:: RecordExprFieldList {
650691 pub fn add_field ( & self , field : ast:: RecordExprField ) {
651692 let is_multiline = self . syntax ( ) . text ( ) . contains_char ( '\n' ) ;
You can’t perform that action at this time.
0 commit comments