Skip to content

Commit 4531184

Browse files
committed
auto merge of #9432 : alexcrichton/rust/correct-item-visibility, r=pcwalton
This fixes private statics and functions from being usable cross-crates, along with some bad privacy error messages. This is a reopening of #8365 with all the privacy checks in privacy.rs instead of resolve.rs (where they should be anyway). These maps of exported items will hopefully get used for generating documentation by rustdoc Closes #8592
2 parents dad32f7 + 30862a6 commit 4531184

File tree

164 files changed

+639
-304
lines changed

Some content is hidden

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

164 files changed

+639
-304
lines changed

Diff for: src/etc/combine-tests.py

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ def scrub(b):
2929
if not ("xfail-test" in s or
3030
"xfail-fast" in s or
3131
"xfail-win32" in s):
32+
if not "pub fn main" in s and "fn main" in s:
33+
print("Warning: no public entry point in " + t)
3234
stage2_tests.append(t)
3335
f.close()
3436

Diff for: src/libextra/arc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ struct MutexArcInner<T> { priv lock: Mutex, priv failed: bool, priv data: T }
162162

163163
/// An Arc with mutable data protected by a blocking mutex.
164164
#[no_freeze]
165-
struct MutexArc<T> { priv x: UnsafeArc<MutexArcInner<T>> }
165+
pub struct MutexArc<T> { priv x: UnsafeArc<MutexArcInner<T>> }
166166

167167

168168
impl<T:Send> Clone for MutexArc<T> {
@@ -343,7 +343,7 @@ struct RWArcInner<T> { priv lock: RWLock, priv failed: bool, priv data: T }
343343
* Unlike mutex_arcs, rw_arcs are safe, because they cannot be nested.
344344
*/
345345
#[no_freeze]
346-
struct RWArc<T> {
346+
pub struct RWArc<T> {
347347
priv x: UnsafeArc<RWArcInner<T>>,
348348
}
349349

Diff for: src/libextra/workcache.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl WorkMap {
127127
}
128128
}
129129

130-
struct Database {
130+
pub struct Database {
131131
db_filename: Path,
132132
db_cache: TreeMap<~str, ~str>,
133133
db_dirty: bool
@@ -207,7 +207,7 @@ impl Drop for Database {
207207
}
208208
}
209209

210-
struct Logger {
210+
pub struct Logger {
211211
// FIXME #4432: Fill in
212212
a: ()
213213
}
@@ -223,10 +223,10 @@ impl Logger {
223223
}
224224
}
225225
226-
type FreshnessMap = TreeMap<~str,extern fn(&str,&str)->bool>;
226+
pub type FreshnessMap = TreeMap<~str,extern fn(&str,&str)->bool>;
227227
228228
#[deriving(Clone)]
229-
struct Context {
229+
pub struct Context {
230230
db: RWArc<Database>,
231231
logger: RWArc<Logger>,
232232
cfg: Arc<json::Object>,
@@ -239,13 +239,13 @@ struct Context {
239239
freshness: Arc<FreshnessMap>
240240
}
241241
242-
struct Prep<'self> {
242+
pub struct Prep<'self> {
243243
ctxt: &'self Context,
244244
fn_name: &'self str,
245245
declared_inputs: WorkMap,
246246
}
247247
248-
struct Exec {
248+
pub struct Exec {
249249
discovered_inputs: WorkMap,
250250
discovered_outputs: WorkMap
251251
}

Diff for: src/librustc/driver/driver.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ pub fn phase_2_configure_and_expand(sess: Session,
197197

198198
pub struct CrateAnalysis {
199199
exp_map2: middle::resolve::ExportMap2,
200+
exported_items: @middle::privacy::ExportedItems,
200201
ty_cx: ty::ctxt,
201202
maps: astencode::Maps,
202203
reachable: @mut HashSet<ast::NodeId>
@@ -258,8 +259,9 @@ pub fn phase_3_run_analysis_passes(sess: Session,
258259
middle::check_const::check_crate(sess, crate, ast_map, def_map,
259260
method_map, ty_cx));
260261

261-
time(time_passes, ~"privacy checking", ||
262-
middle::privacy::check_crate(ty_cx, &method_map, crate));
262+
let exported_items =
263+
time(time_passes, ~"privacy checking", ||
264+
middle::privacy::check_crate(ty_cx, &method_map, &exp_map2, crate));
263265

264266
time(time_passes, ~"effect checking", ||
265267
middle::effect::check_crate(ty_cx, method_map, crate));
@@ -301,6 +303,7 @@ pub fn phase_3_run_analysis_passes(sess: Session,
301303

302304
CrateAnalysis {
303305
exp_map2: exp_map2,
306+
exported_items: @exported_items,
304307
ty_cx: ty_cx,
305308
maps: astencode::Maps {
306309
root_map: root_map,

Diff for: src/librustc/metadata/csearch.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ use syntax::diagnostic::expect;
2727
pub struct StaticMethodInfo {
2828
ident: ast::Ident,
2929
def_id: ast::DefId,
30-
purity: ast::purity
30+
purity: ast::purity,
31+
vis: ast::visibility,
3132
}
3233

3334
pub fn get_symbol(cstore: @mut cstore::CStore, def: ast::DefId) -> ~str {
@@ -52,7 +53,8 @@ pub fn each_lang_item(cstore: @mut cstore::CStore,
5253
/// Iterates over each child of the given item.
5354
pub fn each_child_of_item(cstore: @mut cstore::CStore,
5455
def_id: ast::DefId,
55-
callback: &fn(decoder::DefLike, ast::Ident)) {
56+
callback: &fn(decoder::DefLike, ast::Ident,
57+
ast::visibility)) {
5658
let crate_data = cstore::get_crate_data(cstore, def_id.crate);
5759
let get_crate_data: decoder::GetCrateDataCb = |cnum| {
5860
cstore::get_crate_data(cstore, cnum)
@@ -68,7 +70,8 @@ pub fn each_child_of_item(cstore: @mut cstore::CStore,
6870
pub fn each_top_level_item_of_crate(cstore: @mut cstore::CStore,
6971
cnum: ast::CrateNum,
7072
callback: &fn(decoder::DefLike,
71-
ast::Ident)) {
73+
ast::Ident,
74+
ast::visibility)) {
7275
let crate_data = cstore::get_crate_data(cstore, cnum);
7376
let get_crate_data: decoder::GetCrateDataCb = |cnum| {
7477
cstore::get_crate_data(cstore, cnum)

Diff for: src/librustc/metadata/decoder.rs

+26-17
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ fn find_item(item_id: int, items: ebml::Doc) -> ebml::Doc {
9696

9797
// Looks up an item in the given metadata and returns an ebml doc pointing
9898
// to the item data.
99-
fn lookup_item(item_id: int, data: @~[u8]) -> ebml::Doc {
99+
pub fn lookup_item(item_id: int, data: @~[u8]) -> ebml::Doc {
100100
let items = reader::get_doc(reader::Doc(data), tag_items);
101101
find_item(item_id, items)
102102
}
@@ -291,7 +291,7 @@ fn enum_variant_ids(item: ebml::Doc, cdata: Cmd) -> ~[ast::DefId] {
291291
return ids;
292292
}
293293

294-
fn item_path(item_doc: ebml::Doc) -> ast_map::path {
294+
pub fn item_path(item_doc: ebml::Doc) -> ast_map::path {
295295
let path_doc = reader::get_doc(item_doc, tag_path);
296296

297297
let len_doc = reader::get_doc(path_doc, tag_path_len);
@@ -332,7 +332,7 @@ fn item_name(intr: @ident_interner, item: ebml::Doc) -> ast::Ident {
332332
}
333333
}
334334

335-
fn item_to_def_like(item: ebml::Doc, did: ast::DefId, cnum: ast::CrateNum)
335+
pub fn item_to_def_like(item: ebml::Doc, did: ast::DefId, cnum: ast::CrateNum)
336336
-> DefLike {
337337
let fam = item_family(item);
338338
match fam {
@@ -491,7 +491,7 @@ pub enum DefLike {
491491
DlField
492492
}
493493

494-
fn def_like_to_def(def_like: DefLike) -> ast::Def {
494+
pub fn def_like_to_def(def_like: DefLike) -> ast::Def {
495495
match def_like {
496496
DlDef(def) => return def,
497497
DlImpl(*) => fail!("found impl in def_like_to_def"),
@@ -544,7 +544,8 @@ impl<'self> EachItemContext<'self> {
544544
fn process_item_and_pop_name(&mut self,
545545
doc: ebml::Doc,
546546
def_id: ast::DefId,
547-
old_len: uint)
547+
old_len: uint,
548+
vis: ast::visibility)
548549
-> bool {
549550
let def_like = item_to_def_like(doc, def_id, self.cdata.cnum);
550551
match def_like {
@@ -563,8 +564,6 @@ impl<'self> EachItemContext<'self> {
563564
}
564565
}
565566

566-
let vis = item_visibility(doc);
567-
568567
let mut continue = (self.callback)(*self.path_builder, def_like, vis);
569568

570569
let family = item_family(doc);
@@ -653,9 +652,12 @@ impl<'self> EachItemContext<'self> {
653652
self.push_name(token::ident_to_str(&child_name));
654653

655654
// Process this item.
655+
656+
let vis = item_visibility(child_item_doc);
656657
continue = self.process_item_and_pop_name(child_item_doc,
657658
child_def_id,
658-
old_len);
659+
old_len,
660+
vis);
659661
}
660662
}
661663
continue
@@ -701,12 +703,13 @@ impl<'self> EachItemContext<'self> {
701703

702704
// Get the item.
703705
match maybe_find_item(def_id.node, other_crates_items) {
704-
None => {}
706+
None => { self.pop_name(old_len); }
705707
Some(reexported_item_doc) => {
706708
continue = self.process_item_and_pop_name(
707709
reexported_item_doc,
708710
def_id,
709-
old_len);
711+
old_len,
712+
ast::public);
710713
}
711714
}
712715

@@ -721,7 +724,8 @@ fn each_child_of_item_or_crate(intr: @ident_interner,
721724
cdata: Cmd,
722725
item_doc: ebml::Doc,
723726
get_crate_data: GetCrateDataCb,
724-
callback: &fn(DefLike, ast::Ident)) {
727+
callback: &fn(DefLike, ast::Ident,
728+
ast::visibility)) {
725729
// Iterate over all children.
726730
let _ = do reader::tagged_docs(item_doc, tag_mod_child) |child_info_doc| {
727731
let child_def_id = reader::with_doc_data(child_info_doc,
@@ -746,7 +750,8 @@ fn each_child_of_item_or_crate(intr: @ident_interner,
746750
let def_like = item_to_def_like(child_item_doc,
747751
child_def_id,
748752
cdata.cnum);
749-
callback(def_like, child_name);
753+
let visibility = item_visibility(child_item_doc);
754+
callback(def_like, child_name, visibility);
750755

751756
}
752757
}
@@ -788,7 +793,8 @@ fn each_child_of_item_or_crate(intr: @ident_interner,
788793
impl_method_def_id,
789794
cdata.cnum);
790795
callback(static_method_def_like,
791-
static_method_name);
796+
static_method_name,
797+
item_visibility(impl_method_doc));
792798
}
793799
_ => {}
794800
}
@@ -831,7 +837,8 @@ fn each_child_of_item_or_crate(intr: @ident_interner,
831837
let def_like = item_to_def_like(child_item_doc,
832838
child_def_id,
833839
cdata.cnum);
834-
callback(def_like, token::str_to_ident(name));
840+
callback(def_like, token::str_to_ident(name),
841+
item_visibility(child_item_doc));
835842
}
836843
}
837844

@@ -844,7 +851,7 @@ pub fn each_child_of_item(intr: @ident_interner,
844851
cdata: Cmd,
845852
id: ast::NodeId,
846853
get_crate_data: GetCrateDataCb,
847-
callback: &fn(DefLike, ast::Ident)) {
854+
callback: &fn(DefLike, ast::Ident, ast::visibility)) {
848855
// Find the item.
849856
let root_doc = reader::Doc(cdata.data);
850857
let items = reader::get_doc(root_doc, tag_items);
@@ -864,7 +871,8 @@ pub fn each_child_of_item(intr: @ident_interner,
864871
pub fn each_top_level_item_of_crate(intr: @ident_interner,
865872
cdata: Cmd,
866873
get_crate_data: GetCrateDataCb,
867-
callback: &fn(DefLike, ast::Ident)) {
874+
callback: &fn(DefLike, ast::Ident,
875+
ast::visibility)) {
868876
let root_doc = reader::Doc(cdata.data);
869877
let misc_info_doc = reader::get_doc(root_doc, tag_misc_info);
870878
let crate_items_doc = reader::get_doc(misc_info_doc,
@@ -1161,7 +1169,8 @@ pub fn get_static_methods_if_impl(intr: @ident_interner,
11611169
static_impl_methods.push(StaticMethodInfo {
11621170
ident: item_name(intr, impl_method_doc),
11631171
def_id: item_def_id(impl_method_doc, cdata),
1164-
purity: purity
1172+
purity: purity,
1173+
vis: item_visibility(impl_method_doc),
11651174
});
11661175
}
11671176
_ => {}

0 commit comments

Comments
 (0)