Skip to content

Commit 2bd46e7

Browse files
committed
librustc: Fix problem with cross-crate reexported static methods.
1 parent 6c37e3b commit 2bd46e7

File tree

10 files changed

+95
-25
lines changed

10 files changed

+95
-25
lines changed

src/libextra/stats.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ pub fn write_boxplot(w: @io::Writer, s: &Summary, width_hint: uint) {
368368
/// Returns a HashMap with the number of occurrences of every element in the
369369
/// sequence that the iterator exposes.
370370
pub fn freq_count<T: Iterator<U>, U: Eq+Hash>(mut iter: T) -> hashmap::HashMap<U, uint> {
371-
let mut map = hashmap::HashMap::new::<U, uint>();
371+
let mut map: hashmap::HashMap<U,uint> = hashmap::HashMap::new();
372372
for elem in iter {
373373
map.insert_or_update_with(elem, 1, |_, count| *count += 1);
374374
}

src/librustc/metadata/decoder.rs

+50-6
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,56 @@ fn each_child_of_item_or_crate(intr: @ident_interner,
733733
child_def_id,
734734
cdata.cnum);
735735
callback(def_like, child_name);
736+
737+
}
738+
}
739+
740+
true
741+
};
742+
743+
// As a special case, iterate over all static methods of
744+
// associated implementations too. This is a bit of a botch.
745+
// --pcwalton
746+
let _ = do reader::tagged_docs(item_doc,
747+
tag_items_data_item_inherent_impl)
748+
|inherent_impl_def_id_doc| {
749+
let inherent_impl_def_id = item_def_id(inherent_impl_def_id_doc,
750+
cdata);
751+
let items = reader::get_doc(reader::Doc(cdata.data), tag_items);
752+
match maybe_find_item(inherent_impl_def_id.node, items) {
753+
None => {}
754+
Some(inherent_impl_doc) => {
755+
let _ = do reader::tagged_docs(inherent_impl_doc,
756+
tag_item_impl_method)
757+
|impl_method_def_id_doc| {
758+
let impl_method_def_id =
759+
reader::with_doc_data(impl_method_def_id_doc,
760+
parse_def_id);
761+
let impl_method_def_id =
762+
translate_def_id(cdata, impl_method_def_id);
763+
match maybe_find_item(impl_method_def_id.node, items) {
764+
None => {}
765+
Some(impl_method_doc) => {
766+
match item_family(impl_method_doc) {
767+
StaticMethod | UnsafeStaticMethod => {
768+
// Hand off the static method
769+
// to the callback.
770+
let static_method_name =
771+
item_name(intr, impl_method_doc);
772+
let static_method_def_like =
773+
item_to_def_like(impl_method_doc,
774+
impl_method_def_id,
775+
cdata.cnum);
776+
callback(static_method_def_like,
777+
static_method_name);
778+
}
779+
_ => {}
780+
}
781+
}
782+
}
783+
784+
true
785+
};
736786
}
737787
}
738788

@@ -1403,15 +1453,9 @@ pub fn each_implementation_for_type(cdata: cmd,
14031453
id: ast::NodeId,
14041454
callback: &fn(ast::def_id)) {
14051455
let item_doc = lookup_item(id, cdata.data);
1406-
/*println(fmt!(">>> reading inherent impls from %s",
1407-
token::ident_to_str(&item_name(token::get_ident_interner(),
1408-
item_doc))));*/
14091456
do reader::tagged_docs(item_doc, tag_items_data_item_inherent_impl)
14101457
|impl_doc| {
14111458
let implementation_def_id = item_def_id(impl_doc, cdata);
1412-
/*println(fmt!(">>>>> read inherent impl: %d:%d",
1413-
implementation_def_id.crate,
1414-
implementation_def_id.node));*/
14151459
callback(implementation_def_id);
14161460
true
14171461
};

src/librustc/metadata/encoder.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -513,8 +513,12 @@ fn encode_reexports(ecx: &EncodeContext,
513513
Some(ref exports) => {
514514
debug!("(encoding info for module) found reexports for %d", id);
515515
for exp in exports.iter() {
516-
debug!("(encoding info for module) reexport '%s' for %d",
517-
exp.name, id);
516+
debug!("(encoding info for module) reexport '%s' (%d/%d) for \
517+
%d",
518+
exp.name,
519+
exp.def_id.crate,
520+
exp.def_id.node,
521+
id);
518522
ebml_w.start_tag(tag_items_data_item_reexport);
519523
ebml_w.start_tag(tag_items_data_item_reexport_def_id);
520524
ebml_w.wr_str(def_to_str(exp.def_id));

src/librustc/middle/resolve.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -1658,7 +1658,8 @@ impl Resolver {
16581658
new_parent: ReducedGraphParent) {
16591659
let privacy = visibility_to_privacy(visibility);
16601660
match def {
1661-
def_mod(def_id) | def_foreign_mod(def_id) => {
1661+
def_mod(def_id) | def_foreign_mod(def_id) | def_struct(def_id) |
1662+
def_ty(def_id) => {
16621663
match child_name_bindings.type_def {
16631664
Some(TypeNsDef { module_def: Some(module_def), _ }) => {
16641665
debug!("(building reduced graph for external crate) \
@@ -1680,6 +1681,11 @@ impl Resolver {
16801681
}
16811682
}
16821683
}
1684+
_ => {}
1685+
}
1686+
1687+
match def {
1688+
def_mod(_) | def_foreign_mod(_) => {}
16831689
def_variant(*) => {
16841690
debug!("(building reduced graph for external crate) building \
16851691
variant %s",
@@ -1691,7 +1697,7 @@ impl Resolver {
16911697
}
16921698
def_fn(*) | def_static_method(*) | def_static(*) => {
16931699
debug!("(building reduced graph for external \
1694-
crate) building value %s", final_ident);
1700+
crate) building value (fn/static) %s", final_ident);
16951701
child_name_bindings.define_value(privacy, def, dummy_sp());
16961702
}
16971703
def_trait(def_id) => {
@@ -1903,13 +1909,21 @@ impl Resolver {
19031909

19041910
/// Builds the reduced graph rooted at the given external module.
19051911
fn populate_external_module(@mut self, module: @mut Module) {
1912+
debug!("(populating external module) attempting to populate %s",
1913+
self.module_to_str(module));
1914+
19061915
let def_id = match module.def_id {
1907-
None => return,
1916+
None => {
1917+
debug!("(populating external module) ... no def ID!");
1918+
return
1919+
}
19081920
Some(def_id) => def_id,
19091921
};
19101922

19111923
do csearch::each_child_of_item(self.session.cstore, def_id)
19121924
|def_like, child_ident| {
1925+
debug!("(populating external module) ... found ident: %s",
1926+
token::ident_to_str(&child_ident));
19131927
self.build_reduced_graph_for_external_crate_def(module,
19141928
def_like,
19151929
child_ident)
@@ -3871,7 +3885,7 @@ impl Resolver {
38713885
generics: &Generics,
38723886
fields: &[@struct_field],
38733887
visitor: &mut ResolveVisitor) {
3874-
let mut ident_map = HashMap::new::<ast::ident, @struct_field>();
3888+
let mut ident_map: HashMap<ast::ident,@struct_field> = HashMap::new();
38753889
for &field in fields.iter() {
38763890
match field.node.kind {
38773891
named_field(ident, _) => {

src/libstd/rt/uv/uvio.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -1303,15 +1303,17 @@ fn test_simple_homed_udp_io_bind_then_move_task_then_home_and_close() {
13031303
};
13041304

13051305
let test_function: ~fn() = || {
1306-
let io = unsafe { Local::unsafe_borrow::<IoFactoryObject>() };
1306+
let io: *mut IoFactoryObject = unsafe {
1307+
Local::unsafe_borrow()
1308+
};
13071309
let addr = next_test_ip4();
13081310
let maybe_socket = unsafe { (*io).udp_bind(addr) };
13091311
// this socket is bound to this event loop
13101312
assert!(maybe_socket.is_ok());
13111313

13121314
// block self on sched1
13131315
do task::unkillable { // FIXME(#8674)
1314-
let scheduler = Local::take::<Scheduler>();
1316+
let scheduler: ~Scheduler = Local::take();
13151317
do scheduler.deschedule_running_task_and_then |_, task| {
13161318
// unblock task
13171319
do task.wake().map_move |task| {
@@ -1377,7 +1379,9 @@ fn test_simple_homed_udp_io_bind_then_move_handle_then_home_and_close() {
13771379
let chan = Cell::new(chan);
13781380

13791381
let body1: ~fn() = || {
1380-
let io = unsafe { Local::unsafe_borrow::<IoFactoryObject>() };
1382+
let io: *mut IoFactoryObject = unsafe {
1383+
Local::unsafe_borrow()
1384+
};
13811385
let addr = next_test_ip4();
13821386
let socket = unsafe { (*io).udp_bind(addr) };
13831387
assert!(socket.is_ok());
@@ -1489,7 +1493,9 @@ fn test_simple_tcp_server_and_client_on_diff_threads() {
14891493
};
14901494

14911495
let server_fn: ~fn() = || {
1492-
let io = unsafe { Local::unsafe_borrow::<IoFactoryObject>() };
1496+
let io: *mut IoFactoryObject = unsafe {
1497+
Local::unsafe_borrow()
1498+
};
14931499
let mut listener = unsafe { (*io).tcp_bind(server_addr).unwrap() };
14941500
let mut stream = listener.accept().unwrap();
14951501
let mut buf = [0, .. 2048];
@@ -1501,7 +1507,9 @@ fn test_simple_tcp_server_and_client_on_diff_threads() {
15011507
};
15021508

15031509
let client_fn: ~fn() = || {
1504-
let io = unsafe { Local::unsafe_borrow::<IoFactoryObject>() };
1510+
let io: *mut IoFactoryObject = unsafe {
1511+
Local::unsafe_borrow()
1512+
};
15051513
let mut stream = unsafe { (*io).tcp_connect(client_addr) };
15061514
while stream.is_err() {
15071515
stream = unsafe { (*io).tcp_connect(client_addr) };

src/test/compile-fail/borrowck-borrowed-uniq-rvalue.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
use std::hashmap::HashMap;
1414

1515
fn main() {
16-
let mut buggy_map :HashMap<uint, &uint> =
17-
HashMap::new::<uint, &uint>();
16+
let mut buggy_map: HashMap<uint, &uint> = HashMap::new();
1817
buggy_map.insert(42, &*~1); //~ ERROR borrowed value does not live long enough
1918

2019
// but it is ok if we use a temporary

src/test/compile-fail/map-types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use std::hashmap::HashMap;
1414
// Test that trait types printed in error msgs include the type arguments.
1515

1616
fn main() {
17-
let x: @Map<~str, ~str> = @HashMap::new::<~str, ~str>() as
18-
@Map<~str, ~str>;
17+
let x: @HashMap<~str, ~str> = @HashMap::new();
18+
let x: @Map<~str, ~str> = x as @Map<~str, ~str>;
1919
let y: @Map<uint, ~str> = @x;
2020
//~^ ERROR expected trait std::container::Map but found @-ptr
2121
}

src/test/compile-fail/private-variant-xc.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// aux-build:private_variant_xc.rs
2+
// xfail-test
23

34
extern mod private_variant_xc;
45

src/test/compile-fail/xc-private-method.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ fn main() {
77
// normal method on struct
88
let _ = xc_private_method_lib::Struct{ x: 10 }.meth_struct(); //~ ERROR method `meth_struct` is private
99
// static method on struct
10-
let _ = xc_private_method_lib::Struct::static_meth_struct(); //~ ERROR function `static_meth_struct` is private
10+
let _ = xc_private_method_lib::Struct::static_meth_struct(); //~ ERROR method `static_meth_struct` is private
1111

1212
// normal method on enum
1313
let _ = xc_private_method_lib::Variant1(20).meth_enum(); //~ ERROR method `meth_enum` is private
1414
// static method on enum
15-
let _ = xc_private_method_lib::Enum::static_meth_enum(); //~ ERROR function `static_meth_enum` is private
15+
let _ = xc_private_method_lib::Enum::static_meth_enum(); //~ ERROR method `static_meth_enum` is private
1616
}

src/test/run-pass/issue-3026.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use std::hashmap::HashMap;
1414

1515
pub fn main() {
16-
let mut buggy_map: HashMap<uint, &uint> = HashMap::new::<uint, &uint>();
16+
let mut buggy_map: HashMap<uint, &uint> = HashMap::new();
1717
let x = ~1;
1818
buggy_map.insert(42, &*x);
1919
}

0 commit comments

Comments
 (0)