提交 09a2b4e5 编写于 作者: P Patrick Walton

librustc: Make methods private if the impl is private

上级 107bf96f
......@@ -92,17 +92,6 @@ pub struct DVec<A> {
}
}
#[inline(always)]
fn check_out<B>(f: &fn(v: ~[A]) -> B) -> B {
unsafe {
let mut data = cast::reinterpret_cast(&null::<()>());
data <-> self.data;
let data_ptr: *() = cast::reinterpret_cast(&data);
if data_ptr.is_null() { fail!(~"Recursive use of dvec"); }
return f(data);
}
}
#[inline(always)]
fn give_back(data: ~[A]) {
unsafe {
......@@ -118,6 +107,18 @@ fn unwrap(self) -> ~[A] { unwrap(self) }
// almost nothing works without the copy bound due to limitations
// around closures.
pub impl<A> DVec<A> {
// FIXME (#3758): This should not need to be public.
#[inline(always)]
fn check_out<B>(f: &fn(v: ~[A]) -> B) -> B {
unsafe {
let mut data = cast::reinterpret_cast(&null::<()>());
data <-> self.data;
let data_ptr: *() = cast::reinterpret_cast(&data);
if data_ptr.is_null() { fail!(~"Recursive use of dvec"); }
return f(data);
}
}
/// Reserves space for N elements
fn reserve(count: uint) {
vec::reserve(&mut self.data, count)
......
......@@ -25,7 +25,7 @@
use syntax::ast::{def_variant, expr_field, expr_method_call, expr_struct};
use syntax::ast::{expr_unary, ident, item_struct, item_enum, item_impl};
use syntax::ast::{item_trait, local_crate, node_id, pat_struct, private};
use syntax::ast::{provided, required};
use syntax::ast::{provided, public, required};
use syntax::ast;
use syntax::ast_map::{node_item, node_method};
use syntax::ast_map;
......@@ -107,7 +107,41 @@ pub fn check_crate(tcx: ty::ctxt,
if method_id.crate == local_crate {
match tcx.items.find(&method_id.node) {
Some(node_method(method, impl_id, _)) => {
if method.vis == private &&
let mut is_private = false;
if method.vis == private {
is_private = true;
} else {
// Look up the enclosing impl.
if impl_id.crate != local_crate {
tcx.sess.span_bug(span,
~"local method isn't \
in local impl?!");
}
match tcx.items.find(&impl_id.node) {
Some(node_item(item, _)) => {
match item.node {
item_impl(_, None, _, _)
if item.vis != public => {
is_private = true;
}
_ => {}
}
}
Some(_) => {
tcx.sess.span_bug(span,
~"impl wasn't an \
item?!");
}
None => {
tcx.sess.span_bug(span,
~"impl wasn't in \
AST map?!");
}
}
}
if is_private &&
(impl_id.crate != local_crate ||
!privileged_items
.contains(&(impl_id.node))) {
......
// Tests that inherited visibility applies to methods.
mod a {
pub struct Foo;
impl Foo {
fn f(self) {}
}
}
fn main() {
let x = a::Foo;
x.f(); //~ ERROR method `f` is private
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册