@@ -31,7 +31,6 @@ use rustc::ty::{self, AdtKind, ToPolyTraitRef, Ty, TyCtxt};
3131use rustc:: ty:: { ReprOptions , ToPredicate } ;
3232use rustc:: util:: captures:: Captures ;
3333use rustc:: util:: nodemap:: FxHashMap ;
34- use rustc_data_structures:: sync:: Lrc ;
3534use rustc_target:: spec:: abi;
3635
3736use syntax:: ast;
@@ -178,7 +177,7 @@ impl<'a, 'tcx> AstConv<'tcx, 'tcx> for ItemCtxt<'a, 'tcx> {
178177 }
179178
180179 fn get_type_parameter_bounds ( & self , span : Span , def_id : DefId )
181- -> Lrc < ty:: GenericPredicates < ' tcx > > {
180+ -> & ' tcx ty:: GenericPredicates < ' tcx > {
182181 self . tcx
183182 . at ( span)
184183 . type_param_predicates ( ( self . item_def_id , def_id) )
@@ -243,7 +242,7 @@ impl<'a, 'tcx> AstConv<'tcx, 'tcx> for ItemCtxt<'a, 'tcx> {
243242fn type_param_predicates < ' a , ' tcx > (
244243 tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
245244 ( item_def_id, def_id) : ( DefId , DefId ) ,
246- ) -> Lrc < ty:: GenericPredicates < ' tcx > > {
245+ ) -> & ' tcx ty:: GenericPredicates < ' tcx > {
247246 use rustc:: hir:: * ;
248247
249248 // In the AST, bounds can derive from two places. Either
@@ -264,16 +263,11 @@ fn type_param_predicates<'a, 'tcx>(
264263 tcx. generics_of ( item_def_id) . parent
265264 } ;
266265
267- let mut result = parent. map_or_else (
268- || Lrc :: new ( ty:: GenericPredicates {
269- parent : None ,
270- predicates : vec ! [ ] ,
271- } ) ,
272- |parent| {
273- let icx = ItemCtxt :: new ( tcx, parent) ;
274- icx. get_type_parameter_bounds ( DUMMY_SP , def_id)
275- } ,
276- ) ;
266+ let result = parent. map_or ( & tcx. common . empty_predicates , |parent| {
267+ let icx = ItemCtxt :: new ( tcx, parent) ;
268+ icx. get_type_parameter_bounds ( DUMMY_SP , def_id)
269+ } ) ;
270+ let mut extend = None ;
277271
278272 let item_hir_id = tcx. hir ( ) . as_local_hir_id ( item_def_id) . unwrap ( ) ;
279273 let ast_generics = match tcx. hir ( ) . get_by_hir_id ( item_hir_id) {
@@ -298,9 +292,7 @@ fn type_param_predicates<'a, 'tcx>(
298292 // Implied `Self: Trait` and supertrait bounds.
299293 if param_id == item_hir_id {
300294 let identity_trait_ref = ty:: TraitRef :: identity ( tcx, item_def_id) ;
301- Lrc :: make_mut ( & mut result)
302- . predicates
303- . push ( ( identity_trait_ref. to_predicate ( ) , item. span ) ) ;
295+ extend = Some ( ( identity_trait_ref. to_predicate ( ) , item. span ) ) ;
304296 }
305297 generics
306298 }
@@ -317,11 +309,12 @@ fn type_param_predicates<'a, 'tcx>(
317309 } ;
318310
319311 let icx = ItemCtxt :: new ( tcx, item_def_id) ;
320- Lrc :: make_mut ( & mut result)
321- . predicates
322- . extend ( icx. type_parameter_bounds_in_generics ( ast_generics, param_id, ty,
323- OnlySelfBounds ( true ) ) ) ;
324- result
312+ let mut result = ( * result) . clone ( ) ;
313+ result. predicates . extend ( extend. into_iter ( ) ) ;
314+ result. predicates
315+ . extend ( icx. type_parameter_bounds_in_generics ( ast_generics, param_id, ty,
316+ OnlySelfBounds ( true ) ) ) ;
317+ tcx. arena . alloc ( result)
325318}
326319
327320impl < ' a , ' tcx > ItemCtxt < ' a , ' tcx > {
@@ -690,7 +683,7 @@ fn adt_def<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty::Ad
690683fn super_predicates_of < ' a , ' tcx > (
691684 tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
692685 trait_def_id : DefId ,
693- ) -> Lrc < ty:: GenericPredicates < ' tcx > > {
686+ ) -> & ' tcx ty:: GenericPredicates < ' tcx > {
694687 debug ! ( "super_predicates(trait_def_id={:?})" , trait_def_id) ;
695688 let trait_hir_id = tcx. hir ( ) . as_local_hir_id ( trait_def_id) . unwrap ( ) ;
696689
@@ -734,7 +727,7 @@ fn super_predicates_of<'a, 'tcx>(
734727 }
735728 }
736729
737- Lrc :: new ( ty:: GenericPredicates {
730+ tcx . arena . alloc ( ty:: GenericPredicates {
738731 parent : None ,
739732 predicates : superbounds,
740733 } )
@@ -1842,7 +1835,7 @@ fn early_bound_lifetimes_from_generics<'a, 'tcx>(
18421835fn predicates_defined_on < ' a , ' tcx > (
18431836 tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
18441837 def_id : DefId ,
1845- ) -> Lrc < ty:: GenericPredicates < ' tcx > > {
1838+ ) -> & ' tcx ty:: GenericPredicates < ' tcx > {
18461839 debug ! ( "predicates_defined_on({:?})" , def_id) ;
18471840 let mut result = tcx. explicit_predicates_of ( def_id) ;
18481841 debug ! (
@@ -1858,9 +1851,9 @@ fn predicates_defined_on<'a, 'tcx>(
18581851 def_id,
18591852 inferred_outlives,
18601853 ) ;
1861- Lrc :: make_mut ( & mut result)
1862- . predicates
1863- . extend ( inferred_outlives . iter ( ) . map ( | & p| ( p , span ) ) ) ;
1854+ let mut predicates = ( * result) . clone ( ) ;
1855+ predicates . predicates . extend ( inferred_outlives . iter ( ) . map ( | & p| ( p , span ) ) ) ;
1856+ result = tcx . arena . alloc ( predicates ) ;
18641857 }
18651858 debug ! ( "predicates_defined_on({:?}) = {:?}" , def_id, result) ;
18661859 result
@@ -1872,7 +1865,7 @@ fn predicates_defined_on<'a, 'tcx>(
18721865fn predicates_of < ' a , ' tcx > (
18731866 tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
18741867 def_id : DefId ,
1875- ) -> Lrc < ty:: GenericPredicates < ' tcx > > {
1868+ ) -> & ' tcx ty:: GenericPredicates < ' tcx > {
18761869 let mut result = tcx. predicates_defined_on ( def_id) ;
18771870
18781871 if tcx. is_trait ( def_id) {
@@ -1889,9 +1882,9 @@ fn predicates_of<'a, 'tcx>(
18891882 // used, and adding the predicate into this list ensures
18901883 // that this is done.
18911884 let span = tcx. def_span ( def_id) ;
1892- Lrc :: make_mut ( & mut result)
1893- . predicates
1894- . push ( ( ty :: TraitRef :: identity ( tcx, def_id ) . to_predicate ( ) , span ) ) ;
1885+ let mut predicates = ( * result) . clone ( ) ;
1886+ predicates . predicates . push ( ( ty :: TraitRef :: identity ( tcx , def_id ) . to_predicate ( ) , span ) ) ;
1887+ result = tcx. arena . alloc ( predicates ) ;
18951888 }
18961889 debug ! ( "predicates_of(def_id={:?}) = {:?}" , def_id, result) ;
18971890 result
@@ -1902,7 +1895,7 @@ fn predicates_of<'a, 'tcx>(
19021895fn explicit_predicates_of < ' a , ' tcx > (
19031896 tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
19041897 def_id : DefId ,
1905- ) -> Lrc < ty:: GenericPredicates < ' tcx > > {
1898+ ) -> & ' tcx ty:: GenericPredicates < ' tcx > {
19061899 use rustc:: hir:: * ;
19071900 use rustc_data_structures:: fx:: FxHashSet ;
19081901
@@ -2017,7 +2010,7 @@ fn explicit_predicates_of<'a, 'tcx>(
20172010
20182011 if impl_trait_fn. is_some ( ) {
20192012 // impl Trait
2020- return Lrc :: new ( ty:: GenericPredicates {
2013+ return tcx . arena . alloc ( ty:: GenericPredicates {
20212014 parent : None ,
20222015 predicates : bounds. predicates ( tcx, opaque_ty) ,
20232016 } ) ;
@@ -2228,7 +2221,7 @@ fn explicit_predicates_of<'a, 'tcx>(
22282221 ) ;
22292222 }
22302223
2231- let result = Lrc :: new ( ty:: GenericPredicates {
2224+ let result = tcx . arena . alloc ( ty:: GenericPredicates {
22322225 parent : generics. parent ,
22332226 predicates,
22342227 } ) ;
0 commit comments