@@ -9,6 +9,7 @@ use std::{
99
1010use base_db:: CrateId ;
1111use chalk_ir:: { BoundVar , Safety , TyKind } ;
12+ use either:: Either ;
1213use hir_def:: {
1314 data:: adt:: VariantData ,
1415 db:: DefDatabase ,
@@ -1072,6 +1073,7 @@ impl HirDisplay for Ty {
10721073 write_bounds_like_dyn_trait_with_prefix (
10731074 f,
10741075 "impl" ,
1076+ Either :: Left ( self ) ,
10751077 bounds. skip_binders ( ) ,
10761078 SizedByDefault :: Sized { anchor : krate } ,
10771079 ) ?;
@@ -1087,6 +1089,7 @@ impl HirDisplay for Ty {
10871089 write_bounds_like_dyn_trait_with_prefix (
10881090 f,
10891091 "impl" ,
1092+ Either :: Left ( self ) ,
10901093 bounds. skip_binders ( ) ,
10911094 SizedByDefault :: Sized { anchor : krate } ,
10921095 ) ?;
@@ -1189,21 +1192,24 @@ impl HirDisplay for Ty {
11891192 . generic_predicates ( id. parent )
11901193 . iter ( )
11911194 . map ( |pred| pred. clone ( ) . substitute ( Interner , & substs) )
1192- . filter ( |wc| match & wc. skip_binders ( ) {
1195+ . filter ( |wc| match wc. skip_binders ( ) {
11931196 WhereClause :: Implemented ( tr) => {
1194- & tr. self_type_parameter ( Interner ) == self
1197+ tr. self_type_parameter ( Interner ) == * self
11951198 }
11961199 WhereClause :: AliasEq ( AliasEq {
11971200 alias : AliasTy :: Projection ( proj) ,
11981201 ty : _,
1199- } ) => & proj. self_type_parameter ( db) == self ,
1200- _ => false ,
1202+ } ) => proj. self_type_parameter ( db) == * self ,
1203+ WhereClause :: AliasEq ( _) => false ,
1204+ WhereClause :: TypeOutlives ( to) => to. ty == * self ,
1205+ WhereClause :: LifetimeOutlives ( _) => false ,
12011206 } )
12021207 . collect :: < Vec < _ > > ( ) ;
12031208 let krate = id. parent . module ( db. upcast ( ) ) . krate ( ) ;
12041209 write_bounds_like_dyn_trait_with_prefix (
12051210 f,
12061211 "impl" ,
1212+ Either :: Left ( self ) ,
12071213 & bounds,
12081214 SizedByDefault :: Sized { anchor : krate } ,
12091215 ) ?;
@@ -1229,6 +1235,7 @@ impl HirDisplay for Ty {
12291235 write_bounds_like_dyn_trait_with_prefix (
12301236 f,
12311237 "dyn" ,
1238+ Either :: Left ( self ) ,
12321239 & bounds,
12331240 SizedByDefault :: NotSized ,
12341241 ) ?;
@@ -1252,6 +1259,7 @@ impl HirDisplay for Ty {
12521259 write_bounds_like_dyn_trait_with_prefix (
12531260 f,
12541261 "impl" ,
1262+ Either :: Left ( self ) ,
12551263 bounds. skip_binders ( ) ,
12561264 SizedByDefault :: Sized { anchor : krate } ,
12571265 ) ?;
@@ -1266,6 +1274,7 @@ impl HirDisplay for Ty {
12661274 write_bounds_like_dyn_trait_with_prefix (
12671275 f,
12681276 "impl" ,
1277+ Either :: Left ( self ) ,
12691278 bounds. skip_binders ( ) ,
12701279 SizedByDefault :: Sized { anchor : krate } ,
12711280 ) ?;
@@ -1468,6 +1477,7 @@ impl SizedByDefault {
14681477pub fn write_bounds_like_dyn_trait_with_prefix (
14691478 f : & mut HirFormatter < ' _ > ,
14701479 prefix : & str ,
1480+ this : Either < & Ty , & Lifetime > ,
14711481 predicates : & [ QuantifiedWhereClause ] ,
14721482 default_sized : SizedByDefault ,
14731483) -> Result < ( ) , HirDisplayError > {
@@ -1476,14 +1486,15 @@ pub fn write_bounds_like_dyn_trait_with_prefix(
14761486 || predicates. is_empty ( ) && matches ! ( default_sized, SizedByDefault :: Sized { .. } )
14771487 {
14781488 write ! ( f, " " ) ?;
1479- write_bounds_like_dyn_trait ( f, predicates, default_sized)
1489+ write_bounds_like_dyn_trait ( f, this , predicates, default_sized)
14801490 } else {
14811491 Ok ( ( ) )
14821492 }
14831493}
14841494
14851495fn write_bounds_like_dyn_trait (
14861496 f : & mut HirFormatter < ' _ > ,
1497+ this : Either < & Ty , & Lifetime > ,
14871498 predicates : & [ QuantifiedWhereClause ] ,
14881499 default_sized : SizedByDefault ,
14891500) -> Result < ( ) , HirDisplayError > {
@@ -1541,6 +1552,28 @@ fn write_bounds_like_dyn_trait(
15411552 }
15421553 }
15431554 }
1555+ WhereClause :: TypeOutlives ( to) if Either :: Left ( & to. ty ) == this => {
1556+ if !is_fn_trait && angle_open {
1557+ write ! ( f, ">" ) ?;
1558+ angle_open = false ;
1559+ }
1560+ if !first {
1561+ write ! ( f, " + " ) ?;
1562+ }
1563+ to. lifetime . hir_fmt ( f) ?;
1564+ }
1565+ WhereClause :: TypeOutlives ( _) => { }
1566+ WhereClause :: LifetimeOutlives ( lo) if Either :: Right ( & lo. a ) == this => {
1567+ if !is_fn_trait && angle_open {
1568+ write ! ( f, ">" ) ?;
1569+ angle_open = false ;
1570+ }
1571+ if !first {
1572+ write ! ( f, " + " ) ?;
1573+ }
1574+ lo. b . hir_fmt ( f) ?;
1575+ }
1576+ WhereClause :: LifetimeOutlives ( _) => { }
15441577 WhereClause :: AliasEq ( alias_eq) if is_fn_trait => {
15451578 is_fn_trait = false ;
15461579 if !alias_eq. ty . is_unit ( ) {
@@ -1577,10 +1610,6 @@ fn write_bounds_like_dyn_trait(
15771610 }
15781611 ty. hir_fmt ( f) ?;
15791612 }
1580-
1581- // FIXME implement these
1582- WhereClause :: LifetimeOutlives ( _) => { }
1583- WhereClause :: TypeOutlives ( _) => { }
15841613 }
15851614 first = false ;
15861615 }
0 commit comments