Skip to content

Commit e1d3a4f

Browse files
committed
auto merge of #5156 : pcwalton/rust/method-privacy, r=pcwalton
r? @brson
2 parents b171d0e + 2859c1a commit e1d3a4f

File tree

123 files changed

+349
-214
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+349
-214
lines changed

doc/tutorial.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -2304,11 +2304,10 @@ mod farm {
23042304
farmer: Human
23052305
}
23062306
2307-
// Note - visibility modifiers on impls currently have no effect
23082307
impl Farm {
23092308
priv fn feed_chickens(&self) { ... }
23102309
priv fn feed_cows(&self) { ... }
2311-
fn add_chicken(&self, c: Chicken) { ... }
2310+
pub fn add_chicken(&self, c: Chicken) { ... }
23122311
}
23132312
23142313
pub fn feed_animals(farm: &Farm) {

src/libcore/cell.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub pure fn empty_cell<T>() -> Cell<T> {
2828
Cell { value: None }
2929
}
3030

31-
impl<T> Cell<T> {
31+
pub impl<T> Cell<T> {
3232
/// Yields the value, failing if the cell is empty.
3333
fn take() -> T {
3434
if self.is_empty() {

src/libcore/comm.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ pub fn PortSet<T: Owned>() -> PortSet<T>{
190190
}
191191
}
192192
193-
impl<T: Owned> PortSet<T> {
193+
pub impl<T: Owned> PortSet<T> {
194194
195195
fn add(port: Port<T>) {
196196
self.ports.push(port)
@@ -323,12 +323,12 @@ pub fn oneshot<T: Owned>() -> (PortOne<T>, ChanOne<T>) {
323323
(port, chan)
324324
}
325325
326-
impl<T: Owned> PortOne<T> {
326+
pub impl<T: Owned> PortOne<T> {
327327
fn recv(self) -> T { recv_one(self) }
328328
fn try_recv(self) -> Option<T> { try_recv_one(self) }
329329
}
330330
331-
impl<T: Owned> ChanOne<T> {
331+
pub impl<T: Owned> ChanOne<T> {
332332
fn send(self, data: T) { send_one(self, data) }
333333
fn try_send(self, data: T) -> bool { try_send_one(self, data) }
334334
}

src/libcore/condition.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub struct Condition<T, U> {
2525
key: task::local_data::LocalDataKey<Handler<T, U>>
2626
}
2727

28-
impl<T, U> Condition<T, U> {
28+
pub impl<T, U> Condition<T, U> {
2929
fn trap(&self, h: &self/fn(T) -> U) -> Trap/&self<T, U> {
3030
unsafe {
3131
let p : *RustClosure = ::cast::transmute(&h);
@@ -69,7 +69,7 @@ struct Trap<T, U> {
6969
handler: @Handler<T, U>
7070
}
7171

72-
impl<T, U> Trap<T, U> {
72+
pub impl<T, U> Trap<T, U> {
7373
fn in<V>(&self, inner: &self/fn() -> V) -> V {
7474
unsafe {
7575
let _g = Guard { cond: self.cond };

src/libcore/dlist.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ priv impl<T> DListNode<T> {
6262
}
6363
}
6464
65-
impl<T> DListNode<T> {
65+
pub impl<T> DListNode<T> {
6666
/// Get the next node in the list, if there is one.
6767
pure fn next_link(@mut self) -> DListLink<T> {
6868
self.assert_links();
@@ -208,7 +208,7 @@ priv impl<T> DList<T> {
208208
}
209209
}
210210
211-
impl<T> DList<T> {
211+
pub impl<T> DList<T> {
212212
/// Get the size of the list. O(1).
213213
pure fn len(@mut self) -> uint { self.size }
214214
/// Returns true if the list is empty. O(1).
@@ -457,7 +457,7 @@ impl<T> DList<T> {
457457
}
458458
}
459459

460-
impl<T:Copy> DList<T> {
460+
pub impl<T:Copy> DList<T> {
461461
/// Remove data from the head of the list. O(1).
462462
fn pop(@mut self) -> Option<T> {
463463
self.pop_n().map(|nobe| nobe.data)

src/libcore/dvec.rs

+14-13
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,6 @@ priv impl<A> DVec<A> {
9292
}
9393
}
9494
95-
#[inline(always)]
96-
fn check_out<B>(f: &fn(v: ~[A]) -> B) -> B {
97-
unsafe {
98-
let mut data = cast::reinterpret_cast(&null::<()>());
99-
data <-> self.data;
100-
let data_ptr: *() = cast::reinterpret_cast(&data);
101-
if data_ptr.is_null() { fail!(~"Recursive use of dvec"); }
102-
return f(data);
103-
}
104-
}
105-
10695
#[inline(always)]
10796
fn give_back(data: ~[A]) {
10897
unsafe {
@@ -117,7 +106,19 @@ priv impl<A> DVec<A> {
117106
// In theory, most everything should work with any A, but in practice
118107
// almost nothing works without the copy bound due to limitations
119108
// around closures.
120-
impl<A> DVec<A> {
109+
pub impl<A> DVec<A> {
110+
// FIXME (#3758): This should not need to be public.
111+
#[inline(always)]
112+
fn check_out<B>(f: &fn(v: ~[A]) -> B) -> B {
113+
unsafe {
114+
let mut data = cast::reinterpret_cast(&null::<()>());
115+
data <-> self.data;
116+
let data_ptr: *() = cast::reinterpret_cast(&data);
117+
if data_ptr.is_null() { fail!(~"Recursive use of dvec"); }
118+
return f(data);
119+
}
120+
}
121+
121122
/// Reserves space for N elements
122123
fn reserve(count: uint) {
123124
vec::reserve(&mut self.data, count)
@@ -215,7 +216,7 @@ impl<A> DVec<A> {
215216
}
216217
}
217218
218-
impl<A:Copy> DVec<A> {
219+
pub impl<A:Copy> DVec<A> {
219220
/**
220221
* Append all elements of a vector to the end of the list
221222
*

src/libcore/mutable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub fn unwrap<T>(m: Mut<T>) -> T {
4343
value
4444
}
4545

46-
impl<T> Data<T> {
46+
pub impl<T> Data<T> {
4747
fn borrow_mut<R>(op: &fn(t: &mut T) -> R) -> R {
4848
match self.mode {
4949
Immutable => fail!(fmt!("%? currently immutable",

src/libcore/option.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ pub pure fn expect<T>(opt: Option<T>, reason: &str) -> T {
281281
}
282282
}
283283
284-
impl<T> Option<T> {
284+
pub impl<T> Option<T> {
285285
/// Returns true if the option equals `none`
286286
#[inline(always)]
287287
pure fn is_none(&self) -> bool { is_none(self) }
@@ -393,7 +393,7 @@ impl<T> Option<T> {
393393
pure fn expect(self, reason: &str) -> T { expect(self, reason) }
394394
}
395395
396-
impl<T:Copy> Option<T> {
396+
pub impl<T:Copy> Option<T> {
397397
/**
398398
Gets the value out of an option
399399
@@ -421,7 +421,7 @@ impl<T:Copy> Option<T> {
421421
}
422422
}
423423
424-
impl<T:Copy + Zero> Option<T> {
424+
pub impl<T:Copy + Zero> Option<T> {
425425
#[inline(always)]
426426
pure fn get_or_zero(self) -> T { get_or_zero(self) }
427427
}

src/libcore/path.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ mod stat {
241241
}
242242

243243

244-
impl Path {
244+
pub impl Path {
245245
fn stat(&self) -> Option<libc::stat> {
246246
unsafe {
247247
do str::as_c_str(self.to_str()) |buf| {
@@ -290,7 +290,7 @@ impl Path {
290290
#[cfg(target_os = "freebsd")]
291291
#[cfg(target_os = "linux")]
292292
#[cfg(target_os = "macos")]
293-
impl Path {
293+
pub impl Path {
294294
fn get_atime(&self) -> Option<(i64, int)> {
295295
match self.stat() {
296296
None => None,
@@ -324,7 +324,7 @@ impl Path {
324324

325325
#[cfg(target_os = "freebsd")]
326326
#[cfg(target_os = "macos")]
327-
impl Path {
327+
pub impl Path {
328328
fn get_birthtime(&self) -> Option<(i64, int)> {
329329
match self.stat() {
330330
None => None,
@@ -337,7 +337,7 @@ impl Path {
337337
}
338338

339339
#[cfg(target_os = "win32")]
340-
impl Path {
340+
pub impl Path {
341341
fn get_atime(&self) -> Option<(i64, int)> {
342342
match self.stat() {
343343
None => None,

src/libcore/pipes.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ pub fn SendPacketBuffered<T,Tbuffer>(p: *Packet<T>)
800800
}
801801
}
802802
803-
impl<T,Tbuffer> SendPacketBuffered<T,Tbuffer> {
803+
pub impl<T,Tbuffer> SendPacketBuffered<T,Tbuffer> {
804804
fn unwrap() -> *Packet<T> {
805805
let mut p = None;
806806
p <-> self.p;
@@ -857,7 +857,7 @@ impl<T:Owned,Tbuffer:Owned> ::ops::Drop for RecvPacketBuffered<T,Tbuffer> {
857857
}
858858
}
859859
860-
impl<T:Owned,Tbuffer:Owned> RecvPacketBuffered<T, Tbuffer> {
860+
pub impl<T:Owned,Tbuffer:Owned> RecvPacketBuffered<T, Tbuffer> {
861861
fn unwrap() -> *Packet<T> {
862862
let mut p = None;
863863
p <-> self.p;

src/libcore/private.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ fn LittleLock() -> LittleLock {
335335
}
336336
}
337337
338-
impl LittleLock {
338+
pub impl LittleLock {
339339
#[inline(always)]
340340
unsafe fn lock<T>(f: fn() -> T) -> T {
341341
struct Unlock {
@@ -381,7 +381,7 @@ impl<T:Owned> Clone for Exclusive<T> {
381381
}
382382
}
383383
384-
impl<T:Owned> Exclusive<T> {
384+
pub impl<T:Owned> Exclusive<T> {
385385
// Exactly like std::arc::mutex_arc,access(), but with the little_lock
386386
// instead of a proper mutex. Same reason for being unsafe.
387387
//

src/libcore/private/extfmt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ pub mod ct {
142142
next: uint
143143
}
144144

145-
impl<T> Parsed<T> {
145+
pub impl<T> Parsed<T> {
146146
static pure fn new(val: T, next: uint) -> Parsed<T> {
147147
Parsed {val: val, next: next}
148148
}

src/libcore/rand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ pub struct Weighted<T> {
141141
}
142142

143143
/// Extension methods for random number generators
144-
impl Rng {
144+
pub impl Rng {
145145
/// Return a random value for a Rand type
146146
fn gen<T:Rand>() -> T {
147147
Rand::rand(self)

src/libcore/reflect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub fn MovePtrAdaptor<V:TyVisitor + MovePtr>(v: V) -> MovePtrAdaptor<V> {
4545
MovePtrAdaptor { inner: v }
4646
}
4747

48-
impl<V:TyVisitor + MovePtr> MovePtrAdaptor<V> {
48+
pub impl<V:TyVisitor + MovePtr> MovePtrAdaptor<V> {
4949
#[inline(always)]
5050
fn bump(sz: uint) {
5151
do self.inner.move_ptr() |p| {

src/libcore/repr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl MovePtr for ReprVisitor {
167167
}
168168
}
169169

170-
impl ReprVisitor {
170+
pub impl ReprVisitor {
171171

172172
// Various helpers for the TyVisitor impl
173173

src/libcore/result.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ pub pure fn map_err<T:Copy,E,F:Copy>(res: &Result<T, E>, op: fn(&E) -> F)
228228
}
229229
}
230230
231-
impl<T, E> Result<T, E> {
231+
pub impl<T, E> Result<T, E> {
232232
#[inline(always)]
233233
pure fn get_ref(&self) -> &self/T { get_ref(self) }
234234
@@ -261,7 +261,7 @@ impl<T, E> Result<T, E> {
261261
}
262262
}
263263
264-
impl<T:Copy,E> Result<T, E> {
264+
pub impl<T:Copy,E> Result<T, E> {
265265
#[inline(always)]
266266
pure fn get(&self) -> T { get(self) }
267267
@@ -271,7 +271,7 @@ impl<T:Copy,E> Result<T, E> {
271271
}
272272
}
273273
274-
impl<T, E: Copy> Result<T, E> {
274+
pub impl<T, E: Copy> Result<T, E> {
275275
#[inline(always)]
276276
pure fn get_err(&self) -> E { get_err(self) }
277277

src/libcore/task/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ priv impl TaskBuilder {
232232
}
233233
}
234234
235-
impl TaskBuilder {
235+
pub impl TaskBuilder {
236236
/**
237237
* Decouple the child task's failure from the parent's. If either fails,
238238
* the other will not be killed.

src/librustc/metadata/common.rs

+1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ pub const tag_lang_items_item_node_id: uint = 0x75;
155155

156156
pub const tag_item_unnamed_field: uint = 0x76;
157157
pub const tag_items_data_item_struct_ctor: uint = 0x77;
158+
pub const tag_items_data_item_visibility: uint = 0x78;
158159

159160
pub struct LinkMeta {
160161
name: @str,

src/librustc/metadata/csearch.rs

+8
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,14 @@ pub fn struct_dtor(cstore: @mut cstore::CStore, def: ast::def_id)
234234
let cdata = cstore::get_crate_data(cstore, def.crate);
235235
decoder::struct_dtor(cdata, def.node)
236236
}
237+
238+
pub fn get_method_visibility(cstore: @mut cstore::CStore,
239+
def_id: ast::def_id)
240+
-> ast::visibility {
241+
let cdata = cstore::get_crate_data(cstore, def_id.crate);
242+
decoder::get_method_visibility(cdata, def_id.node)
243+
}
244+
237245
// Local Variables:
238246
// mode: rust
239247
// fill-column: 78;

src/librustc/metadata/decoder.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,16 @@ fn item_family(item: ebml::Doc) -> Family {
151151
}
152152
}
153153

154+
fn item_visibility(item: ebml::Doc) -> ast::visibility {
155+
let visibility = reader::get_doc(item, tag_items_data_item_visibility);
156+
match reader::doc_as_u8(visibility) as char {
157+
'y' => ast::public,
158+
'n' => ast::private,
159+
'i' => ast::inherited,
160+
_ => fail!(~"unknown visibility character"),
161+
}
162+
}
163+
154164
fn item_method_sort(item: ebml::Doc) -> char {
155165
for reader::tagged_docs(item, tag_item_trait_method_sort) |doc| {
156166
return str::from_bytes(reader::doc_data(doc))[0] as char;
@@ -860,7 +870,7 @@ pub fn get_item_attrs(cdata: cmd,
860870
}
861871
}
862872

863-
pure fn family_to_visibility(family: Family) -> ast::visibility {
873+
pure fn struct_field_family_to_visibility(family: Family) -> ast::visibility {
864874
match family {
865875
PublicField => ast::public,
866876
PrivateField => ast::private,
@@ -883,7 +893,7 @@ pub fn get_struct_fields(intr: @ident_interner, cdata: cmd, id: ast::node_id)
883893
result.push(ty::field_ty {
884894
ident: name,
885895
id: did, vis:
886-
family_to_visibility(f),
896+
struct_field_family_to_visibility(f),
887897
mutability: mt,
888898
});
889899
}
@@ -900,6 +910,11 @@ pub fn get_struct_fields(intr: @ident_interner, cdata: cmd, id: ast::node_id)
900910
result
901911
}
902912

913+
pub fn get_method_visibility(cdata: cmd, id: ast::node_id)
914+
-> ast::visibility {
915+
item_visibility(lookup_item(id, cdata.data))
916+
}
917+
903918
fn family_has_type_params(fam: Family) -> bool {
904919
match fam {
905920
Const | ForeignType | Mod | ForeignMod | PublicField | PrivateField

0 commit comments

Comments
 (0)