@@ -65,6 +65,8 @@ use crate::{
65
65
pub trait HirWrite : fmt:: Write {
66
66
fn start_location_link ( & mut self , _location : ModuleDefId ) { }
67
67
fn end_location_link ( & mut self ) { }
68
+ fn start_truncated ( & mut self ) { }
69
+ fn end_truncated ( & mut self ) { }
68
70
}
69
71
70
72
// String will ignore link metadata
@@ -356,19 +358,26 @@ impl HirFormatter<'_> {
356
358
sep : & str ,
357
359
) -> Result < ( ) , HirDisplayError > {
358
360
let mut first = true ;
361
+ let mut truncated = false ;
359
362
for e in iter {
360
363
if !first {
361
364
write ! ( self , "{sep}" ) ?;
362
365
}
363
366
first = false ;
364
367
365
368
// Abbreviate multiple omitted types with a single ellipsis.
366
- if self . should_truncate ( ) {
367
- return write ! ( self , "{TYPE_HINT_TRUNCATION}" ) ;
369
+ if !truncated && self . should_truncate ( ) {
370
+ truncated = true ;
371
+ self . fmt . start_truncated ( ) ;
368
372
}
369
373
370
374
e. hir_fmt ( self ) ?;
371
375
}
376
+
377
+ if truncated {
378
+ self . fmt . end_truncated ( ) ;
379
+ }
380
+
372
381
Ok ( ( ) )
373
382
}
374
383
@@ -556,9 +565,11 @@ impl<T: HirDisplay + Internable> HirDisplay for Interned<T> {
556
565
557
566
impl HirDisplay for ProjectionTy {
558
567
fn hir_fmt ( & self , f : & mut HirFormatter < ' _ > ) -> Result < ( ) , HirDisplayError > {
559
- if f. should_truncate ( ) {
560
- return write ! ( f, "{TYPE_HINT_TRUNCATION}" ) ;
568
+ let truncated = f. should_truncate ( ) ;
569
+ if truncated {
570
+ f. fmt . start_truncated ( ) ;
561
571
}
572
+
562
573
let trait_ref = self . trait_ref ( f. db ) ;
563
574
let self_ty = trait_ref. self_type_parameter ( Interner ) ;
564
575
@@ -624,17 +635,30 @@ impl HirDisplay for ProjectionTy {
624
635
let proj_params_count =
625
636
self . substitution . len ( Interner ) - trait_ref. substitution . len ( Interner ) ;
626
637
let proj_params = & self . substitution . as_slice ( Interner ) [ ..proj_params_count] ;
627
- hir_fmt_generics ( f, proj_params, None , None )
638
+ hir_fmt_generics ( f, proj_params, None , None ) ?;
639
+
640
+ if truncated {
641
+ f. fmt . end_truncated ( ) ;
642
+ }
643
+
644
+ Ok ( ( ) )
628
645
}
629
646
}
630
647
631
648
impl HirDisplay for OpaqueTy {
632
649
fn hir_fmt ( & self , f : & mut HirFormatter < ' _ > ) -> Result < ( ) , HirDisplayError > {
633
- if f. should_truncate ( ) {
634
- return write ! ( f, "{TYPE_HINT_TRUNCATION}" ) ;
650
+ let truncated = f. should_truncate ( ) ;
651
+ if truncated {
652
+ f. fmt . start_truncated ( ) ;
653
+ }
654
+
655
+ self . substitution . at ( Interner , 0 ) . hir_fmt ( f) ?;
656
+
657
+ if truncated {
658
+ f. fmt . end_truncated ( ) ;
635
659
}
636
660
637
- self . substitution . at ( Interner , 0 ) . hir_fmt ( f )
661
+ Ok ( ( ) )
638
662
}
639
663
}
640
664
@@ -997,8 +1021,9 @@ impl HirDisplay for Ty {
997
1021
& self ,
998
1022
f @ & mut HirFormatter { db, .. } : & mut HirFormatter < ' _ > ,
999
1023
) -> Result < ( ) , HirDisplayError > {
1000
- if f. should_truncate ( ) {
1001
- return write ! ( f, "{TYPE_HINT_TRUNCATION}" ) ;
1024
+ let truncated = f. should_truncate ( ) ;
1025
+ if truncated {
1026
+ f. fmt . start_truncated ( ) ;
1002
1027
}
1003
1028
1004
1029
match self . kind ( Interner ) {
@@ -1408,11 +1433,18 @@ impl HirDisplay for Ty {
1408
1433
_ => unreachable ! ( ) ,
1409
1434
}
1410
1435
if sig. params ( ) . is_empty ( ) {
1411
- } else if f. should_truncate ( ) {
1412
- write ! ( f, "{TYPE_HINT_TRUNCATION}" ) ?;
1413
1436
} else {
1437
+ let truncated = f. should_truncate ( ) ;
1438
+ if truncated {
1439
+ f. fmt . start_truncated ( ) ;
1440
+ }
1441
+
1414
1442
f. write_joined ( sig. params ( ) , ", " ) ?;
1415
- } ;
1443
+
1444
+ if truncated {
1445
+ f. fmt . end_truncated ( ) ;
1446
+ }
1447
+ }
1416
1448
match f. closure_style {
1417
1449
ClosureStyle :: ImplFn => write ! ( f, ")" ) ?,
1418
1450
ClosureStyle :: RANotation => write ! ( f, "|" ) ?,
@@ -1576,6 +1608,11 @@ impl HirDisplay for Ty {
1576
1608
}
1577
1609
TyKind :: CoroutineWitness ( ..) => write ! ( f, "{{coroutine witness}}" ) ?,
1578
1610
}
1611
+
1612
+ if truncated {
1613
+ f. fmt . end_truncated ( ) ;
1614
+ }
1615
+
1579
1616
Ok ( ( ) )
1580
1617
}
1581
1618
}
@@ -1929,8 +1966,9 @@ impl HirDisplay for TraitRef {
1929
1966
1930
1967
impl HirDisplay for WhereClause {
1931
1968
fn hir_fmt ( & self , f : & mut HirFormatter < ' _ > ) -> Result < ( ) , HirDisplayError > {
1932
- if f. should_truncate ( ) {
1933
- return write ! ( f, "{TYPE_HINT_TRUNCATION}" ) ;
1969
+ let truncated = f. should_truncate ( ) ;
1970
+ if truncated {
1971
+ f. fmt . start_truncated ( ) ;
1934
1972
}
1935
1973
1936
1974
match self {
@@ -1963,6 +2001,11 @@ impl HirDisplay for WhereClause {
1963
2001
WhereClause :: TypeOutlives ( ..) => { }
1964
2002
WhereClause :: LifetimeOutlives ( ..) => { }
1965
2003
}
2004
+
2005
+ if truncated {
2006
+ f. fmt . end_truncated ( ) ;
2007
+ }
2008
+
1966
2009
Ok ( ( ) )
1967
2010
}
1968
2011
}
0 commit comments