@@ -108,6 +108,23 @@ impl<'tcx> Context for Tables<'tcx> {
108108 let generic_def = self . tcx . generics_of ( def_id) ;
109109 generic_def. stable ( self )
110110 }
111+
112+ fn predicates_of (
113+ & mut self ,
114+ trait_def : & stable_mir:: ty:: TraitDef ,
115+ ) -> stable_mir:: GenericPredicates {
116+ let trait_def_id = self . trait_def_id ( trait_def) ;
117+ let ty:: GenericPredicates { parent, predicates } = self . tcx . predicates_of ( trait_def_id) ;
118+ stable_mir:: GenericPredicates {
119+ parent : parent. map ( |did| self . trait_def ( did) ) ,
120+ predicates : predicates
121+ . iter ( )
122+ . map ( |( clause, span) | {
123+ ( clause. as_predicate ( ) . kind ( ) . skip_binder ( ) . stable ( self ) , span. stable ( self ) )
124+ } )
125+ . collect ( ) ,
126+ }
127+ }
111128}
112129
113130pub struct Tables < ' tcx > {
@@ -200,7 +217,7 @@ impl<'tcx> Stable<'tcx> for mir::Rvalue<'tcx> {
200217 stable_mir:: mir:: Rvalue :: Repeat ( op. stable ( tables) , len)
201218 }
202219 Ref ( region, kind, place) => stable_mir:: mir:: Rvalue :: Ref (
203- opaque ( region) ,
220+ region. stable ( tables ) ,
204221 kind. stable ( tables) ,
205222 place. stable ( tables) ,
206223 ) ,
@@ -842,12 +859,9 @@ impl<'tcx> Stable<'tcx> for ty::GenericArgKind<'tcx> {
842859 fn stable ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
843860 use stable_mir:: ty:: GenericArgKind ;
844861 match self {
845- ty:: GenericArgKind :: Lifetime ( region) => GenericArgKind :: Lifetime ( opaque ( region) ) ,
862+ ty:: GenericArgKind :: Lifetime ( region) => GenericArgKind :: Lifetime ( region. stable ( tables ) ) ,
846863 ty:: GenericArgKind :: Type ( ty) => GenericArgKind :: Type ( tables. intern_ty ( * ty) ) ,
847- ty:: GenericArgKind :: Const ( cnst) => {
848- let cnst = ConstantKind :: from_const ( * cnst, tables. tcx ) ;
849- GenericArgKind :: Const ( stable_mir:: ty:: Const { literal : cnst. stable ( tables) } )
850- }
864+ ty:: GenericArgKind :: Const ( cnst) => GenericArgKind :: Const ( cnst. stable ( tables) ) ,
851865 }
852866 }
853867}
@@ -950,12 +964,12 @@ impl<'tcx> Stable<'tcx> for ty::BoundTyKind {
950964impl < ' tcx > Stable < ' tcx > for ty:: BoundRegionKind {
951965 type T = stable_mir:: ty:: BoundRegionKind ;
952966
953- fn stable ( & self , _ : & mut Tables < ' tcx > ) -> Self :: T {
967+ fn stable ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
954968 use stable_mir:: ty:: BoundRegionKind ;
955969
956970 match self {
957971 ty:: BoundRegionKind :: BrAnon ( option_span) => {
958- BoundRegionKind :: BrAnon ( option_span. map ( |span| opaque ( & span) ) )
972+ BoundRegionKind :: BrAnon ( option_span. map ( |span| span. stable ( tables ) ) )
959973 }
960974 ty:: BoundRegionKind :: BrNamed ( def_id, symbol) => {
961975 BoundRegionKind :: BrNamed ( rustc_internal:: br_named_def ( * def_id) , symbol. to_string ( ) )
@@ -1053,16 +1067,14 @@ impl<'tcx> Stable<'tcx> for Ty<'tcx> {
10531067 }
10541068 ty:: Str => TyKind :: RigidTy ( RigidTy :: Str ) ,
10551069 ty:: Array ( ty, constant) => {
1056- let cnst = ConstantKind :: from_const ( * constant, tables. tcx ) ;
1057- let cnst = stable_mir:: ty:: Const { literal : cnst. stable ( tables) } ;
1058- TyKind :: RigidTy ( RigidTy :: Array ( tables. intern_ty ( * ty) , cnst) )
1070+ TyKind :: RigidTy ( RigidTy :: Array ( tables. intern_ty ( * ty) , constant. stable ( tables) ) )
10591071 }
10601072 ty:: Slice ( ty) => TyKind :: RigidTy ( RigidTy :: Slice ( tables. intern_ty ( * ty) ) ) ,
10611073 ty:: RawPtr ( ty:: TypeAndMut { ty, mutbl } ) => {
10621074 TyKind :: RigidTy ( RigidTy :: RawPtr ( tables. intern_ty ( * ty) , mutbl. stable ( tables) ) )
10631075 }
10641076 ty:: Ref ( region, ty, mutbl) => TyKind :: RigidTy ( RigidTy :: Ref (
1065- opaque ( region) ,
1077+ region. stable ( tables ) ,
10661078 tables. intern_ty ( * ty) ,
10671079 mutbl. stable ( tables) ,
10681080 ) ) ,
@@ -1077,7 +1089,7 @@ impl<'tcx> Stable<'tcx> for Ty<'tcx> {
10771089 . iter ( )
10781090 . map ( |existential_predicate| existential_predicate. stable ( tables) )
10791091 . collect ( ) ,
1080- opaque ( region) ,
1092+ region. stable ( tables ) ,
10811093 dyn_kind. stable ( tables) ,
10821094 ) )
10831095 }
@@ -1112,6 +1124,15 @@ impl<'tcx> Stable<'tcx> for Ty<'tcx> {
11121124 }
11131125}
11141126
1127+ impl < ' tcx > Stable < ' tcx > for ty:: Const < ' tcx > {
1128+ type T = stable_mir:: ty:: Const ;
1129+
1130+ fn stable ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
1131+ let cnst = ConstantKind :: from_const ( * self , tables. tcx ) ;
1132+ stable_mir:: ty:: Const { literal : cnst. stable ( tables) }
1133+ }
1134+ }
1135+
11151136impl < ' tcx > Stable < ' tcx > for ty:: ParamTy {
11161137 type T = stable_mir:: ty:: ParamTy ;
11171138 fn stable ( & self , _: & mut Tables < ' tcx > ) -> Self :: T {
@@ -1238,14 +1259,6 @@ impl<'tcx> Stable<'tcx> for ty::Generics {
12381259 }
12391260}
12401261
1241- impl < ' tcx > Stable < ' tcx > for rustc_span:: Span {
1242- type T = stable_mir:: ty:: Span ;
1243-
1244- fn stable ( & self , _: & mut Tables < ' tcx > ) -> Self :: T {
1245- opaque ( self )
1246- }
1247- }
1248-
12491262impl < ' tcx > Stable < ' tcx > for rustc_middle:: ty:: GenericParamDefKind {
12501263 type T = stable_mir:: ty:: GenericParamDefKind ;
12511264
@@ -1276,3 +1289,188 @@ impl<'tcx> Stable<'tcx> for rustc_middle::ty::GenericParamDef {
12761289 }
12771290 }
12781291}
1292+
1293+ impl < ' tcx > Stable < ' tcx > for ty:: PredicateKind < ' tcx > {
1294+ type T = stable_mir:: ty:: PredicateKind ;
1295+
1296+ fn stable ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
1297+ use ty:: PredicateKind ;
1298+ match self {
1299+ PredicateKind :: Clause ( clause_kind) => {
1300+ stable_mir:: ty:: PredicateKind :: Clause ( clause_kind. stable ( tables) )
1301+ }
1302+ PredicateKind :: ObjectSafe ( did) => {
1303+ stable_mir:: ty:: PredicateKind :: ObjectSafe ( tables. trait_def ( * did) )
1304+ }
1305+ PredicateKind :: ClosureKind ( did, generic_args, closure_kind) => {
1306+ stable_mir:: ty:: PredicateKind :: ClosureKind (
1307+ tables. closure_def ( * did) ,
1308+ generic_args. stable ( tables) ,
1309+ closure_kind. stable ( tables) ,
1310+ )
1311+ }
1312+ PredicateKind :: Subtype ( subtype_predicate) => {
1313+ stable_mir:: ty:: PredicateKind :: SubType ( subtype_predicate. stable ( tables) )
1314+ }
1315+ PredicateKind :: Coerce ( coerce_predicate) => {
1316+ stable_mir:: ty:: PredicateKind :: Coerce ( coerce_predicate. stable ( tables) )
1317+ }
1318+ PredicateKind :: ConstEquate ( a, b) => {
1319+ stable_mir:: ty:: PredicateKind :: ConstEquate ( a. stable ( tables) , b. stable ( tables) )
1320+ }
1321+ PredicateKind :: Ambiguous => stable_mir:: ty:: PredicateKind :: Ambiguous ,
1322+ PredicateKind :: AliasRelate ( a, b, alias_relation_direction) => {
1323+ stable_mir:: ty:: PredicateKind :: AliasRelate (
1324+ a. unpack ( ) . stable ( tables) ,
1325+ b. unpack ( ) . stable ( tables) ,
1326+ alias_relation_direction. stable ( tables) ,
1327+ )
1328+ }
1329+ }
1330+ }
1331+ }
1332+
1333+ impl < ' tcx > Stable < ' tcx > for ty:: ClauseKind < ' tcx > {
1334+ type T = stable_mir:: ty:: ClauseKind ;
1335+
1336+ fn stable ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
1337+ use ty:: ClauseKind :: * ;
1338+ match * self {
1339+ Trait ( trait_object) => stable_mir:: ty:: ClauseKind :: Trait ( trait_object. stable ( tables) ) ,
1340+ RegionOutlives ( region_outlives) => {
1341+ stable_mir:: ty:: ClauseKind :: RegionOutlives ( region_outlives. stable ( tables) )
1342+ }
1343+ TypeOutlives ( type_outlives) => {
1344+ let ty:: OutlivesPredicate :: < _ , _ > ( a, b) = type_outlives;
1345+ stable_mir:: ty:: ClauseKind :: TypeOutlives ( stable_mir:: ty:: OutlivesPredicate (
1346+ tables. intern_ty ( a) ,
1347+ b. stable ( tables) ,
1348+ ) )
1349+ }
1350+ Projection ( projection_predicate) => {
1351+ stable_mir:: ty:: ClauseKind :: Projection ( projection_predicate. stable ( tables) )
1352+ }
1353+ ConstArgHasType ( const_, ty) => stable_mir:: ty:: ClauseKind :: ConstArgHasType (
1354+ const_. stable ( tables) ,
1355+ tables. intern_ty ( ty) ,
1356+ ) ,
1357+ WellFormed ( generic_arg) => {
1358+ stable_mir:: ty:: ClauseKind :: WellFormed ( generic_arg. unpack ( ) . stable ( tables) )
1359+ }
1360+ ConstEvaluatable ( const_) => {
1361+ stable_mir:: ty:: ClauseKind :: ConstEvaluatable ( const_. stable ( tables) )
1362+ }
1363+ }
1364+ }
1365+ }
1366+
1367+ impl < ' tcx > Stable < ' tcx > for ty:: ClosureKind {
1368+ type T = stable_mir:: ty:: ClosureKind ;
1369+
1370+ fn stable ( & self , _: & mut Tables < ' tcx > ) -> Self :: T {
1371+ use ty:: ClosureKind :: * ;
1372+ match self {
1373+ Fn => stable_mir:: ty:: ClosureKind :: Fn ,
1374+ FnMut => stable_mir:: ty:: ClosureKind :: FnMut ,
1375+ FnOnce => stable_mir:: ty:: ClosureKind :: FnOnce ,
1376+ }
1377+ }
1378+ }
1379+
1380+ impl < ' tcx > Stable < ' tcx > for ty:: SubtypePredicate < ' tcx > {
1381+ type T = stable_mir:: ty:: SubtypePredicate ;
1382+
1383+ fn stable ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
1384+ let ty:: SubtypePredicate { a, b, a_is_expected : _ } = self ;
1385+ stable_mir:: ty:: SubtypePredicate { a : tables. intern_ty ( * a) , b : tables. intern_ty ( * b) }
1386+ }
1387+ }
1388+
1389+ impl < ' tcx > Stable < ' tcx > for ty:: CoercePredicate < ' tcx > {
1390+ type T = stable_mir:: ty:: CoercePredicate ;
1391+
1392+ fn stable ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
1393+ let ty:: CoercePredicate { a, b } = self ;
1394+ stable_mir:: ty:: CoercePredicate { a : tables. intern_ty ( * a) , b : tables. intern_ty ( * b) }
1395+ }
1396+ }
1397+
1398+ impl < ' tcx > Stable < ' tcx > for ty:: AliasRelationDirection {
1399+ type T = stable_mir:: ty:: AliasRelationDirection ;
1400+
1401+ fn stable ( & self , _: & mut Tables < ' tcx > ) -> Self :: T {
1402+ use ty:: AliasRelationDirection :: * ;
1403+ match self {
1404+ Equate => stable_mir:: ty:: AliasRelationDirection :: Equate ,
1405+ Subtype => stable_mir:: ty:: AliasRelationDirection :: Subtype ,
1406+ }
1407+ }
1408+ }
1409+
1410+ impl < ' tcx > Stable < ' tcx > for ty:: TraitPredicate < ' tcx > {
1411+ type T = stable_mir:: ty:: TraitPredicate ;
1412+
1413+ fn stable ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
1414+ let ty:: TraitPredicate { trait_ref, polarity } = self ;
1415+ stable_mir:: ty:: TraitPredicate {
1416+ trait_ref : trait_ref. stable ( tables) ,
1417+ polarity : polarity. stable ( tables) ,
1418+ }
1419+ }
1420+ }
1421+
1422+ impl < ' tcx , A , B , U , V > Stable < ' tcx > for ty:: OutlivesPredicate < A , B >
1423+ where
1424+ A : Stable < ' tcx , T = U > ,
1425+ B : Stable < ' tcx , T = V > ,
1426+ {
1427+ type T = stable_mir:: ty:: OutlivesPredicate < U , V > ;
1428+
1429+ fn stable ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
1430+ let ty:: OutlivesPredicate ( a, b) = self ;
1431+ stable_mir:: ty:: OutlivesPredicate ( a. stable ( tables) , b. stable ( tables) )
1432+ }
1433+ }
1434+
1435+ impl < ' tcx > Stable < ' tcx > for ty:: ProjectionPredicate < ' tcx > {
1436+ type T = stable_mir:: ty:: ProjectionPredicate ;
1437+
1438+ fn stable ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
1439+ let ty:: ProjectionPredicate { projection_ty, term } = self ;
1440+ stable_mir:: ty:: ProjectionPredicate {
1441+ projection_ty : projection_ty. stable ( tables) ,
1442+ term : term. unpack ( ) . stable ( tables) ,
1443+ }
1444+ }
1445+ }
1446+
1447+ impl < ' tcx > Stable < ' tcx > for ty:: ImplPolarity {
1448+ type T = stable_mir:: ty:: ImplPolarity ;
1449+
1450+ fn stable ( & self , _: & mut Tables < ' tcx > ) -> Self :: T {
1451+ use ty:: ImplPolarity :: * ;
1452+ match self {
1453+ Positive => stable_mir:: ty:: ImplPolarity :: Positive ,
1454+ Negative => stable_mir:: ty:: ImplPolarity :: Negative ,
1455+ Reservation => stable_mir:: ty:: ImplPolarity :: Reservation ,
1456+ }
1457+ }
1458+ }
1459+
1460+ impl < ' tcx > Stable < ' tcx > for ty:: Region < ' tcx > {
1461+ type T = stable_mir:: ty:: Region ;
1462+
1463+ fn stable ( & self , _: & mut Tables < ' tcx > ) -> Self :: T {
1464+ // FIXME: add a real implementation of stable regions
1465+ opaque ( self )
1466+ }
1467+ }
1468+
1469+ impl < ' tcx > Stable < ' tcx > for rustc_span:: Span {
1470+ type T = stable_mir:: ty:: Span ;
1471+
1472+ fn stable ( & self , _: & mut Tables < ' tcx > ) -> Self :: T {
1473+ // FIXME: add a real implementation of stable spans
1474+ opaque ( self )
1475+ }
1476+ }
0 commit comments