@@ -1606,6 +1606,13 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
16061606}
16071607
16081608impl < ' gcx : ' tcx , ' tcx > GlobalCtxt < ' gcx > {
1609+ pub fn tcx ( & self ) -> TyCtxt < ' _ , ' gcx , ' gcx > {
1610+ TyCtxt {
1611+ gcx : self ,
1612+ interners : & self . global_interners ,
1613+ }
1614+ }
1615+
16091616 /// Call the closure with a local `TyCtxt` using the given arena.
16101617 pub fn enter_local < F , R > (
16111618 & self ,
@@ -1616,21 +1623,9 @@ impl<'gcx: 'tcx, 'tcx> GlobalCtxt<'gcx> {
16161623 F : for < ' a > FnOnce ( TyCtxt < ' a , ' gcx , ' tcx > ) -> R
16171624 {
16181625 let interners = CtxtInterners :: new ( arena) ;
1619- let tcx = TyCtxt {
1626+ f ( TyCtxt {
16201627 gcx : self ,
16211628 interners : & interners,
1622- } ;
1623- ty:: tls:: with_related_context ( tcx. global_tcx ( ) , |icx| {
1624- let new_icx = ty:: tls:: ImplicitCtxt {
1625- tcx,
1626- query : icx. query ,
1627- diagnostics : icx. diagnostics ,
1628- layout_depth : icx. layout_depth ,
1629- task : icx. task ,
1630- } ;
1631- ty:: tls:: enter_context ( & new_icx, |new_icx| {
1632- f ( new_icx. tcx )
1633- } )
16341629 } )
16351630 }
16361631}
@@ -1888,10 +1883,10 @@ pub mod tls {
18881883 /// you should also have access to an ImplicitCtxt through the functions
18891884 /// in this module.
18901885 #[ derive( Clone ) ]
1891- pub struct ImplicitCtxt < ' a , ' gcx : ' a + ' tcx , ' tcx : ' a > {
1886+ pub struct ImplicitCtxt < ' a , ' gcx > {
18921887 /// The current TyCtxt. Initially created by `enter_global` and updated
18931888 /// by `enter_local` with a new local interner
1894- pub tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
1889+ pub gcx : & ' a GlobalCtxt < ' gcx > ,
18951890
18961891 /// The current query job, if any. This is updated by start_job in
18971892 /// ty::query::plumbing when executing a query
@@ -2010,9 +2005,9 @@ pub mod tls {
20102005
20112006 /// Sets `context` as the new current ImplicitCtxt for the duration of the function `f`
20122007 #[ inline]
2013- pub fn enter_context < ' a , ' gcx : ' tcx , ' tcx , F , R > ( context : & ImplicitCtxt < ' a , ' gcx , ' tcx > ,
2008+ pub fn enter_context < ' a , ' gcx , F , R > ( context : & ImplicitCtxt < ' a , ' gcx > ,
20142009 f : F ) -> R
2015- where F : FnOnce ( & ImplicitCtxt < ' a , ' gcx , ' tcx > ) -> R
2010+ where F : FnOnce ( & ImplicitCtxt < ' a , ' gcx > ) -> R
20162011 {
20172012 set_tlv ( context as * const _ as usize , || {
20182013 f ( & context)
@@ -2041,7 +2036,7 @@ pub mod tls {
20412036 interners : & gcx. global_interners ,
20422037 } ;
20432038 let icx = ImplicitCtxt {
2044- tcx ,
2039+ gcx ,
20452040 query : None ,
20462041 diagnostics : None ,
20472042 layout_depth : 0 ,
@@ -2073,7 +2068,7 @@ pub mod tls {
20732068 let icx = ImplicitCtxt {
20742069 query : None ,
20752070 diagnostics : None ,
2076- tcx ,
2071+ gcx ,
20772072 layout_depth : 0 ,
20782073 task : & OpenTask :: Ignore ,
20792074 } ;
@@ -2083,25 +2078,25 @@ pub mod tls {
20832078 /// Allows access to the current ImplicitCtxt in a closure if one is available
20842079 #[ inline]
20852080 pub fn with_context_opt < F , R > ( f : F ) -> R
2086- where F : for <' a , ' gcx , ' tcx > FnOnce ( Option < & ImplicitCtxt < ' a , ' gcx , ' tcx > > ) -> R
2081+ where F : for <' a , ' gcx > FnOnce ( Option < & ImplicitCtxt < ' a , ' gcx > > ) -> R
20872082 {
20882083 let context = get_tlv ( ) ;
20892084 if context == 0 {
20902085 f ( None )
20912086 } else {
20922087 // We could get a ImplicitCtxt pointer from another thread.
20932088 // Ensure that ImplicitCtxt is Sync
2094- sync:: assert_sync :: < ImplicitCtxt < ' _ , ' _ , ' _ > > ( ) ;
2089+ sync:: assert_sync :: < ImplicitCtxt < ' _ , ' _ > > ( ) ;
20952090
2096- unsafe { f ( Some ( & * ( context as * const ImplicitCtxt < ' _ , ' _ , ' _ > ) ) ) }
2091+ unsafe { f ( Some ( & * ( context as * const ImplicitCtxt < ' _ , ' _ > ) ) ) }
20972092 }
20982093 }
20992094
21002095 /// Allows access to the current ImplicitCtxt.
21012096 /// Panics if there is no ImplicitCtxt available
21022097 #[ inline]
21032098 pub fn with_context < F , R > ( f : F ) -> R
2104- where F : for <' a , ' gcx , ' tcx > FnOnce ( & ImplicitCtxt < ' a , ' gcx , ' tcx > ) -> R
2099+ where F : for <' a , ' gcx > FnOnce ( & ImplicitCtxt < ' a , ' gcx > ) -> R
21052100 {
21062101 with_context_opt ( |opt_context| f ( opt_context. expect ( "no ImplicitCtxt stored in tls" ) ) )
21072102 }
@@ -2112,35 +2107,14 @@ pub mod tls {
21122107 /// This will panic if you pass it a TyCtxt which has a different global interner from
21132108 /// the current ImplicitCtxt's tcx field.
21142109 #[ inline]
2115- pub fn with_related_context < ' a , ' gcx , ' tcx1 , F , R > ( tcx : TyCtxt < ' a , ' gcx , ' tcx1 > , f : F ) -> R
2116- where F : for <' b , ' tcx2 > FnOnce ( & ImplicitCtxt < ' b , ' gcx , ' tcx2 > ) -> R
2110+ pub fn with_related_context < ' a , ' gcx , ' tcx , F , R > ( tcx : TyCtxt < ' a , ' gcx , ' tcx > , f : F ) -> R
2111+ where F : for < ' b > FnOnce ( & ImplicitCtxt < ' b , ' gcx > ) -> R
21172112 {
21182113 with_context ( |context| {
21192114 unsafe {
21202115 let gcx = tcx. gcx as * const _ as usize ;
2121- assert ! ( context. tcx. gcx as * const _ as usize == gcx) ;
2122- let context: & ImplicitCtxt < ' _ , ' _ , ' _ > = mem:: transmute ( context) ;
2123- f ( context)
2124- }
2125- } )
2126- }
2127-
2128- /// Allows access to the current ImplicitCtxt whose tcx field has the same global
2129- /// interner and local interner as the tcx argument passed in. This means the closure
2130- /// is given an ImplicitCtxt with the same 'tcx and 'gcx lifetimes as the TyCtxt passed in.
2131- /// This will panic if you pass it a TyCtxt which has a different global interner or
2132- /// a different local interner from the current ImplicitCtxt's tcx field.
2133- #[ inline]
2134- pub fn with_fully_related_context < ' a , ' gcx , ' tcx , F , R > ( tcx : TyCtxt < ' a , ' gcx , ' tcx > , f : F ) -> R
2135- where F : for < ' b > FnOnce ( & ImplicitCtxt < ' b , ' gcx , ' tcx > ) -> R
2136- {
2137- with_context ( |context| {
2138- unsafe {
2139- let gcx = tcx. gcx as * const _ as usize ;
2140- let interners = tcx. interners as * const _ as usize ;
2141- assert ! ( context. tcx. gcx as * const _ as usize == gcx) ;
2142- assert ! ( context. tcx. interners as * const _ as usize == interners) ;
2143- let context: & ImplicitCtxt < ' _ , ' _ , ' _ > = mem:: transmute ( context) ;
2116+ assert ! ( context. gcx as * const _ as usize == gcx) ;
2117+ let context: & ImplicitCtxt < ' _ , ' _ > = mem:: transmute ( context) ;
21442118 f ( context)
21452119 }
21462120 } )
@@ -2150,18 +2124,18 @@ pub mod tls {
21502124 /// Panics if there is no ImplicitCtxt available
21512125 #[ inline]
21522126 pub fn with < F , R > ( f : F ) -> R
2153- where F : for <' a , ' gcx , ' tcx > FnOnce ( TyCtxt < ' a , ' gcx , ' tcx > ) -> R
2127+ where F : for <' a , ' gcx > FnOnce ( TyCtxt < ' a , ' gcx , ' gcx > ) -> R
21542128 {
2155- with_context ( |context| f ( context. tcx ) )
2129+ with_context ( |context| f ( context. gcx . tcx ( ) ) )
21562130 }
21572131
21582132 /// Allows access to the TyCtxt in the current ImplicitCtxt.
21592133 /// The closure is passed None if there is no ImplicitCtxt available
21602134 #[ inline]
21612135 pub fn with_opt < F , R > ( f : F ) -> R
2162- where F : for <' a , ' gcx , ' tcx > FnOnce ( Option < TyCtxt < ' a , ' gcx , ' tcx > > ) -> R
2136+ where F : for <' a , ' gcx > FnOnce ( Option < TyCtxt < ' a , ' gcx , ' gcx > > ) -> R
21632137 {
2164- with_context_opt ( |opt_context| f ( opt_context. map ( |context| context. tcx ) ) )
2138+ with_context_opt ( |opt_context| f ( opt_context. map ( |context| context. gcx . tcx ( ) ) ) )
21652139 }
21662140}
21672141
0 commit comments