@@ -471,10 +471,55 @@ impl HirDisplay for ProjectionTy {
471471 if f. should_truncate ( ) {
472472 return write ! ( f, "{TYPE_HINT_TRUNCATION}" ) ;
473473 }
474-
475474 let trait_ref = self . trait_ref ( f. db ) ;
475+ let self_ty = trait_ref. self_type_parameter ( Interner ) ;
476+
477+ // if we are projection on a type parameter, check if the projection target has bounds
478+ // itself, if so, we render them directly as `impl Bound` instead of the less useful
479+ // `<Param as Trait>::Assoc`
480+ if !f. display_target . is_source_code ( ) {
481+ if let TyKind :: Placeholder ( idx) = self_ty. kind ( Interner ) {
482+ let db = f. db ;
483+ let id = from_placeholder_idx ( db, * idx) ;
484+ let generics = generics ( db. upcast ( ) , id. parent ) ;
485+
486+ let substs = generics. placeholder_subst ( db) ;
487+ let bounds = db
488+ . generic_predicates ( id. parent )
489+ . iter ( )
490+ . map ( |pred| pred. clone ( ) . substitute ( Interner , & substs) )
491+ . filter ( |wc| match wc. skip_binders ( ) {
492+ WhereClause :: Implemented ( tr) => {
493+ match tr. self_type_parameter ( Interner ) . kind ( Interner ) {
494+ TyKind :: Alias ( AliasTy :: Projection ( proj) ) => proj == self ,
495+ _ => false ,
496+ }
497+ }
498+ WhereClause :: TypeOutlives ( t) => match t. ty . kind ( Interner ) {
499+ TyKind :: Alias ( AliasTy :: Projection ( proj) ) => proj == self ,
500+ _ => false ,
501+ } ,
502+ // We shouldn't be here if these exist
503+ WhereClause :: AliasEq ( _) => false ,
504+ WhereClause :: LifetimeOutlives ( _) => false ,
505+ } )
506+ . collect :: < Vec < _ > > ( ) ;
507+ if !bounds. is_empty ( ) {
508+ return write_bounds_like_dyn_trait_with_prefix (
509+ f,
510+ "impl" ,
511+ Either :: Left (
512+ & TyKind :: Alias ( AliasTy :: Projection ( self . clone ( ) ) ) . intern ( Interner ) ,
513+ ) ,
514+ & bounds,
515+ SizedByDefault :: NotSized ,
516+ ) ;
517+ } ;
518+ }
519+ }
520+
476521 write ! ( f, "<" ) ?;
477- trait_ref . self_type_parameter ( Interner ) . hir_fmt ( f) ?;
522+ self_ty . hir_fmt ( f) ?;
478523 write ! ( f, " as " ) ?;
479524 trait_ref. hir_fmt ( f) ?;
480525 write ! (
0 commit comments