@@ -9,6 +9,7 @@ use std::{
9
9
10
10
use base_db:: CrateId ;
11
11
use chalk_ir:: { BoundVar , Safety , TyKind } ;
12
+ use either:: Either ;
12
13
use hir_def:: {
13
14
data:: adt:: VariantData ,
14
15
db:: DefDatabase ,
@@ -1072,6 +1073,7 @@ impl HirDisplay for Ty {
1072
1073
write_bounds_like_dyn_trait_with_prefix (
1073
1074
f,
1074
1075
"impl" ,
1076
+ Either :: Left ( self ) ,
1075
1077
bounds. skip_binders ( ) ,
1076
1078
SizedByDefault :: Sized { anchor : krate } ,
1077
1079
) ?;
@@ -1087,6 +1089,7 @@ impl HirDisplay for Ty {
1087
1089
write_bounds_like_dyn_trait_with_prefix (
1088
1090
f,
1089
1091
"impl" ,
1092
+ Either :: Left ( self ) ,
1090
1093
bounds. skip_binders ( ) ,
1091
1094
SizedByDefault :: Sized { anchor : krate } ,
1092
1095
) ?;
@@ -1189,21 +1192,24 @@ impl HirDisplay for Ty {
1189
1192
. generic_predicates ( id. parent )
1190
1193
. iter ( )
1191
1194
. map ( |pred| pred. clone ( ) . substitute ( Interner , & substs) )
1192
- . filter ( |wc| match & wc. skip_binders ( ) {
1195
+ . filter ( |wc| match wc. skip_binders ( ) {
1193
1196
WhereClause :: Implemented ( tr) => {
1194
- & tr. self_type_parameter ( Interner ) == self
1197
+ tr. self_type_parameter ( Interner ) == * self
1195
1198
}
1196
1199
WhereClause :: AliasEq ( AliasEq {
1197
1200
alias : AliasTy :: Projection ( proj) ,
1198
1201
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 ,
1201
1206
} )
1202
1207
. collect :: < Vec < _ > > ( ) ;
1203
1208
let krate = id. parent . module ( db. upcast ( ) ) . krate ( ) ;
1204
1209
write_bounds_like_dyn_trait_with_prefix (
1205
1210
f,
1206
1211
"impl" ,
1212
+ Either :: Left ( self ) ,
1207
1213
& bounds,
1208
1214
SizedByDefault :: Sized { anchor : krate } ,
1209
1215
) ?;
@@ -1229,6 +1235,7 @@ impl HirDisplay for Ty {
1229
1235
write_bounds_like_dyn_trait_with_prefix (
1230
1236
f,
1231
1237
"dyn" ,
1238
+ Either :: Left ( self ) ,
1232
1239
& bounds,
1233
1240
SizedByDefault :: NotSized ,
1234
1241
) ?;
@@ -1252,6 +1259,7 @@ impl HirDisplay for Ty {
1252
1259
write_bounds_like_dyn_trait_with_prefix (
1253
1260
f,
1254
1261
"impl" ,
1262
+ Either :: Left ( self ) ,
1255
1263
bounds. skip_binders ( ) ,
1256
1264
SizedByDefault :: Sized { anchor : krate } ,
1257
1265
) ?;
@@ -1266,6 +1274,7 @@ impl HirDisplay for Ty {
1266
1274
write_bounds_like_dyn_trait_with_prefix (
1267
1275
f,
1268
1276
"impl" ,
1277
+ Either :: Left ( self ) ,
1269
1278
bounds. skip_binders ( ) ,
1270
1279
SizedByDefault :: Sized { anchor : krate } ,
1271
1280
) ?;
@@ -1468,6 +1477,7 @@ impl SizedByDefault {
1468
1477
pub fn write_bounds_like_dyn_trait_with_prefix (
1469
1478
f : & mut HirFormatter < ' _ > ,
1470
1479
prefix : & str ,
1480
+ this : Either < & Ty , & Lifetime > ,
1471
1481
predicates : & [ QuantifiedWhereClause ] ,
1472
1482
default_sized : SizedByDefault ,
1473
1483
) -> Result < ( ) , HirDisplayError > {
@@ -1476,14 +1486,15 @@ pub fn write_bounds_like_dyn_trait_with_prefix(
1476
1486
|| predicates. is_empty ( ) && matches ! ( default_sized, SizedByDefault :: Sized { .. } )
1477
1487
{
1478
1488
write ! ( f, " " ) ?;
1479
- write_bounds_like_dyn_trait ( f, predicates, default_sized)
1489
+ write_bounds_like_dyn_trait ( f, this , predicates, default_sized)
1480
1490
} else {
1481
1491
Ok ( ( ) )
1482
1492
}
1483
1493
}
1484
1494
1485
1495
fn write_bounds_like_dyn_trait (
1486
1496
f : & mut HirFormatter < ' _ > ,
1497
+ this : Either < & Ty , & Lifetime > ,
1487
1498
predicates : & [ QuantifiedWhereClause ] ,
1488
1499
default_sized : SizedByDefault ,
1489
1500
) -> Result < ( ) , HirDisplayError > {
@@ -1541,6 +1552,28 @@ fn write_bounds_like_dyn_trait(
1541
1552
}
1542
1553
}
1543
1554
}
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 ( _) => { }
1544
1577
WhereClause :: AliasEq ( alias_eq) if is_fn_trait => {
1545
1578
is_fn_trait = false ;
1546
1579
if !alias_eq. ty . is_unit ( ) {
@@ -1577,10 +1610,6 @@ fn write_bounds_like_dyn_trait(
1577
1610
}
1578
1611
ty. hir_fmt ( f) ?;
1579
1612
}
1580
-
1581
- // FIXME implement these
1582
- WhereClause :: LifetimeOutlives ( _) => { }
1583
- WhereClause :: TypeOutlives ( _) => { }
1584
1613
}
1585
1614
first = false ;
1586
1615
}
0 commit comments