Skip to content

Commit ffbbf24

Browse files
committed
Refactor away hir::Visibility::inherit_from
1 parent a9f34c8 commit ffbbf24

File tree

2 files changed

+7
-26
lines changed

2 files changed

+7
-26
lines changed

src/librustc/hir/mod.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,15 +1437,6 @@ pub enum Visibility {
14371437
Inherited,
14381438
}
14391439

1440-
impl Visibility {
1441-
pub fn inherit_from(&self, parent_visibility: Visibility) -> Visibility {
1442-
match self {
1443-
&Inherited => parent_visibility,
1444-
&Public => *self,
1445-
}
1446-
}
1447-
}
1448-
14491440
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
14501441
pub struct StructField {
14511442
pub span: Span,

src/librustc_typeck/collect.rs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -738,17 +738,6 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) {
738738
tcx.predicates.borrow_mut().insert(def_id, ty_predicates.clone());
739739

740740

741-
// If there is a trait reference, treat the methods as always public.
742-
// This is to work around some incorrect behavior in privacy checking:
743-
// when the method belongs to a trait, it should acquire the privacy
744-
// from the trait, not the impl. Forcing the visibility to be public
745-
// makes things sorta work.
746-
let parent_visibility = if opt_trait_ref.is_some() {
747-
hir::Public
748-
} else {
749-
it.vis
750-
};
751-
752741
// Convert all the associated consts.
753742
// Also, check if there are any duplicate associated items
754743
let mut seen_type_items = FnvHashSet();
@@ -771,9 +760,12 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) {
771760
generics: ty_generics.clone(),
772761
ty: ty,
773762
});
763+
// Trait-associated constants are always public.
764+
let visibility =
765+
if opt_trait_ref.is_some() { hir::Public } else { impl_item.vis };
774766
convert_associated_const(ccx, ImplContainer(def_id),
775767
impl_item.name, impl_item.id,
776-
impl_item.vis.inherit_from(parent_visibility),
768+
visibility,
777769
impl_item.defaultness,
778770
ty, true /* has_value */);
779771
}
@@ -797,11 +789,9 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) {
797789

798790
for impl_item in impl_items {
799791
if let hir::ImplItemKind::Method(ref sig, _) = impl_item.node {
800-
// if the method specifies a visibility, use that, otherwise
801-
// inherit the visibility from the impl (so `foo` in `pub impl
802-
// { fn foo(); }` is public, but private in `impl { fn
803-
// foo(); }`).
804-
let method_vis = impl_item.vis.inherit_from(parent_visibility);
792+
// Trait methods are always public.
793+
let method_vis =
794+
if opt_trait_ref.is_some() { hir::Public } else { impl_item.vis };
805795

806796
convert_method(ccx, ImplContainer(def_id),
807797
impl_item.name, impl_item.id, method_vis,

0 commit comments

Comments
 (0)