@@ -39,6 +39,7 @@ use rustc::ty::{self, AdtKind, ToPolyTraitRef, Ty, TyCtxt};
39
39
use rustc:: ty:: { ReprOptions , ToPredicate } ;
40
40
use rustc:: util:: captures:: Captures ;
41
41
use rustc:: util:: nodemap:: FxHashMap ;
42
+ use rustc_data_structures:: sync:: Lrc ;
42
43
use rustc_target:: spec:: abi;
43
44
44
45
use syntax:: ast;
@@ -178,7 +179,8 @@ impl<'a, 'tcx> AstConv<'tcx, 'tcx> for ItemCtxt<'a, 'tcx> {
178
179
self . tcx
179
180
}
180
181
181
- fn get_type_parameter_bounds ( & self , span : Span , def_id : DefId ) -> ty:: GenericPredicates < ' tcx > {
182
+ fn get_type_parameter_bounds ( & self , span : Span , def_id : DefId )
183
+ -> Lrc < ty:: GenericPredicates < ' tcx > > {
182
184
self . tcx
183
185
. at ( span)
184
186
. type_param_predicates ( ( self . item_def_id , def_id) )
@@ -243,7 +245,7 @@ impl<'a, 'tcx> AstConv<'tcx, 'tcx> for ItemCtxt<'a, 'tcx> {
243
245
fn type_param_predicates < ' a , ' tcx > (
244
246
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
245
247
( item_def_id, def_id) : ( DefId , DefId ) ,
246
- ) -> ty:: GenericPredicates < ' tcx > {
248
+ ) -> Lrc < ty:: GenericPredicates < ' tcx > > {
247
249
use rustc:: hir:: * ;
248
250
249
251
// In the AST, bounds can derive from two places. Either
@@ -264,11 +266,11 @@ fn type_param_predicates<'a, 'tcx>(
264
266
tcx. generics_of ( item_def_id) . parent
265
267
} ;
266
268
267
- let mut result = parent. map_or (
268
- ty:: GenericPredicates {
269
+ let mut result = parent. map_or_else (
270
+ || Lrc :: new ( ty:: GenericPredicates {
269
271
parent : None ,
270
272
predicates : vec ! [ ] ,
271
- } ,
273
+ } ) ,
272
274
|parent| {
273
275
let icx = ItemCtxt :: new ( tcx, parent) ;
274
276
icx. get_type_parameter_bounds ( DUMMY_SP , def_id)
@@ -298,7 +300,7 @@ fn type_param_predicates<'a, 'tcx>(
298
300
// Implied `Self: Trait` and supertrait bounds.
299
301
if param_id == item_node_id {
300
302
let identity_trait_ref = ty:: TraitRef :: identity ( tcx, item_def_id) ;
301
- result
303
+ Lrc :: make_mut ( & mut result)
302
304
. predicates
303
305
. push ( ( identity_trait_ref. to_predicate ( ) , item. span ) ) ;
304
306
}
@@ -317,7 +319,7 @@ fn type_param_predicates<'a, 'tcx>(
317
319
} ;
318
320
319
321
let icx = ItemCtxt :: new ( tcx, item_def_id) ;
320
- result
322
+ Lrc :: make_mut ( & mut result)
321
323
. predicates
322
324
. extend ( icx. type_parameter_bounds_in_generics ( ast_generics, param_id, ty,
323
325
OnlySelfBounds ( true ) ) ) ;
@@ -685,7 +687,7 @@ fn adt_def<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty::Ad
685
687
fn super_predicates_of < ' a , ' tcx > (
686
688
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
687
689
trait_def_id : DefId ,
688
- ) -> ty:: GenericPredicates < ' tcx > {
690
+ ) -> Lrc < ty:: GenericPredicates < ' tcx > > {
689
691
debug ! ( "super_predicates(trait_def_id={:?})" , trait_def_id) ;
690
692
let trait_node_id = tcx. hir . as_local_node_id ( trait_def_id) . unwrap ( ) ;
691
693
@@ -729,10 +731,10 @@ fn super_predicates_of<'a, 'tcx>(
729
731
}
730
732
}
731
733
732
- ty:: GenericPredicates {
734
+ Lrc :: new ( ty:: GenericPredicates {
733
735
parent : None ,
734
736
predicates : superbounds,
735
- }
737
+ } )
736
738
}
737
739
738
740
fn trait_def < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , def_id : DefId ) -> & ' tcx ty:: TraitDef {
@@ -1605,27 +1607,23 @@ fn early_bound_lifetimes_from_generics<'a, 'tcx>(
1605
1607
fn predicates_defined_on < ' a , ' tcx > (
1606
1608
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
1607
1609
def_id : DefId ,
1608
- ) -> ty:: GenericPredicates < ' tcx > {
1609
- let explicit = tcx. explicit_predicates_of ( def_id) ;
1610
- let span = tcx. def_span ( def_id) ;
1611
- let predicates = explicit. predicates . into_iter ( ) . chain (
1612
- tcx. inferred_outlives_of ( def_id) . iter ( ) . map ( |& p| ( p, span) )
1613
- ) . collect ( ) ;
1614
-
1615
- ty:: GenericPredicates {
1616
- parent : explicit. parent ,
1617
- predicates : predicates,
1610
+ ) -> Lrc < ty:: GenericPredicates < ' tcx > > {
1611
+ let mut result = tcx. explicit_predicates_of ( def_id) ;
1612
+ let inferred_outlives = tcx. inferred_outlives_of ( def_id) ;
1613
+ if !inferred_outlives. is_empty ( ) {
1614
+ let span = tcx. def_span ( def_id) ;
1615
+ Lrc :: make_mut ( & mut result)
1616
+ . predicates
1617
+ . extend ( inferred_outlives. iter ( ) . map ( |& p| ( p, span) ) ) ;
1618
1618
}
1619
+ result
1619
1620
}
1620
1621
1621
1622
fn predicates_of < ' a , ' tcx > (
1622
1623
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
1623
1624
def_id : DefId ,
1624
- ) -> ty:: GenericPredicates < ' tcx > {
1625
- let ty:: GenericPredicates {
1626
- parent,
1627
- mut predicates,
1628
- } = tcx. predicates_defined_on ( def_id) ;
1625
+ ) -> Lrc < ty:: GenericPredicates < ' tcx > > {
1626
+ let mut result = tcx. predicates_defined_on ( def_id) ;
1629
1627
1630
1628
if tcx. is_trait ( def_id) {
1631
1629
// For traits, add `Self: Trait` predicate. This is
@@ -1641,16 +1639,17 @@ fn predicates_of<'a, 'tcx>(
1641
1639
// used, and adding the predicate into this list ensures
1642
1640
// that this is done.
1643
1641
let span = tcx. def_span ( def_id) ;
1644
- predicates. push ( ( ty:: TraitRef :: identity ( tcx, def_id) . to_predicate ( ) , span) ) ;
1642
+ Lrc :: make_mut ( & mut result)
1643
+ . predicates
1644
+ . push ( ( ty:: TraitRef :: identity ( tcx, def_id) . to_predicate ( ) , span) ) ;
1645
1645
}
1646
-
1647
- ty:: GenericPredicates { parent, predicates }
1646
+ result
1648
1647
}
1649
1648
1650
1649
fn explicit_predicates_of < ' a , ' tcx > (
1651
1650
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
1652
1651
def_id : DefId ,
1653
- ) -> ty:: GenericPredicates < ' tcx > {
1652
+ ) -> Lrc < ty:: GenericPredicates < ' tcx > > {
1654
1653
use rustc:: hir:: * ;
1655
1654
use rustc_data_structures:: fx:: FxHashSet ;
1656
1655
@@ -1761,10 +1760,10 @@ fn explicit_predicates_of<'a, 'tcx>(
1761
1760
1762
1761
if impl_trait_fn. is_some ( ) {
1763
1762
// impl Trait
1764
- return ty:: GenericPredicates {
1763
+ return Lrc :: new ( ty:: GenericPredicates {
1765
1764
parent : None ,
1766
1765
predicates : bounds. predicates ( tcx, opaque_ty) ,
1767
- } ;
1766
+ } ) ;
1768
1767
} else {
1769
1768
// named existential types
1770
1769
predicates. extend ( bounds. predicates ( tcx, opaque_ty) ) ;
@@ -1794,7 +1793,7 @@ fn explicit_predicates_of<'a, 'tcx>(
1794
1793
// on a trait we need to add in the supertrait bounds and bounds found on
1795
1794
// associated types.
1796
1795
if let Some ( ( _trait_ref, _) ) = is_trait {
1797
- predicates. extend ( tcx. super_predicates_of ( def_id) . predicates ) ;
1796
+ predicates. extend ( tcx. super_predicates_of ( def_id) . predicates . iter ( ) . cloned ( ) ) ;
1798
1797
}
1799
1798
1800
1799
// In default impls, we can assume that the self type implements
@@ -1971,10 +1970,10 @@ fn explicit_predicates_of<'a, 'tcx>(
1971
1970
) ;
1972
1971
}
1973
1972
1974
- ty:: GenericPredicates {
1973
+ Lrc :: new ( ty:: GenericPredicates {
1975
1974
parent : generics. parent ,
1976
1975
predicates,
1977
- }
1976
+ } )
1978
1977
}
1979
1978
1980
1979
pub enum SizedByDefault {
0 commit comments