Skip to content

Commit e90dc6f

Browse files
committed
Auto merge of #52911 - Mark-Simulacrum:visibility-hirid, r=oli-obk
Add HirId to VisibilityKind::Restricted I'm not confident that these changes are correct -- mostly just tried to copy previous PRs. Specifically, it's unclear to me if/how to remove the NodeId now that we have HirIds in more structs; is that a all-at-once change that'll happen later?
2 parents ccb550f + 3baec3c commit e90dc6f

File tree

14 files changed

+56
-39
lines changed

14 files changed

+56
-39
lines changed

src/librustc/hir/intravisit.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,10 @@ pub trait Visitor<'v> : Sized {
353353
fn visit_lifetime(&mut self, lifetime: &'v Lifetime) {
354354
walk_lifetime(self, lifetime)
355355
}
356-
fn visit_qpath(&mut self, qpath: &'v QPath, id: NodeId, span: Span) {
356+
fn visit_qpath(&mut self, qpath: &'v QPath, id: HirId, span: Span) {
357357
walk_qpath(self, qpath, id, span)
358358
}
359-
fn visit_path(&mut self, path: &'v Path, _id: NodeId) {
359+
fn visit_path(&mut self, path: &'v Path, _id: HirId) {
360360
walk_path(self, path)
361361
}
362362
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'v PathSegment) {
@@ -456,7 +456,7 @@ pub fn walk_trait_ref<'v, V>(visitor: &mut V, trait_ref: &'v TraitRef)
456456
where V: Visitor<'v>
457457
{
458458
visitor.visit_id(trait_ref.ref_id);
459-
visitor.visit_path(&trait_ref.path, trait_ref.ref_id)
459+
visitor.visit_path(&trait_ref.path, trait_ref.hir_ref_id)
460460
}
461461

462462
pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
@@ -471,7 +471,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
471471
}
472472
ItemKind::Use(ref path, _) => {
473473
visitor.visit_id(item.id);
474-
visitor.visit_path(path, item.id);
474+
visitor.visit_path(path, item.hir_id);
475475
}
476476
ItemKind::Static(ref typ, _, body) |
477477
ItemKind::Const(ref typ, body) => {
@@ -602,7 +602,7 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) {
602602
visitor.visit_fn_decl(&function_declaration.decl);
603603
}
604604
TyKind::Path(ref qpath) => {
605-
visitor.visit_qpath(qpath, typ.id, typ.span);
605+
visitor.visit_qpath(qpath, typ.hir_id, typ.span);
606606
}
607607
TyKind::Array(ref ty, ref length) => {
608608
visitor.visit_ty(ty);
@@ -621,7 +621,7 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) {
621621
}
622622
}
623623

624-
pub fn walk_qpath<'v, V: Visitor<'v>>(visitor: &mut V, qpath: &'v QPath, id: NodeId, span: Span) {
624+
pub fn walk_qpath<'v, V: Visitor<'v>>(visitor: &mut V, qpath: &'v QPath, id: HirId, span: Span) {
625625
match *qpath {
626626
QPath::Resolved(ref maybe_qself, ref path) => {
627627
if let Some(ref qself) = *maybe_qself {
@@ -670,14 +670,14 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) {
670670
visitor.visit_id(pattern.id);
671671
match pattern.node {
672672
PatKind::TupleStruct(ref qpath, ref children, _) => {
673-
visitor.visit_qpath(qpath, pattern.id, pattern.span);
673+
visitor.visit_qpath(qpath, pattern.hir_id, pattern.span);
674674
walk_list!(visitor, visit_pat, children);
675675
}
676676
PatKind::Path(ref qpath) => {
677-
visitor.visit_qpath(qpath, pattern.id, pattern.span);
677+
visitor.visit_qpath(qpath, pattern.hir_id, pattern.span);
678678
}
679679
PatKind::Struct(ref qpath, ref fields, _) => {
680-
visitor.visit_qpath(qpath, pattern.id, pattern.span);
680+
visitor.visit_qpath(qpath, pattern.hir_id, pattern.span);
681681
for field in fields {
682682
visitor.visit_id(field.node.id);
683683
visitor.visit_ident(field.node.ident);
@@ -985,7 +985,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
985985
visitor.visit_anon_const(count)
986986
}
987987
ExprKind::Struct(ref qpath, ref fields, ref optional_base) => {
988-
visitor.visit_qpath(qpath, expression.id, expression.span);
988+
visitor.visit_qpath(qpath, expression.hir_id, expression.span);
989989
for field in fields {
990990
visitor.visit_id(field.id);
991991
visitor.visit_ident(field.ident);
@@ -1062,7 +1062,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
10621062
visitor.visit_expr(index_expression)
10631063
}
10641064
ExprKind::Path(ref qpath) => {
1065-
visitor.visit_qpath(qpath, expression.id, expression.span);
1065+
visitor.visit_qpath(qpath, expression.hir_id, expression.span);
10661066
}
10671067
ExprKind::Break(ref destination, ref opt_expr) => {
10681068
if let Some(ref label) = destination.label {
@@ -1108,9 +1108,9 @@ pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v Arm) {
11081108
}
11091109

11101110
pub fn walk_vis<'v, V: Visitor<'v>>(visitor: &mut V, vis: &'v Visibility) {
1111-
if let VisibilityKind::Restricted { ref path, id } = vis.node {
1111+
if let VisibilityKind::Restricted { ref path, id, hir_id } = vis.node {
11121112
visitor.visit_id(id);
1113-
visitor.visit_path(path, id)
1113+
visitor.visit_path(path, hir_id)
11141114
}
11151115
}
11161116

src/librustc/hir/lowering.rs

+25-12
Original file line numberDiff line numberDiff line change
@@ -2155,12 +2155,14 @@ impl<'a> LoweringContext<'a> {
21552155
let future_path =
21562156
this.std_path(span, &["future", "Future"], Some(future_params), false);
21572157

2158+
let LoweredNodeId { node_id, hir_id } = this.next_id();
21582159
let mut bounds = vec![
21592160
hir::GenericBound::Trait(
21602161
hir::PolyTraitRef {
21612162
trait_ref: hir::TraitRef {
21622163
path: future_path,
2163-
ref_id: this.next_id().node_id,
2164+
ref_id: node_id,
2165+
hir_ref_id: hir_id,
21642166
},
21652167
bound_generic_params: hir_vec![],
21662168
span,
@@ -2482,9 +2484,11 @@ impl<'a> LoweringContext<'a> {
24822484
hir::QPath::Resolved(None, path) => path.and_then(|path| path),
24832485
qpath => bug!("lower_trait_ref: unexpected QPath `{:?}`", qpath),
24842486
};
2487+
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(p.ref_id);
24852488
hir::TraitRef {
24862489
path,
2487-
ref_id: self.lower_node_id(p.ref_id).node_id,
2490+
ref_id: node_id,
2491+
hir_ref_id: hir_id,
24882492
}
24892493
}
24902494

@@ -2843,11 +2847,13 @@ impl<'a> LoweringContext<'a> {
28432847
hir::VisibilityKind::Public => hir::VisibilityKind::Public,
28442848
hir::VisibilityKind::Crate(sugar) => hir::VisibilityKind::Crate(sugar),
28452849
hir::VisibilityKind::Inherited => hir::VisibilityKind::Inherited,
2846-
hir::VisibilityKind::Restricted { ref path, id: _ } => {
2850+
hir::VisibilityKind::Restricted { ref path, id: _, hir_id: _ } => {
2851+
let id = this.next_id();
28472852
hir::VisibilityKind::Restricted {
28482853
path: path.clone(),
28492854
// We are allocating a new NodeId here
2850-
id: this.next_id().node_id,
2855+
id: id.node_id,
2856+
hir_id: id.hir_id,
28512857
}
28522858
}
28532859
};
@@ -2916,11 +2922,13 @@ impl<'a> LoweringContext<'a> {
29162922
hir::VisibilityKind::Public => hir::VisibilityKind::Public,
29172923
hir::VisibilityKind::Crate(sugar) => hir::VisibilityKind::Crate(sugar),
29182924
hir::VisibilityKind::Inherited => hir::VisibilityKind::Inherited,
2919-
hir::VisibilityKind::Restricted { ref path, id: _ } => {
2925+
hir::VisibilityKind::Restricted { ref path, id: _, hir_id: _ } => {
2926+
let id = this.next_id();
29202927
hir::VisibilityKind::Restricted {
29212928
path: path.clone(),
29222929
// We are allocating a new NodeId here
2923-
id: this.next_id().node_id,
2930+
id: id.node_id,
2931+
hir_id: id.hir_id,
29242932
}
29252933
}
29262934
};
@@ -4350,13 +4358,17 @@ impl<'a> LoweringContext<'a> {
43504358
let node = match v.node {
43514359
VisibilityKind::Public => hir::VisibilityKind::Public,
43524360
VisibilityKind::Crate(sugar) => hir::VisibilityKind::Crate(sugar),
4353-
VisibilityKind::Restricted { ref path, id } => hir::VisibilityKind::Restricted {
4354-
path: P(self.lower_path(id, path, ParamMode::Explicit)),
4355-
id: if let Some(owner) = explicit_owner {
4356-
self.lower_node_id_with_owner(id, owner).node_id
4361+
VisibilityKind::Restricted { ref path, id } => {
4362+
let lowered_id = if let Some(owner) = explicit_owner {
4363+
self.lower_node_id_with_owner(id, owner)
43574364
} else {
4358-
self.lower_node_id(id).node_id
4359-
},
4365+
self.lower_node_id(id)
4366+
};
4367+
hir::VisibilityKind::Restricted {
4368+
path: P(self.lower_path(id, path, ParamMode::Explicit)),
4369+
id: lowered_id.node_id,
4370+
hir_id: lowered_id.hir_id,
4371+
}
43604372
},
43614373
VisibilityKind::Inherited => hir::VisibilityKind::Inherited,
43624374
};
@@ -4675,6 +4687,7 @@ impl<'a> LoweringContext<'a> {
46754687
trait_ref: hir::TraitRef {
46764688
path: path.and_then(|path| path),
46774689
ref_id: id.node_id,
4690+
hir_ref_id: id.hir_id,
46784691
},
46794692
span,
46804693
};

src/librustc/hir/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1912,6 +1912,7 @@ pub enum UseKind {
19121912
pub struct TraitRef {
19131913
pub path: Path,
19141914
pub ref_id: NodeId,
1915+
pub hir_ref_id: HirId,
19151916
}
19161917

19171918
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
@@ -1931,7 +1932,7 @@ pub type Visibility = Spanned<VisibilityKind>;
19311932
pub enum VisibilityKind {
19321933
Public,
19331934
Crate(CrateSugar),
1934-
Restricted { path: P<Path>, id: NodeId },
1935+
Restricted { path: P<Path>, id: NodeId, hir_id: HirId },
19351936
Inherited,
19361937
}
19371938

src/librustc/ich/impls_hir.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ impl_stable_hash_for!(enum hir::FunctionRetTy {
360360
impl_stable_hash_for!(struct hir::TraitRef {
361361
// Don't hash the ref_id. It is tracked via the thing it is used to access
362362
ref_id -> _,
363+
hir_ref_id -> _,
363364
path,
364365
});
365366

@@ -723,9 +724,10 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::VisibilityKind {
723724
hir::VisibilityKind::Crate(sugar) => {
724725
sugar.hash_stable(hcx, hasher);
725726
}
726-
hir::VisibilityKind::Restricted { ref path, id } => {
727+
hir::VisibilityKind::Restricted { ref path, id, hir_id } => {
727728
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
728729
id.hash_stable(hcx, hasher);
730+
hir_id.hash_stable(hcx, hasher);
729731
});
730732
path.hash_stable(hcx, hasher);
731733
}

src/librustc/lint/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> {
869869
hir_visit::walk_lifetime(self, lt);
870870
}
871871

872-
fn visit_path(&mut self, p: &'tcx hir::Path, id: ast::NodeId) {
872+
fn visit_path(&mut self, p: &'tcx hir::Path, id: hir::HirId) {
873873
run_lints!(self, check_path, p, id);
874874
hir_visit::walk_path(self, p);
875875
}

src/librustc/lint/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ macro_rules! late_lint_methods {
242242
fn check_variant(a: &$hir hir::Variant, b: &$hir hir::Generics);
243243
fn check_variant_post(a: &$hir hir::Variant, b: &$hir hir::Generics);
244244
fn check_lifetime(a: &$hir hir::Lifetime);
245-
fn check_path(a: &$hir hir::Path, b: ast::NodeId);
245+
fn check_path(a: &$hir hir::Path, b: hir::HirId);
246246
fn check_attribute(a: &$hir ast::Attribute);
247247

248248
/// Called when entering a syntax node that can have lint attributes such

src/librustc/middle/dead.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
279279
self.in_pat = false;
280280
}
281281

282-
fn visit_path(&mut self, path: &'tcx hir::Path, _: ast::NodeId) {
282+
fn visit_path(&mut self, path: &'tcx hir::Path, _: hir::HirId) {
283283
self.handle_definition(path.def);
284284
intravisit::walk_path(self, path);
285285
}

src/librustc/middle/resolve_lifetime.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
903903
self.resolve_lifetime_ref(lifetime_ref);
904904
}
905905

906-
fn visit_path(&mut self, path: &'tcx hir::Path, _: ast::NodeId) {
906+
fn visit_path(&mut self, path: &'tcx hir::Path, _: hir::HirId) {
907907
for (i, segment) in path.segments.iter().enumerate() {
908908
let depth = path.segments.len() - i - 1;
909909
if let Some(ref args) = segment.args {

src/librustc/middle/stability.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,8 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
780780
intravisit::walk_item(self, item);
781781
}
782782

783-
fn visit_path(&mut self, path: &'tcx hir::Path, id: ast::NodeId) {
783+
fn visit_path(&mut self, path: &'tcx hir::Path, id: hir::HirId) {
784+
let id = self.tcx.hir.hir_to_node_id(id);
784785
match path.def {
785786
Def::Local(..) | Def::Upvar(..) |
786787
Def::PrimTy(..) | Def::SelfTy(..) | Def::Err => {}

src/librustc_lint/builtin.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1526,7 +1526,6 @@ impl TypeAliasBounds {
15261526

15271527
// We use a HIR visitor to walk the type.
15281528
use rustc::hir::intravisit::{self, Visitor};
1529-
use syntax::ast::NodeId;
15301529
struct WalkAssocTypes<'a, 'db> where 'db: 'a {
15311530
err: &'a mut DiagnosticBuilder<'db>
15321531
}
@@ -1536,7 +1535,7 @@ impl TypeAliasBounds {
15361535
intravisit::NestedVisitorMap::None
15371536
}
15381537

1539-
fn visit_qpath(&mut self, qpath: &'v hir::QPath, id: NodeId, span: Span) {
1538+
fn visit_qpath(&mut self, qpath: &'v hir::QPath, id: hir::HirId, span: Span) {
15401539
if TypeAliasBounds::is_type_variable_assoc(qpath) {
15411540
self.err.span_help(span,
15421541
"use fully disambiguated paths (i.e., `<T as Trait>::Assoc`) to refer to \

src/librustc_passes/hir_stats.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,11 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
224224
self.record("Lifetime", Id::Node(lifetime.id), lifetime);
225225
hir_visit::walk_lifetime(self, lifetime)
226226
}
227-
fn visit_qpath(&mut self, qpath: &'v hir::QPath, id: NodeId, span: Span) {
227+
fn visit_qpath(&mut self, qpath: &'v hir::QPath, id: hir::HirId, span: Span) {
228228
self.record("QPath", Id::None, qpath);
229229
hir_visit::walk_qpath(self, qpath, id, span)
230230
}
231-
fn visit_path(&mut self, path: &'v hir::Path, _id: NodeId) {
231+
fn visit_path(&mut self, path: &'v hir::Path, _id: hir::HirId) {
232232
self.record("Path", Id::None, path);
233233
hir_visit::walk_path(self, path)
234234
}

src/librustc_privacy/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -815,16 +815,15 @@ impl<'a, 'tcx> Visitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> {
815815
// we prohibit access to private statics from other crates, this allows to give
816816
// more code internal visibility at link time. (Access to private functions
817817
// is already prohibited by type privacy for function types.)
818-
fn visit_qpath(&mut self, qpath: &'tcx hir::QPath, id: ast::NodeId, span: Span) {
818+
fn visit_qpath(&mut self, qpath: &'tcx hir::QPath, id: hir::HirId, span: Span) {
819819
let def = match *qpath {
820820
hir::QPath::Resolved(_, ref path) => match path.def {
821821
Def::Method(..) | Def::AssociatedConst(..) |
822822
Def::AssociatedTy(..) | Def::Static(..) => Some(path.def),
823823
_ => None,
824824
}
825825
hir::QPath::TypeRelative(..) => {
826-
let hir_id = self.tcx.hir.node_to_hir_id(id);
827-
self.tables.type_dependent_defs().get(hir_id).cloned()
826+
self.tables.type_dependent_defs().get(id).cloned()
828827
}
829828
};
830829
if let Some(def) = def {

src/librustdoc/clean/auto_trait.rs

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ impl<'a, 'tcx, 'rcx, 'cstore> AutoTraitFinder<'a, 'tcx, 'rcx, 'cstore> {
126126
let trait_ = hir::TraitRef {
127127
path: get_path_for_type(self.cx.tcx, trait_def_id, hir::def::Def::Trait),
128128
ref_id: ast::DUMMY_NODE_ID,
129+
hir_ref_id: hir::DUMMY_HIR_ID,
129130
};
130131

131132
let polarity;

src/librustdoc/clean/blanket_impl.rs

+1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ impl<'a, 'tcx, 'rcx, 'cstore> BlanketImplFinder <'a, 'tcx, 'rcx, 'cstore> {
119119
trait_def_id,
120120
hir::def::Def::Trait),
121121
ref_id: ast::DUMMY_NODE_ID,
122+
hir_ref_id: hir::DUMMY_HIR_ID,
122123
};
123124
let provided_trait_methods =
124125
infcx.tcx.provided_trait_methods(trait_def_id)

0 commit comments

Comments
 (0)