Skip to content

Commit 2e73b1d

Browse files
committed
use tcx instead of self.tcx when available
1 parent 77d8722 commit 2e73b1d

1 file changed

Lines changed: 47 additions & 48 deletions

File tree

‎compiler/rustc_metadata/src/rmeta/encoder.rs‎

Lines changed: 47 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -889,14 +889,14 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
889889
// Slot 0 (`LOCAL_CRATE`) is filler; this crate's own value is `extra_filename`.
890890
let mut dep_extra_filenames = IndexVec::from_elem_n(String::new(), 1);
891891
if !self.is_proc_macro {
892-
for &cnum in self.tcx.crates(()).iter() {
893-
let idx = dep_extra_filenames.push(self.tcx.extra_filename(cnum).to_owned());
892+
for &cnum in tcx.crates(()).iter() {
893+
let idx = dep_extra_filenames.push(tcx.extra_filename(cnum).to_owned());
894894
assert_eq!(idx, cnum, "dep_extra_filenames must be indexed by CrateNum");
895895
}
896896
}
897897

898898
self.lazy(CrateRootUnhashed {
899-
extra_filename: self.tcx.sess.opts.cg.extra_filename.clone(),
899+
extra_filename: tcx.sess.opts.cg.extra_filename.clone(),
900900
dep_extra_filenames,
901901
})
902902
});
@@ -1565,19 +1565,18 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
15651565
self.encode_attrs(local_id);
15661566
}
15671567
if should_encode_expn_that_defined(def_kind) {
1568-
record_some_lazy!(self.tables.expn_that_defined[local_id] <- self.tcx.expn_that_defined(def_id));
1568+
record_some_lazy!(self.tables.expn_that_defined[local_id] <- tcx.expn_that_defined(def_id));
15691569
}
15701570
if should_encode_span(def_kind)
15711571
&& let Some(ident_span) = tcx.def_ident_span(def_id)
15721572
{
15731573
record_some_lazy!(self.tables.def_ident_span[local_id] <- ident_span);
15741574
}
15751575
if def_kind.has_codegen_attrs() {
1576-
record_some_lazy!(self.tables.codegen_fn_attrs[local_id] <- self.tcx.codegen_fn_attrs(def_id));
1576+
record_some_lazy!(self.tables.codegen_fn_attrs[local_id] <- tcx.codegen_fn_attrs(def_id));
15771577
}
15781578
if should_encode_visibility(def_kind) {
1579-
let vis =
1580-
self.tcx.local_visibility(local_id).map_id(|mod_id| mod_id.to_local_def_id());
1579+
let vis = tcx.local_visibility(local_id).map_id(|mod_id| mod_id.to_local_def_id());
15811580
record_some_lazy!(self.tables.visibility[local_id] <- vis);
15821581
}
15831582
if should_encode_stability(def_kind) {
@@ -1587,7 +1586,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
15871586
self.encode_deprecation(local_id);
15881587
}
15891588
if should_encode_variances(tcx, def_id, def_kind) {
1590-
let v = self.tcx.variances_of(def_id);
1589+
let v = tcx.variances_of(def_id);
15911590
record_array!(self.tables.variances_of[local_id] <- v);
15921591
}
15931592
if should_encode_fn_sig(def_kind) {
@@ -1596,25 +1595,25 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
15961595
if should_encode_generics(def_kind) {
15971596
let g = tcx.generics_of(def_id);
15981597
record_some_lazy!(self.tables.generics_of[local_id] <- g);
1599-
record_some_lazy!(self.tables.explicit_clauses_of[local_id] <- self.tcx.explicit_clauses_of(def_id));
1600-
let inferred_outlives = self.tcx.inferred_outlives_of(def_id);
1598+
record_some_lazy!(self.tables.explicit_clauses_of[local_id] <- tcx.explicit_clauses_of(def_id));
1599+
let inferred_outlives = tcx.inferred_outlives_of(def_id);
16011600
record_defaulted_array!(self.tables.inferred_outlives_of[local_id] <- inferred_outlives);
16021601

16031602
for param in &g.own_params {
16041603
if let ty::GenericParamDefKind::Const { has_default: true, .. } = param.kind {
1605-
let default = self.tcx.const_param_default(param.def_id);
1604+
let default = tcx.const_param_default(param.def_id);
16061605
record_some_lazy!(self.tables.const_param_default[param.def_id.expect_local()] <- default);
16071606
}
16081607
}
16091608
}
16101609
if tcx.is_conditionally_const(def_id) {
1611-
record_some_lazy!(self.tables.const_conditions[local_id] <- self.tcx.const_conditions(def_id));
1610+
record_some_lazy!(self.tables.const_conditions[local_id] <- tcx.const_conditions(def_id));
16121611
}
16131612
if should_encode_type(tcx, local_id, def_kind) {
1614-
record_some_lazy!(self.tables.type_of[local_id] <- self.tcx.type_of(def_id));
1613+
record_some_lazy!(self.tables.type_of[local_id] <- tcx.type_of(def_id));
16151614
}
16161615
if should_encode_constness(def_kind) {
1617-
let constness = self.tcx.constness(def_id);
1616+
let constness = tcx.constness(def_id);
16181617
record_value!(self.tables.constness[local_id] <- constness)
16191618
}
16201619
if let DefKind::Fn | DefKind::AssocFn = def_kind {
@@ -1626,32 +1625,32 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
16261625
record_some_lazy!(self.tables.intrinsic[local_id] <- name);
16271626
}
16281627
if let DefKind::TyParam | DefKind::Trait = def_kind {
1629-
let default = self.tcx.object_lifetime_default(def_id);
1628+
let default = tcx.object_lifetime_default(def_id);
16301629
record_some_lazy!(self.tables.object_lifetime_default[local_id] <- default);
16311630
}
16321631
if let DefKind::Trait = def_kind {
1633-
record_some_lazy!(self.tables.trait_def[local_id] <- self.tcx.trait_def(def_id));
1632+
record_some_lazy!(self.tables.trait_def[local_id] <- tcx.trait_def(def_id));
16341633
record_defaulted_array!(self.tables.explicit_super_clauses_of[local_id] <-
1635-
self.tcx.explicit_super_clauses_of(def_id).skip_binder());
1634+
tcx.explicit_super_clauses_of(def_id).skip_binder());
16361635
record_defaulted_array!(self.tables.explicit_implied_clauses_of[local_id] <-
1637-
self.tcx.explicit_implied_clauses_of(def_id).skip_binder());
1638-
let module_children = self.tcx.module_children_local(local_id);
1636+
tcx.explicit_implied_clauses_of(def_id).skip_binder());
1637+
let module_children = tcx.module_children_local(local_id);
16391638
record_array!(self.tables.module_children_non_reexports[local_id] <-
16401639
module_children.iter().map(|child| child.res.def_id().expect_local()));
1641-
if self.tcx.is_const_trait(def_id) {
1640+
if tcx.is_const_trait(def_id) {
16421641
record_defaulted_array!(self.tables.explicit_implied_const_bounds[local_id]
1643-
<- self.tcx.explicit_implied_const_bounds(def_id).skip_binder());
1642+
<- tcx.explicit_implied_const_bounds(def_id).skip_binder());
16441643
}
16451644
}
16461645
if let DefKind::TraitAlias = def_kind {
1647-
record_some_lazy!(self.tables.trait_def[local_id] <- self.tcx.trait_def(def_id));
1646+
record_some_lazy!(self.tables.trait_def[local_id] <- tcx.trait_def(def_id));
16481647
record_defaulted_array!(self.tables.explicit_super_clauses_of[local_id] <-
1649-
self.tcx.explicit_super_clauses_of(def_id).skip_binder());
1648+
tcx.explicit_super_clauses_of(def_id).skip_binder());
16501649
record_defaulted_array!(self.tables.explicit_implied_clauses_of[local_id] <-
1651-
self.tcx.explicit_implied_clauses_of(def_id).skip_binder());
1650+
tcx.explicit_implied_clauses_of(def_id).skip_binder());
16521651
}
16531652
if let DefKind::Trait | DefKind::Impl { .. } = def_kind {
1654-
let associated_item_def_ids = self.tcx.associated_item_def_ids(def_id);
1653+
let associated_item_def_ids = tcx.associated_item_def_ids(def_id);
16551654
record_array!(self.tables.associated_item_or_field_def_ids[local_id] <-
16561655
associated_item_def_ids.iter().map(|&def_id| {
16571656
def_id.expect_local()
@@ -1662,22 +1661,22 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
16621661
}
16631662
}
16641663
if let DefKind::Closure | DefKind::SyntheticCoroutineBody = def_kind
1665-
&& let Some(coroutine_kind) = self.tcx.coroutine_kind(def_id)
1664+
&& let Some(coroutine_kind) = tcx.coroutine_kind(def_id)
16661665
{
16671666
record_value!(self.tables.coroutine_kind[local_id] <- Some(coroutine_kind))
16681667
}
16691668
if def_kind == DefKind::Closure
16701669
&& tcx.type_of(def_id).skip_binder().is_coroutine_closure()
16711670
{
1672-
let coroutine_for_closure = self.tcx.coroutine_for_closure(def_id);
1671+
let coroutine_for_closure = tcx.coroutine_for_closure(def_id);
16731672
let remapped_id =
16741673
RemappedRawDefId::create(coroutine_for_closure, &self.local_defs_remapping);
16751674

16761675
record_some!(self.tables.coroutine_for_closure[local_id] <- remapped_id);
16771676

16781677
// If this async closure has a by-move body, record it too.
16791678
if tcx.needs_coroutine_by_move_body_def_id(coroutine_for_closure) {
1680-
let id = self.tcx.coroutine_by_move_body_def_id(coroutine_for_closure);
1679+
let id = tcx.coroutine_by_move_body_def_id(coroutine_for_closure);
16811680
let id = RemappedRawDefId::create(id, &self.local_defs_remapping);
16821681

16831682
record_some!(
@@ -1686,14 +1685,14 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
16861685
}
16871686
}
16881687
if let DefKind::Static { .. } = def_kind {
1689-
if !self.tcx.is_foreign_item(def_id) {
1690-
match self.tcx.eval_static_initializer(def_id) {
1688+
if !tcx.is_foreign_item(def_id) {
1689+
match tcx.eval_static_initializer(def_id) {
16911690
Ok(data) => {
16921691
record_some_lazy!(self.tables.eval_static_initializer[local_id] <- data)
16931692
}
16941693
Err(err) => match err {
16951694
interpret::ErrorHandled::Reported(_, _) => {
1696-
self.tcx.dcx().delayed_bug(format!(
1695+
tcx.dcx().delayed_bug(format!(
16971696
"eval_static_initializer returned an error in metadata emission"
16981697
));
16991698
}
@@ -1714,16 +1713,16 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
17141713
self.encode_info_for_macro(local_id);
17151714
}
17161715
if let DefKind::TyAlias = def_kind {
1717-
record_value!(self.tables.type_alias_is_checked[local_id] <- self.tcx.type_alias_is_checked(def_id));
1716+
record_value!(self.tables.type_alias_is_checked[local_id] <- tcx.type_alias_is_checked(def_id));
17181717

1719-
if self.tcx.type_alias_is_checked(def_id) {
1718+
if tcx.type_alias_is_checked(def_id) {
17201719
record_some_lazy!(self.tables.args_known_to_outlive_alias_params[local_id] <- tcx.args_known_to_outlive_alias_params(def_id));
17211720
}
17221721
}
17231722
if let DefKind::OpaqueTy = def_kind {
17241723
self.encode_explicit_item_bounds(local_id);
17251724
self.encode_explicit_item_self_bounds(local_id);
1726-
record_some_lazy!(self.tables.opaque_ty_origin[local_id] <- self.tcx.opaque_ty_origin(def_id));
1725+
record_some_lazy!(self.tables.opaque_ty_origin[local_id] <- tcx.opaque_ty_origin(def_id));
17271726
self.encode_precise_capturing_args(local_id);
17281727
if tcx.is_conditionally_const(def_id) {
17291728
record_defaulted_array!(self.tables.explicit_implied_const_bounds[local_id]
@@ -1744,13 +1743,13 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
17441743
}
17451744
}
17461745
if let DefKind::AnonConst = def_kind {
1747-
record_some_lazy!(self.tables.anon_const_kind[local_id] <- self.tcx.anon_const_kind(def_id));
1746+
record_some_lazy!(self.tables.anon_const_kind[local_id] <- tcx.anon_const_kind(def_id));
17481747
}
17491748
if let DefKind::Const | DefKind::AssocConst = def_kind {
1750-
record_some_lazy!(self.tables.const_of_item[local_id] <- self.tcx.const_of_item(def_id));
1749+
record_some_lazy!(self.tables.const_of_item[local_id] <- tcx.const_of_item(def_id));
17511750
}
17521751
if tcx.impl_method_has_trait_impl_trait_tys(def_id)
1753-
&& let Ok(table) = self.tcx.collect_return_position_impl_trait_in_trait_tys(def_id)
1752+
&& let Ok(table) = tcx.collect_return_position_impl_trait_in_trait_tys(def_id)
17541753
{
17551754
record_some_lazy!(self.tables.collect_return_position_impl_trait_in_trait_tys[local_id] <- table);
17561755
}
@@ -1796,7 +1795,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
17961795
let adt_def = tcx.adt_def(def_id);
17971796
record_some_lazy!(self.tables.repr_options[local_def_id] <- adt_def.repr());
17981797

1799-
let params_in_repr = self.tcx.params_in_repr(def_id);
1798+
let params_in_repr = tcx.params_in_repr(def_id);
18001799
record_some_lazy!(self.tables.params_in_repr[local_def_id] <- params_in_repr);
18011800

18021801
if adt_def.is_enum() {
@@ -1911,15 +1910,15 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
19111910
self.encode_explicit_item_self_bounds(def_id);
19121911
if tcx.is_conditionally_const(def_id) {
19131912
record_defaulted_array!(self.tables.explicit_implied_const_bounds[def_id]
1914-
<- self.tcx.explicit_implied_const_bounds(def_id).skip_binder());
1913+
<- tcx.explicit_implied_const_bounds(def_id).skip_binder());
19151914
}
19161915
}
19171916
if let ty::AssocKind::Type { data: ty::AssocTypeData::Rpitit(rpitit_info) } = item.kind {
19181917
record_some_lazy!(self.tables.opt_rpitit_info[def_id] <- rpitit_info);
19191918
if matches!(rpitit_info, ty::ImplTraitInTraitData::Trait { .. }) {
19201919
record_array!(
19211920
self.tables.assumed_wf_types_for_rpitit[def_id]
1922-
<- self.tcx.assumed_wf_types_for_rpitit(def_id)
1921+
<- tcx.assumed_wf_types_for_rpitit(def_id)
19231922
);
19241923
self.encode_precise_capturing_args(def_id);
19251924
}
@@ -1953,12 +1952,12 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
19531952
if encode_opt {
19541953
record_some_lazy!(self.tables.optimized_mir[def_id] <- tcx.optimized_mir(def_id));
19551954

1956-
record_value!(self.tables.cross_crate_inlinable[def_id] <- self.tcx.cross_crate_inlinable(def_id));
1955+
record_value!(self.tables.cross_crate_inlinable[def_id] <- tcx.cross_crate_inlinable(def_id));
19571956

19581957
record_some_lazy!(self.tables.closure_saved_names_of_captured_variables[def_id]
19591958
<- tcx.closure_saved_names_of_captured_variables(def_id));
19601959

1961-
if self.tcx.is_coroutine(def_id.to_def_id())
1960+
if tcx.is_coroutine(def_id.to_def_id())
19621961
&& let Some(witnesses) = tcx.mir_coroutine_witnesses(def_id)
19631962
{
19641963
record_some_lazy!(self.tables.mir_coroutine_witnesses[def_id] <- witnesses);
@@ -1985,7 +1984,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
19851984
record_some_lazy!(self.tables.mir_const_qualif[def_id] <- qualifs);
19861985
let body = tcx.hir_maybe_body_owned_by(def_id);
19871986
if let Some(body) = body {
1988-
let const_data = rendered_const(self.tcx, &body, def_id);
1987+
let const_data = rendered_const(tcx, &body, def_id);
19891988
record_some_lazy!(self.tables.rendered_const[def_id] <- const_data);
19901989
}
19911990
}
@@ -1994,7 +1993,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
19941993
record_some_lazy!(self.tables.promoted_mir[def_id] <- tcx.promoted_mir(def_id));
19951994
}
19961995

1997-
if self.tcx.is_coroutine(def_id.to_def_id())
1996+
if tcx.is_coroutine(def_id.to_def_id())
19981997
&& let Some(witnesses) = tcx.mir_coroutine_witnesses(def_id)
19991998
{
20001999
record_some_lazy!(self.tables.mir_coroutine_witnesses[def_id] <- witnesses);
@@ -2011,7 +2010,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
20112010
for &local_def_id in tcx.mir_keys(()) {
20122011
if let DefKind::AssocFn | DefKind::Fn = tcx.def_kind(local_def_id) {
20132012
record_array!(self.tables.deduced_param_attrs[local_def_id] <-
2014-
self.tcx.deduced_param_attrs(local_def_id.to_def_id()));
2013+
tcx.deduced_param_attrs(local_def_id.to_def_id()));
20152014
}
20162015
}
20172016
}
@@ -2169,7 +2168,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
21692168

21702169
macros.push((id, self.lazy(kind)));
21712170

2172-
let mut def_key = self.tcx.hir_def_key(id);
2171+
let mut def_key = tcx.hir_def_key(id);
21732172
def_key.disambiguated_data.data = DefPathData::MacroNs(name);
21742173

21752174
record_some!(self.tables.def_kind[id] <- DefKind::Macro(macro_kind.into()));
@@ -2187,7 +2186,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
21872186
let macros = self.lazy_array(macros);
21882187

21892188
let mut proc_macro_quoted_spans = TableBuilder::default();
2190-
for (i, span) in self.tcx.sess.proc_macro_quoted_spans() {
2189+
for (i, span) in tcx.sess.proc_macro_quoted_spans() {
21912190
proc_macro_quoted_spans.set_some(i, self.lazy(span));
21922191
}
21932192

@@ -2358,7 +2357,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
23582357

23592358
let trait_ref = header.trait_ref.instantiate_identity().skip_norm_wip();
23602359
let simplified_self_ty = fast_reject::simplify_type(
2361-
self.tcx,
2360+
tcx,
23622361
trait_ref.self_ty(),
23632362
TreatParams::InstantiateWithInfer,
23642363
);

0 commit comments

Comments
 (0)