extern crate syntax_pos;
extern crate rustc_data_structures;
-use rustc::hir::{self, PatKind};
-use hir::Node;
+use rustc::hir::{self, Node, PatKind};
use rustc::hir::def::Def;
use rustc::hir::def_id::{CRATE_DEF_INDEX, LOCAL_CRATE, CrateNum, DefId};
use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
use rustc::ty::query::Providers;
use rustc::ty::subst::UnpackedKind;
use rustc::util::nodemap::NodeSet;
+use rustc_data_structures::fx::FxHashSet;
+use rustc_data_structures::sync::Lrc;
use syntax::ast::{self, CRATE_NODE_ID, Ident};
use syntax::symbol::keywords;
use syntax_pos::Span;
use std::cmp;
use std::mem::replace;
-use rustc_data_structures::fx::FxHashSet;
-use rustc_data_structures::sync::Lrc;
mod diagnostics;
impl<'a, 'tcx> Visitor<'tcx> for PubRestrictedVisitor<'a, 'tcx> {
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
- NestedVisitorMap::All(&self.tcx.hir)
+ NestedVisitorMap::All(&self.tcx.hir())
}
fn visit_vis(&mut self, vis: &'tcx hir::Visibility) {
self.has_pub_restricted = self.has_pub_restricted || vis.node.is_pub_restricted();
struct EmbargoVisitor<'a, 'tcx: 'a> {
tcx: TyCtxt<'a, 'tcx, 'tcx>,
- // Accessibility levels for reachable nodes
+ // Accessibility levels for reachable nodes.
access_levels: AccessLevels,
- // Previous accessibility level, None means unreachable
+ // Previous accessibility level; `None` means unreachable.
prev_level: Option<AccessLevel>,
- // Have something changed in the level map?
+ // Has something changed in the level map?
changed: bool,
}
ty::Projection(ref proj) => proj.trait_ref(self.tcx).def_id,
_ => return Some(AccessLevel::Public)
};
- if let Some(node_id) = self.tcx.hir.as_local_node_id(ty_def_id) {
+ if let Some(node_id) = self.tcx.hir().as_local_node_id(ty_def_id) {
self.get(node_id)
} else {
Some(AccessLevel::Public)
fn impl_trait_level(&self, impl_def_id: DefId) -> Option<AccessLevel> {
if let Some(trait_ref) = self.tcx.impl_trait_ref(impl_def_id) {
- if let Some(node_id) = self.tcx.hir.as_local_node_id(trait_ref.def_id) {
+ if let Some(node_id) = self.tcx.hir().as_local_node_id(trait_ref.def_id) {
return self.get(node_id);
}
}
self.access_levels.map.get(&id).cloned()
}
- // Updates node level and returns the updated level
+ // Updates node level and returns the updated level.
fn update(&mut self, id: ast::NodeId, level: Option<AccessLevel>) -> Option<AccessLevel> {
let old_level = self.get(id);
- // Accessibility levels can only grow
+ // Accessibility levels can only grow.
if level > old_level {
self.access_levels.map.insert(id, level.unwrap());
self.changed = true;
-> ReachEverythingInTheInterfaceVisitor<'b, 'a, 'tcx> {
ReachEverythingInTheInterfaceVisitor {
access_level: self.prev_level.map(|l| l.min(AccessLevel::Reachable)),
- item_def_id: self.tcx.hir.local_def_id(item_id),
+ item_def_id: self.tcx.hir().local_def_id(item_id),
ev: self,
}
}
/// We want to visit items in the context of their containing
/// module and so forth, so supply a crate for doing a deep walk.
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
- NestedVisitorMap::All(&self.tcx.hir)
+ NestedVisitorMap::All(&self.tcx.hir())
}
fn visit_item(&mut self, item: &'tcx hir::Item) {
let inherited_item_level = match item.node {
- // Impls inherit level from their types and traits
+ // Impls inherit level from their types and traits.
hir::ItemKind::Impl(..) => {
- let def_id = self.tcx.hir.local_def_id(item.id);
+ let def_id = self.tcx.hir().local_def_id(item.id);
cmp::min(self.item_ty_level(def_id), self.impl_trait_level(def_id))
}
- // Foreign mods inherit level from parents
+ // Foreign modules inherit level from parents.
hir::ItemKind::ForeignMod(..) => {
self.prev_level
}
- // Other `pub` items inherit levels from parents
+ // Other `pub` items inherit levels from parents.
hir::ItemKind::Const(..) | hir::ItemKind::Enum(..) | hir::ItemKind::ExternCrate(..) |
hir::ItemKind::GlobalAsm(..) | hir::ItemKind::Fn(..) | hir::ItemKind::Mod(..) |
hir::ItemKind::Static(..) | hir::ItemKind::Struct(..) |
}
};
- // Update level of the item itself
+ // Update level of the item itself.
let item_level = self.update(item.id, inherited_item_level);
- // Update levels of nested things
+ // Update levels of nested things.
match item.node {
hir::ItemKind::Enum(ref def, _) => {
for variant in &def.variants {
// It (and its children) are revisited if the change applies.
hir::ItemKind::Existential(ref ty_data) => {
if let Some(impl_trait_fn) = ty_data.impl_trait_fn {
- if let Some(node_id) = self.tcx.hir.as_local_node_id(impl_trait_fn) {
+ if let Some(node_id) = self.tcx.hir().as_local_node_id(impl_trait_fn) {
self.update(node_id, Some(AccessLevel::ReachableFromImplTrait));
}
}
// reachability level through interfaces and children.
let orig_level = replace(&mut self.prev_level, item_level);
- // Mark all items in interfaces of reachable items as reachable
+ // Mark all items in interfaces of reachable items as reachable.
match item.node {
- // The interface is empty
+ // The interface is empty.
hir::ItemKind::ExternCrate(..) => {}
- // All nested items are checked by visit_item
+ // All nested items are checked by `visit_item`.
hir::ItemKind::Mod(..) => {}
- // Re-exports are handled in visit_mod
+ // Re-exports are handled in `visit_mod`.
hir::ItemKind::Use(..) => {}
- // The interface is empty
+ // The interface is empty.
hir::ItemKind::GlobalAsm(..) => {}
hir::ItemKind::Existential(hir::ExistTy { impl_trait_fn: Some(_), .. }) => {
if item_level.is_some() {
- // Reach the (potentially private) type and the API being exposed
+ // Reach the (potentially private) type and the API being exposed.
self.reach(item.id).ty().predicates();
}
}
- // Visit everything
+ // Visit everything.
hir::ItemKind::Const(..) | hir::ItemKind::Static(..) |
hir::ItemKind::Existential(..) |
hir::ItemKind::Fn(..) | hir::ItemKind::Ty(..) => {
self.reach(item.id).generics().predicates();
}
}
- // Visit everything except for private impl items
+ // Visit everything except for private impl items.
hir::ItemKind::Impl(.., ref trait_ref, _, ref impl_item_refs) => {
if item_level.is_some() {
self.reach(item.id).generics().predicates().impl_trait_ref();
}
}
- // Visit everything, but enum variants have their own levels
+ // Visit everything, but enum variants have their own levels.
hir::ItemKind::Enum(ref def, _) => {
if item_level.is_some() {
self.reach(item.id).generics().predicates();
}
}
}
- // Visit everything, but foreign items have their own levels
+ // Visit everything, but foreign items have their own levels.
hir::ItemKind::ForeignMod(ref foreign_mod) => {
for foreign_item in &foreign_mod.items {
if self.get(foreign_item.id).is_some() {
}
}
}
- // Visit everything except for private fields
+ // Visit everything except for private fields.
hir::ItemKind::Struct(ref struct_def, _) |
hir::ItemKind::Union(ref struct_def, _) => {
if item_level.is_some() {
// Blocks can have public items, for example impls, but they always
// start as completely private regardless of publicity of a function,
- // constant, type, field, etc. in which this block resides
+ // constant, type, field, etc., in which this block resides.
intravisit::walk_block(self, b);
self.prev_level = orig_level;
// This code is here instead of in visit_item so that the
// crate module gets processed as well.
if self.prev_level.is_some() {
- let def_id = self.tcx.hir.local_def_id(id);
+ let def_id = self.tcx.hir().local_def_id(id);
if let Some(exports) = self.tcx.module_exports(def_id) {
for export in exports.iter() {
if export.vis == ty::Visibility::Public {
if let Some(def_id) = export.def.opt_def_id() {
- if let Some(node_id) = self.tcx.hir.as_local_node_id(def_id) {
+ if let Some(node_id) = self.tcx.hir().as_local_node_id(def_id) {
self.update(node_id, Some(AccessLevel::Exported));
}
}
return
}
- let module_did = ty::DefIdTree::parent(self.tcx, self.tcx.hir.local_def_id(md.id)).unwrap();
- let mut module_id = self.tcx.hir.as_local_node_id(module_did).unwrap();
+ let module_did = ty::DefIdTree::parent(
+ self.tcx,
+ self.tcx.hir().local_def_id(md.id)
+ ).unwrap();
+ let mut module_id = self.tcx.hir().as_local_node_id(module_did).unwrap();
let level = if md.vis.node.is_pub() { self.get(module_id) } else { None };
let level = self.update(md.id, level);
if level.is_none() {
loop {
let module = if module_id == ast::CRATE_NODE_ID {
- &self.tcx.hir.krate().module
- } else if let hir::ItemKind::Mod(ref module) = self.tcx.hir.expect_item(module_id).node
- {
+ &self.tcx.hir().krate().module
+ } else if let hir::ItemKind::Mod(ref module) =
+ self.tcx.hir().expect_item(module_id).node {
module
} else {
unreachable!()
for id in &module.item_ids {
self.update(id.id, level);
}
- let def_id = self.tcx.hir.local_def_id(module_id);
+ let def_id = self.tcx.hir().local_def_id(module_id);
if let Some(exports) = self.tcx.module_exports(def_id) {
for export in exports.iter() {
- if let Some(node_id) = self.tcx.hir.as_local_node_id(export.def.def_id()) {
+ if let Some(node_id) = self.tcx.hir().as_local_node_id(export.def.def_id()) {
self.update(node_id, level);
}
}
if module_id == ast::CRATE_NODE_ID {
break
}
- module_id = self.tcx.hir.get_parent_node(module_id);
+ module_id = self.tcx.hir().get_parent_node(module_id);
}
}
}
}
fn check_trait_ref(&mut self, trait_ref: ty::TraitRef<'tcx>) {
- if let Some(node_id) = self.ev.tcx.hir.as_local_node_id(trait_ref.def_id) {
- let item = self.ev.tcx.hir.expect_item(node_id);
+ if let Some(node_id) = self.ev.tcx.hir().as_local_node_id(trait_ref.def_id) {
+ let item = self.ev.tcx.hir().expect_item(node_id);
self.ev.update(item.id, self.access_level);
}
}
};
if let Some(def_id) = ty_def_id {
- if let Some(node_id) = self.ev.tcx.hir.as_local_node_id(def_id) {
+ if let Some(node_id) = self.ev.tcx.hir().as_local_node_id(def_id) {
self.ev.update(node_id, self.access_level);
}
}
impl<'a, 'tcx> NamePrivacyVisitor<'a, 'tcx> {
// Checks that a field in a struct constructor (expression or pattern) is accessible.
fn check_field(&mut self,
- use_ctxt: Span, // Syntax context of the field name at the use site
- span: Span, // Span of the field pattern, e.g. `x: 0`
- def: &'tcx ty::AdtDef, // Definition of the struct or enum
- field: &'tcx ty::FieldDef) { // Definition of the field
+ use_ctxt: Span, // syntax context of the field name at the use site
+ span: Span, // span of the field pattern, e.g., `x: 0`
+ def: &'tcx ty::AdtDef, // definition of the struct or enum
+ field: &'tcx ty::FieldDef) { // definition of the field
let ident = Ident::new(keywords::Invalid.name(), use_ctxt);
let def_id = self.tcx.adjust_ident(ident, def.did, self.current_item).1;
if !def.is_enum() && !field.vis.is_accessible_from(def_id, self.tcx) {
}
}
-// Set the correct TypeckTables for the given `item_id` (or an empty table if
-// there is no TypeckTables for the item).
+// Set the correct `TypeckTables` for the given `item_id` (or an empty table if
+// there is no `TypeckTables` for the item).
fn update_tables<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
item_id: ast::NodeId,
tables: &mut &'a ty::TypeckTables<'tcx>,
empty_tables: &'a ty::TypeckTables<'tcx>)
-> &'a ty::TypeckTables<'tcx> {
- let def_id = tcx.hir.local_def_id(item_id);
+ let def_id = tcx.hir().local_def_id(item_id);
if tcx.has_typeck_tables(def_id) {
replace(tables, tcx.typeck_tables_of(def_id))
/// We want to visit items in the context of their containing
/// module and so forth, so supply a crate for doing a deep walk.
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
- NestedVisitorMap::All(&self.tcx.hir)
+ NestedVisitorMap::All(&self.tcx.hir())
}
fn visit_nested_body(&mut self, body: hir::BodyId) {
let orig_tables = replace(&mut self.tables, self.tcx.body_tables(body));
- let body = self.tcx.hir.body(body);
+ let body = self.tcx.hir().body(body);
self.visit_body(body);
self.tables = orig_tables;
}
impl<'a, 'tcx> TypePrivacyVisitor<'a, 'tcx> {
fn def_id_visibility(&self, did: DefId) -> ty::Visibility {
- match self.tcx.hir.as_local_node_id(did) {
+ match self.tcx.hir().as_local_node_id(did) {
Some(node_id) => {
- let vis = match self.tcx.hir.get(node_id) {
+ let vis = match self.tcx.hir().get(node_id) {
Node::Item(item) => &item.vis,
Node::ForeignItem(foreign_item) => &foreign_item.vis,
Node::ImplItem(impl_item) => &impl_item.vis,
Node::TraitItem(..) |
Node::Variant(..) => {
- return self.def_id_visibility(self.tcx.hir.get_parent_did(node_id));
+ return self.def_id_visibility(self.tcx.hir().get_parent_did(node_id));
}
Node::StructCtor(vdata) => {
- let struct_node_id = self.tcx.hir.get_parent(node_id);
- let struct_vis = match self.tcx.hir.get(struct_node_id) {
+ let struct_node_id = self.tcx.hir().get_parent(node_id);
+ let struct_vis = match self.tcx.hir().get(struct_node_id) {
Node::Item(item) => &item.vis,
node => bug!("unexpected node kind: {:?}", node),
};
// If the structure is marked as non_exhaustive then lower the
// visibility to within the crate.
- let struct_def_id = self.tcx.hir.get_parent_did(node_id);
+ let struct_def_id = self.tcx.hir().get_parent_did(node_id);
let adt_def = self.tcx.adt_def(struct_def_id);
if adt_def.non_enum_variant().is_field_list_non_exhaustive()
&& ctor_vis == ty::Visibility::Public
self.def_id_visibility(did).is_accessible_from(self.current_item, self.tcx)
}
- // Take node ID of an expression or pattern and check its type for privacy.
+ // Take node-id of an expression or pattern and check its type for privacy.
fn check_expr_pat_type(&mut self, id: hir::HirId, span: Span) -> bool {
self.span = span;
if self.tables.node_id_to_type(id).visit_with(self) {
/// We want to visit items in the context of their containing
/// module and so forth, so supply a crate for doing a deep walk.
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
- NestedVisitorMap::All(&self.tcx.hir)
+ NestedVisitorMap::All(&self.tcx.hir())
}
fn visit_nested_body(&mut self, body: hir::BodyId) {
let orig_tables = replace(&mut self.tables, self.tcx.body_tables(body));
let orig_in_body = replace(&mut self.in_body, true);
- let body = self.tcx.hir.body(body);
+ let body = self.tcx.hir().body(body);
self.visit_body(body);
self.tables = orig_tables;
self.in_body = orig_in_body;
intravisit::walk_qpath(self, qpath, id, span);
}
- // Check types of patterns
+ // Check types of patterns.
fn visit_pat(&mut self, pattern: &'tcx hir::Pat) {
if self.check_expr_pat_type(pattern.hir_id, pattern.span) {
// Do not check nested patterns if the error already happened.
intravisit::walk_local(self, local);
}
- // Check types in item interfaces
+ // Check types in item interfaces.
fn visit_item(&mut self, item: &'tcx hir::Item) {
let orig_current_item = self.current_item;
let orig_tables = update_tables(self.tcx,
&mut self.tables,
self.empty_tables);
let orig_in_body = replace(&mut self.in_body, false);
- self.current_item = self.tcx.hir.local_def_id(item.id);
+ self.current_item = self.tcx.hir().local_def_id(item.id);
intravisit::walk_item(self, item);
self.tables = orig_tables;
self.in_body = orig_in_body;
Some(poly_projection_predicate.skip_binder()
.projection_ty.trait_ref(self.tcx))
}
- ty::Predicate::TypeOutlives(..) => None,
+ ty::Predicate::TypeOutlives(..) | ty::Predicate::RegionOutlives(..) => None,
_ => bug!("unexpected predicate: {:?}", predicate),
};
if let Some(trait_ref) = trait_ref {
tcx: TyCtxt<'a, 'tcx, 'tcx>,
access_levels: &'a AccessLevels,
in_variant: bool,
- // set of errors produced by this obsolete visitor
+ // Set of errors produced by this obsolete visitor.
old_error_set: NodeSet,
}
struct ObsoleteCheckTypeForPrivatenessVisitor<'a, 'b: 'a, 'tcx: 'b> {
inner: &'a ObsoleteVisiblePrivateTypesVisitor<'b, 'tcx>,
- /// whether the type refers to private types.
+ /// Whether the type refers to private types.
contains_private: bool,
- /// whether we've recurred at all (i.e. if we're pointing at the
- /// first type on which visit_ty was called).
+ /// Whether we've recurred at all (i.e., if we're pointing at the
+ /// first type on which `visit_ty` was called).
at_outer_type: bool,
- // whether that first type is a public path.
+ /// Whether that first type is a public path.
outer_type_is_public_path: bool,
}
// A path can only be private if:
// it's in this crate...
- if let Some(node_id) = self.tcx.hir.as_local_node_id(did) {
+ if let Some(node_id) = self.tcx.hir().as_local_node_id(did) {
// .. and it corresponds to a private type in the AST (this returns
- // None for type parameters)
- match self.tcx.hir.find(node_id) {
+ // `None` for type parameters).
+ match self.tcx.hir().find(node_id) {
Some(Node::Item(ref item)) => !item.vis.node.is_pub(),
Some(_) | None => false,
}
fn trait_is_public(&self, trait_id: ast::NodeId) -> bool {
// FIXME: this would preferably be using `exported_items`, but all
- // traits are exported currently (see `EmbargoVisitor.exported_trait`)
+ // traits are exported currently (see `EmbargoVisitor.exported_trait`).
self.access_levels.is_public(trait_id)
}
if let hir::TyKind::Path(hir::QPath::Resolved(_, ref path)) = ty.node {
if self.inner.path_is_private_type(path) {
self.contains_private = true;
- // found what we're looking for so let's stop
- // working.
+ // Found what we're looking for, so let's stop working.
return
}
}
intravisit::walk_ty(self, ty)
}
- // don't want to recurse into [, .. expr]
+ // Don't want to recurse into `[, .. expr]`.
fn visit_expr(&mut self, _: &hir::Expr) {}
}
/// We want to visit items in the context of their containing
/// module and so forth, so supply a crate for doing a deep walk.
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
- NestedVisitorMap::All(&self.tcx.hir)
+ NestedVisitorMap::All(&self.tcx.hir())
}
fn visit_item(&mut self, item: &'tcx hir::Item) {
match item.node {
- // contents of a private mod can be re-exported, so we need
+ // Contents of a private mod can be re-exported, so we need
// to check internals.
hir::ItemKind::Mod(_) => {}
}
}
- // impls need some special handling to try to offer useful
+ // Impls need some special handling to try to offer useful
// error messages without (too many) false positives
- // (i.e. we could just return here to not check them at
+ // (i.e., we could just return here to not check them at
// all, or some worse estimation of whether an impl is
// publicly visible).
hir::ItemKind::Impl(.., ref g, ref trait_ref, ref self_, ref impl_item_refs) => {
// `impl [... for] Private` is never visible.
let self_contains_private;
- // impl [... for] Public<...>, but not `impl [... for]
- // Vec<Public>` or `(Public,)` etc.
+ // `impl [... for] Public<...>`, but not `impl [... for]
+ // Vec<Public>` or `(Public,)`, etc.
let self_is_public_path;
- // check the properties of the Self type:
+ // Check the properties of the `Self` type:
{
let mut visitor = ObsoleteCheckTypeForPrivatenessVisitor {
inner: self,
self_is_public_path = visitor.outer_type_is_public_path;
}
- // miscellaneous info about the impl
+ // Miscellaneous info about the impl:
// `true` iff this is `impl Private for ...`.
let not_private_trait =
|tr| {
let did = tr.path.def.def_id();
- if let Some(node_id) = self.tcx.hir.as_local_node_id(did) {
+ if let Some(node_id) = self.tcx.hir().as_local_node_id(did) {
self.trait_is_public(node_id)
} else {
true // external traits must be public
trait_ref.is_some() ||
impl_item_refs.iter()
.any(|impl_item_ref| {
- let impl_item = self.tcx.hir.impl_item(impl_item_ref.id);
+ let impl_item = self.tcx.hir().impl_item(impl_item_ref.id);
match impl_item.node {
hir::ImplItemKind::Const(..) |
hir::ImplItemKind::Method(..) => {
// should only walk into public items so that we
// don't erroneously report errors for private
// types in private items.
- let impl_item = self.tcx.hir.impl_item(impl_item_ref.id);
+ let impl_item = self.tcx.hir().impl_item(impl_item_ref.id);
match impl_item.node {
hir::ImplItemKind::Const(..) |
hir::ImplItemKind::Method(..)
// Those in 3. are warned with this call.
for impl_item_ref in impl_item_refs {
- let impl_item = self.tcx.hir.impl_item(impl_item_ref.id);
+ let impl_item = self.tcx.hir().impl_item(impl_item_ref.id);
if let hir::ImplItemKind::Type(ref ty) = impl_item.node {
self.visit_ty(ty);
}
}
}
} else if trait_ref.is_none() && self_is_public_path {
- // impl Public<Private> { ... }. Any public static
+ // `impl Public<Private> { ... }`. Any public static
// methods will be visible as `Public::foo`.
let mut found_pub_static = false;
for impl_item_ref in impl_item_refs {
if self.item_is_public(&impl_item_ref.id.node_id, &impl_item_ref.vis) {
- let impl_item = self.tcx.hir.impl_item(impl_item_ref.id);
+ let impl_item = self.tcx.hir().impl_item(impl_item_ref.id);
match impl_item_ref.kind {
hir::AssociatedItemKind::Const => {
found_pub_static = true;
// we're introducing a new name.
hir::ItemKind::Ty(..) => return,
- // not at all public, so we don't care
+ // Not at all public, so we don't care.
_ if !self.item_is_public(&item.id, &item.vis) => {
return;
}
// We've carefully constructed it so that if we're here, then
// any `visit_ty`'s will be called on things that are in
- // public signatures, i.e. things that we're interested in for
+ // public signatures, i.e., things that we're interested in for
// this visitor.
intravisit::walk_item(self, item);
}
}
}
- // we don't need to introspect into these at all: an
+ // We don't need to introspect into these at all: an
// expression/block context can't possibly contain exported things.
// (Making them no-ops stops us from traversing the whole AST without
// having to be super careful about our `walk_...` calls above.)
tcx: TyCtxt<'a, 'tcx, 'tcx>,
item_def_id: DefId,
span: Span,
- /// The visitor checks that each component type is at least this visible
+ /// The visitor checks that each component type is at least this visible.
required_visibility: ty::Visibility,
- /// The visibility of the least visible component that has been visited
+ /// The visibility of the least visible component that has been visited.
min_visibility: ty::Visibility,
has_pub_restricted: bool,
has_old_errors: bool,
}
fn predicates(&mut self) -> &mut Self {
- // NB: We use `explicit_predicates_of` and not `predicates_of`
+ // N.B., we use `explicit_predicates_of` and not `predicates_of`
// because we don't want to report privacy errors due to where
// clauses that the compiler inferred. We only want to
// consider the ones that the user wrote. This is important
}
fn check_trait_ref(&mut self, trait_ref: ty::TraitRef<'tcx>) {
- // Non-local means public (private items can't leave their crate, modulo bugs)
- if let Some(node_id) = self.tcx.hir.as_local_node_id(trait_ref.def_id) {
- let item = self.tcx.hir.expect_item(node_id);
+ // Non-local means public (private items can't leave their crate, modulo bugs).
+ if let Some(node_id) = self.tcx.hir().as_local_node_id(trait_ref.def_id) {
+ let item = self.tcx.hir().expect_item(node_id);
let vis = ty::Visibility::from_hir(&item.vis, node_id, self.tcx);
if !vis.is_at_least(self.min_visibility, self.tcx) {
self.min_visibility = vis;
};
if let Some(def_id) = ty_def_id {
- // Non-local means public (private items can't leave their crate, modulo bugs)
- if let Some(node_id) = self.tcx.hir.as_local_node_id(def_id) {
- let hir_vis = match self.tcx.hir.find(node_id) {
+ // Non-local means public (private items can't leave their crate, modulo bugs).
+ if let Some(node_id) = self.tcx.hir().as_local_node_id(def_id) {
+ let hir_vis = match self.tcx.hir().find(node_id) {
Some(Node::Item(item)) => &item.vis,
Some(Node::ForeignItem(item)) => &item.vis,
_ => bug!("expected item of foreign item"),
has_old_errors = true;
break;
}
- let parent = self.tcx.hir.get_parent_node(id);
+ let parent = self.tcx.hir().get_parent_node(id);
if parent == id {
break;
}
SearchInterfaceForPrivateItemsVisitor {
tcx: self.tcx,
- item_def_id: self.tcx.hir.local_def_id(item_id),
- span: self.tcx.hir.span(item_id),
+ item_def_id: self.tcx.hir().local_def_id(item_id),
+ span: self.tcx.hir().span(item_id),
min_visibility: ty::Visibility::Public,
required_visibility,
has_pub_restricted: self.has_pub_restricted,
impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> {
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
- NestedVisitorMap::OnlyBodies(&self.tcx.hir)
+ NestedVisitorMap::OnlyBodies(&self.tcx.hir())
}
fn visit_item(&mut self, item: &'tcx hir::Item) {
let item_visibility = ty::Visibility::from_hir(&item.vis, item.id, tcx);
match item.node {
- // Crates are always public
+ // Crates are always public.
hir::ItemKind::ExternCrate(..) => {}
- // All nested items are checked by visit_item
+ // All nested items are checked by `visit_item`.
hir::ItemKind::Mod(..) => {}
- // Checked in resolve
+ // Checked in resolve.
hir::ItemKind::Use(..) => {}
- // No subitems
+ // No subitems.
hir::ItemKind::GlobalAsm(..) => {}
hir::ItemKind::Existential(hir::ExistTy { impl_trait_fn: Some(_), .. }) => {
// Check the traits being exposed, as they're separate,
- // e.g. `impl Iterator<Item=T>` has two predicates,
+ // e.g., `impl Iterator<Item=T>` has two predicates,
// `X: Iterator` and `<X as Iterator>::Item == T`,
// where `X` is the `impl Iterator<Item=T>` itself,
// stored in `predicates_of`, not in the `Ty` itself.
-
self.check(item.id, item_visibility).predicates();
}
- // Subitems of these items have inherited publicity
+ // Subitems of these items have inherited publicity.
hir::ItemKind::Const(..) | hir::ItemKind::Static(..) | hir::ItemKind::Fn(..) |
hir::ItemKind::Existential(..) |
hir::ItemKind::Ty(..) => {
self.check(item.id, item_visibility).generics().predicates().ty();
- // Recurse for e.g. `impl Trait` (see `visit_ty`).
+ // Recurse for e.g., `impl Trait` (see `visit_ty`).
self.inner_visibility = item_visibility;
intravisit::walk_item(self, item);
}
}
}
}
- // Subitems of foreign modules have their own publicity
+ // Subitems of foreign modules have their own publicity.
hir::ItemKind::ForeignMod(ref foreign_mod) => {
for foreign_item in &foreign_mod.items {
let vis = ty::Visibility::from_hir(&foreign_item.vis, item.id, tcx);
self.check(foreign_item.id, vis).generics().predicates().ty();
}
}
- // Subitems of structs and unions have their own publicity
+ // Subitems of structs and unions have their own publicity.
hir::ItemKind::Struct(ref struct_def, _) |
hir::ItemKind::Union(ref struct_def, _) => {
self.check(item.id, item_visibility).generics().predicates();
}
}
// An inherent impl is public when its type is public
- // Subitems of inherent impls have their own publicity
+ // Subitems of inherent impls have their own publicity.
hir::ItemKind::Impl(.., None, _, ref impl_item_refs) => {
let ty_vis =
self.check(item.id, ty::Visibility::Invisible).ty().min_visibility;
self.check(item.id, ty_vis).generics().predicates();
for impl_item_ref in impl_item_refs {
- let impl_item = self.tcx.hir.impl_item(impl_item_ref.id);
+ let impl_item = self.tcx.hir().impl_item(impl_item_ref.id);
let impl_item_vis = ty::Visibility::from_hir(&impl_item.vis, item.id, tcx);
let mut check = self.check(impl_item.id, min(impl_item_vis, ty_vis));
check.in_assoc_ty = impl_item_ref.kind == hir::AssociatedItemKind::Type;
check.generics().predicates().ty();
- // Recurse for e.g. `impl Trait` (see `visit_ty`).
+ // Recurse for e.g., `impl Trait` (see `visit_ty`).
self.inner_visibility = impl_item_vis;
intravisit::walk_impl_item(self, impl_item);
}
}
// A trait impl is public when both its type and its trait are public
- // Subitems of trait impls have inherited publicity
+ // Subitems of trait impls have inherited publicity.
hir::ItemKind::Impl(.., Some(_), _, ref impl_item_refs) => {
let vis = self.check(item.id, ty::Visibility::Invisible)
.ty().impl_trait_ref().min_visibility;
self.check(item.id, vis).generics().predicates();
for impl_item_ref in impl_item_refs {
- let impl_item = self.tcx.hir.impl_item(impl_item_ref.id);
+ let impl_item = self.tcx.hir().impl_item(impl_item_ref.id);
let mut check = self.check(impl_item.id, vis);
check.in_assoc_ty = impl_item_ref.kind == hir::AssociatedItemKind::Type;
check.generics().predicates().ty();
- // Recurse for e.g. `impl Trait` (see `visit_ty`).
+ // Recurse for e.g., `impl Trait` (see `visit_ty`).
self.inner_visibility = vis;
intravisit::walk_impl_item(self, impl_item);
}
}
fn visit_impl_item(&mut self, _impl_item: &'tcx hir::ImplItem) {
- // handled in `visit_item` above
+ // Handled in `visit_item` above.
}
- // Don't recurse into expressions in array sizes or const initializers
+ // Don't recurse into expressions in array sizes or const initializers.
fn visit_expr(&mut self, _: &'tcx hir::Expr) {}
- // Don't recurse into patterns in function arguments
+ // Don't recurse into patterns in function arguments.
fn visit_pat(&mut self, _: &'tcx hir::Pat) {}
}
-> Lrc<AccessLevels> {
assert_eq!(krate, LOCAL_CRATE);
- let krate = tcx.hir.krate();
+ let krate = tcx.hir().krate();
let empty_tables = ty::TypeckTables::empty(None);
// Check privacy of names not checked in previous compilation stages.
pub_restricted_visitor.has_pub_restricted
};
- // Check for private types and traits in public interfaces
+ // Check for private types and traits in public interfaces.
let mut visitor = PrivateItemsInPublicInterfacesVisitor {
tcx,
has_pub_restricted,