Skip to content

Commit 4a45578

Browse files
committed
Auto merge of #56502 - Zoxc:hir-func, r=eddyb
Use a function to access the Hir map to be able to turn it into a query later r? @eddyb
2 parents a40fded + a70babe commit 4a45578

File tree

160 files changed

+1220
-1210
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

160 files changed

+1220
-1210
lines changed

src/librustc/cfg/construct.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub fn construct<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
5353
let body_exit;
5454

5555
// Find the tables for this body.
56-
let owner_def_id = tcx.hir.local_def_id(tcx.hir.body_owner(body.id()));
56+
let owner_def_id = tcx.hir().local_def_id(tcx.hir().body_owner(body.id()));
5757
let tables = tcx.typeck_tables_of(owner_def_id);
5858

5959
let mut cfg_builder = CFGBuilder {
@@ -109,7 +109,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
109109
}
110110

111111
fn stmt(&mut self, stmt: &hir::Stmt, pred: CFGIndex) -> CFGIndex {
112-
let hir_id = self.tcx.hir.node_to_hir_id(stmt.node.id());
112+
let hir_id = self.tcx.hir().node_to_hir_id(stmt.node.id());
113113
match stmt.node {
114114
hir::StmtKind::Decl(ref decl, _) => {
115115
let exit = self.decl(&decl, pred);
@@ -588,9 +588,9 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
588588
match destination.target_id {
589589
Ok(loop_id) => {
590590
for b in &self.breakable_block_scopes {
591-
if b.block_expr_id == self.tcx.hir.node_to_hir_id(loop_id).local_id {
591+
if b.block_expr_id == self.tcx.hir().node_to_hir_id(loop_id).local_id {
592592
let scope = region::Scope {
593-
id: self.tcx.hir.node_to_hir_id(loop_id).local_id,
593+
id: self.tcx.hir().node_to_hir_id(loop_id).local_id,
594594
data: region::ScopeData::Node
595595
};
596596
return (scope, match scope_cf_kind {
@@ -600,9 +600,9 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
600600
}
601601
}
602602
for l in &self.loop_scopes {
603-
if l.loop_id == self.tcx.hir.node_to_hir_id(loop_id).local_id {
603+
if l.loop_id == self.tcx.hir().node_to_hir_id(loop_id).local_id {
604604
let scope = region::Scope {
605-
id: self.tcx.hir.node_to_hir_id(loop_id).local_id,
605+
id: self.tcx.hir().node_to_hir_id(loop_id).local_id,
606606
data: region::ScopeData::Node
607607
};
608608
return (scope, match scope_cf_kind {

src/librustc/cfg/graphviz.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ pub struct LabelledCFG<'a, 'tcx: 'a> {
3232
impl<'a, 'tcx> LabelledCFG<'a, 'tcx> {
3333
fn local_id_to_string(&self, local_id: hir::ItemLocalId) -> String {
3434
assert!(self.cfg.owner_def_id.is_local());
35-
let node_id = self.tcx.hir.hir_to_node_id(hir::HirId {
36-
owner: self.tcx.hir.def_index_to_hir_id(self.cfg.owner_def_id.index).owner,
35+
let node_id = self.tcx.hir().hir_to_node_id(hir::HirId {
36+
owner: self.tcx.hir().def_index_to_hir_id(self.cfg.owner_def_id.index).owner,
3737
local_id
3838
});
39-
let s = self.tcx.hir.node_to_string(node_id);
39+
let s = self.tcx.hir().node_to_string(node_id);
4040

4141
// Replacing newlines with \\l causes each line to be left-aligned,
4242
// improving presentation of (long) pretty-printed expressions.

src/librustc/dep_graph/dep_node.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -449,10 +449,10 @@ define_dep_nodes!( <'tcx>
449449
// Represents the `Krate` as a whole (the `hir::Krate` value) (as
450450
// distinct from the krate module). This is basically a hash of
451451
// the entire krate, so if you read from `Krate` (e.g., by calling
452-
// `tcx.hir.krate()`), we will have to assume that any change
452+
// `tcx.hir().krate()`), we will have to assume that any change
453453
// means that you need to be recompiled. This is because the
454454
// `Krate` value gives you access to all other items. To avoid
455-
// this fate, do not call `tcx.hir.krate()`; instead, prefer
455+
// this fate, do not call `tcx.hir().krate()`; instead, prefer
456456
// wrappers like `tcx.visit_all_items_in_krate()`. If there is no
457457
// suitable wrapper, you can use `tcx.dep_graph.ignore()` to gain
458458
// access to the krate, but you must remember to add suitable
@@ -733,7 +733,7 @@ impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for DefIndex {
733733
const CAN_RECONSTRUCT_QUERY_KEY: bool = true;
734734

735735
fn to_fingerprint(&self, tcx: TyCtxt<'_, '_, '_>) -> Fingerprint {
736-
tcx.hir.definitions().def_path_hash(*self).0
736+
tcx.hir().definitions().def_path_hash(*self).0
737737
}
738738

739739
fn to_debug_str(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> String {

src/librustc/dep_graph/dep_tracking_map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl<M: DepTrackingMapConfig> MemoizationMap for RefCell<DepTrackingMap<M>> {
6565
///
6666
/// ```
6767
/// fn type_of_item(..., item: &hir::Item) -> Ty<'tcx> {
68-
/// let item_def_id = ccx.tcx.hir.local_def_id(it.id);
68+
/// let item_def_id = ccx.tcx.hir().local_def_id(it.id);
6969
/// ccx.tcx.item_types.memoized(item_def_id, || {
7070
/// ccx.tcx.dep_graph.read(DepNode::Hir(item_def_id)); // (*)
7171
/// compute_type_of_item(ccx, item)

src/librustc/hir/check_attr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
100100
/// Check any attribute.
101101
fn check_attributes(&self, item: &hir::Item, target: Target) {
102102
if target == Target::Fn || target == Target::Const {
103-
self.tcx.codegen_fn_attrs(self.tcx.hir.local_def_id(item.id));
103+
self.tcx.codegen_fn_attrs(self.tcx.hir().local_def_id(item.id));
104104
} else if let Some(a) = item.attrs.iter().find(|a| a.check_name("target_feature")) {
105105
self.tcx.sess.struct_span_err(a.span, "attribute should be applied to a function")
106106
.span_label(item.span, "not a function")
@@ -352,7 +352,7 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
352352

353353
impl<'a, 'tcx> Visitor<'tcx> for CheckAttrVisitor<'a, 'tcx> {
354354
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
355-
NestedVisitorMap::OnlyBodies(&self.tcx.hir)
355+
NestedVisitorMap::OnlyBodies(&self.tcx.hir())
356356
}
357357

358358
fn visit_item(&mut self, item: &'tcx hir::Item) {
@@ -375,7 +375,7 @@ impl<'a, 'tcx> Visitor<'tcx> for CheckAttrVisitor<'a, 'tcx> {
375375

376376
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
377377
let mut checker = CheckAttrVisitor { tcx };
378-
tcx.hir.krate().visit_all_item_likes(&mut checker.as_deep_visitor());
378+
tcx.hir().krate().visit_all_item_likes(&mut checker.as_deep_visitor());
379379
}
380380

381381
fn is_c_like_enum(item: &hir::Item) -> bool {

src/librustc/hir/itemlikevisit.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use super::intravisit::Visitor;
1919
///
2020
/// 1. **Shallow visit**: Get a simple callback for every item (or item-like thing) in the HIR.
2121
/// - Example: find all items with a `#[foo]` attribute on them.
22-
/// - How: Implement `ItemLikeVisitor` and call `tcx.hir.krate().visit_all_item_likes()`.
22+
/// - How: Implement `ItemLikeVisitor` and call `tcx.hir().krate().visit_all_item_likes()`.
2323
/// - Pro: Efficient; just walks the lists of item-like things, not the nodes themselves.
2424
/// - Con: Don't get information about nesting
2525
/// - Con: Don't have methods for specific bits of HIR, like "on
@@ -29,7 +29,7 @@ use super::intravisit::Visitor;
2929
/// within one another.
3030
/// - Example: Examine each expression to look for its type and do some check or other.
3131
/// - How: Implement `intravisit::Visitor` and use
32-
/// `tcx.hir.krate().visit_all_item_likes(visitor.as_deep_visitor())`. Within
32+
/// `tcx.hir().krate().visit_all_item_likes(visitor.as_deep_visitor())`. Within
3333
/// your `intravisit::Visitor` impl, implement methods like
3434
/// `visit_expr()`; don't forget to invoke
3535
/// `intravisit::walk_visit_expr()` to keep walking the subparts.
@@ -43,7 +43,7 @@ use super::intravisit::Visitor;
4343
/// - How: Implement `intravisit::Visitor` and override the
4444
/// `nested_visit_map()` methods to return
4545
/// `NestedVisitorMap::All`. Walk your crate with
46-
/// `intravisit::walk_crate()` invoked on `tcx.hir.krate()`.
46+
/// `intravisit::walk_crate()` invoked on `tcx.hir().krate()`.
4747
/// - Pro: Visitor methods for any kind of HIR node, not just item-like things.
4848
/// - Pro: Preserves nesting information
4949
/// - Con: Does not integrate well into dependency tracking.

src/librustc/hir/map/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1258,8 +1258,8 @@ fn node_id_to_string(map: &Map<'_>, id: NodeId, include_id: bool) -> String {
12581258
}
12591259

12601260
pub fn describe_def(tcx: TyCtxt<'_, '_, '_>, def_id: DefId) -> Option<Def> {
1261-
if let Some(node_id) = tcx.hir.as_local_node_id(def_id) {
1262-
tcx.hir.describe_def(node_id)
1261+
if let Some(node_id) = tcx.hir().as_local_node_id(def_id) {
1262+
tcx.hir().describe_def(node_id)
12631263
} else {
12641264
bug!("Calling local describe_def query provider for upstream DefId: {:?}",
12651265
def_id)

src/librustc/infer/error_reporting/mod.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
9797
)
9898
};
9999
let span = scope.span(self, region_scope_tree);
100-
let tag = match self.hir.find(scope.node_id(self, region_scope_tree)) {
100+
let tag = match self.hir().find(scope.node_id(self, region_scope_tree)) {
101101
Some(Node::Block(_)) => "block",
102102
Some(Node::Expr(expr)) => match expr.node {
103103
hir::ExprKind::Call(..) => "call",
@@ -190,8 +190,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
190190
let cm = self.sess.source_map();
191191

192192
let scope = region.free_region_binding_scope(self);
193-
let node = self.hir.as_local_node_id(scope).unwrap_or(DUMMY_NODE_ID);
194-
let tag = match self.hir.find(node) {
193+
let node = self.hir().as_local_node_id(scope).unwrap_or(DUMMY_NODE_ID);
194+
let tag = match self.hir().find(node) {
195195
Some(Node::Block(_)) | Some(Node::Expr(_)) => "body",
196196
Some(Node::Item(it)) => Self::item_scope_tag(&it),
197197
Some(Node::TraitItem(it)) => Self::trait_item_scope_tag(&it),
@@ -200,8 +200,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
200200
};
201201
let (prefix, span) = match *region {
202202
ty::ReEarlyBound(ref br) => {
203-
let mut sp = cm.def_span(self.hir.span(node));
204-
if let Some(param) = self.hir
203+
let mut sp = cm.def_span(self.hir().span(node));
204+
if let Some(param) = self.hir()
205205
.get_generics(scope)
206206
.and_then(|generics| generics.get_named(&br.name))
207207
{
@@ -213,8 +213,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
213213
bound_region: ty::BoundRegion::BrNamed(_, ref name),
214214
..
215215
}) => {
216-
let mut sp = cm.def_span(self.hir.span(node));
217-
if let Some(param) = self.hir
216+
let mut sp = cm.def_span(self.hir().span(node));
217+
if let Some(param) = self.hir()
218218
.get_generics(scope)
219219
.and_then(|generics| generics.get_named(&name))
220220
{
@@ -225,15 +225,15 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
225225
ty::ReFree(ref fr) => match fr.bound_region {
226226
ty::BrAnon(idx) => (
227227
format!("the anonymous lifetime #{} defined on", idx + 1),
228-
self.hir.span(node),
228+
self.hir().span(node),
229229
),
230230
ty::BrFresh(_) => (
231231
"an anonymous lifetime defined on".to_owned(),
232-
self.hir.span(node),
232+
self.hir().span(node),
233233
),
234234
_ => (
235235
format!("the lifetime {} as defined on", fr.bound_region),
236-
cm.def_span(self.hir.span(node)),
236+
cm.def_span(self.hir().span(node)),
237237
),
238238
},
239239
_ => bug!(),
@@ -1083,7 +1083,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10831083
// the expected type argument.
10841084
if !param.is_self() {
10851085
let type_param = generics.type_param(param, self.tcx);
1086-
let hir = &self.tcx.hir;
1086+
let hir = &self.tcx.hir();
10871087
hir.as_local_node_id(type_param.def_id).map(|id| {
10881088
// Get the `hir::Param` to verify whether it already has any bounds.
10891089
// We do this to avoid suggesting code that ends up as `T: 'a'b`,
@@ -1315,8 +1315,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
13151315
format!(" for lifetime parameter `{}` in coherence check", name)
13161316
}
13171317
infer::UpvarRegion(ref upvar_id, _) => {
1318-
let var_node_id = self.tcx.hir.hir_to_node_id(upvar_id.var_path.hir_id);
1319-
let var_name = self.tcx.hir.name(var_node_id);
1318+
let var_node_id = self.tcx.hir().hir_to_node_id(upvar_id.var_path.hir_id);
1319+
let var_name = self.tcx.hir().name(var_node_id);
13201320
format!(" for capture of `{}` by closure", var_name)
13211321
}
13221322
infer::NLL(..) => bug!("NLL variable found in lexical phase"),

src/librustc/infer/error_reporting/need_type_info.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,13 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
109109
let mut local_visitor = FindLocalByTypeVisitor {
110110
infcx: &self,
111111
target_ty: &ty,
112-
hir_map: &self.tcx.hir,
112+
hir_map: &self.tcx.hir(),
113113
found_local_pattern: None,
114114
found_arg_pattern: None,
115115
};
116116

117117
if let Some(body_id) = body_id {
118-
let expr = self.tcx.hir.expect_expr(body_id.node_id);
118+
let expr = self.tcx.hir().expect_expr(body_id.node_id);
119119
local_visitor.visit_expr(expr);
120120
}
121121

src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
3838
) -> Option<(&hir::Ty, &hir::FnDecl)> {
3939
if let Some(anon_reg) = self.tcx.is_suitable_region(region) {
4040
let def_id = anon_reg.def_id;
41-
if let Some(node_id) = self.tcx.hir.as_local_node_id(def_id) {
42-
let fndecl = match self.tcx.hir.get(node_id) {
41+
if let Some(node_id) = self.tcx.hir().as_local_node_id(def_id) {
42+
let fndecl = match self.tcx.hir().get(node_id) {
4343
Node::Item(&hir::Item {
4444
node: hir::ItemKind::Fn(ref fndecl, ..),
4545
..
@@ -104,7 +104,7 @@ struct FindNestedTypeVisitor<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
104104

105105
impl<'a, 'gcx, 'tcx> Visitor<'gcx> for FindNestedTypeVisitor<'a, 'gcx, 'tcx> {
106106
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'gcx> {
107-
NestedVisitorMap::OnlyBodies(&self.tcx.hir)
107+
NestedVisitorMap::OnlyBodies(&self.tcx.hir())
108108
}
109109

110110
fn visit_ty(&mut self, arg: &'gcx hir::Ty) {
@@ -124,7 +124,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for FindNestedTypeVisitor<'a, 'gcx, 'tcx> {
124124

125125
hir::TyKind::Rptr(ref lifetime, _) => {
126126
// the lifetime of the TyRptr
127-
let hir_id = self.tcx.hir.node_to_hir_id(lifetime.id);
127+
let hir_id = self.tcx.hir().node_to_hir_id(lifetime.id);
128128
match (self.tcx.named_region(hir_id), self.bound_region) {
129129
// Find the index of the anonymous region that was part of the
130130
// error. We will then search the function parameters for a bound
@@ -150,7 +150,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for FindNestedTypeVisitor<'a, 'gcx, 'tcx> {
150150
// region at the right depth with the same index
151151
(Some(rl::Region::EarlyBound(_, id, _)), ty::BrNamed(def_id, _)) => {
152152
debug!(
153-
"EarlyBound self.infcx.tcx.hir.local_def_id(id)={:?} \
153+
"EarlyBound self.infcx.tcx.hir().local_def_id(id)={:?} \
154154
def_id={:?}",
155155
id,
156156
def_id
@@ -172,7 +172,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for FindNestedTypeVisitor<'a, 'gcx, 'tcx> {
172172
"FindNestedTypeVisitor::visit_ty: LateBound depth = {:?}",
173173
debruijn_index
174174
);
175-
debug!("self.infcx.tcx.hir.local_def_id(id)={:?}", id);
175+
debug!("self.infcx.tcx.hir().local_def_id(id)={:?}", id);
176176
debug!("def_id={:?}", def_id);
177177
if debruijn_index == self.current_index && id == def_id {
178178
self.found_type = Some(arg);
@@ -227,11 +227,11 @@ struct TyPathVisitor<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
227227

228228
impl<'a, 'gcx, 'tcx> Visitor<'gcx> for TyPathVisitor<'a, 'gcx, 'tcx> {
229229
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'gcx> {
230-
NestedVisitorMap::OnlyBodies(&self.tcx.hir)
230+
NestedVisitorMap::OnlyBodies(&self.tcx.hir())
231231
}
232232

233233
fn visit_lifetime(&mut self, lifetime: &hir::Lifetime) {
234-
let hir_id = self.tcx.hir.node_to_hir_id(lifetime.id);
234+
let hir_id = self.tcx.hir().node_to_hir_id(lifetime.id);
235235
match (self.tcx.named_region(hir_id), self.bound_region) {
236236
// the lifetime of the TyPath!
237237
(Some(rl::Region::LateBoundAnon(debruijn_index, anon_index)), ty::BrAnon(br_index)) => {
@@ -243,7 +243,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for TyPathVisitor<'a, 'gcx, 'tcx> {
243243

244244
(Some(rl::Region::EarlyBound(_, id, _)), ty::BrNamed(def_id, _)) => {
245245
debug!(
246-
"EarlyBound self.infcx.tcx.hir.local_def_id(id)={:?} \
246+
"EarlyBound self.infcx.tcx.hir().local_def_id(id)={:?} \
247247
def_id={:?}",
248248
id,
249249
def_id

src/librustc/infer/error_reporting/nice_region_error/outlives_closure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
5656
// closure, provide a specific message pointing this out.
5757
if let (&SubregionOrigin::BindingTypeIsNotValidAtDecl(ref external_span),
5858
&RegionKind::ReFree(ref free_region)) = (&sub_origin, sup_region) {
59-
let hir = &self.tcx.hir;
59+
let hir = &self.tcx.hir();
6060
if let Some(node_id) = hir.as_local_node_id(free_region.scope) {
6161
if let Node::Expr(Expr {
6262
node: Closure(_, _, _, closure_span, None),

src/librustc/infer/error_reporting/nice_region_error/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
6060
_ => return None, // not a free region
6161
};
6262

63-
let hir = &self.tcx.hir;
63+
let hir = &self.tcx.hir();
6464
if let Some(node_id) = hir.as_local_node_id(id) {
6565
if let Some(body_id) = hir.maybe_body_owned_by(node_id) {
6666
let body = hir.body(body_id);

0 commit comments

Comments
 (0)