/// Necessary because we can't write the following bound:
/// `F: for<'b, 'tcx> where 'tcx FnOnce(InferCtxt<'b, 'tcx>)`.
pub struct InferCtxtBuilder<'tcx> {
- global_tcx: TyCtxt<'tcx>,
+ tcx: TyCtxt<'tcx>,
fresh_tables: Option<RefCell<ty::TypeckTables<'tcx>>>,
}
impl TyCtxtInferExt<'tcx> for TyCtxt<'tcx> {
fn infer_ctxt(self) -> InferCtxtBuilder<'tcx> {
- InferCtxtBuilder { global_tcx: self, fresh_tables: None }
+ InferCtxtBuilder { tcx: self, fresh_tables: None }
}
}
}
pub fn enter<R>(&mut self, f: impl for<'a> FnOnce(InferCtxt<'a, 'tcx>) -> R) -> R {
- let InferCtxtBuilder { global_tcx, ref fresh_tables } = *self;
+ let InferCtxtBuilder { tcx, ref fresh_tables } = *self;
let in_progress_tables = fresh_tables.as_ref();
- global_tcx.enter_local(|tcx| {
- f(InferCtxt {
- tcx,
- in_progress_tables,
- inner: RefCell::new(InferCtxtInner::new()),
- lexical_region_resolutions: RefCell::new(None),
- selection_cache: Default::default(),
- evaluation_cache: Default::default(),
- reported_trait_errors: Default::default(),
- reported_closure_mismatch: Default::default(),
- tainted_by_errors_flag: Cell::new(false),
- err_count_on_creation: tcx.sess.err_count(),
- in_snapshot: Cell::new(false),
- skip_leak_check: Cell::new(false),
- universe: Cell::new(ty::UniverseIndex::ROOT),
- })
+ f(InferCtxt {
+ tcx,
+ in_progress_tables,
+ inner: RefCell::new(InferCtxtInner::new()),
+ lexical_region_resolutions: RefCell::new(None),
+ selection_cache: Default::default(),
+ evaluation_cache: Default::default(),
+ reported_trait_errors: Default::default(),
+ reported_closure_mismatch: Default::default(),
+ tainted_by_errors_flag: Cell::new(false),
+ err_count_on_creation: tcx.sess.err_count(),
+ in_snapshot: Cell::new(false),
+ skip_leak_check: Cell::new(false),
+ universe: Cell::new(ty::UniverseIndex::ROOT),
})
}
}
}
}
-impl<'tcx> GlobalCtxt<'tcx> {
- /// Calls the closure with a local `TyCtxt` using the given arena.
- /// `interners` is a slot passed so we can create a CtxtInterners
- /// with the same lifetime as `arena`.
- pub fn enter_local<F, R>(&'tcx self, f: F) -> R
- where
- F: FnOnce(TyCtxt<'tcx>) -> R,
- {
- let tcx = TyCtxt { gcx: self };
- ty::tls::with_related_context(tcx, |icx| {
- let new_icx = ty::tls::ImplicitCtxt {
- tcx,
- query: icx.query,
- diagnostics: icx.diagnostics,
- layout_depth: icx.layout_depth,
- task_deps: icx.task_deps,
- };
- ty::tls::enter_context(&new_icx, |_| f(tcx))
- })
- }
-}
-
/// A trait implemented for all `X<'a>` types that can be safely and
/// efficiently converted to `X<'tcx>` as long as they are part of the
/// provided `TyCtxt<'tcx>`.
with_context_opt(|opt_context| f(opt_context.expect("no ImplicitCtxt stored in tls")))
}
- /// Allows access to the current `ImplicitCtxt` whose tcx field has the same global
- /// interner as the tcx argument passed in. This means the closure is given an `ImplicitCtxt`
- /// with the same `'tcx` lifetime as the `TyCtxt` passed in.
- /// This will panic if you pass it a `TyCtxt` which has a different global interner from
- /// the current `ImplicitCtxt`'s `tcx` field.
+ /// Allows access to the current `ImplicitCtxt` whose tcx field is the same as the tcx argument
+ /// passed in. This means the closure is given an `ImplicitCtxt` with the same `'tcx` lifetime
+ /// as the `TyCtxt` passed in.
+ /// This will panic if you pass it a `TyCtxt` which is different from the current
+ /// `ImplicitCtxt`'s `tcx` field.
#[inline]
pub fn with_related_context<'tcx, F, R>(tcx: TyCtxt<'tcx>, f: F) -> R
where