Skip to content

Commit 856b081

Browse files
committed
middle: replace NodeId with HirId in AccessLevels
1 parent cf6d881 commit 856b081

File tree

8 files changed

+55
-52
lines changed

8 files changed

+55
-52
lines changed

src/librustc/middle/dead.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ fn create_and_seed_worklist<'a, 'tcx>(
414414
) -> (Vec<hir::HirId>, FxHashMap<hir::HirId, hir::HirId>) {
415415
let worklist = access_levels.map.iter().filter_map(|(&id, level)| {
416416
if level >= &privacy::AccessLevel::Reachable {
417-
Some(tcx.hir().node_to_hir_id(id))
417+
Some(id)
418418
} else {
419419
None
420420
}

src/librustc/middle/privacy.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
//! outside their scopes. This pass will also generate a set of exported items
33
//! which are available for use externally when compiled as a library.
44
5+
use crate::hir::HirId;
56
use crate::util::nodemap::{DefIdSet, FxHashMap};
67

78
use std::hash::Hash;
89
use std::fmt;
9-
use syntax::ast::NodeId;
1010
use rustc_macros::HashStable;
1111

1212
// Accessibility levels, sorted in ascending order
@@ -27,7 +27,7 @@ pub enum AccessLevel {
2727

2828
// Accessibility levels for reachable HIR nodes
2929
#[derive(Clone)]
30-
pub struct AccessLevels<Id = NodeId> {
30+
pub struct AccessLevels<Id = HirId> {
3131
pub map: FxHashMap<Id, AccessLevel>
3232
}
3333

src/librustc/middle/reachable.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,7 @@ impl<'a, 'tcx: 'a> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a,
354354

355355
// We need only trait impls here, not inherent impls, and only non-exported ones
356356
if let hir::ItemKind::Impl(.., Some(ref trait_ref), _, ref impl_item_refs) = item.node {
357-
let node_id = self.tcx.hir().hir_to_node_id(item.hir_id);
358-
if !self.access_levels.is_reachable(node_id) {
357+
if !self.access_levels.is_reachable(item.hir_id) {
359358
self.worklist.extend(impl_item_refs.iter().map(|ii_ref| ii_ref.id.hir_id));
360359

361360
let trait_def_id = match trait_ref.path.def {
@@ -415,7 +414,7 @@ fn reachable_set<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum) ->
415414
// use the lang items, so we need to be sure to mark them as
416415
// exported.
417416
reachable_context.worklist.extend(
418-
access_levels.map.iter().map(|(id, _)| tcx.hir().node_to_hir_id(*id)));
417+
access_levels.map.iter().map(|(id, _)| *id));
419418
for item in tcx.lang_items().items().iter() {
420419
if let Some(did) = *item {
421420
if let Some(hir_id) = tcx.hir().as_local_hir_id(did) {

src/librustc/middle/stability.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ impl<'a, 'tcx: 'a> MissingStabilityAnnotations<'a, 'tcx> {
319319
let stab = self.tcx.stability().local_stability(hir_id);
320320
let is_error = !self.tcx.sess.opts.test &&
321321
stab.is_none() &&
322-
self.access_levels.is_reachable(self.tcx.hir().hir_to_node_id(hir_id));
322+
self.access_levels.is_reachable(hir_id);
323323
if is_error {
324324
self.tcx.sess.span_err(
325325
span,

src/librustc_lint/builtin.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,7 @@ impl MissingDoc {
380380
// It's an option so the crate root can also use this function (it doesn't
381381
// have a NodeId).
382382
if let Some(id) = id {
383-
let node_id = cx.tcx.hir().hir_to_node_id(id);
384-
if !cx.access_levels.is_exported(node_id) {
383+
if !cx.access_levels.is_exported(id) {
385384
return;
386385
}
387386
}
@@ -557,8 +556,7 @@ impl LintPass for MissingCopyImplementations {
557556

558557
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingCopyImplementations {
559558
fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &hir::Item) {
560-
let node_id = cx.tcx.hir().hir_to_node_id(item.hir_id);
561-
if !cx.access_levels.is_reachable(node_id) {
559+
if !cx.access_levels.is_reachable(item.hir_id) {
562560
return;
563561
}
564562
let (def, ty) = match item.node {
@@ -629,8 +627,7 @@ impl LintPass for MissingDebugImplementations {
629627

630628
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDebugImplementations {
631629
fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &hir::Item) {
632-
let node_id = cx.tcx.hir().hir_to_node_id(item.hir_id);
633-
if !cx.access_levels.is_reachable(node_id) {
630+
if !cx.access_levels.is_reachable(item.hir_id) {
634631
return;
635632
}
636633

@@ -1169,9 +1166,8 @@ impl UnreachablePub {
11691166
fn perform_lint(&self, cx: &LateContext<'_, '_>, what: &str, id: hir::HirId,
11701167
vis: &hir::Visibility, span: Span, exportable: bool) {
11711168
let mut applicability = Applicability::MachineApplicable;
1172-
let node_id = cx.tcx.hir().hir_to_node_id(id);
11731169
match vis.node {
1174-
hir::VisibilityKind::Public if !cx.access_levels.is_reachable(node_id) => {
1170+
hir::VisibilityKind::Public if !cx.access_levels.is_reachable(id) => {
11751171
if span.ctxt().outer().expn_info().is_some() {
11761172
applicability = Applicability::MaybeIncorrect;
11771173
}

src/librustc_privacy/lib.rs

+9-16
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,8 @@ impl VisibilityLike for Option<AccessLevel> {
379379
// (which require reaching the `DefId`s in them).
380380
const SHALLOW: bool = true;
381381
fn new_min<'a, 'tcx>(find: &FindMin<'a, 'tcx, Self>, def_id: DefId) -> Self {
382-
cmp::min(if let Some(node_id) = find.tcx.hir().as_local_node_id(def_id) {
383-
find.access_levels.map.get(&node_id).cloned()
382+
cmp::min(if let Some(hir_id) = find.tcx.hir().as_local_hir_id(def_id) {
383+
find.access_levels.map.get(&hir_id).cloned()
384384
} else {
385385
Self::MAX
386386
}, find.min)
@@ -410,17 +410,15 @@ struct ReachEverythingInTheInterfaceVisitor<'b, 'a: 'b, 'tcx: 'a> {
410410

411411
impl<'a, 'tcx> EmbargoVisitor<'a, 'tcx> {
412412
fn get(&self, id: hir::HirId) -> Option<AccessLevel> {
413-
let node_id = self.tcx.hir().hir_to_node_id(id);
414-
self.access_levels.map.get(&node_id).cloned()
413+
self.access_levels.map.get(&id).cloned()
415414
}
416415

417416
// Updates node level and returns the updated level.
418417
fn update(&mut self, id: hir::HirId, level: Option<AccessLevel>) -> Option<AccessLevel> {
419418
let old_level = self.get(id);
420419
// Accessibility levels can only grow.
421420
if level > old_level {
422-
let node_id = self.tcx.hir().hir_to_node_id(id);
423-
self.access_levels.map.insert(node_id, level.unwrap());
421+
self.access_levels.map.insert(id, level.unwrap());
424422
self.changed = true;
425423
level
426424
} else {
@@ -1197,8 +1195,7 @@ impl<'a, 'tcx> ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
11971195
fn trait_is_public(&self, trait_id: hir::HirId) -> bool {
11981196
// FIXME: this would preferably be using `exported_items`, but all
11991197
// traits are exported currently (see `EmbargoVisitor.exported_trait`).
1200-
let node_id = self.tcx.hir().hir_to_node_id(trait_id);
1201-
self.access_levels.is_public(node_id)
1198+
self.access_levels.is_public(trait_id)
12021199
}
12031200

12041201
fn check_generic_bound(&mut self, bound: &hir::GenericBound) {
@@ -1210,8 +1207,7 @@ impl<'a, 'tcx> ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
12101207
}
12111208

12121209
fn item_is_public(&self, id: &hir::HirId, vis: &hir::Visibility) -> bool {
1213-
let node_id = self.tcx.hir().hir_to_node_id(*id);
1214-
self.access_levels.is_reachable(node_id) || vis.node.is_pub()
1210+
self.access_levels.is_reachable(*id) || vis.node.is_pub()
12151211
}
12161212
}
12171213

@@ -1325,8 +1321,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
13251321
hir::ImplItemKind::Const(..) |
13261322
hir::ImplItemKind::Method(..) => {
13271323
self.access_levels.is_reachable(
1328-
self.tcx.hir().hir_to_node_id(
1329-
impl_item_ref.id.hir_id))
1324+
impl_item_ref.id.hir_id)
13301325
}
13311326
hir::ImplItemKind::Existential(..) |
13321327
hir::ImplItemKind::Type(_) => false,
@@ -1455,8 +1450,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
14551450
}
14561451

14571452
fn visit_foreign_item(&mut self, item: &'tcx hir::ForeignItem) {
1458-
let node_id = self.tcx.hir().hir_to_node_id(item.hir_id);
1459-
if self.access_levels.is_reachable(node_id) {
1453+
if self.access_levels.is_reachable(item.hir_id) {
14601454
intravisit::walk_foreign_item(self, item)
14611455
}
14621456
}
@@ -1474,8 +1468,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
14741468
v: &'tcx hir::Variant,
14751469
g: &'tcx hir::Generics,
14761470
item_id: hir::HirId) {
1477-
let node_id = self.tcx.hir().hir_to_node_id(v.node.data.hir_id());
1478-
if self.access_levels.is_reachable(node_id) {
1471+
if self.access_levels.is_reachable(v.node.data.hir_id()) {
14791472
self.in_variant = true;
14801473
intravisit::walk_variant(self, v, g, item_id);
14811474
self.in_variant = false;

src/librustc_save_analysis/dump_visitor.rs

+33-18
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,19 @@ macro_rules! down_cast_data {
5858
}
5959

6060
macro_rules! access_from {
61-
($save_ctxt:expr, $vis:expr, $id:expr) => {
61+
($save_ctxt:expr, $item:expr, $id:expr) => {
6262
Access {
63-
public: $vis.node.is_pub(),
63+
public: $item.vis.node.is_pub(),
6464
reachable: $save_ctxt.access_levels.is_reachable($id),
6565
}
6666
};
67+
}
6768

68-
($save_ctxt:expr, $item:expr) => {
69+
macro_rules! access_from_vis {
70+
($save_ctxt:expr, $vis:expr, $id:expr) => {
6971
Access {
70-
public: $item.vis.node.is_pub(),
71-
reachable: $save_ctxt.access_levels.is_reachable($item.id),
72+
public: $vis.node.is_pub(),
73+
reachable: $save_ctxt.access_levels.is_reachable($id),
7274
}
7375
};
7476
}
@@ -303,7 +305,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
303305

304306
method_data.value = sig_str;
305307
method_data.sig = sig::method_signature(id, ident, generics, sig, &self.save_ctxt);
306-
self.dumper.dump_def(&access_from!(self.save_ctxt, vis, id), method_data);
308+
let hir_id = self.tcx.hir().node_to_hir_id(id);
309+
self.dumper.dump_def(&access_from_vis!(self.save_ctxt, vis, hir_id), method_data);
307310
}
308311

309312
// walk arg and return types
@@ -324,7 +327,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
324327
fn process_struct_field_def(&mut self, field: &ast::StructField, parent_id: NodeId) {
325328
let field_data = self.save_ctxt.get_field_data(field, parent_id);
326329
if let Some(field_data) = field_data {
327-
self.dumper.dump_def(&access_from!(self.save_ctxt, field), field_data);
330+
let hir_id = self.tcx.hir().node_to_hir_id(field.id);
331+
self.dumper.dump_def(&access_from!(self.save_ctxt, field, hir_id), field_data);
328332
}
329333
}
330334

@@ -389,7 +393,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
389393
|v| v.process_formals(&decl.inputs, &fn_data.qualname),
390394
);
391395
self.process_generic_params(ty_params, &fn_data.qualname, item.id);
392-
self.dumper.dump_def(&access_from!(self.save_ctxt, item), fn_data);
396+
let hir_id = self.tcx.hir().node_to_hir_id(item.id);
397+
self.dumper.dump_def(&access_from!(self.save_ctxt, item, hir_id), fn_data);
393398
}
394399

395400
for arg in &decl.inputs {
@@ -409,10 +414,11 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
409414
typ: &'l ast::Ty,
410415
expr: &'l ast::Expr,
411416
) {
417+
let hir_id = self.tcx.hir().node_to_hir_id(item.id);
412418
self.nest_tables(item.id, |v| {
413419
if let Some(var_data) = v.save_ctxt.get_item_data(item) {
414420
down_cast_data!(var_data, DefData, item.span);
415-
v.dumper.dump_def(&access_from!(v.save_ctxt, item), var_data);
421+
v.dumper.dump_def(&access_from!(v.save_ctxt, item, hir_id), var_data);
416422
}
417423
v.visit_ty(&typ);
418424
v.visit_expr(expr);
@@ -434,9 +440,10 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
434440
if !self.span.filter_generated(ident.span) {
435441
let sig = sig::assoc_const_signature(id, ident.name, typ, expr, &self.save_ctxt);
436442
let span = self.span_from_span(ident.span);
443+
let hir_id = self.tcx.hir().node_to_hir_id(id);
437444

438445
self.dumper.dump_def(
439-
&access_from!(self.save_ctxt, vis, id),
446+
&access_from_vis!(self.save_ctxt, vis, hir_id),
440447
Def {
441448
kind: DefKind::Const,
442449
id: id_from_node_id(id, &self.save_ctxt),
@@ -510,8 +517,9 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
510517

511518
if !self.span.filter_generated(item.ident.span) {
512519
let span = self.span_from_span(item.ident.span);
520+
let hir_id = self.tcx.hir().node_to_hir_id(item.id);
513521
self.dumper.dump_def(
514-
&access_from!(self.save_ctxt, item),
522+
&access_from!(self.save_ctxt, item, hir_id),
515523
Def {
516524
kind,
517525
id: id_from_node_id(item.id, &self.save_ctxt),
@@ -550,7 +558,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
550558
};
551559
down_cast_data!(enum_data, DefData, item.span);
552560

553-
let access = access_from!(self.save_ctxt, item);
561+
let hir_id = self.tcx.hir().node_to_hir_id(item.id);
562+
let access = access_from!(self.save_ctxt, item, hir_id);
554563

555564
for variant in &enum_definition.variants {
556565
let name = variant.node.ident.name.to_string();
@@ -698,8 +707,9 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
698707
.iter()
699708
.map(|i| id_from_node_id(i.id, &self.save_ctxt))
700709
.collect();
710+
let hir_id = self.tcx.hir().node_to_hir_id(item.id);
701711
self.dumper.dump_def(
702-
&access_from!(self.save_ctxt, item),
712+
&access_from!(self.save_ctxt, item, hir_id),
703713
Def {
704714
kind: DefKind::Trait,
705715
id,
@@ -757,7 +767,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
757767
fn process_mod(&mut self, item: &ast::Item) {
758768
if let Some(mod_data) = self.save_ctxt.get_item_data(item) {
759769
down_cast_data!(mod_data, DefData, item.span);
760-
self.dumper.dump_def(&access_from!(self.save_ctxt, item), mod_data);
770+
let hir_id = self.tcx.hir().node_to_hir_id(item.id);
771+
self.dumper.dump_def(&access_from!(self.save_ctxt, item, hir_id), mod_data);
761772
}
762773
}
763774

@@ -1197,7 +1208,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
11971208

11981209
// The access is calculated using the current tree ID, but with the root tree's visibility
11991210
// (since nested trees don't have their own visibility).
1200-
let access = access_from!(self.save_ctxt, root_item.vis, id);
1211+
let hir_id = self.tcx.hir().node_to_hir_id(id);
1212+
let access = access_from!(self.save_ctxt, root_item, hir_id);
12011213

12021214
// The parent def id of a given use tree is always the enclosing item.
12031215
let parent = self.save_ctxt.tcx.hir().opt_local_def_id(id)
@@ -1394,9 +1406,10 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
13941406
if !self.span.filter_generated(item.ident.span) {
13951407
let span = self.span_from_span(item.ident.span);
13961408
let id = id_from_node_id(item.id, &self.save_ctxt);
1409+
let hir_id = self.tcx.hir().node_to_hir_id(item.id);
13971410

13981411
self.dumper.dump_def(
1399-
&access_from!(self.save_ctxt, item),
1412+
&access_from!(self.save_ctxt, item, hir_id),
14001413
Def {
14011414
kind: DefKind::Type,
14021415
id,
@@ -1424,9 +1437,10 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
14241437
if !self.span.filter_generated(item.ident.span) {
14251438
let span = self.span_from_span(item.ident.span);
14261439
let id = id_from_node_id(item.id, &self.save_ctxt);
1440+
let hir_id = self.tcx.hir().node_to_hir_id(item.id);
14271441

14281442
self.dumper.dump_def(
1429-
&access_from!(self.save_ctxt, item),
1443+
&access_from!(self.save_ctxt, item, hir_id),
14301444
Def {
14311445
kind: DefKind::Type,
14321446
id,
@@ -1624,7 +1638,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
16241638
}
16251639

16261640
fn visit_foreign_item(&mut self, item: &'l ast::ForeignItem) {
1627-
let access = access_from!(self.save_ctxt, item);
1641+
let hir_id = self.tcx.hir().node_to_hir_id(item.id);
1642+
let access = access_from!(self.save_ctxt, item, hir_id);
16281643

16291644
match item.node {
16301645
ast::ForeignItemKind::Fn(ref decl, ref generics) => {

src/librustdoc/core.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -461,11 +461,11 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
461461
sess.abort_if_errors();
462462

463463
let access_levels = tcx.privacy_access_levels(LOCAL_CRATE);
464-
// Convert from a NodeId set to a DefId set since we don't always have easy access
465-
// to the map from defid -> nodeid
464+
// Convert from a HirId set to a DefId set since we don't always have easy access
465+
// to the map from defid -> hirid
466466
let access_levels = AccessLevels {
467467
map: access_levels.map.iter()
468-
.map(|(&k, &v)| (tcx.hir().local_def_id(k), v))
468+
.map(|(&k, &v)| (tcx.hir().local_def_id_from_hir_id(k), v))
469469
.collect()
470470
};
471471

0 commit comments

Comments
 (0)