@@ -8,7 +8,7 @@ use itertools::Itertools;
8
8
use stdx:: to_lower_snake_case;
9
9
use syntax:: {
10
10
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 ,
12
12
} ;
13
13
14
14
use crate :: FileId ;
@@ -60,7 +60,7 @@ pub enum InlayKind {
60
60
pub struct InlayHint {
61
61
pub range : TextRange ,
62
62
pub kind : InlayKind ,
63
- pub label : SmolStr ,
63
+ pub label : String ,
64
64
}
65
65
66
66
// Feature: Inlay Hints
@@ -248,7 +248,7 @@ fn closing_brace_hints(
248
248
acc. push ( InlayHint {
249
249
range : closing_token. text_range ( ) ,
250
250
kind : InlayKind :: ClosingBraceHint ,
251
- label : label . into ( ) ,
251
+ label,
252
252
} ) ;
253
253
254
254
None
@@ -262,6 +262,13 @@ fn lifetime_fn_hints(
262
262
if config. lifetime_elision_hints == LifetimeElisionHints :: Never {
263
263
return None ;
264
264
}
265
+
266
+ let mk_lt_hint = |t : SyntaxToken , label| InlayHint {
267
+ range : t. text_range ( ) ,
268
+ kind : InlayKind :: LifetimeHint ,
269
+ label,
270
+ } ;
271
+
265
272
let param_list = func. param_list ( ) ?;
266
273
let generic_param_list = func. generic_param_list ( ) ;
267
274
let ret_type = func. ret_type ( ) ;
@@ -378,11 +385,7 @@ fn lifetime_fn_hints(
378
385
ast:: Type :: RefType ( ty) if ty. lifetime ( ) . is_none ( ) => {
379
386
if let Some ( amp) = ty. amp_token ( ) {
380
387
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 ( ) ) ) ;
386
389
}
387
390
}
388
391
_ => ( ) ,
@@ -398,8 +401,8 @@ fn lifetime_fn_hints(
398
401
for ( _, amp_token, _, is_elided) in potential_lt_refs {
399
402
if is_elided {
400
403
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 ( ) ) ) ;
403
406
}
404
407
}
405
408
@@ -409,16 +412,14 @@ fn lifetime_fn_hints(
409
412
( Some ( gpl) , allocated_lifetimes) => {
410
413
let angle_tok = gpl. l_angle_token ( ) ?;
411
414
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 ! (
416
418
"{}{}" ,
417
419
allocated_lifetimes. iter( ) . format( ", " ) ,
418
420
if is_empty { "" } else { ", " }
419
- )
420
- . into ( ) ,
421
- } ) ;
421
+ ) ,
422
+ ) ) ;
422
423
}
423
424
( None , allocated_lifetimes) => acc. push ( InlayHint {
424
425
range : func. name ( ) ?. syntax ( ) . text_range ( ) ,
@@ -456,7 +457,7 @@ fn closure_ret_hints(
456
457
range : param_list. syntax ( ) . text_range ( ) ,
457
458
kind : InlayKind :: ClosureReturnTypeHint ,
458
459
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 ( ) ) ,
460
461
} ) ;
461
462
Some ( ( ) )
462
463
}
@@ -482,7 +483,7 @@ fn reborrow_hints(
482
483
acc. push ( InlayHint {
483
484
range : expr. syntax ( ) . text_range ( ) ,
484
485
kind : InlayKind :: ImplicitReborrowHint ,
485
- label : SmolStr :: new_inline ( label) ,
486
+ label : label. to_string ( ) ,
486
487
} ) ;
487
488
Some ( ( ) )
488
489
}
@@ -539,7 +540,7 @@ fn chaining_hints(
539
540
range : expr. syntax ( ) . text_range ( ) ,
540
541
kind : InlayKind :: ChainingHint ,
541
542
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 ( )
543
544
} ) ,
544
545
} ) ;
545
546
}
@@ -606,11 +607,7 @@ fn binding_mode_hints(
606
607
( true , false ) => "&" ,
607
608
_ => return ,
608
609
} ;
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 ( ) } ) ;
614
611
} ) ;
615
612
match pat {
616
613
ast:: Pat :: IdentPat ( pat) if pat. ref_token ( ) . is_none ( ) && pat. mut_token ( ) . is_none ( ) => {
@@ -620,11 +617,7 @@ fn binding_mode_hints(
620
617
hir:: BindingMode :: Ref ( Mutability :: Mut ) => "ref mut" ,
621
618
hir:: BindingMode :: Ref ( Mutability :: Shared ) => "ref" ,
622
619
} ;
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 ( ) } ) ;
628
621
}
629
622
_ => ( ) ,
630
623
}
@@ -663,7 +656,7 @@ fn bind_pat_hints(
663
656
{
664
657
return None ;
665
658
}
666
- ty_name. into ( )
659
+ ty_name
667
660
}
668
661
} ;
669
662
@@ -738,7 +731,7 @@ fn hint_iterator(
738
731
famous_defs : & FamousDefs ,
739
732
config : & InlayHintsConfig ,
740
733
ty : & hir:: Type ,
741
- ) -> Option < SmolStr > {
734
+ ) -> Option < String > {
742
735
let db = sema. db ;
743
736
let strukt = ty. strip_references ( ) . as_adt ( ) ?;
744
737
let krate = strukt. module ( db) . krate ( ) ;
@@ -775,7 +768,7 @@ fn hint_iterator(
775
768
)
776
769
. to_string ( )
777
770
} ) ;
778
- return Some ( format ! ( "{}{}{}" , LABEL_START , ty_display, LABEL_END ) . into ( ) ) ;
771
+ return Some ( format ! ( "{}{}{}" , LABEL_START , ty_display, LABEL_END ) ) ;
779
772
}
780
773
}
781
774
0 commit comments