in which hir::Visibility recalls whence it came (i.e., becomes Spanned)

There are at least a couple (and plausibly even three) diagnostics that
could use the spans of visibility modifiers in order to be reliably
correct (rather than hacking and munging surrounding spans to try to
infer where the visibility keyword must have been).

We follow the naming convention established by the other `Spanned` HIR
nodes: the "outer" type alias gets the "prime" node-type name, the
"inner" enum gets the name suffixed with an underscore, and the variant
names are prefixed with the prime name and `pub use` exported from here
(from HIR).

Thanks to veteran reviewer Vadim Petrochenkov for suggesting this
uniform approach. (A previous draft, based on the reasoning that
`Visibility::Inherited` should not have a span, tried to hack in a named
`span` field on `Visibility::Restricted` and a positional field on
`Public` and `Crate`. This was ... not so uniform.)
This commit is contained in:
Zack M. Davis 2018-06-30 20:34:18 -07:00
parent 9df9c9df7b
commit 4ae89129e1
17 changed files with 121 additions and 99 deletions

View file

@ -1104,7 +1104,7 @@ 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 Visibility::Restricted { ref path, id } = *vis {
if let VisibilityRestricted { ref path, id } = vis.node {
visitor.visit_id(id);
visitor.visit_path(path, id)
}

View file

@ -1285,7 +1285,7 @@ impl<'a> LoweringContext<'a> {
name: keywords::Invalid.name(),
attrs: Default::default(),
node: exist_ty_item_kind,
vis: hir::Visibility::Inherited,
vis: respan(span.shrink_to_lo(), hir::VisibilityInherited),
span: exist_ty_span,
};
@ -2770,18 +2770,19 @@ impl<'a> LoweringContext<'a> {
let new_id = this.lower_node_id(new_node_id);
let path = this.lower_path_extra(def, &path, None, ParamMode::Explicit);
let item = hir::ItemUse(P(path), hir::UseKind::Single);
let vis = match vis {
hir::Visibility::Public => hir::Visibility::Public,
hir::Visibility::Crate(sugar) => hir::Visibility::Crate(sugar),
hir::Visibility::Inherited => hir::Visibility::Inherited,
hir::Visibility::Restricted { ref path, id: _ } => {
hir::Visibility::Restricted {
let vis_kind = match vis.node {
hir::VisibilityPublic => hir::VisibilityPublic,
hir::VisibilityCrate(sugar) => hir::VisibilityCrate(sugar),
hir::VisibilityInherited => hir::VisibilityInherited,
hir::VisibilityRestricted { ref path, id: _ } => {
hir::VisibilityRestricted {
path: path.clone(),
// We are allocating a new NodeId here
id: this.next_id().node_id,
}
}
};
let vis = respan(vis.span, vis_kind);
this.items.insert(
new_id.node_id,
@ -2842,18 +2843,19 @@ impl<'a> LoweringContext<'a> {
self.lower_use_tree(use_tree, &prefix, new_id, &mut vis, &mut name, &attrs);
self.with_hir_id_owner(new_id, |this| {
let vis = match vis {
hir::Visibility::Public => hir::Visibility::Public,
hir::Visibility::Crate(sugar) => hir::Visibility::Crate(sugar),
hir::Visibility::Inherited => hir::Visibility::Inherited,
hir::Visibility::Restricted { ref path, id: _ } => {
hir::Visibility::Restricted {
let vis_kind = match vis.node {
hir::VisibilityPublic => hir::VisibilityPublic,
hir::VisibilityCrate(sugar) => hir::VisibilityCrate(sugar),
hir::VisibilityInherited => hir::VisibilityInherited,
hir::VisibilityRestricted { ref path, id: _ } => {
hir::VisibilityRestricted {
path: path.clone(),
// We are allocating a new NodeId here
id: this.next_id().node_id,
}
}
};
let vis = respan(vis.span, vis_kind);
this.items.insert(
new_id,
@ -2874,7 +2876,7 @@ impl<'a> LoweringContext<'a> {
// the stability of `use a::{};`, to avoid it showing up as
// a re-export by accident when `pub`, e.g. in documentation.
let path = P(self.lower_path(id, &prefix, ParamMode::Explicit));
*vis = hir::Inherited;
*vis = respan(prefix.span.shrink_to_lo(), hir::VisibilityInherited);
hir::ItemUse(path, hir::UseKind::ListStem)
}
}
@ -4274,10 +4276,10 @@ impl<'a> LoweringContext<'a> {
v: &Visibility,
explicit_owner: Option<NodeId>,
) -> hir::Visibility {
match v.node {
VisibilityKind::Public => hir::Public,
VisibilityKind::Crate(sugar) => hir::Visibility::Crate(sugar),
VisibilityKind::Restricted { ref path, id, .. } => hir::Visibility::Restricted {
let node = match v.node {
VisibilityKind::Public => hir::VisibilityPublic,
VisibilityKind::Crate(sugar) => hir::VisibilityCrate(sugar),
VisibilityKind::Restricted { ref path, id } => hir::VisibilityRestricted {
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
@ -4285,8 +4287,9 @@ impl<'a> LoweringContext<'a> {
self.lower_node_id(id).node_id
},
},
VisibilityKind::Inherited => hir::Inherited,
}
VisibilityKind::Inherited => hir::VisibilityInherited,
};
respan(v.span, node)
}
fn lower_defaultness(&mut self, d: Defaultness, has_value: bool) -> hir::Defaultness {

View file

@ -458,11 +458,11 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
}
fn visit_vis(&mut self, visibility: &'hir Visibility) {
match *visibility {
Visibility::Public |
Visibility::Crate(_) |
Visibility::Inherited => {}
Visibility::Restricted { id, .. } => {
match visibility.node {
VisibilityPublic |
VisibilityCrate(_) |
VisibilityInherited => {}
VisibilityRestricted { id, .. } => {
self.insert(id, NodeVisibility(visibility));
self.with_parent(id, |this| {
intravisit::walk_vis(this, visibility);

View file

@ -1049,7 +1049,9 @@ impl<'hir> Map<'hir> {
Some(EntryStructCtor(_, _, _)) => self.expect_item(self.get_parent(id)).span,
Some(EntryLifetime(_, _, lifetime)) => lifetime.span,
Some(EntryGenericParam(_, _, param)) => param.span,
Some(EntryVisibility(_, _, &Visibility::Restricted { ref path, .. })) => path.span,
Some(EntryVisibility(_, _, &Spanned {
node: VisibilityRestricted { ref path, .. }, ..
})) => path.span,
Some(EntryVisibility(_, _, v)) => bug!("unexpected Visibility {:?}", v),
Some(EntryLocal(_, _, local)) => local.span,
Some(EntryMacroDef(_, macro_def)) => macro_def.span,

View file

@ -24,7 +24,7 @@ pub use self::Stmt_::*;
pub use self::Ty_::*;
pub use self::UnOp::*;
pub use self::UnsafeSource::*;
pub use self::Visibility::{Public, Inherited};
pub use self::Visibility_::*;
use hir::def::Def;
use hir::def_id::{DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX};
@ -1929,22 +1929,30 @@ pub struct PolyTraitRef {
pub span: Span,
}
pub type Visibility = Spanned<Visibility_>;
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub enum Visibility {
Public,
Crate(CrateSugar),
Restricted { path: P<Path>, id: NodeId },
Inherited,
pub enum Visibility_ {
VisibilityPublic,
VisibilityCrate(CrateSugar),
VisibilityRestricted { path: P<Path>, id: NodeId },
VisibilityInherited,
}
impl Visibility {
impl Visibility_ {
pub fn is_pub(&self) -> bool {
match *self {
VisibilityPublic => true,
_ => false
}
}
pub fn is_pub_restricted(&self) -> bool {
use self::Visibility::*;
match self {
&Public |
&Inherited => false,
&Crate(_) |
&Restricted { .. } => true,
match *self {
VisibilityPublic |
VisibilityInherited => false,
VisibilityCrate(..) |
VisibilityRestricted { .. } => true,
}
}
}

View file

@ -12,7 +12,7 @@ pub use self::AnnNode::*;
use rustc_target::spec::abi::Abi;
use syntax::ast;
use syntax::codemap::CodeMap;
use syntax::codemap::{CodeMap, Spanned};
use syntax::parse::ParseSess;
use syntax::parse::lexer::comments;
use syntax::print::pp::{self, Breaks};
@ -839,11 +839,11 @@ impl<'a> State<'a> {
}
pub fn print_visibility(&mut self, vis: &hir::Visibility) -> io::Result<()> {
match *vis {
hir::Public => self.word_nbsp("pub")?,
hir::Visibility::Crate(ast::CrateSugar::JustCrate) => self.word_nbsp("crate")?,
hir::Visibility::Crate(ast::CrateSugar::PubCrate) => self.word_nbsp("pub(crate)")?,
hir::Visibility::Restricted { ref path, .. } => {
match vis.node {
hir::VisibilityPublic => self.word_nbsp("pub")?,
hir::VisibilityCrate(ast::CrateSugar::JustCrate) => self.word_nbsp("crate")?,
hir::VisibilityCrate(ast::CrateSugar::PubCrate) => self.word_nbsp("pub(crate)")?,
hir::VisibilityRestricted { ref path, .. } => {
self.s.word("pub(")?;
if path.segments.len() == 1 &&
path.segments[0].ident.name == keywords::Super.name() {
@ -856,7 +856,7 @@ impl<'a> State<'a> {
}
self.word_nbsp(")")?;
}
hir::Inherited => ()
hir::VisibilityInherited => ()
}
Ok(())
@ -952,17 +952,18 @@ impl<'a> State<'a> {
self.print_outer_attributes(&ti.attrs)?;
match ti.node {
hir::TraitItemKind::Const(ref ty, default) => {
self.print_associated_const(ti.ident, &ty, default, &hir::Inherited)?;
let vis = Spanned { span: syntax_pos::DUMMY_SP, node: hir::VisibilityInherited };
self.print_associated_const(ti.ident, &ty, default, &vis)?;
}
hir::TraitItemKind::Method(ref sig, hir::TraitMethod::Required(ref arg_names)) => {
self.print_method_sig(ti.ident, sig, &ti.generics, &hir::Inherited, arg_names,
None)?;
let vis = Spanned { span: syntax_pos::DUMMY_SP, node: hir::VisibilityInherited };
self.print_method_sig(ti.ident, sig, &ti.generics, &vis, arg_names, None)?;
self.s.word(";")?;
}
hir::TraitItemKind::Method(ref sig, hir::TraitMethod::Provided(body)) => {
let vis = Spanned { span: syntax_pos::DUMMY_SP, node: hir::VisibilityInherited };
self.head("")?;
self.print_method_sig(ti.ident, sig, &ti.generics, &hir::Inherited, &[],
Some(body))?;
self.print_method_sig(ti.ident, sig, &ti.generics, &vis, &[], Some(body))?;
self.nbsp()?;
self.end()?; // need to close a box
self.end()?; // need to close a box
@ -2266,7 +2267,7 @@ impl<'a> State<'a> {
},
name,
&generics,
&hir::Inherited,
&Spanned { span: syntax_pos::DUMMY_SP, node: hir::VisibilityInherited },
arg_names,
None)?;
self.end()

View file

@ -710,20 +710,20 @@ impl_stable_hash_for!(enum ::syntax::ast::CrateSugar {
PubCrate,
});
impl<'a> HashStable<StableHashingContext<'a>> for hir::Visibility {
impl<'a> HashStable<StableHashingContext<'a>> for hir::Visibility_ {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
mem::discriminant(self).hash_stable(hcx, hasher);
match *self {
hir::Visibility::Public |
hir::Visibility::Inherited => {
hir::VisibilityPublic |
hir::VisibilityInherited => {
// No fields to hash.
}
hir::Visibility::Crate(sugar) => {
hir::VisibilityCrate(sugar) => {
sugar.hash_stable(hcx, hasher);
}
hir::Visibility::Restricted { ref path, id } => {
hir::VisibilityRestricted { ref path, id } => {
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
id.hash_stable(hcx, hasher);
});
@ -733,6 +733,8 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::Visibility {
}
}
impl_stable_hash_for_spanned!(hir::Visibility_);
impl<'a> HashStable<StableHashingContext<'a>> for hir::Defaultness {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,

View file

@ -157,7 +157,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
intravisit::walk_item(self, &item);
}
hir::ItemEnum(..) => {
self.inherited_pub_visibility = item.vis == hir::Public;
self.inherited_pub_visibility = item.vis.node.is_pub();
intravisit::walk_item(self, &item);
}
hir::ItemFn(..)
@ -212,7 +212,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
let has_repr_c = self.repr_has_repr_c;
let inherited_pub_visibility = self.inherited_pub_visibility;
let live_fields = def.fields().iter().filter(|f| {
has_repr_c || inherited_pub_visibility || f.vis == hir::Public
has_repr_c || inherited_pub_visibility || f.vis.node.is_pub()
});
self.live_symbols.extend(live_fields.map(|f| f.id));

View file

@ -268,16 +268,16 @@ impl<'a, 'gcx, 'tcx> DefIdTree for TyCtxt<'a, 'gcx, 'tcx> {
impl Visibility {
pub fn from_hir(visibility: &hir::Visibility, id: NodeId, tcx: TyCtxt) -> Self {
match *visibility {
hir::Public => Visibility::Public,
hir::Visibility::Crate(_) => Visibility::Restricted(DefId::local(CRATE_DEF_INDEX)),
hir::Visibility::Restricted { ref path, .. } => match path.def {
match visibility.node {
hir::VisibilityPublic => Visibility::Public,
hir::VisibilityCrate(_) => Visibility::Restricted(DefId::local(CRATE_DEF_INDEX)),
hir::VisibilityRestricted { ref path, .. } => match path.def {
// If there is no resolution, `resolve` will have already reported an error, so
// assume that the visibility is public to avoid reporting more privacy errors.
Def::Err => Visibility::Public,
def => Visibility::Restricted(def.def_id()),
},
hir::Inherited => {
hir::VisibilityInherited => {
Visibility::Restricted(tcx.hir.get_module_parent(id))
}
}

View file

@ -397,7 +397,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
hir::ItemUnion(..) => "a union",
hir::ItemTrait(.., ref trait_item_refs) => {
// Issue #11592, traits are always considered exported, even when private.
if it.vis == hir::Visibility::Inherited {
if it.vis.node == hir::VisibilityInherited {
self.private_traits.insert(it.id);
for trait_item_ref in trait_item_refs {
self.private_traits.insert(trait_item_ref.id.node_id);
@ -414,7 +414,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
if let Some(node_id) = cx.tcx.hir.as_local_node_id(real_trait) {
match cx.tcx.hir.find(node_id) {
Some(hir_map::NodeItem(item)) => {
if item.vis == hir::Visibility::Inherited {
if item.vis.node == hir::VisibilityInherited {
for impl_item_ref in impl_item_refs {
self.private_traits.insert(impl_item_ref.id.node_id);
}
@ -1187,7 +1187,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidNoMangleItems {
let msg = "function is marked #[no_mangle], but not exported";
let mut err = cx.struct_span_lint(PRIVATE_NO_MANGLE_FNS, it.span, msg);
let insertion_span = it.span.shrink_to_lo();
if it.vis == hir::Visibility::Inherited {
if it.vis.node == hir::VisibilityInherited {
err.span_suggestion(insertion_span,
"try making it public",
"pub ".to_owned());
@ -1218,7 +1218,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidNoMangleItems {
let msg = "static is marked #[no_mangle], but not exported";
let mut err = cx.struct_span_lint(PRIVATE_NO_MANGLE_STATICS, it.span, msg);
let insertion_span = it.span.shrink_to_lo();
if it.vis == hir::Visibility::Inherited {
if it.vis.node == hir::VisibilityInherited {
err.span_suggestion(insertion_span,
"try making it public",
"pub ".to_owned());
@ -1388,7 +1388,7 @@ impl UnreachablePub {
fn perform_lint(&self, cx: &LateContext, what: &str, id: ast::NodeId,
vis: &hir::Visibility, span: Span, exportable: bool,
mut applicability: Applicability) {
if !cx.access_levels.is_reachable(id) && *vis == hir::Visibility::Public {
if !cx.access_levels.is_reachable(id) && vis.node.is_pub() {
if span.ctxt().outer().expn_info().is_some() {
applicability = Applicability::MaybeIncorrect;
}

View file

@ -40,6 +40,7 @@ use rustc_data_structures::sync::Lrc;
use std::u32;
use syntax::ast::{self, CRATE_NODE_ID};
use syntax::attr;
use syntax::codemap::Spanned;
use syntax::symbol::keywords;
use syntax_pos::{self, hygiene, FileName, FileMap, Span};
@ -319,9 +320,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
fn encode_info_for_items(&mut self) -> Index {
let krate = self.tcx.hir.krate();
let mut index = IndexBuilder::new(self);
let vis = Spanned { span: syntax_pos::DUMMY_SP, node: hir::VisibilityPublic };
index.record(DefId::local(CRATE_DEF_INDEX),
IsolatedEncoder::encode_info_for_mod,
FromId(CRATE_NODE_ID, (&krate.module, &krate.attrs, &hir::Public)));
FromId(CRATE_NODE_ID, (&krate.module, &krate.attrs, &vis)));
let mut visitor = EncodeVisitor { index: index };
krate.visit_all_item_likes(&mut visitor.as_deep_visitor());
for macro_def in &krate.exported_macros {

View file

@ -61,7 +61,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PubRestrictedVisitor<'a, 'tcx> {
NestedVisitorMap::All(&self.tcx.hir)
}
fn visit_vis(&mut self, vis: &'tcx hir::Visibility) {
self.has_pub_restricted = self.has_pub_restricted || vis.is_pub_restricted();
self.has_pub_restricted = self.has_pub_restricted || vis.node.is_pub_restricted();
}
}
@ -162,7 +162,7 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> {
hir::ItemTrait(..) | hir::ItemTraitAlias(..) |
hir::ItemExistential(..) |
hir::ItemTy(..) | hir::ItemUnion(..) | hir::ItemUse(..) => {
if item.vis == hir::Public { self.prev_level } else { None }
if item.vis.node.is_pub() { self.prev_level } else { None }
}
};
@ -181,7 +181,7 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> {
}
hir::ItemImpl(.., None, _, ref impl_item_refs) => {
for impl_item_ref in impl_item_refs {
if impl_item_ref.vis == hir::Public {
if impl_item_ref.vis.node.is_pub() {
self.update(impl_item_ref.id.node_id, item_level);
}
}
@ -201,14 +201,14 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> {
self.update(def.id(), item_level);
}
for field in def.fields() {
if field.vis == hir::Public {
if field.vis.node.is_pub() {
self.update(field.id, item_level);
}
}
}
hir::ItemForeignMod(ref foreign_mod) => {
for foreign_item in &foreign_mod.items {
if foreign_item.vis == hir::Public {
if foreign_item.vis.node.is_pub() {
self.update(foreign_item.id, item_level);
}
}
@ -358,7 +358,7 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> {
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 == hir::Public { self.get(module_id) } else { None };
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() {
return
@ -1023,7 +1023,7 @@ impl<'a, 'tcx> ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
// .. and it corresponds to a private type in the AST (this returns
// None for type parameters)
match self.tcx.hir.find(node_id) {
Some(hir::map::NodeItem(ref item)) => item.vis != hir::Public,
Some(hir::map::NodeItem(ref item)) => !item.vis.node.is_pub(),
Some(_) | None => false,
}
} else {
@ -1046,7 +1046,7 @@ impl<'a, 'tcx> ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
}
fn item_is_public(&self, id: &ast::NodeId, vis: &hir::Visibility) -> bool {
self.access_levels.is_reachable(*id) || *vis == hir::Public
self.access_levels.is_reachable(*id) || vis.node.is_pub()
}
}
@ -1317,7 +1317,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
}
fn visit_struct_field(&mut self, s: &'tcx hir::StructField) {
if s.vis == hir::Public || self.in_variant {
if s.vis.node.is_pub() || self.in_variant {
intravisit::walk_struct_field(self, s);
}
}

View file

@ -55,6 +55,7 @@ use std::fs::File;
use std::path::{Path, PathBuf};
use syntax::ast::{self, Attribute, NodeId, PatKind};
use syntax::codemap::Spanned;
use syntax::parse::lexer::comments::strip_doc_comment_decoration;
use syntax::parse::token;
use syntax::print::pprust;
@ -631,7 +632,8 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
node: hir::ItemUse(ref path, _),
..
}) |
Node::NodeVisibility(&hir::Visibility::Restricted { ref path, .. }) => path.def,
Node::NodeVisibility(&Spanned {
node: hir::VisibilityRestricted { ref path, .. }, .. }) => path.def,
Node::NodeExpr(&hir::Expr {
node: hir::ExprStruct(ref qpath, ..),

View file

@ -39,7 +39,7 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for CheckVisitor<'a, 'tcx> {
fn visit_item(&mut self, item: &hir::Item) {
if item.vis == hir::Public || item.span.is_dummy() {
if item.vis.node.is_pub() || item.span.is_dummy() {
return;
}
if let hir::ItemUse(ref path, _) = item.node {
@ -214,4 +214,3 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for CollectExternCrateVisitor<'a, 'tcx> {
fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem) {
}
}

View file

@ -286,7 +286,7 @@ impl Clean<ExternalCrate> for CrateNum {
as_primitive(Def::Mod(cx.tcx.hir.local_def_id(id.id)))
}
hir::ItemUse(ref path, hir::UseKind::Single)
if item.vis == hir::Visibility::Public => {
if item.vis.node.is_pub() => {
as_primitive(path.def).map(|(_, prim, attrs)| {
// Pretend the primitive is local.
(cx.tcx.hir.local_def_id(id.id), prim, attrs)
@ -328,7 +328,7 @@ impl Clean<ExternalCrate> for CrateNum {
as_keyword(Def::Mod(cx.tcx.hir.local_def_id(id.id)))
}
hir::ItemUse(ref path, hir::UseKind::Single)
if item.vis == hir::Visibility::Public => {
if item.vis.node.is_pub() => {
as_keyword(path.def).map(|(_, prim, attrs)| {
(cx.tcx.hir.local_def_id(id.id), prim, attrs)
})
@ -3225,11 +3225,11 @@ pub enum Visibility {
impl Clean<Option<Visibility>> for hir::Visibility {
fn clean(&self, cx: &DocContext) -> Option<Visibility> {
Some(match *self {
hir::Visibility::Public => Visibility::Public,
hir::Visibility::Inherited => Visibility::Inherited,
hir::Visibility::Crate(_) => Visibility::Crate,
hir::Visibility::Restricted { ref path, .. } => {
Some(match self.node {
hir::VisibilityPublic => Visibility::Public,
hir::VisibilityInherited => Visibility::Inherited,
hir::VisibilityCrate(_) => Visibility::Crate,
hir::VisibilityRestricted { ref path, .. } => {
let path = path.clean(cx);
let did = register_def(cx, path.def);
Visibility::Restricted(did, path)
@ -3932,7 +3932,7 @@ impl Clean<Vec<Item>> for doctree::Import {
// forcefully don't inline if this is not public or if the
// #[doc(no_inline)] attribute is present.
// Don't inline doc(hidden) imports so they can be stripped at a later stage.
let denied = self.vis != hir::Public || self.attrs.iter().any(|a| {
let denied = !self.vis.node.is_pub() || self.attrs.iter().any(|a| {
a.name() == "doc" && match a.meta_item_list() {
Some(l) => attr::list_contains_name(&l, "no_inline") ||
attr::list_contains_name(&l, "hidden"),

View file

@ -17,6 +17,7 @@ use syntax::ast;
use syntax::ast::{Name, NodeId};
use syntax::attr;
use syntax::ptr::P;
use syntax::codemap::Spanned;
use syntax_pos::{self, Span};
use rustc::hir;
@ -53,7 +54,7 @@ impl Module {
Module {
name : name,
id: ast::CRATE_NODE_ID,
vis: hir::Inherited,
vis: Spanned { span: syntax_pos::DUMMY_SP, node: hir::VisibilityInherited },
stab: None,
depr: None,
where_outer: syntax_pos::DUMMY_SP,

View file

@ -15,7 +15,8 @@ use std::mem;
use syntax::ast;
use syntax::attr;
use syntax_pos::Span;
use syntax::codemap::Spanned;
use syntax_pos::{self, Span};
use rustc::hir::map as hir_map;
use rustc::hir::def::Def;
@ -94,7 +95,8 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
self.module = self.visit_mod_contents(krate.span,
krate.attrs.clone(),
hir::Public,
Spanned { span: syntax_pos::DUMMY_SP,
node: hir::VisibilityPublic },
ast::CRATE_NODE_ID,
&krate.module,
None);
@ -204,7 +206,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
om.id = id;
// Keep track of if there were any private modules in the path.
let orig_inside_public_path = self.inside_public_path;
self.inside_public_path &= vis == hir::Public;
self.inside_public_path &= vis.node.is_pub();
for i in &m.item_ids {
let item = self.cx.tcx.hir.expect_item(i.id);
self.visit_item(item, None, &mut om);
@ -376,7 +378,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
debug!("Visiting item {:?}", item);
let name = renamed.unwrap_or(item.name);
if item.vis == hir::Public {
if item.vis.node.is_pub() {
let def_id = self.cx.tcx.hir.local_def_id(item.id);
self.store_path(def_id);
}
@ -387,14 +389,14 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
om.foreigns.push(if self.inlining {
hir::ForeignMod {
abi: fm.abi,
items: fm.items.iter().filter(|i| i.vis == hir::Public).cloned().collect(),
items: fm.items.iter().filter(|i| i.vis.node.is_pub()).cloned().collect(),
}
} else {
fm.clone()
});
}
// If we're inlining, skip private items.
_ if self.inlining && item.vis != hir::Public => {}
_ if self.inlining && !item.vis.node.is_pub() => {}
hir::ItemGlobalAsm(..) => {}
hir::ItemExternCrate(orig_name) => {
let def_id = self.cx.tcx.hir.local_def_id(item.id);
@ -414,7 +416,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
// If there was a private module in the current path then don't bother inlining
// anything as it will probably be stripped anyway.
if item.vis == hir::Public && self.inside_public_path {
if item.vis.node.is_pub() && self.inside_public_path {
let please_inline = item.attrs.iter().any(|item| {
match item.meta_item_list() {
Some(ref list) if item.check_name("doc") => {