Skip to content

Commit 40fad74

Browse files
Remove global_tcx from TyCtxt
The non-global context was removed; there's only one context now. This is a noop method that only serves to confuse readers -- remove it.
1 parent 6c2c29c commit 40fad74

File tree

31 files changed

+59
-77
lines changed

31 files changed

+59
-77
lines changed

src/librustc/dep_graph/graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ impl DepGraph {
590590
// mark it as green by recursively marking all of its
591591
// dependencies green.
592592
self.try_mark_previous_green(
593-
tcx.global_tcx(),
593+
tcx,
594594
data,
595595
prev_index,
596596
&dep_node

src/librustc/infer/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1460,7 +1460,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14601460
// type-checking closure types are in local tables only.
14611461
if !self.in_progress_tables.is_some() || !ty.has_closure_types() {
14621462
if !(param_env, ty).has_local_value() {
1463-
return ty.is_copy_modulo_regions(self.tcx.global_tcx(), param_env, span);
1463+
return ty.is_copy_modulo_regions(self.tcx, param_env, span);
14641464
}
14651465
}
14661466

src/librustc/infer/opaque_types/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -561,15 +561,13 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
561561
def_id, instantiated_ty
562562
);
563563

564-
let gcx = self.tcx.global_tcx();
565-
566564
// Use substs to build up a reverse map from regions to their
567565
// identity mappings. This is necessary because of `impl
568566
// Trait` lifetimes are computed by replacing existing
569567
// lifetimes with 'static and remapping only those used in the
570568
// `impl Trait` return type, resulting in the parameters
571569
// shifting.
572-
let id_substs = InternalSubsts::identity_for_item(gcx, def_id);
570+
let id_substs = InternalSubsts::identity_for_item(self.tcx, def_id);
573571
let map: FxHashMap<Kind<'tcx>, Kind<'tcx>> = opaque_defn
574572
.substs
575573
.iter()
@@ -851,7 +849,7 @@ impl TypeFolder<'tcx> for ReverseMapper<'tcx> {
851849
)
852850
.emit();
853851

854-
self.tcx().global_tcx().mk_region(ty::ReStatic)
852+
self.tcx().mk_region(ty::ReStatic)
855853
},
856854
}
857855
}

src/librustc/middle/intrinsicck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl ExprVisitor<'tcx> {
8282

8383
// Special-case transmutting from `typeof(function)` and
8484
// `Option<typeof(function)>` to present a clearer error.
85-
let from = unpack_option_like(self.tcx.global_tcx(), from);
85+
let from = unpack_option_like(self.tcx, from);
8686
if let (&ty::FnDef(..), SizeSkeleton::Known(size_to)) = (&from.sty, sk_to) {
8787
if size_to == Pointer.size(&self.tcx) {
8888
struct_span_err!(self.tcx.sess, span, E0591,

src/librustc/middle/mem_categorization.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
749749
.unwrap_or(ty::ClosureKind::LATTICE_BOTTOM),
750750

751751
None =>
752-
closure_substs.closure_kind(closure_def_id, self.tcx.global_tcx()),
752+
closure_substs.closure_kind(closure_def_id, self.tcx),
753753
}
754754
}
755755
_ => span_bug!(span, "unexpected type for fn in mem_categorization: {:?}", ty),

src/librustc/traits/chalk_fulfill.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl TraitEngine<'tcx> for FulfillmentContext<'tcx> {
108108
goal: obligation.goal.predicate,
109109
}, &mut orig_values);
110110

111-
match infcx.tcx.global_tcx().evaluate_goal(canonical_goal) {
111+
match infcx.tcx.evaluate_goal(canonical_goal) {
112112
Ok(response) => {
113113
if response.is_proven() {
114114
making_progress = true;

src/librustc/traits/error_reporting.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
497497
4
498498
};
499499

500-
let normalize = |candidate| self.tcx.global_tcx().infer_ctxt().enter(|ref infcx| {
500+
let normalize = |candidate| self.tcx.infer_ctxt().enter(|ref infcx| {
501501
let normalized = infcx
502502
.at(&ObligationCause::dummy(), ty::ParamEnv::empty())
503503
.normalize(candidate)
@@ -783,8 +783,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
783783
}
784784

785785
ty::Predicate::ObjectSafe(trait_def_id) => {
786-
let violations = self.tcx.global_tcx()
787-
.object_safety_violations(trait_def_id);
786+
let violations = self.tcx.object_safety_violations(trait_def_id);
788787
if let Some(err) = self.tcx.report_object_safety_error(
789788
span,
790789
trait_def_id,
@@ -920,7 +919,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
920919
}
921920

922921
TraitNotObjectSafe(did) => {
923-
let violations = self.tcx.global_tcx().object_safety_violations(did);
922+
let violations = self.tcx.object_safety_violations(did);
924923
if let Some(err) = self.tcx.report_object_safety_error(span, did, violations) {
925924
err
926925
} else {

src/librustc/traits/fulfill.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
495495
} else {
496496
if !substs.has_local_value() {
497497
let instance = ty::Instance::resolve(
498-
self.selcx.tcx().global_tcx(),
498+
self.selcx.tcx(),
499499
obligation.param_env,
500500
def_id,
501501
substs,

src/librustc/traits/query/dropck_outlives.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,11 @@ impl<'cx, 'tcx> At<'cx, 'tcx> {
4040
};
4141
}
4242

43-
let gcx = tcx.global_tcx();
4443
let mut orig_values = OriginalQueryValues::default();
4544
let c_ty = self.infcx.canonicalize_query(&self.param_env.and(ty), &mut orig_values);
4645
let span = self.cause.span;
4746
debug!("c_ty = {:?}", c_ty);
48-
if let Ok(result) = &gcx.dropck_outlives(c_ty) {
47+
if let Ok(result) = &tcx.dropck_outlives(c_ty) {
4948
if result.is_proven() {
5049
if let Ok(InferOk { value, obligations }) =
5150
self.infcx.instantiate_query_response_and_region_obligations(

src/librustc/traits/query/evaluate_obligation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
5050
// Run canonical query. If overflow occurs, rerun from scratch but this time
5151
// in standard trait query mode so that overflow is handled appropriately
5252
// within `SelectionContext`.
53-
self.tcx.global_tcx().evaluate_obligation(c_pred)
53+
self.tcx.evaluate_obligation(c_pred)
5454
}
5555

5656
// Helper function that canonicalizes and runs the query. If an

src/librustc/traits/query/normalize.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
141141
// binder). It would be better to normalize in a
142142
// binding-aware fashion.
143143

144-
let gcx = self.infcx.tcx.global_tcx();
144+
let tcx = self.infcx.tcx;
145145

146146
let mut orig_values = OriginalQueryValues::default();
147147
// HACK(matthewjasper) `'static` is special-cased in selection,
@@ -150,7 +150,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
150150
&self.param_env.and(*data), &mut orig_values);
151151
debug!("QueryNormalizer: c_data = {:#?}", c_data);
152152
debug!("QueryNormalizer: orig_values = {:#?}", orig_values);
153-
match gcx.normalize_projection_ty(c_data) {
153+
match tcx.normalize_projection_ty(c_data) {
154154
Ok(result) => {
155155
// We don't expect ambiguity.
156156
if result.is_ambiguous() {

src/librustc/traits/query/outlives_bounds.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
9797

9898
let mut orig_values = OriginalQueryValues::default();
9999
let key = self.canonicalize_query(&param_env.and(ty), &mut orig_values);
100-
let result = match self.tcx.global_tcx().implied_outlives_bounds(key) {
100+
let result = match self.tcx.implied_outlives_bounds(key) {
101101
Ok(r) => r,
102102
Err(NoSolution) => {
103103
self.tcx.sess.delay_span_bug(

src/librustc/traits/select.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2460,7 +2460,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
24602460
if other.evaluation.must_apply_modulo_regions() {
24612461
match victim.candidate {
24622462
ImplCandidate(victim_def) => {
2463-
let tcx = self.tcx().global_tcx();
2463+
let tcx = self.tcx();
24642464
return tcx.specializes((other_def, victim_def))
24652465
|| tcx.impls_are_allowed_to_overlap(
24662466
other_def, victim_def).is_some();

src/librustc/traits/specialize/specialization_graph.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ impl<'tcx> Children {
162162
}
163163
};
164164

165-
let tcx = tcx.global_tcx();
166165
let (le, ge) = traits::overlapping_impls(
167166
tcx,
168167
possible_sibling,

src/librustc/traits/util.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,8 +661,7 @@ impl<'tcx> TyCtxt<'tcx> {
661661
}
662662
}
663663
None => {
664-
self.global_tcx()
665-
.impl_defaultness(node_item_def_id)
664+
self.impl_defaultness(node_item_def_id)
666665
.is_default()
667666
}
668667
}

src/librustc/ty/context.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,14 +1076,6 @@ pub struct GlobalCtxt<'tcx> {
10761076
}
10771077

10781078
impl<'tcx> TyCtxt<'tcx> {
1079-
/// Gets the global `TyCtxt`.
1080-
#[inline]
1081-
pub fn global_tcx(self) -> TyCtxt<'tcx> {
1082-
TyCtxt {
1083-
gcx: self.gcx,
1084-
}
1085-
}
1086-
10871079
#[inline(always)]
10881080
pub fn hir(self) -> &'tcx hir_map::Map<'tcx> {
10891081
&self.hir_map
@@ -1167,7 +1159,7 @@ impl<'tcx> TyCtxt<'tcx> {
11671159

11681160
/// Like lift, but only tries in the global tcx.
11691161
pub fn lift_to_global<T: ?Sized + Lift<'tcx>>(self, value: &T) -> Option<T::Lifted> {
1170-
value.lift_to_tcx(self.global_tcx())
1162+
value.lift_to_tcx(self)
11711163
}
11721164

11731165
/// Creates a type context and call the closure with a `TyCtxt` reference
@@ -1443,7 +1435,7 @@ impl<'tcx> TyCtxt<'tcx> {
14431435
-> Result<(), E::Error>
14441436
where E: ty::codec::TyEncoder
14451437
{
1446-
self.queries.on_disk_cache.serialize(self.global_tcx(), encoder)
1438+
self.queries.on_disk_cache.serialize(self, encoder)
14471439
}
14481440

14491441
/// If `true`, we should use the AST-based borrowck (we may *also* use
@@ -1617,7 +1609,7 @@ impl<'tcx> GlobalCtxt<'tcx> {
16171609
let tcx = TyCtxt {
16181610
gcx: self,
16191611
};
1620-
ty::tls::with_related_context(tcx.global_tcx(), |icx| {
1612+
ty::tls::with_related_context(tcx, |icx| {
16211613
let new_icx = ty::tls::ImplicitCtxt {
16221614
tcx,
16231615
query: icx.query.clone(),
@@ -2442,7 +2434,7 @@ impl<'tcx> TyCtxt<'tcx> {
24422434

24432435
#[inline]
24442436
pub fn mk_array(self, ty: Ty<'tcx>, n: u64) -> Ty<'tcx> {
2445-
self.mk_ty(Array(ty, ty::Const::from_usize(self.global_tcx(), n)))
2437+
self.mk_ty(Array(ty, ty::Const::from_usize(self, n)))
24462438
}
24472439

24482440
#[inline]
@@ -2657,7 +2649,7 @@ impl<'tcx> TyCtxt<'tcx> {
26572649
if ts.len() == 0 {
26582650
List::empty()
26592651
} else {
2660-
self.global_tcx()._intern_canonical_var_infos(ts)
2652+
self._intern_canonical_var_infos(ts)
26612653
}
26622654
}
26632655

src/librustc/ty/instance.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ impl<'tcx> Instance<'tcx> {
210210
}
211211

212212
pub fn mono(tcx: TyCtxt<'tcx>, def_id: DefId) -> Instance<'tcx> {
213-
Instance::new(def_id, tcx.global_tcx().empty_substs_for_def_id(def_id))
213+
Instance::new(def_id, tcx.empty_substs_for_def_id(def_id))
214214
}
215215

216216
#[inline]

src/librustc/ty/layout.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1883,7 +1883,7 @@ impl<'tcx> HasDataLayout for TyCtxt<'tcx> {
18831883

18841884
impl<'tcx> HasTyCtxt<'tcx> for TyCtxt<'tcx> {
18851885
fn tcx(&self) -> TyCtxt<'tcx> {
1886-
self.global_tcx()
1886+
*self
18871887
}
18881888
}
18891889

@@ -2003,7 +2003,7 @@ impl TyCtxt<'tcx> {
20032003
pub fn layout_of(self, param_env_and_ty: ty::ParamEnvAnd<'tcx, Ty<'tcx>>)
20042004
-> Result<TyLayout<'tcx>, LayoutError<'tcx>> {
20052005
let cx = LayoutCx {
2006-
tcx: self.global_tcx(),
2006+
tcx: self,
20072007
param_env: param_env_and_ty.param_env
20082008
};
20092009
cx.layout_of(param_env_and_ty.value)
@@ -2017,7 +2017,7 @@ impl ty::query::TyCtxtAt<'tcx> {
20172017
pub fn layout_of(self, param_env_and_ty: ty::ParamEnvAnd<'tcx, Ty<'tcx>>)
20182018
-> Result<TyLayout<'tcx>, LayoutError<'tcx>> {
20192019
let cx = LayoutCx {
2020-
tcx: self.global_tcx().at(self.span),
2020+
tcx: self.at(self.span),
20212021
param_env: param_env_and_ty.param_env
20222022
};
20232023
cx.layout_of(param_env_and_ty.value)

src/librustc/ty/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2365,7 +2365,7 @@ impl<'tcx> AdtDef {
23652365
pub fn eval_explicit_discr(&self, tcx: TyCtxt<'tcx>, expr_did: DefId) -> Option<Discr<'tcx>> {
23662366
let param_env = tcx.param_env(expr_did);
23672367
let repr_type = self.repr.discr_type();
2368-
let substs = InternalSubsts::identity_for_item(tcx.global_tcx(), expr_did);
2368+
let substs = InternalSubsts::identity_for_item(tcx, expr_did);
23692369
let instance = ty::Instance::new(expr_did, substs);
23702370
let cid = GlobalId {
23712371
instance,
@@ -2374,7 +2374,7 @@ impl<'tcx> AdtDef {
23742374
match tcx.const_eval(param_env.and(cid)) {
23752375
Ok(val) => {
23762376
// FIXME: Find the right type and use it instead of `val.ty` here
2377-
if let Some(b) = val.try_eval_bits(tcx.global_tcx(), param_env, val.ty) {
2377+
if let Some(b) = val.try_eval_bits(tcx, param_env, val.ty) {
23782378
trace!("discriminants: {} ({:?})", b, repr_type);
23792379
Some(Discr {
23802380
val: b,
@@ -2410,7 +2410,7 @@ impl<'tcx> AdtDef {
24102410
tcx: TyCtxt<'tcx>,
24112411
) -> impl Iterator<Item = (VariantIdx, Discr<'tcx>)> + Captures<'tcx> {
24122412
let repr_type = self.repr.discr_type();
2413-
let initial = repr_type.initial_discriminant(tcx.global_tcx());
2413+
let initial = repr_type.initial_discriminant(tcx);
24142414
let mut prev_discr = None::<Discr<'tcx>>;
24152415
self.variants.iter_enumerated().map(move |(i, v)| {
24162416
let mut discr = prev_discr.map_or(initial, |d| d.wrap_incr(tcx));
@@ -2444,7 +2444,7 @@ impl<'tcx> AdtDef {
24442444
let (val, offset) = self.discriminant_def_for_variant(variant_index);
24452445
let explicit_value = val
24462446
.and_then(|expr_did| self.eval_explicit_discr(tcx, expr_did))
2447-
.unwrap_or_else(|| self.repr.discr_type().initial_discriminant(tcx.global_tcx()));
2447+
.unwrap_or_else(|| self.repr.discr_type().initial_discriminant(tcx));
24482448
explicit_value.checked_add(tcx, offset as u128).0
24492449
}
24502450

src/librustc/ty/query/plumbing.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ impl<'tcx> TyCtxt<'tcx> {
265265
tls::with_related_context(self, move |current_icx| {
266266
// Update the `ImplicitCtxt` to point to our new query job.
267267
let new_icx = tls::ImplicitCtxt {
268-
tcx: self.global_tcx(),
268+
tcx: self,
269269
query: Some(job),
270270
diagnostics,
271271
layout_depth: current_icx.layout_depth,
@@ -274,7 +274,7 @@ impl<'tcx> TyCtxt<'tcx> {
274274

275275
// Use the `ImplicitCtxt` while we execute the query.
276276
tls::enter_context(&new_icx, |_| {
277-
compute(self.global_tcx())
277+
compute(self)
278278
})
279279
})
280280
}
@@ -384,7 +384,7 @@ impl<'tcx> TyCtxt<'tcx> {
384384
let ((result, dep_node_index), diagnostics) = with_diagnostics(|diagnostics| {
385385
self.start_query(job.job.clone(), diagnostics, |tcx| {
386386
tcx.dep_graph.with_anon_task(Q::dep_kind(), || {
387-
Q::compute(tcx.global_tcx(), key)
387+
Q::compute(tcx, key)
388388
})
389389
})
390390
});
@@ -445,10 +445,10 @@ impl<'tcx> TyCtxt<'tcx> {
445445
debug_assert!(self.dep_graph.is_green(dep_node));
446446

447447
// First we try to load the result from the on-disk cache.
448-
let result = if Q::cache_on_disk(self.global_tcx(), key.clone(), None) &&
448+
let result = if Q::cache_on_disk(self, key.clone(), None) &&
449449
self.sess.opts.debugging_opts.incremental_queries {
450450
self.sess.profiler(|p| p.incremental_load_result_start(Q::NAME));
451-
let result = Q::try_load_from_disk(self.global_tcx(), prev_dep_node_index);
451+
let result = Q::try_load_from_disk(self, prev_dep_node_index);
452452
self.sess.profiler(|p| p.incremental_load_result_end(Q::NAME));
453453

454454
// We always expect to find a cached result for things that
@@ -643,7 +643,7 @@ impl<'tcx> TyCtxt<'tcx> {
643643
macro_rules! handle_cycle_error {
644644
([][$tcx: expr, $error:expr]) => {{
645645
$tcx.report_cycle($error).emit();
646-
Value::from_cycle_error($tcx.global_tcx())
646+
Value::from_cycle_error($tcx)
647647
}};
648648
([fatal_cycle$(, $modifiers:ident)*][$tcx:expr, $error:expr]) => {{
649649
$tcx.report_cycle($error).emit();
@@ -652,7 +652,7 @@ macro_rules! handle_cycle_error {
652652
}};
653653
([cycle_delay_bug$(, $modifiers:ident)*][$tcx:expr, $error:expr]) => {{
654654
$tcx.report_cycle($error).delay_as_bug();
655-
Value::from_cycle_error($tcx.global_tcx())
655+
Value::from_cycle_error($tcx)
656656
}};
657657
([$other:ident$(, $modifiers:ident)*][$($args:tt)*]) => {
658658
handle_cycle_error!([$($modifiers),*][$($args)*])
@@ -999,7 +999,7 @@ macro_rules! define_queries_inner {
999999
// would be missing appropriate entries in `providers`.
10001000
.unwrap_or(&tcx.queries.fallback_extern_providers)
10011001
.$name;
1002-
provider(tcx.global_tcx(), key)
1002+
provider(tcx, key)
10031003
})
10041004
}
10051005

src/librustc_macros/src/query.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,8 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
442442
.map(|c| c.is_green())
443443
.unwrap_or(false));
444444

445-
let key = RecoverKey::recover(tcx.global_tcx(), self).unwrap();
446-
if queries::#name::cache_on_disk(tcx.global_tcx(), key, None) {
445+
let key = RecoverKey::recover(tcx, self).unwrap();
446+
if queries::#name::cache_on_disk(tcx, key, None) {
447447
let _ = tcx.#name(key);
448448
}
449449
}

0 commit comments

Comments
 (0)