@@ -22,15 +22,15 @@ use super::cres;
22
22
use super :: { RegionVariableOrigin , SubregionOrigin , TypeTrace , MiscVariable } ;
23
23
24
24
use middle:: region;
25
- use middle:: ty;
25
+ use middle:: ty:: { mod , Ty } ;
26
26
use middle:: ty:: { BoundRegion , FreeRegion , Region , RegionVid } ;
27
27
use middle:: ty:: { ReEmpty , ReStatic , ReInfer , ReFree , ReEarlyBound } ;
28
28
use middle:: ty:: { ReLateBound , ReScope , ReVar , ReSkolemized , BrFresh } ;
29
29
use middle:: graph;
30
30
use middle:: graph:: { Direction , NodeIndex } ;
31
31
use util:: common:: indenter;
32
32
use util:: nodemap:: { FnvHashMap , FnvHashSet } ;
33
- use util:: ppaux:: Repr ;
33
+ use util:: ppaux:: { Repr , UserString } ;
34
34
35
35
use std:: cell:: { Cell , RefCell } ;
36
36
use std:: cmp:: Ordering :: { self , Less , Greater , Equal } ;
@@ -61,12 +61,18 @@ pub enum Verify<'tcx> {
61
61
// `b` are inference variables.
62
62
VerifyRegSubReg ( SubregionOrigin < ' tcx > , Region , Region ) ,
63
63
64
- // VerifyParamBound(T, _, R, RS): The parameter type `T` must
65
- // outlive the region `R`. `T` is known to outlive `RS`. Therefore
66
- // verify that `R <= RS[i]` for some `i`. Inference variables may
67
- // be involved (but this verification step doesn't influence
68
- // inference).
69
- VerifyParamBound ( ty:: ParamTy , SubregionOrigin < ' tcx > , Region , Vec < Region > ) ,
64
+ // VerifyGenericBound(T, _, R, RS): The parameter type `T` (or
65
+ // associated type) must outlive the region `R`. `T` is known to
66
+ // outlive `RS`. Therefore verify that `R <= RS[i]` for some
67
+ // `i`. Inference variables may be involved (but this verification
68
+ // step doesn't influence inference).
69
+ VerifyGenericBound ( GenericKind < ' tcx > , SubregionOrigin < ' tcx > , Region , Vec < Region > ) ,
70
+ }
71
+
72
+ #[ deriving( Clone , Show , PartialEq , Eq ) ]
73
+ pub enum GenericKind < ' tcx > {
74
+ Param ( ty:: ParamTy ) ,
75
+ Projection ( ty:: ProjectionTy < ' tcx > ) ,
70
76
}
71
77
72
78
#[ derive( Copy , PartialEq , Eq , Hash ) ]
@@ -98,12 +104,12 @@ pub enum RegionResolutionError<'tcx> {
98
104
/// `o` requires that `a <= b`, but this does not hold
99
105
ConcreteFailure ( SubregionOrigin < ' tcx > , Region , Region ) ,
100
106
101
- /// `ParamBoundFailure (p, s, a, bs)
107
+ /// `GenericBoundFailure (p, s, a, bs)
102
108
///
103
- /// The parameter type `p` must be known to outlive the lifetime
109
+ /// The parameter/assocated- type `p` must be known to outlive the lifetime
104
110
/// `a`, but it is only known to outlive `bs` (and none of the
105
111
/// regions in `bs` outlive `a`).
106
- ParamBoundFailure ( SubregionOrigin < ' tcx > , ty :: ParamTy , Region , Vec < Region > ) ,
112
+ GenericBoundFailure ( SubregionOrigin < ' tcx > , GenericKind < ' tcx > , Region , Vec < Region > ) ,
107
113
108
114
/// `SubSupConflict(v, sub_origin, sub_r, sup_origin, sup_r)`:
109
115
///
@@ -489,12 +495,13 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
489
495
}
490
496
}
491
497
492
- pub fn verify_param_bound ( & self ,
493
- origin : SubregionOrigin < ' tcx > ,
494
- param_ty : ty:: ParamTy ,
495
- sub : Region ,
496
- sups : Vec < Region > ) {
497
- self . add_verify ( VerifyParamBound ( param_ty, origin, sub, sups) ) ;
498
+ /// See `Verify::VerifyGenericBound`
499
+ pub fn verify_generic_bound ( & self ,
500
+ origin : SubregionOrigin < ' tcx > ,
501
+ kind : GenericKind < ' tcx > ,
502
+ sub : Region ,
503
+ sups : Vec < Region > ) {
504
+ self . add_verify ( VerifyGenericBound ( kind, origin, sub, sups) ) ;
498
505
}
499
506
500
507
pub fn lub_regions ( & self ,
@@ -660,7 +667,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
660
667
& mut result_set, r,
661
668
a, b) ;
662
669
}
663
- VerifyParamBound ( _, _, a, ref bs) => {
670
+ VerifyGenericBound ( _, _, a, ref bs) => {
664
671
for & b in bs. iter ( ) {
665
672
consider_adding_bidirectional_edges (
666
673
& mut result_set, r,
@@ -1211,7 +1218,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
1211
1218
errors. push ( ConcreteFailure ( ( * origin) . clone ( ) , sub, sup) ) ;
1212
1219
}
1213
1220
1214
- VerifyParamBound ( ref param_ty , ref origin, sub, ref sups) => {
1221
+ VerifyGenericBound ( ref kind , ref origin, sub, ref sups) => {
1215
1222
let sub = normalize ( values, sub) ;
1216
1223
if sups. iter ( )
1217
1224
. map ( |& sup| normalize ( values, sup) )
@@ -1223,8 +1230,8 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
1223
1230
let sups = sups. iter ( ) . map ( |& sup| normalize ( values, sup) )
1224
1231
. collect ( ) ;
1225
1232
errors. push (
1226
- ParamBoundFailure (
1227
- ( * origin) . clone ( ) , * param_ty , sub, sups) ) ;
1233
+ GenericBoundFailure (
1234
+ ( * origin) . clone ( ) , kind . clone ( ) , sub, sups) ) ;
1228
1235
}
1229
1236
}
1230
1237
}
@@ -1584,8 +1591,8 @@ impl<'tcx> Repr<'tcx> for Verify<'tcx> {
1584
1591
VerifyRegSubReg ( _, ref a, ref b) => {
1585
1592
format ! ( "VerifyRegSubReg({}, {})" , a. repr( tcx) , b. repr( tcx) )
1586
1593
}
1587
- VerifyParamBound ( _, ref p, ref a, ref bs) => {
1588
- format ! ( "VerifyParamBound ({}, {}, {})" ,
1594
+ VerifyGenericBound ( _, ref p, ref a, ref bs) => {
1595
+ format ! ( "VerifyGenericBound ({}, {}, {})" ,
1589
1596
p. repr( tcx) , a. repr( tcx) , bs. repr( tcx) )
1590
1597
}
1591
1598
}
@@ -1624,3 +1631,32 @@ impl<'tcx> Repr<'tcx> for RegionAndOrigin<'tcx> {
1624
1631
self . origin. repr( tcx) )
1625
1632
}
1626
1633
}
1634
+
1635
+ impl < ' tcx > Repr < ' tcx > for GenericKind < ' tcx > {
1636
+ fn repr ( & self , tcx : & ty:: ctxt < ' tcx > ) -> String {
1637
+ match * self {
1638
+ GenericKind :: Param ( ref p) => p. repr ( tcx) ,
1639
+ GenericKind :: Projection ( ref p) => p. repr ( tcx) ,
1640
+ }
1641
+ }
1642
+ }
1643
+
1644
+ impl < ' tcx > UserString < ' tcx > for GenericKind < ' tcx > {
1645
+ fn user_string ( & self , tcx : & ty:: ctxt < ' tcx > ) -> String {
1646
+ match * self {
1647
+ GenericKind :: Param ( ref p) => p. user_string ( tcx) ,
1648
+ GenericKind :: Projection ( ref p) => p. user_string ( tcx) ,
1649
+ }
1650
+ }
1651
+ }
1652
+
1653
+ impl < ' tcx > GenericKind < ' tcx > {
1654
+ pub fn to_ty ( & self , tcx : & ty:: ctxt < ' tcx > ) -> Ty < ' tcx > {
1655
+ match * self {
1656
+ GenericKind :: Param ( ref p) =>
1657
+ p. to_ty ( tcx) ,
1658
+ GenericKind :: Projection ( ref p) =>
1659
+ ty:: mk_projection ( tcx, p. trait_ref . clone ( ) , p. item_name ) ,
1660
+ }
1661
+ }
1662
+ }
0 commit comments