@@ -18,15 +18,14 @@ use std::cell::RefCell;
1818use std:: fmt:: Debug ;
1919use std:: hash:: Hash ;
2020use std:: ops:: Index ;
21- use std:: rc:: Rc ;
2221
2322mod internal;
2423
25- pub unsafe fn stable < ' tcx , S : Stable < ' tcx > > ( item : & S ) -> S :: T {
24+ pub fn stable < ' tcx , S : Stable < ' tcx > > ( item : & S ) -> S :: T {
2625 with_tables ( |tables| item. stable ( tables) )
2726}
2827
29- pub unsafe fn internal < ' tcx , S : RustcInternal < ' tcx > > ( item : & S ) -> S :: T {
28+ pub fn internal < ' tcx , S : RustcInternal < ' tcx > > ( item : & S ) -> S :: T {
3029 with_tables ( |tables| item. internal ( tables) )
3130}
3231
@@ -141,15 +140,12 @@ pub fn crate_num(item: &stable_mir::Crate) -> CrateNum {
141140// datastructures and stable MIR datastructures
142141scoped_thread_local ! ( static TLV : Cell <* const ( ) >) ;
143142
144- pub ( crate ) fn init < ' tcx > ( tables : TablesWrapper < ' tcx > , f : impl FnOnce ( ) ) {
143+ pub ( crate ) fn init < ' tcx > ( tables : & TablesWrapper < ' tcx > , f : impl FnOnce ( ) ) {
145144 assert ! ( !TLV . is_set( ) ) ;
146- fn g < ' a , ' tcx > ( context : & ' a TablesWrapper < ' tcx > , f : impl FnOnce ( ) ) {
147- let ptr: * const ( ) = & context as * const & _ as _ ;
148- TLV . set ( & Cell :: new ( ptr) , || {
149- f ( ) ;
150- } ) ;
151- }
152- g ( & tables, f) ;
145+ let ptr: * const ( ) = & tables as * const & _ as _ ;
146+ TLV . set ( & Cell :: new ( ptr) , || {
147+ f ( ) ;
148+ } ) ;
153149}
154150
155151/// Loads the current context and calls a function with it.
@@ -166,15 +162,15 @@ pub(crate) fn with_tables<'tcx, R>(f: impl FnOnce(&mut Tables<'tcx>) -> R) -> R
166162}
167163
168164pub fn run ( tcx : TyCtxt < ' _ > , f : impl FnOnce ( ) ) {
169- let tables = Rc :: new ( RefCell :: new ( Tables {
165+ let tables = TablesWrapper ( RefCell :: new ( Tables {
170166 tcx,
171167 def_ids : IndexMap :: default ( ) ,
172168 alloc_ids : IndexMap :: default ( ) ,
173169 spans : IndexMap :: default ( ) ,
174170 types : vec ! [ ] ,
175171 instances : IndexMap :: default ( ) ,
176172 } ) ) ;
177- stable_mir:: run ( TablesWrapper ( Rc :: clone ( & tables) ) , || init ( TablesWrapper ( tables) , f) ) ;
173+ stable_mir:: run ( & tables, || init ( & tables, f) ) ;
178174}
179175
180176#[ macro_export]
0 commit comments