Skip to content

Commit ca253ad

Browse files
committed
---
yaml --- r: 65214 b: refs/heads/master c: 565942b h: refs/heads/master v: v3
1 parent 4f24716 commit ca253ad

File tree

8 files changed

+82
-35
lines changed

8 files changed

+82
-35
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 211d038abc05c77785f72a31840016517cf218c2
2+
refs/heads/master: 565942b145efbf6c1d1f66db46423d721b55d32c
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 18e3db7392d2d0697b7e27d6d986139960144d85
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9

trunk/src/librustc/metadata/csearch.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,22 @@ pub fn each_lang_item(cstore: @mut cstore::CStore,
5252
}
5353

5454
/// Iterates over all the paths in the given crate.
55+
#[cfg(stage0)]
5556
pub fn each_path(cstore: @mut cstore::CStore,
5657
cnum: ast::crate_num,
57-
f: &fn(&str, decoder::def_like) -> bool) -> bool {
58+
f: &fn(&str, decoder::def_like, ast::visibility) -> bool) {
59+
let crate_data = cstore::get_crate_data(cstore, cnum);
60+
let get_crate_data: decoder::GetCrateDataCb = |cnum| {
61+
cstore::get_crate_data(cstore, cnum)
62+
};
63+
decoder::each_path(cstore.intr, crate_data, get_crate_data, f)
64+
}
65+
/// Iterates over all the paths in the given crate.
66+
#[cfg(not(stage0))]
67+
pub fn each_path(cstore: @mut cstore::CStore,
68+
cnum: ast::crate_num,
69+
f: &fn(&str, decoder::def_like, ast::visibility) -> bool)
70+
-> bool {
5871
let crate_data = cstore::get_crate_data(cstore, cnum);
5972
let get_crate_data: decoder::GetCrateDataCb = |cnum| {
6073
cstore::get_crate_data(cstore, cnum)

trunk/src/librustc/metadata/decoder.rs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,7 @@ fn item_name(intr: @ident_interner, item: ebml::Doc) -> ast::ident {
319319
}
320320

321321
fn item_to_def_like(item: ebml::Doc, did: ast::def_id, cnum: ast::crate_num)
322-
-> def_like
323-
{
322+
-> def_like {
324323
let fam = item_family(item);
325324
match fam {
326325
Const => dl_def(ast::def_const(did)),
@@ -474,9 +473,11 @@ pub fn each_lang_item(cdata: cmd, f: &fn(ast::node_id, uint) -> bool) -> bool {
474473
}
475474

476475
/// Iterates over all the paths in the given crate.
477-
pub fn _each_path(intr: @ident_interner, cdata: cmd,
476+
pub fn _each_path(intr: @ident_interner,
477+
cdata: cmd,
478478
get_crate_data: GetCrateDataCb,
479-
f: &fn(&str, def_like) -> bool) -> bool {
479+
f: &fn(&str, def_like, ast::visibility) -> bool)
480+
-> bool {
480481
let root = reader::Doc(cdata.data);
481482
let items = reader::get_doc(root, tag_items);
482483
let items_data = reader::get_doc(items, tag_items_data);
@@ -497,8 +498,10 @@ pub fn _each_path(intr: @ident_interner, cdata: cmd,
497498
debug!("(each_path) yielding explicit item: %s", path);
498499
let def_like = item_to_def_like(item_doc, def_id, cdata.cnum);
499500

501+
let vis = item_visibility(item_doc);
502+
500503
// Hand the information off to the iteratee.
501-
if !f(path, def_like) {
504+
if !f(path, def_like, vis) {
502505
broken = true; // FIXME #4572: This is awful.
503506
}
504507
}
@@ -548,7 +551,7 @@ pub fn _each_path(intr: @ident_interner, cdata: cmd,
548551
debug!("(each_path) yielding reexported \
549552
item: %s", reexport_path);
550553

551-
if (!f(reexport_path, def_like)) {
554+
if (!f(reexport_path, def_like, ast::public)) {
552555
broken = true; // FIXME #4572: This is awful.
553556
}
554557
}
@@ -561,9 +564,19 @@ pub fn _each_path(intr: @ident_interner, cdata: cmd,
561564
return broken;
562565
}
563566

564-
pub fn each_path(intr: @ident_interner, cdata: cmd,
567+
#[cfg(stage0)]
568+
pub fn each_path(intr: @ident_interner,
569+
cdata: cmd,
570+
get_crate_data: GetCrateDataCb,
571+
f: &fn(&str, def_like, ast::visibility) -> bool) {
572+
_each_path(intr, cdata, get_crate_data, f);
573+
}
574+
#[cfg(not(stage0))]
575+
pub fn each_path(intr: @ident_interner,
576+
cdata: cmd,
565577
get_crate_data: GetCrateDataCb,
566-
f: &fn(&str, def_like) -> bool) -> bool {
578+
f: &fn(&str, def_like, ast::visibility) -> bool)
579+
-> bool {
567580
_each_path(intr, cdata, get_crate_data, f)
568581
}
569582

@@ -1127,7 +1140,7 @@ pub fn get_crate_vers(data: @~[u8]) -> @~str {
11271140
fn iter_crate_items(intr: @ident_interner, cdata: cmd,
11281141
get_crate_data: GetCrateDataCb,
11291142
proc: &fn(path: &str, ast::def_id)) {
1130-
for each_path(intr, cdata, get_crate_data) |path_string, def_like| {
1143+
for each_path(intr, cdata, get_crate_data) |path_string, def_like, _| {
11311144
match def_like {
11321145
dl_impl(*) | dl_field => {}
11331146
dl_def(def) => {

trunk/src/librustc/metadata/encoder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ fn encode_enum_variant_info(ecx: @EncodeContext,
316316
encode_family(ebml_w, 'v');
317317
encode_name(ecx, ebml_w, variant.node.name);
318318
encode_parent_item(ebml_w, local_def(id));
319+
encode_visibility(ebml_w, variant.node.vis);
319320
encode_type(ecx, ebml_w,
320321
node_id_to_type(ecx.tcx, variant.node.id));
321322
match variant.node.kind {

trunk/src/librustc/middle/resolve.rs

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,8 @@ pub impl NameBindings {
539539
self.type_def = Some(TypeNsDef {
540540
privacy: privacy,
541541
module_def: Some(module),
542-
type_def: None
542+
type_def: None,
543+
type_span: None,
543544
})
544545
}
545546
Some(type_def) => {
@@ -549,7 +550,8 @@ pub impl NameBindings {
549550
self.type_def = Some(TypeNsDef {
550551
privacy: privacy,
551552
module_def: Some(module),
552-
type_def: type_def.type_def
553+
type_def: type_def.type_def,
554+
type_span: None,
553555
})
554556
}
555557
Some(module_def) => module_def.kind = kind,
@@ -1392,10 +1394,8 @@ pub impl Resolver {
13921394
}
13931395
}
13941396

1395-
/**
1396-
* Constructs the reduced graph for one 'view item'. View items consist
1397-
* of imports and use directives.
1398-
*/
1397+
/// Constructs the reduced graph for one 'view item'. View items consist
1398+
/// of imports and use directives.
13991399
fn build_reduced_graph_for_view_item(@mut self,
14001400
view_item: @view_item,
14011401
parent: ReducedGraphParent,
@@ -1551,11 +1551,13 @@ pub impl Resolver {
15511551

15521552
fn handle_external_def(@mut self,
15531553
def: def,
1554+
visibility: ast::visibility,
15541555
modules: &mut HashMap<def_id, @mut Module>,
15551556
child_name_bindings: @mut NameBindings,
15561557
final_ident: &str,
15571558
ident: ident,
15581559
new_parent: ReducedGraphParent) {
1560+
let privacy = visibility_to_privacy(visibility);
15591561
match def {
15601562
def_mod(def_id) | def_foreign_mod(def_id) => {
15611563
match child_name_bindings.type_def {
@@ -1573,7 +1575,7 @@ pub impl Resolver {
15731575

15741576
// FIXME (#5074): this should be a match on find
15751577
if !modules.contains_key(&def_id) {
1576-
child_name_bindings.define_module(Public,
1578+
child_name_bindings.define_module(privacy,
15771579
parent_link,
15781580
Some(def_id),
15791581
NormalModuleKind,
@@ -1582,9 +1584,9 @@ pub impl Resolver {
15821584
child_name_bindings.get_module());
15831585
} else {
15841586
let existing_module = *modules.get(&def_id);
1585-
// Create an import resolution to
1586-
// avoid creating cycles in the
1587-
// module graph.
1587+
1588+
// Create an import resolution to avoid creating cycles in
1589+
// the module graph.
15881590

15891591
let resolution = @mut ImportResolution(Public, 0);
15901592
resolution.outstanding_references = 0;
@@ -1610,11 +1612,19 @@ pub impl Resolver {
16101612
}
16111613
}
16121614
}
1613-
def_fn(*) | def_static_method(*) | def_const(*) |
16141615
def_variant(*) => {
1616+
debug!("(building reduced graph for external crate) building \
1617+
variant %s",
1618+
final_ident);
1619+
// We assume the parent is visible, or else we wouldn't have seen
1620+
// it.
1621+
let privacy = variant_visibility_to_privacy(visibility, true);
1622+
child_name_bindings.define_value(privacy, def, dummy_sp());
1623+
}
1624+
def_fn(*) | def_static_method(*) | def_const(*) => {
16151625
debug!("(building reduced graph for external \
16161626
crate) building value %s", final_ident);
1617-
child_name_bindings.define_value(Public, def, dummy_sp());
1627+
child_name_bindings.define_value(privacy, def, dummy_sp());
16181628
}
16191629
def_trait(def_id) => {
16201630
debug!("(building reduced graph for external \
@@ -1651,11 +1661,11 @@ pub impl Resolver {
16511661
}
16521662
}
16531663

1654-
child_name_bindings.define_type(Public, def, dummy_sp());
1664+
child_name_bindings.define_type(privacy, def, dummy_sp());
16551665

16561666
// Define a module if necessary.
16571667
let parent_link = self.get_parent_link(new_parent, ident);
1658-
child_name_bindings.set_module_kind(Public,
1668+
child_name_bindings.set_module_kind(privacy,
16591669
parent_link,
16601670
Some(def_id),
16611671
TraitModuleKind,
@@ -1665,13 +1675,13 @@ pub impl Resolver {
16651675
debug!("(building reduced graph for external \
16661676
crate) building type %s", final_ident);
16671677

1668-
child_name_bindings.define_type(Public, def, dummy_sp());
1678+
child_name_bindings.define_type(privacy, def, dummy_sp());
16691679
}
16701680
def_struct(def_id) => {
16711681
debug!("(building reduced graph for external \
16721682
crate) building type %s",
16731683
final_ident);
1674-
child_name_bindings.define_type(Public, def, dummy_sp());
1684+
child_name_bindings.define_type(privacy, def, dummy_sp());
16751685
self.structs.insert(def_id);
16761686
}
16771687
def_self(*) | def_arg(*) | def_local(*) |
@@ -1692,7 +1702,7 @@ pub impl Resolver {
16921702

16931703
// Create all the items reachable by paths.
16941704
for each_path(self.session.cstore, root.def_id.get().crate)
1695-
|path_string, def_like| {
1705+
|path_string, def_like, visibility| {
16961706

16971707
debug!("(building reduced graph for external crate) found path \
16981708
entry: %s (%?)",
@@ -1760,6 +1770,7 @@ pub impl Resolver {
17601770
dummy_sp());
17611771

17621772
self.handle_external_def(def,
1773+
visibility,
17631774
&mut modules,
17641775
child_name_bindings,
17651776
*self.session.str_of(
@@ -2995,14 +3006,9 @@ pub impl Resolver {
29953006

29963007
// If this is a search of all imports, we should be done with glob
29973008
// resolution at this point.
2998-
<<<<<<< HEAD
2999-
if name_search_type == SearchItemsAndAllImports {
3000-
assert_eq!(module_.glob_count, 0);
3001-
=======
30023009
if name_search_type == PathPublicOrPrivateSearch ||
30033010
name_search_type == PathPublicOnlySearch {
3004-
assert!(module_.glob_count == 0);
3005-
>>>>>>> librustc: Disallow `use` from reaching into impls or traits.
3011+
assert_eq!(module_.glob_count, 0);
30063012
}
30073013

30083014
// Check the list of resolved imports.

trunk/src/librustc/middle/typeck/coherence.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ pub impl CoherenceChecker {
975975
def_id { crate: crate_number,
976976
node: 0 });
977977

978-
for each_path(crate_store, crate_number) |_p, def_like| {
978+
for each_path(crate_store, crate_number) |_, def_like, _| {
979979
match def_like {
980980
dl_def(def_mod(def_id)) => {
981981
self.add_impls_for_module(&mut impls_seen,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pub enum Foo {
2+
pub Bar,
3+
priv Baz,
4+
}
5+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// aux-build:private_variant_xc.rs
2+
3+
extern mod private_variant_xc;
4+
5+
pub fn main() {
6+
let _ = private_variant_xc::Bar;
7+
let _ = private_variant_xc::Baz; //~ ERROR unresolved name
8+
}
9+

0 commit comments

Comments
 (0)