ty::ImplContainer(_) => {
self.check_static_method(span, method_def_id, name)
}
- // Trait methods are always all public. The only controlling factor
- // is whether the trait itself is accessible or not.
- ty::TraitContainer(trait_def_id) => {
- self.report_error(self.ensure_public(span, trait_def_id,
- None, "source trait"));
- }
+ // Trait methods are always accessible if the trait is in scope.
+ ty::TraitContainer(_) => {}
}
}
}
impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
fn visit_item(&mut self, item: &hir::Item) {
- if let hir::ItemUse(ref vpath) = item.node {
- if let hir::ViewPathList(ref prefix, ref list) = vpath.node {
- for pid in list {
- match pid.node {
- hir::PathListIdent { id, name, .. } => {
- debug!("privacy - ident item {}", id);
- self.check_path(pid.span, id, name.name);
- }
- hir::PathListMod { id, .. } => {
- debug!("privacy - mod item {}", id);
- let name = prefix.segments.last().unwrap().identifier.name;
- self.check_path(pid.span, id, name);
- }
- }
- }
- }
- }
let orig_curitem = replace(&mut self.curitem, item.id);
visit::walk_item(self, item);
self.curitem = orig_curitem;
}
fn visit_path(&mut self, path: &hir::Path, id: ast::NodeId) {
- self.check_path(path.span, id, path.segments.last().unwrap().identifier.name);
- visit::walk_path(self, path);
+ if !path.segments.is_empty() {
+ self.check_path(path.span, id, path.segments.last().unwrap().identifier.name);
+ visit::walk_path(self, path);
+ }
+ }
+
+ fn visit_path_list_item(&mut self, prefix: &hir::Path, item: &hir::PathListItem) {
+ let name = if let hir::PathListIdent { name, .. } = item.node {
+ name.name
+ } else if !prefix.segments.is_empty() {
+ prefix.segments.last().unwrap().identifier.name
+ } else {
+ self.tcx.sess.bug("`self` import in an import list with empty prefix");
+ };
+ self.check_path(item.span, item.node.id(), name);
+ visit::walk_path_list_item(self, prefix, item);
}
}
instead");
}
- hir::ItemEnum(ref def, _) => {
- for v in &def.variants {
- match v.node.vis {
- hir::Public => {
- if item.vis == hir::Public {
- span_err!(tcx.sess, v.span, E0448,
- "unnecessary `pub` visibility");
- }
- }
- hir::Inherited => {}
- }
- }
- }
-
+ hir::ItemEnum(..) |
hir::ItemTrait(..) | hir::ItemDefaultImpl(..) |
hir::ItemConst(..) | hir::ItemStatic(..) | hir::ItemStruct(..) |
hir::ItemFn(..) | hir::ItemMod(..) | hir::ItemTy(..) |
check_inherited(tcx, i.span, i.vis);
}
}
- hir::ItemEnum(ref def, _) => {
- for v in &def.variants {
- check_inherited(tcx, v.span, v.node.vis);
- }
- }
hir::ItemStruct(ref def, _) => check_struct(&**def),
+ hir::ItemEnum(..) |
hir::ItemExternCrate(_) | hir::ItemUse(_) |
hir::ItemTrait(..) | hir::ItemDefaultImpl(..) |
hir::ItemStatic(..) | hir::ItemConst(..) |