Skip to content

Commit

Permalink
Auto merge of #52911 - Mark-Simulacrum:visibility-hirid, r=oli-obk
Browse files Browse the repository at this point in the history
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?
  • Loading branch information
bors committed Aug 7, 2018
2 parents ccb550f + 3baec3c commit e90dc6f
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 39 deletions.
26 changes: 13 additions & 13 deletions src/librustc/hir/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,10 @@ pub trait Visitor<'v> : Sized {
fn visit_lifetime(&mut self, lifetime: &'v Lifetime) {
walk_lifetime(self, lifetime)
}
fn visit_qpath(&mut self, qpath: &'v QPath, id: NodeId, span: Span) {
fn visit_qpath(&mut self, qpath: &'v QPath, id: HirId, span: Span) {
walk_qpath(self, qpath, id, span)
}
fn visit_path(&mut self, path: &'v Path, _id: NodeId) {
fn visit_path(&mut self, path: &'v Path, _id: HirId) {
walk_path(self, path)
}
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'v PathSegment) {
Expand Down Expand Up @@ -456,7 +456,7 @@ pub fn walk_trait_ref<'v, V>(visitor: &mut V, trait_ref: &'v TraitRef)
where V: Visitor<'v>
{
visitor.visit_id(trait_ref.ref_id);
visitor.visit_path(&trait_ref.path, trait_ref.ref_id)
visitor.visit_path(&trait_ref.path, trait_ref.hir_ref_id)
}

pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
Expand All @@ -471,7 +471,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
}
ItemKind::Use(ref path, _) => {
visitor.visit_id(item.id);
visitor.visit_path(path, item.id);
visitor.visit_path(path, item.hir_id);
}
ItemKind::Static(ref typ, _, body) |
ItemKind::Const(ref typ, body) => {
Expand Down Expand Up @@ -602,7 +602,7 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) {
visitor.visit_fn_decl(&function_declaration.decl);
}
TyKind::Path(ref qpath) => {
visitor.visit_qpath(qpath, typ.id, typ.span);
visitor.visit_qpath(qpath, typ.hir_id, typ.span);
}
TyKind::Array(ref ty, ref length) => {
visitor.visit_ty(ty);
Expand All @@ -621,7 +621,7 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) {
}
}

pub fn walk_qpath<'v, V: Visitor<'v>>(visitor: &mut V, qpath: &'v QPath, id: NodeId, span: Span) {
pub fn walk_qpath<'v, V: Visitor<'v>>(visitor: &mut V, qpath: &'v QPath, id: HirId, span: Span) {
match *qpath {
QPath::Resolved(ref maybe_qself, ref path) => {
if let Some(ref qself) = *maybe_qself {
Expand Down Expand Up @@ -670,14 +670,14 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) {
visitor.visit_id(pattern.id);
match pattern.node {
PatKind::TupleStruct(ref qpath, ref children, _) => {
visitor.visit_qpath(qpath, pattern.id, pattern.span);
visitor.visit_qpath(qpath, pattern.hir_id, pattern.span);
walk_list!(visitor, visit_pat, children);
}
PatKind::Path(ref qpath) => {
visitor.visit_qpath(qpath, pattern.id, pattern.span);
visitor.visit_qpath(qpath, pattern.hir_id, pattern.span);
}
PatKind::Struct(ref qpath, ref fields, _) => {
visitor.visit_qpath(qpath, pattern.id, pattern.span);
visitor.visit_qpath(qpath, pattern.hir_id, pattern.span);
for field in fields {
visitor.visit_id(field.node.id);
visitor.visit_ident(field.node.ident);
Expand Down Expand Up @@ -985,7 +985,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
visitor.visit_anon_const(count)
}
ExprKind::Struct(ref qpath, ref fields, ref optional_base) => {
visitor.visit_qpath(qpath, expression.id, expression.span);
visitor.visit_qpath(qpath, expression.hir_id, expression.span);
for field in fields {
visitor.visit_id(field.id);
visitor.visit_ident(field.ident);
Expand Down Expand Up @@ -1062,7 +1062,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
visitor.visit_expr(index_expression)
}
ExprKind::Path(ref qpath) => {
visitor.visit_qpath(qpath, expression.id, expression.span);
visitor.visit_qpath(qpath, expression.hir_id, expression.span);
}
ExprKind::Break(ref destination, ref opt_expr) => {
if let Some(ref label) = destination.label {
Expand Down Expand Up @@ -1108,9 +1108,9 @@ pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v Arm) {
}

pub fn walk_vis<'v, V: Visitor<'v>>(visitor: &mut V, vis: &'v Visibility) {
if let VisibilityKind::Restricted { ref path, id } = vis.node {
if let VisibilityKind::Restricted { ref path, id, hir_id } = vis.node {
visitor.visit_id(id);
visitor.visit_path(path, id)
visitor.visit_path(path, hir_id)
}
}

Expand Down
37 changes: 25 additions & 12 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2155,12 +2155,14 @@ impl<'a> LoweringContext<'a> {
let future_path =
this.std_path(span, &["future", "Future"], Some(future_params), false);

let LoweredNodeId { node_id, hir_id } = this.next_id();
let mut bounds = vec![
hir::GenericBound::Trait(
hir::PolyTraitRef {
trait_ref: hir::TraitRef {
path: future_path,
ref_id: this.next_id().node_id,
ref_id: node_id,
hir_ref_id: hir_id,
},
bound_generic_params: hir_vec![],
span,
Expand Down Expand Up @@ -2482,9 +2484,11 @@ impl<'a> LoweringContext<'a> {
hir::QPath::Resolved(None, path) => path.and_then(|path| path),
qpath => bug!("lower_trait_ref: unexpected QPath `{:?}`", qpath),
};
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(p.ref_id);
hir::TraitRef {
path,
ref_id: self.lower_node_id(p.ref_id).node_id,
ref_id: node_id,
hir_ref_id: hir_id,
}
}

Expand Down Expand Up @@ -2843,11 +2847,13 @@ impl<'a> LoweringContext<'a> {
hir::VisibilityKind::Public => hir::VisibilityKind::Public,
hir::VisibilityKind::Crate(sugar) => hir::VisibilityKind::Crate(sugar),
hir::VisibilityKind::Inherited => hir::VisibilityKind::Inherited,
hir::VisibilityKind::Restricted { ref path, id: _ } => {
hir::VisibilityKind::Restricted { ref path, id: _, hir_id: _ } => {
let id = this.next_id();
hir::VisibilityKind::Restricted {
path: path.clone(),
// We are allocating a new NodeId here
id: this.next_id().node_id,
id: id.node_id,
hir_id: id.hir_id,
}
}
};
Expand Down Expand Up @@ -2916,11 +2922,13 @@ impl<'a> LoweringContext<'a> {
hir::VisibilityKind::Public => hir::VisibilityKind::Public,
hir::VisibilityKind::Crate(sugar) => hir::VisibilityKind::Crate(sugar),
hir::VisibilityKind::Inherited => hir::VisibilityKind::Inherited,
hir::VisibilityKind::Restricted { ref path, id: _ } => {
hir::VisibilityKind::Restricted { ref path, id: _, hir_id: _ } => {
let id = this.next_id();
hir::VisibilityKind::Restricted {
path: path.clone(),
// We are allocating a new NodeId here
id: this.next_id().node_id,
id: id.node_id,
hir_id: id.hir_id,
}
}
};
Expand Down Expand Up @@ -4350,13 +4358,17 @@ impl<'a> LoweringContext<'a> {
let node = match v.node {
VisibilityKind::Public => hir::VisibilityKind::Public,
VisibilityKind::Crate(sugar) => hir::VisibilityKind::Crate(sugar),
VisibilityKind::Restricted { ref path, id } => hir::VisibilityKind::Restricted {
path: P(self.lower_path(id, path, ParamMode::Explicit)),
id: if let Some(owner) = explicit_owner {
self.lower_node_id_with_owner(id, owner).node_id
VisibilityKind::Restricted { ref path, id } => {
let lowered_id = if let Some(owner) = explicit_owner {
self.lower_node_id_with_owner(id, owner)
} else {
self.lower_node_id(id).node_id
},
self.lower_node_id(id)
};
hir::VisibilityKind::Restricted {
path: P(self.lower_path(id, path, ParamMode::Explicit)),
id: lowered_id.node_id,
hir_id: lowered_id.hir_id,
}
},
VisibilityKind::Inherited => hir::VisibilityKind::Inherited,
};
Expand Down Expand Up @@ -4675,6 +4687,7 @@ impl<'a> LoweringContext<'a> {
trait_ref: hir::TraitRef {
path: path.and_then(|path| path),
ref_id: id.node_id,
hir_ref_id: id.hir_id,
},
span,
};
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1912,6 +1912,7 @@ pub enum UseKind {
pub struct TraitRef {
pub path: Path,
pub ref_id: NodeId,
pub hir_ref_id: HirId,
}

#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
Expand All @@ -1931,7 +1932,7 @@ pub type Visibility = Spanned<VisibilityKind>;
pub enum VisibilityKind {
Public,
Crate(CrateSugar),
Restricted { path: P<Path>, id: NodeId },
Restricted { path: P<Path>, id: NodeId, hir_id: HirId },
Inherited,
}

Expand Down
4 changes: 3 additions & 1 deletion src/librustc/ich/impls_hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ impl_stable_hash_for!(enum hir::FunctionRetTy {
impl_stable_hash_for!(struct hir::TraitRef {
// Don't hash the ref_id. It is tracked via the thing it is used to access
ref_id -> _,
hir_ref_id -> _,
path,
});

Expand Down Expand Up @@ -723,9 +724,10 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::VisibilityKind {
hir::VisibilityKind::Crate(sugar) => {
sugar.hash_stable(hcx, hasher);
}
hir::VisibilityKind::Restricted { ref path, id } => {
hir::VisibilityKind::Restricted { ref path, id, hir_id } => {
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
id.hash_stable(hcx, hasher);
hir_id.hash_stable(hcx, hasher);
});
path.hash_stable(hcx, hasher);
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> {
hir_visit::walk_lifetime(self, lt);
}

fn visit_path(&mut self, p: &'tcx hir::Path, id: ast::NodeId) {
fn visit_path(&mut self, p: &'tcx hir::Path, id: hir::HirId) {
run_lints!(self, check_path, p, id);
hir_visit::walk_path(self, p);
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ macro_rules! late_lint_methods {
fn check_variant(a: &$hir hir::Variant, b: &$hir hir::Generics);
fn check_variant_post(a: &$hir hir::Variant, b: &$hir hir::Generics);
fn check_lifetime(a: &$hir hir::Lifetime);
fn check_path(a: &$hir hir::Path, b: ast::NodeId);
fn check_path(a: &$hir hir::Path, b: hir::HirId);
fn check_attribute(a: &$hir ast::Attribute);

/// Called when entering a syntax node that can have lint attributes such
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
self.in_pat = false;
}

fn visit_path(&mut self, path: &'tcx hir::Path, _: ast::NodeId) {
fn visit_path(&mut self, path: &'tcx hir::Path, _: hir::HirId) {
self.handle_definition(path.def);
intravisit::walk_path(self, path);
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/resolve_lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
self.resolve_lifetime_ref(lifetime_ref);
}

fn visit_path(&mut self, path: &'tcx hir::Path, _: ast::NodeId) {
fn visit_path(&mut self, path: &'tcx hir::Path, _: hir::HirId) {
for (i, segment) in path.segments.iter().enumerate() {
let depth = path.segments.len() - i - 1;
if let Some(ref args) = segment.args {
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,8 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
intravisit::walk_item(self, item);
}

fn visit_path(&mut self, path: &'tcx hir::Path, id: ast::NodeId) {
fn visit_path(&mut self, path: &'tcx hir::Path, id: hir::HirId) {
let id = self.tcx.hir.hir_to_node_id(id);
match path.def {
Def::Local(..) | Def::Upvar(..) |
Def::PrimTy(..) | Def::SelfTy(..) | Def::Err => {}
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1526,7 +1526,6 @@ impl TypeAliasBounds {

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

fn visit_qpath(&mut self, qpath: &'v hir::QPath, id: NodeId, span: Span) {
fn visit_qpath(&mut self, qpath: &'v hir::QPath, id: hir::HirId, span: Span) {
if TypeAliasBounds::is_type_variable_assoc(qpath) {
self.err.span_help(span,
"use fully disambiguated paths (i.e., `<T as Trait>::Assoc`) to refer to \
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_passes/hir_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,11 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
self.record("Lifetime", Id::Node(lifetime.id), lifetime);
hir_visit::walk_lifetime(self, lifetime)
}
fn visit_qpath(&mut self, qpath: &'v hir::QPath, id: NodeId, span: Span) {
fn visit_qpath(&mut self, qpath: &'v hir::QPath, id: hir::HirId, span: Span) {
self.record("QPath", Id::None, qpath);
hir_visit::walk_qpath(self, qpath, id, span)
}
fn visit_path(&mut self, path: &'v hir::Path, _id: NodeId) {
fn visit_path(&mut self, path: &'v hir::Path, _id: hir::HirId) {
self.record("Path", Id::None, path);
hir_visit::walk_path(self, path)
}
Expand Down
5 changes: 2 additions & 3 deletions src/librustc_privacy/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -815,16 +815,15 @@ impl<'a, 'tcx> Visitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> {
// we prohibit access to private statics from other crates, this allows to give
// more code internal visibility at link time. (Access to private functions
// is already prohibited by type privacy for function types.)
fn visit_qpath(&mut self, qpath: &'tcx hir::QPath, id: ast::NodeId, span: Span) {
fn visit_qpath(&mut self, qpath: &'tcx hir::QPath, id: hir::HirId, span: Span) {
let def = match *qpath {
hir::QPath::Resolved(_, ref path) => match path.def {
Def::Method(..) | Def::AssociatedConst(..) |
Def::AssociatedTy(..) | Def::Static(..) => Some(path.def),
_ => None,
}
hir::QPath::TypeRelative(..) => {
let hir_id = self.tcx.hir.node_to_hir_id(id);
self.tables.type_dependent_defs().get(hir_id).cloned()
self.tables.type_dependent_defs().get(id).cloned()
}
};
if let Some(def) = def {
Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/clean/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ impl<'a, 'tcx, 'rcx, 'cstore> AutoTraitFinder<'a, 'tcx, 'rcx, 'cstore> {
let trait_ = hir::TraitRef {
path: get_path_for_type(self.cx.tcx, trait_def_id, hir::def::Def::Trait),
ref_id: ast::DUMMY_NODE_ID,
hir_ref_id: hir::DUMMY_HIR_ID,
};

let polarity;
Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/clean/blanket_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ impl<'a, 'tcx, 'rcx, 'cstore> BlanketImplFinder <'a, 'tcx, 'rcx, 'cstore> {
trait_def_id,
hir::def::Def::Trait),
ref_id: ast::DUMMY_NODE_ID,
hir_ref_id: hir::DUMMY_HIR_ID,
};
let provided_trait_methods =
infcx.tcx.provided_trait_methods(trait_def_id)
Expand Down

0 comments on commit e90dc6f

Please sign in to comment.