@@ -8,7 +8,7 @@ use itertools::Itertools;
88use stdx:: to_lower_snake_case;
99use syntax:: {
1010 ast:: { self , AstNode , HasArgList , HasGenericParams , HasName , UnaryOp } ,
11- match_ast, Direction , NodeOrToken , SmolStr , SyntaxKind , SyntaxNode , TextRange , T ,
11+ match_ast, Direction , NodeOrToken , SmolStr , SyntaxKind , SyntaxNode , SyntaxToken , TextRange , T ,
1212} ;
1313
1414use crate :: FileId ;
@@ -60,7 +60,7 @@ pub enum InlayKind {
6060pub struct InlayHint {
6161 pub range : TextRange ,
6262 pub kind : InlayKind ,
63- pub label : SmolStr ,
63+ pub label : String ,
6464}
6565
6666// Feature: Inlay Hints
@@ -248,7 +248,7 @@ fn closing_brace_hints(
248248 acc. push ( InlayHint {
249249 range : closing_token. text_range ( ) ,
250250 kind : InlayKind :: ClosingBraceHint ,
251- label : label . into ( ) ,
251+ label,
252252 } ) ;
253253
254254 None
@@ -262,6 +262,13 @@ fn lifetime_fn_hints(
262262 if config. lifetime_elision_hints == LifetimeElisionHints :: Never {
263263 return None ;
264264 }
265+
266+ let mk_lt_hint = |t : SyntaxToken , label| InlayHint {
267+ range : t. text_range ( ) ,
268+ kind : InlayKind :: LifetimeHint ,
269+ label,
270+ } ;
271+
265272 let param_list = func. param_list ( ) ?;
266273 let generic_param_list = func. generic_param_list ( ) ;
267274 let ret_type = func. ret_type ( ) ;
@@ -378,11 +385,7 @@ fn lifetime_fn_hints(
378385 ast:: Type :: RefType ( ty) if ty. lifetime ( ) . is_none ( ) => {
379386 if let Some ( amp) = ty. amp_token ( ) {
380387 is_trivial = false ;
381- acc. push ( InlayHint {
382- range : amp. text_range ( ) ,
383- kind : InlayKind :: LifetimeHint ,
384- label : output_lt. clone ( ) ,
385- } ) ;
388+ acc. push ( mk_lt_hint ( amp, output_lt. to_string ( ) ) ) ;
386389 }
387390 }
388391 _ => ( ) ,
@@ -398,8 +401,8 @@ fn lifetime_fn_hints(
398401 for ( _, amp_token, _, is_elided) in potential_lt_refs {
399402 if is_elided {
400403 let t = amp_token?;
401- let lt = a. next ( ) ?. clone ( ) ;
402- acc. push ( InlayHint { range : t . text_range ( ) , kind : InlayKind :: LifetimeHint , label : lt } ) ;
404+ let lt = a. next ( ) ?;
405+ acc. push ( mk_lt_hint ( t , lt . to_string ( ) ) ) ;
403406 }
404407 }
405408
@@ -409,16 +412,14 @@ fn lifetime_fn_hints(
409412 ( Some ( gpl) , allocated_lifetimes) => {
410413 let angle_tok = gpl. l_angle_token ( ) ?;
411414 let is_empty = gpl. generic_params ( ) . next ( ) . is_none ( ) ;
412- acc. push ( InlayHint {
413- range : angle_tok. text_range ( ) ,
414- kind : InlayKind :: GenericParamListHint ,
415- label : format ! (
415+ acc. push ( mk_lt_hint (
416+ angle_tok,
417+ format ! (
416418 "{}{}" ,
417419 allocated_lifetimes. iter( ) . format( ", " ) ,
418420 if is_empty { "" } else { ", " }
419- )
420- . into ( ) ,
421- } ) ;
421+ ) ,
422+ ) ) ;
422423 }
423424 ( None , allocated_lifetimes) => acc. push ( InlayHint {
424425 range : func. name ( ) ?. syntax ( ) . text_range ( ) ,
@@ -456,7 +457,7 @@ fn closure_ret_hints(
456457 range : param_list. syntax ( ) . text_range ( ) ,
457458 kind : InlayKind :: ClosureReturnTypeHint ,
458459 label : hint_iterator ( sema, & famous_defs, config, & ty)
459- . unwrap_or_else ( || ty. display_truncated ( sema. db , config. max_length ) . to_string ( ) . into ( ) ) ,
460+ . unwrap_or_else ( || ty. display_truncated ( sema. db , config. max_length ) . to_string ( ) ) ,
460461 } ) ;
461462 Some ( ( ) )
462463}
@@ -482,7 +483,7 @@ fn reborrow_hints(
482483 acc. push ( InlayHint {
483484 range : expr. syntax ( ) . text_range ( ) ,
484485 kind : InlayKind :: ImplicitReborrowHint ,
485- label : SmolStr :: new_inline ( label) ,
486+ label : label. to_string ( ) ,
486487 } ) ;
487488 Some ( ( ) )
488489}
@@ -539,7 +540,7 @@ fn chaining_hints(
539540 range : expr. syntax ( ) . text_range ( ) ,
540541 kind : InlayKind :: ChainingHint ,
541542 label : hint_iterator ( sema, & famous_defs, config, & ty) . unwrap_or_else ( || {
542- ty. display_truncated ( sema. db , config. max_length ) . to_string ( ) . into ( )
543+ ty. display_truncated ( sema. db , config. max_length ) . to_string ( )
543544 } ) ,
544545 } ) ;
545546 }
@@ -606,11 +607,7 @@ fn binding_mode_hints(
606607 ( true , false ) => "&" ,
607608 _ => return ,
608609 } ;
609- acc. push ( InlayHint {
610- range,
611- kind : InlayKind :: BindingModeHint ,
612- label : SmolStr :: new_inline ( r) ,
613- } ) ;
610+ acc. push ( InlayHint { range, kind : InlayKind :: BindingModeHint , label : r. to_string ( ) } ) ;
614611 } ) ;
615612 match pat {
616613 ast:: Pat :: IdentPat ( pat) if pat. ref_token ( ) . is_none ( ) && pat. mut_token ( ) . is_none ( ) => {
@@ -620,11 +617,7 @@ fn binding_mode_hints(
620617 hir:: BindingMode :: Ref ( Mutability :: Mut ) => "ref mut" ,
621618 hir:: BindingMode :: Ref ( Mutability :: Shared ) => "ref" ,
622619 } ;
623- acc. push ( InlayHint {
624- range,
625- kind : InlayKind :: BindingModeHint ,
626- label : SmolStr :: new_inline ( bm) ,
627- } ) ;
620+ acc. push ( InlayHint { range, kind : InlayKind :: BindingModeHint , label : bm. to_string ( ) } ) ;
628621 }
629622 _ => ( ) ,
630623 }
@@ -663,7 +656,7 @@ fn bind_pat_hints(
663656 {
664657 return None ;
665658 }
666- ty_name. into ( )
659+ ty_name
667660 }
668661 } ;
669662
@@ -738,7 +731,7 @@ fn hint_iterator(
738731 famous_defs : & FamousDefs ,
739732 config : & InlayHintsConfig ,
740733 ty : & hir:: Type ,
741- ) -> Option < SmolStr > {
734+ ) -> Option < String > {
742735 let db = sema. db ;
743736 let strukt = ty. strip_references ( ) . as_adt ( ) ?;
744737 let krate = strukt. module ( db) . krate ( ) ;
@@ -775,7 +768,7 @@ fn hint_iterator(
775768 )
776769 . to_string ( )
777770 } ) ;
778- return Some ( format ! ( "{}{}{}" , LABEL_START , ty_display, LABEL_END ) . into ( ) ) ;
771+ return Some ( format ! ( "{}{}{}" , LABEL_START , ty_display, LABEL_END ) ) ;
779772 }
780773 }
781774
0 commit comments