Skip to content

Commit 4b3745f

Browse files
committed
Remove with_related_context.
There is only one GlobalCtxt ever.
1 parent ab33f71 commit 4b3745f

File tree

3 files changed

+5
-29
lines changed

3 files changed

+5
-29
lines changed

compiler/rustc_middle/src/ty/context.rs

+1-25
Original file line numberDiff line numberDiff line change
@@ -1681,14 +1681,13 @@ nop_list_lift! {substs; GenericArg<'a> => GenericArg<'tcx>}
16811681
CloneLiftImpls! { for<'tcx> { Constness, traits::WellFormedLoc, } }
16821682

16831683
pub mod tls {
1684-
use super::{ptr_eq, GlobalCtxt, TyCtxt};
1684+
use super::{GlobalCtxt, TyCtxt};
16851685

16861686
use crate::dep_graph::TaskDepsRef;
16871687
use crate::ty::query;
16881688
use rustc_data_structures::sync::{self, Lock};
16891689
use rustc_data_structures::thin_vec::ThinVec;
16901690
use rustc_errors::Diagnostic;
1691-
use std::mem;
16921691

16931692
#[cfg(not(parallel_compiler))]
16941693
use std::cell::Cell;
@@ -1814,23 +1813,6 @@ pub mod tls {
18141813
with_context_opt(|opt_context| f(opt_context.expect("no ImplicitCtxt stored in tls")))
18151814
}
18161815

1817-
/// Allows access to the current `ImplicitCtxt` whose tcx field is the same as the tcx argument
1818-
/// passed in. This means the closure is given an `ImplicitCtxt` with the same `'tcx` lifetime
1819-
/// as the `TyCtxt` passed in.
1820-
/// This will panic if you pass it a `TyCtxt` which is different from the current
1821-
/// `ImplicitCtxt`'s `tcx` field.
1822-
#[inline]
1823-
pub fn with_related_context<'tcx, F, R>(tcx: TyCtxt<'tcx>, f: F) -> R
1824-
where
1825-
F: FnOnce(&ImplicitCtxt<'_, 'tcx>) -> R,
1826-
{
1827-
with_context(|context| unsafe {
1828-
assert!(ptr_eq(context.tcx.gcx, tcx.gcx));
1829-
let context: &ImplicitCtxt<'_, '_> = mem::transmute(context);
1830-
f(context)
1831-
})
1832-
}
1833-
18341816
/// Allows access to the `TyCtxt` in the current `ImplicitCtxt`.
18351817
/// Panics if there is no `ImplicitCtxt` available.
18361818
#[inline]
@@ -2872,12 +2854,6 @@ impl<T, R, E> InternIteratorElement<T, R> for Result<T, E> {
28722854
}
28732855
}
28742856

2875-
// We are comparing types with different invariant lifetimes, so `ptr::eq`
2876-
// won't work for us.
2877-
fn ptr_eq<T, U>(t: *const T, u: *const U) -> bool {
2878-
t as *const () == u as *const ()
2879-
}
2880-
28812857
pub fn provide(providers: &mut ty::query::Providers) {
28822858
providers.resolutions = |tcx, ()| &tcx.untracked_resolutions;
28832859
providers.module_reexports =

compiler/rustc_middle/src/ty/layout.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ fn layout_of<'tcx>(
225225
tcx: TyCtxt<'tcx>,
226226
query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>,
227227
) -> Result<TyAndLayout<'tcx>, LayoutError<'tcx>> {
228-
ty::tls::with_related_context(tcx, move |icx| {
228+
ty::tls::with_context(move |icx| {
229229
let (param_env, ty) = query.into_parts();
230230
debug!(?ty);
231231

compiler/rustc_query_impl/src/plumbing.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl QueryContext for QueryCtxt<'_> {
5353
}
5454

5555
fn current_query_job(&self) -> Option<QueryJobId> {
56-
tls::with_related_context(**self, |icx| icx.query)
56+
tls::with_context(|icx| icx.query)
5757
}
5858

5959
fn try_collect_active_jobs(&self) -> Option<QueryMap> {
@@ -96,9 +96,9 @@ impl QueryContext for QueryCtxt<'_> {
9696
compute: impl FnOnce() -> R,
9797
) -> R {
9898
// The `TyCtxt` stored in TLS has the same global interner lifetime
99-
// as `self`, so we use `with_related_context` to relate the 'tcx lifetimes
99+
// as `self`, so we use `with_context` to relate the 'tcx lifetimes
100100
// when accessing the `ImplicitCtxt`.
101-
tls::with_related_context(**self, move |current_icx| {
101+
tls::with_context(move |current_icx| {
102102
// Update the `ImplicitCtxt` to point to our new query job.
103103
let new_icx = ImplicitCtxt {
104104
tcx: **self,

0 commit comments

Comments
 (0)