]> git.lizzy.rs Git - rust.git/commitdiff
in which hir::Visibility recalls whence it came (i.e., becomes Spanned)
authorZack M. Davis <code@zackmdavis.net>
Sun, 1 Jul 2018 03:34:18 +0000 (20:34 -0700)
committerZack M. Davis <code@zackmdavis.net>
Sun, 1 Jul 2018 05:41:01 +0000 (22:41 -0700)
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.)

17 files changed:
src/librustc/hir/intravisit.rs
src/librustc/hir/lowering.rs
src/librustc/hir/map/collector.rs
src/librustc/hir/map/mod.rs
src/librustc/hir/mod.rs
src/librustc/hir/print.rs
src/librustc/ich/impls_hir.rs
src/librustc/middle/dead.rs
src/librustc/ty/mod.rs
src/librustc_lint/builtin.rs
src/librustc_metadata/encoder.rs
src/librustc_privacy/lib.rs
src/librustc_save_analysis/lib.rs
src/librustc_typeck/check_unused.rs
src/librustdoc/clean/mod.rs
src/librustdoc/doctree.rs
src/librustdoc/visit_ast.rs

index c5e5fa65fc69e75fc2814ca3c97c46e33380cace..7173f670cd55486470937e84d28f8c44662dd583 100644 (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)
     }
index 0bd5b6b627fe17018ae5538b92b9f63d5f247bf3..4db12c95168306b7f3903703582a2643b9bff4c1 100644 (file)
@@ -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 {
index f0fc0d9b1c23c93a5fc08bae3f2daee6fda9530f..55ad73515c0d3a34444c784a046f978ecdb552c8 100644 (file)
@@ -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);
index dbf99cf30e56b58416bf35013139b77d27f3011b..a5c0a5e33f7053f907b8d85ad7579a4acf8e09d0 100644 (file)
@@ -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,
index d8bf5fe9b6ddfe7075c48dd4ba50450305c1fa3a..6f8981e1e6cd40c82ad4c58b1fdc748bcc341ecd 100644 (file)
@@ -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,
         }
     }
 }
index c6f69a84d034d73f0657ee829189913ea8f29239..5b52764f08d3dbec6cc0cb301171b5cb06230519 100644 (file)
@@ -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()
index d59a20c652250d12b9ee511ecc9a5ec5c599aa9e..3170f9efafb6beac636ef2fdc48c89c14a6ef72a 100644 (file)
@@ -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>,
index caf73096ebf5e88e506091eff7779fcb72732ef1..976dee3f7da2a4b9f228284eed71c32de8d15ed8 100644 (file)
@@ -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));
 
index 1f647d811b08931145801d1e2d974ca7a34ff68b..aad60c0247d2650737aecff0ebe8b84509b67fc3 100644 (file)
@@ -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))
             }
         }
index b4dc5f9c85b0b78f6bd760daf8c7fe1b1c9973f9..c5bde8af9cf54fce26f547a32eb86c68d602f582 100644 (file)
@@ -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;
             }
index 93294075272584cdc4de217562d9c797f577b3bd..196c53970f6702cd32a473e0522a50b5441aeb06 100644 (file)
@@ -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 {
index 2aecbf32ec5a1e81fc53f166cee4cb5853187fa0..05ee85e92f5735c369ff617eee4e642b96652c34 100644 (file)
@@ -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);
         }
     }
index 685c86029b668a278e4c663b3ebf2d8f5b5e4a0f..414247d22a87a60f87408f0dca97bc18bb04159d 100644 (file)
@@ -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, ..),
index ae5ca5441adf67675d3d3df6d23edc592d04f518..3a8ed0ea25facc3a2a18cf2df893441de93fa00e 100644 (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 @@ fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem) {
     fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem) {
     }
 }
-
index 65babbffffef11e93d0c83e3cf234a5602d4a222..7394b6d580c9f0d7903378ffec54c13a9f948244 100644 (file)
@@ -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"),
index 0807db2997626fadc34b8a4de1432792a06cf4e6..76c11a4e7cdd8b86bd22203b1b01c77c68a90c81 100644 (file)
@@ -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,
index 6bf1931e468dece633fd29456b204a28fe24cf35..3a13f61327e2905cd636d40c25344ebeb1b1f51e 100644 (file)
@@ -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") => {