From ffbbf241868588c5ca3880ed023e97aa806ea1d3 Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Sat, 26 Mar 2016 00:35:59 +0000 Subject: [PATCH] Refactor away `hir::Visibility::inherit_from` --- src/librustc/hir/mod.rs | 9 --------- src/librustc_typeck/collect.rs | 24 +++++++----------------- 2 files changed, 7 insertions(+), 26 deletions(-) diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index edb9b783527..2bf279601c8 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -1437,15 +1437,6 @@ pub enum Visibility { Inherited, } -impl Visibility { - pub fn inherit_from(&self, parent_visibility: Visibility) -> Visibility { - match self { - &Inherited => parent_visibility, - &Public => *self, - } - } -} - #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct StructField { pub span: Span, diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 9d76b4c5284..a27f507170b 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -738,17 +738,6 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) { tcx.predicates.borrow_mut().insert(def_id, ty_predicates.clone()); - // If there is a trait reference, treat the methods as always public. - // This is to work around some incorrect behavior in privacy checking: - // when the method belongs to a trait, it should acquire the privacy - // from the trait, not the impl. Forcing the visibility to be public - // makes things sorta work. - let parent_visibility = if opt_trait_ref.is_some() { - hir::Public - } else { - it.vis - }; - // Convert all the associated consts. // Also, check if there are any duplicate associated items let mut seen_type_items = FnvHashSet(); @@ -771,9 +760,12 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) { generics: ty_generics.clone(), ty: ty, }); + // Trait-associated constants are always public. + let visibility = + if opt_trait_ref.is_some() { hir::Public } else { impl_item.vis }; convert_associated_const(ccx, ImplContainer(def_id), impl_item.name, impl_item.id, - impl_item.vis.inherit_from(parent_visibility), + visibility, impl_item.defaultness, ty, true /* has_value */); } @@ -797,11 +789,9 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) { for impl_item in impl_items { if let hir::ImplItemKind::Method(ref sig, _) = impl_item.node { - // if the method specifies a visibility, use that, otherwise - // inherit the visibility from the impl (so `foo` in `pub impl - // { fn foo(); }` is public, but private in `impl { fn - // foo(); }`). - let method_vis = impl_item.vis.inherit_from(parent_visibility); + // Trait methods are always public. + let method_vis = + if opt_trait_ref.is_some() { hir::Public } else { impl_item.vis }; convert_method(ccx, ImplContainer(def_id), impl_item.name, impl_item.id, method_vis,