Skip to content

Commit 1b1e866

Browse files
committed
Remove with_related_context.
There is only one GlobalCtxt ever.
1 parent 55ccbd0 commit 1b1e866

File tree

3 files changed

+5
-29
lines changed

3 files changed

+5
-29
lines changed

compiler/rustc_middle/src/ty/context.rs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,14 +1684,13 @@ nop_list_lift! {substs; GenericArg<'a> => GenericArg<'tcx>}
16841684
CloneLiftImpls! { for<'tcx> { Constness, traits::WellFormedLoc, } }
16851685

16861686
pub mod tls {
1687-
use super::{ptr_eq, GlobalCtxt, TyCtxt};
1687+
use super::{GlobalCtxt, TyCtxt};
16881688

16891689
use crate::dep_graph::{DepKind, TaskDeps};
16901690
use crate::ty::query;
16911691
use rustc_data_structures::sync::{self, Lock};
16921692
use rustc_data_structures::thin_vec::ThinVec;
16931693
use rustc_errors::Diagnostic;
1694-
use std::mem;
16951694

16961695
#[cfg(not(parallel_compiler))]
16971696
use std::cell::Cell;
@@ -1811,23 +1810,6 @@ pub mod tls {
18111810
with_context_opt(|opt_context| f(opt_context.expect("no ImplicitCtxt stored in tls")))
18121811
}
18131812

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

2837-
// We are comparing types with different invariant lifetimes, so `ptr::eq`
2838-
// won't work for us.
2839-
fn ptr_eq<T, U>(t: *const T, u: *const U) -> bool {
2840-
t as *const () == u as *const ()
2841-
}
2842-
28432819
pub fn provide(providers: &mut ty::query::Providers) {
28442820
providers.in_scope_traits_map =
28452821
|tcx, id| tcx.hir_crate(()).owners[id].as_ref().map(|owner_info| &owner_info.trait_map);

compiler/rustc_middle/src/ty/layout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ fn layout_of<'tcx>(
216216
tcx: TyCtxt<'tcx>,
217217
query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>,
218218
) -> Result<TyAndLayout<'tcx>, LayoutError<'tcx>> {
219-
ty::tls::with_related_context(tcx, move |icx| {
219+
ty::tls::with_context(move |icx| {
220220
let (param_env, ty) = query.into_parts();
221221

222222
if !tcx.recursion_limit().value_within_limit(icx.layout_depth) {

compiler/rustc_query_impl/src/plumbing.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl HasDepContext for QueryCtxt<'tcx> {
4646

4747
impl QueryContext for QueryCtxt<'tcx> {
4848
fn current_query_job(&self) -> Option<QueryJobId<Self::DepKind>> {
49-
tls::with_related_context(**self, |icx| icx.query)
49+
tls::with_context(|icx| icx.query)
5050
}
5151

5252
fn try_collect_active_jobs(&self) -> Option<QueryMap<Self::DepKind>> {
@@ -89,9 +89,9 @@ impl QueryContext for QueryCtxt<'tcx> {
8989
compute: impl FnOnce() -> R,
9090
) -> R {
9191
// The `TyCtxt` stored in TLS has the same global interner lifetime
92-
// as `self`, so we use `with_related_context` to relate the 'tcx lifetimes
92+
// as `self`, so we use `with_context` to relate the 'tcx lifetimes
9393
// when accessing the `ImplicitCtxt`.
94-
tls::with_related_context(**self, move |current_icx| {
94+
tls::with_context(move |current_icx| {
9595
// Update the `ImplicitCtxt` to point to our new query job.
9696
let new_icx = ImplicitCtxt {
9797
tcx: **self,

0 commit comments

Comments
 (0)