提交 4ae89129 编写于 作者: Z Zack M. Davis

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.)
上级 9df9c9df
......@@ -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)
}
......
......@@ -1285,7 +1285,7 @@ fn lower_existential_impl_trait(
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 @@ fn lower_use_tree(
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 @@ fn lower_use_tree(
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 @@ fn lower_use_tree(
// 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 @@ fn lower_visibility(
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 @@ fn lower_visibility(
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 {
......
......@@ -458,11 +458,11 @@ fn visit_lifetime(&mut self, lifetime: &'hir Lifetime) {
}
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);
......
......@@ -1049,7 +1049,9 @@ pub fn span(&self, id: NodeId) -> Span {
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,
......
......@@ -24,7 +24,7 @@
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,
}
}
}
......
......@@ -12,7 +12,7 @@
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 @@ pub fn print_variants(&mut self,
}
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 @@ pub fn print_visibility(&mut self, vis: &hir::Visibility) -> io::Result<()> {
}
self.word_nbsp(")")?;
}
hir::Inherited => ()
hir::VisibilityInherited => ()
}
Ok(())
......@@ -952,17 +952,18 @@ pub fn print_trait_item(&mut self, ti: &hir::TraitItem) -> io::Result<()> {
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 @@ pub fn print_ty_fn(&mut self,
},
name,
&generics,
&hir::Inherited,
&Spanned { span: syntax_pos::DUMMY_SP, node: hir::VisibilityInherited },
arg_names,
None)?;
self.end()
......
......@@ -710,20 +710,20 @@ fn hash_stable<W: StableHasherResult>(&self,
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 @@ fn hash_stable<W: StableHasherResult>(&self,
}
}
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>,
......
......@@ -157,7 +157,7 @@ fn visit_node(&mut self, node: &hir_map::Node<'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 @@ fn visit_variant_data(&mut self, def: &'tcx hir::VariantData, _: ast::Name,
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));
......
......@@ -268,16 +268,16 @@ fn parent(self, id: DefId) -> Option<DefId> {
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))
}
}
......
......@@ -397,7 +397,7 @@ fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
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 @@ fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
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 @@ fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
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 @@ fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
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;
}
......
......@@ -40,6 +40,7 @@
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 @@ pub fn tracked<'x, DATA, R>(&'x mut self,
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 {
......
......@@ -61,7 +61,7 @@ fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, '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 @@ fn visit_item(&mut self, item: &'tcx hir::Item) {
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 @@ fn visit_item(&mut self, item: &'tcx hir::Item) {
}
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 @@ fn visit_item(&mut self, item: &'tcx hir::Item) {
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 @@ fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef) {
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 @@ fn path_is_private_type(&self, path: &hir::Path) -> bool {
// .. 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 @@ fn check_generic_bound(&mut self, bound: &hir::GenericBound) {
}
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 @@ fn visit_variant(&mut self,
}
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);
}
}
......
......@@ -55,6 +55,7 @@
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 @@ pub fn get_path_def(&self, id: NodeId) -> HirDef {
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, ..),
......
......@@ -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 @@ fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem) {
fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem) {
}
}
......@@ -286,7 +286,7 @@ fn clean(&self, cx: &DocContext) -> ExternalCrate {
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 @@ fn clean(&self, cx: &DocContext) -> ExternalCrate {
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 @@ fn clean(&self, cx: &DocContext) -> Vec<Item> {
// 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"),
......
......@@ -17,6 +17,7 @@
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 @@ pub fn new(name: Option<Name>) -> 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,
......
......@@ -15,7 +15,8 @@
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 @@ pub fn visit(&mut self, krate: &hir::Crate) {
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 @@ pub fn visit_mod_contents(&mut self, span: Span, attrs: hir::HirVec<ast::Attribu
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 @@ pub fn visit_item(&mut self, item: &hir::Item,
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 @@ pub fn visit_item(&mut self, item: &hir::Item,
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 @@ pub fn visit_item(&mut self, item: &hir::Item,
// 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") => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册