@@ -467,8 +467,7 @@ impl HirDisplay for ApplicationTy {
467
467
. as_ref ( )
468
468
. map ( |rpit| rpit. impl_traits [ idx as usize ] . bounds . clone ( ) ) ;
469
469
let bounds = data. subst ( & self . parameters ) ;
470
- write ! ( f, "impl " ) ?;
471
- write_bounds_like_dyn_trait ( & bounds. value , f) ?;
470
+ write_bounds_like_dyn_trait_with_prefix ( "impl" , & bounds. value , f) ?;
472
471
// FIXME: it would maybe be good to distinguish this from the alias type (when debug printing), and to show the substitution
473
472
}
474
473
OpaqueTyId :: AsyncBlockTypeImplTrait ( ..) => {
@@ -548,10 +547,10 @@ impl HirDisplay for Ty {
548
547
write ! ( f, "{}" , param_data. name. clone( ) . unwrap_or_else( Name :: missing) ) ?
549
548
}
550
549
TypeParamProvenance :: ArgumentImplTrait => {
551
- write ! ( f, "impl " ) ?;
552
550
let bounds = f. db . generic_predicates_for_param ( * id) ;
553
551
let substs = Substs :: type_params_for_generics ( & generics) ;
554
- write_bounds_like_dyn_trait (
552
+ write_bounds_like_dyn_trait_with_prefix (
553
+ "impl" ,
555
554
& bounds. iter ( ) . map ( |b| b. clone ( ) . subst ( & substs) ) . collect :: < Vec < _ > > ( ) ,
556
555
f,
557
556
) ?;
@@ -560,8 +559,7 @@ impl HirDisplay for Ty {
560
559
}
561
560
Ty :: Bound ( idx) => write ! ( f, "?{}.{}" , idx. debruijn. depth( ) , idx. index) ?,
562
561
Ty :: Dyn ( predicates) => {
563
- write ! ( f, "dyn " ) ?;
564
- write_bounds_like_dyn_trait ( predicates, f) ?;
562
+ write_bounds_like_dyn_trait_with_prefix ( "dyn" , predicates, f) ?;
565
563
}
566
564
Ty :: Opaque ( opaque_ty) => {
567
565
match opaque_ty. opaque_ty_id {
@@ -572,8 +570,7 @@ impl HirDisplay for Ty {
572
570
. as_ref ( )
573
571
. map ( |rpit| rpit. impl_traits [ idx as usize ] . bounds . clone ( ) ) ;
574
572
let bounds = data. subst ( & opaque_ty. parameters ) ;
575
- write ! ( f, "impl " ) ?;
576
- write_bounds_like_dyn_trait ( & bounds. value , f) ?;
573
+ write_bounds_like_dyn_trait_with_prefix ( "impl" , & bounds. value , f) ?;
577
574
}
578
575
OpaqueTyId :: AsyncBlockTypeImplTrait ( ..) => {
579
576
write ! ( f, "{{async block}}" ) ?;
@@ -627,7 +624,21 @@ fn fn_traits(db: &dyn DefDatabase, trait_: TraitId) -> impl Iterator<Item = Trai
627
624
ArrayVec :: from ( fn_traits) . into_iter ( ) . flatten ( ) . flat_map ( |it| it. as_trait ( ) )
628
625
}
629
626
630
- pub fn write_bounds_like_dyn_trait (
627
+ pub fn write_bounds_like_dyn_trait_with_prefix (
628
+ prefix : & str ,
629
+ predicates : & [ GenericPredicate ] ,
630
+ f : & mut HirFormatter ,
631
+ ) -> Result < ( ) , HirDisplayError > {
632
+ write ! ( f, "{}" , prefix) ?;
633
+ if !predicates. is_empty ( ) {
634
+ write ! ( f, " " ) ?;
635
+ write_bounds_like_dyn_trait ( predicates, f)
636
+ } else {
637
+ Ok ( ( ) )
638
+ }
639
+ }
640
+
641
+ fn write_bounds_like_dyn_trait (
631
642
predicates : & [ GenericPredicate ] ,
632
643
f : & mut HirFormatter ,
633
644
) -> Result < ( ) , HirDisplayError > {
0 commit comments