librustc: Fix problem with cross-crate reexported static methods.

This commit is contained in:
Patrick Walton 2013-08-23 18:31:43 -07:00
parent 6c37e3b7f8
commit 2bd46e767c
10 changed files with 95 additions and 25 deletions

View File

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

View File

@ -733,6 +733,56 @@ fn each_child_of_item_or_crate(intr: @ident_interner,
child_def_id,
cdata.cnum);
callback(def_like, child_name);
}
}
true
};
// As a special case, iterate over all static methods of
// associated implementations too. This is a bit of a botch.
// --pcwalton
let _ = do reader::tagged_docs(item_doc,
tag_items_data_item_inherent_impl)
|inherent_impl_def_id_doc| {
let inherent_impl_def_id = item_def_id(inherent_impl_def_id_doc,
cdata);
let items = reader::get_doc(reader::Doc(cdata.data), tag_items);
match maybe_find_item(inherent_impl_def_id.node, items) {
None => {}
Some(inherent_impl_doc) => {
let _ = do reader::tagged_docs(inherent_impl_doc,
tag_item_impl_method)
|impl_method_def_id_doc| {
let impl_method_def_id =
reader::with_doc_data(impl_method_def_id_doc,
parse_def_id);
let impl_method_def_id =
translate_def_id(cdata, impl_method_def_id);
match maybe_find_item(impl_method_def_id.node, items) {
None => {}
Some(impl_method_doc) => {
match item_family(impl_method_doc) {
StaticMethod | UnsafeStaticMethod => {
// Hand off the static method
// to the callback.
let static_method_name =
item_name(intr, impl_method_doc);
let static_method_def_like =
item_to_def_like(impl_method_doc,
impl_method_def_id,
cdata.cnum);
callback(static_method_def_like,
static_method_name);
}
_ => {}
}
}
}
true
};
}
}
@ -1403,15 +1453,9 @@ pub fn each_implementation_for_type(cdata: cmd,
id: ast::NodeId,
callback: &fn(ast::def_id)) {
let item_doc = lookup_item(id, cdata.data);
/*println(fmt!(">>> reading inherent impls from %s",
token::ident_to_str(&item_name(token::get_ident_interner(),
item_doc))));*/
do reader::tagged_docs(item_doc, tag_items_data_item_inherent_impl)
|impl_doc| {
let implementation_def_id = item_def_id(impl_doc, cdata);
/*println(fmt!(">>>>> read inherent impl: %d:%d",
implementation_def_id.crate,
implementation_def_id.node));*/
callback(implementation_def_id);
true
};

View File

@ -513,8 +513,12 @@ fn encode_reexports(ecx: &EncodeContext,
Some(ref exports) => {
debug!("(encoding info for module) found reexports for %d", id);
for exp in exports.iter() {
debug!("(encoding info for module) reexport '%s' for %d",
exp.name, id);
debug!("(encoding info for module) reexport '%s' (%d/%d) for \
%d",
exp.name,
exp.def_id.crate,
exp.def_id.node,
id);
ebml_w.start_tag(tag_items_data_item_reexport);
ebml_w.start_tag(tag_items_data_item_reexport_def_id);
ebml_w.wr_str(def_to_str(exp.def_id));

View File

@ -1658,7 +1658,8 @@ impl Resolver {
new_parent: ReducedGraphParent) {
let privacy = visibility_to_privacy(visibility);
match def {
def_mod(def_id) | def_foreign_mod(def_id) => {
def_mod(def_id) | def_foreign_mod(def_id) | def_struct(def_id) |
def_ty(def_id) => {
match child_name_bindings.type_def {
Some(TypeNsDef { module_def: Some(module_def), _ }) => {
debug!("(building reduced graph for external crate) \
@ -1680,6 +1681,11 @@ impl Resolver {
}
}
}
_ => {}
}
match def {
def_mod(_) | def_foreign_mod(_) => {}
def_variant(*) => {
debug!("(building reduced graph for external crate) building \
variant %s",
@ -1691,7 +1697,7 @@ impl Resolver {
}
def_fn(*) | def_static_method(*) | def_static(*) => {
debug!("(building reduced graph for external \
crate) building value %s", final_ident);
crate) building value (fn/static) %s", final_ident);
child_name_bindings.define_value(privacy, def, dummy_sp());
}
def_trait(def_id) => {
@ -1903,13 +1909,21 @@ impl Resolver {
/// Builds the reduced graph rooted at the given external module.
fn populate_external_module(@mut self, module: @mut Module) {
debug!("(populating external module) attempting to populate %s",
self.module_to_str(module));
let def_id = match module.def_id {
None => return,
None => {
debug!("(populating external module) ... no def ID!");
return
}
Some(def_id) => def_id,
};
do csearch::each_child_of_item(self.session.cstore, def_id)
|def_like, child_ident| {
debug!("(populating external module) ... found ident: %s",
token::ident_to_str(&child_ident));
self.build_reduced_graph_for_external_crate_def(module,
def_like,
child_ident)
@ -3871,7 +3885,7 @@ impl Resolver {
generics: &Generics,
fields: &[@struct_field],
visitor: &mut ResolveVisitor) {
let mut ident_map = HashMap::new::<ast::ident, @struct_field>();
let mut ident_map: HashMap<ast::ident,@struct_field> = HashMap::new();
for &field in fields.iter() {
match field.node.kind {
named_field(ident, _) => {

View File

@ -1303,7 +1303,9 @@ fn test_simple_homed_udp_io_bind_then_move_task_then_home_and_close() {
};
let test_function: ~fn() = || {
let io = unsafe { Local::unsafe_borrow::<IoFactoryObject>() };
let io: *mut IoFactoryObject = unsafe {
Local::unsafe_borrow()
};
let addr = next_test_ip4();
let maybe_socket = unsafe { (*io).udp_bind(addr) };
// this socket is bound to this event loop
@ -1311,7 +1313,7 @@ fn test_simple_homed_udp_io_bind_then_move_task_then_home_and_close() {
// block self on sched1
do task::unkillable { // FIXME(#8674)
let scheduler = Local::take::<Scheduler>();
let scheduler: ~Scheduler = Local::take();
do scheduler.deschedule_running_task_and_then |_, task| {
// unblock task
do task.wake().map_move |task| {
@ -1377,7 +1379,9 @@ fn test_simple_homed_udp_io_bind_then_move_handle_then_home_and_close() {
let chan = Cell::new(chan);
let body1: ~fn() = || {
let io = unsafe { Local::unsafe_borrow::<IoFactoryObject>() };
let io: *mut IoFactoryObject = unsafe {
Local::unsafe_borrow()
};
let addr = next_test_ip4();
let socket = unsafe { (*io).udp_bind(addr) };
assert!(socket.is_ok());
@ -1489,7 +1493,9 @@ fn test_simple_tcp_server_and_client_on_diff_threads() {
};
let server_fn: ~fn() = || {
let io = unsafe { Local::unsafe_borrow::<IoFactoryObject>() };
let io: *mut IoFactoryObject = unsafe {
Local::unsafe_borrow()
};
let mut listener = unsafe { (*io).tcp_bind(server_addr).unwrap() };
let mut stream = listener.accept().unwrap();
let mut buf = [0, .. 2048];
@ -1501,7 +1507,9 @@ fn test_simple_tcp_server_and_client_on_diff_threads() {
};
let client_fn: ~fn() = || {
let io = unsafe { Local::unsafe_borrow::<IoFactoryObject>() };
let io: *mut IoFactoryObject = unsafe {
Local::unsafe_borrow()
};
let mut stream = unsafe { (*io).tcp_connect(client_addr) };
while stream.is_err() {
stream = unsafe { (*io).tcp_connect(client_addr) };

View File

@ -13,8 +13,7 @@
use std::hashmap::HashMap;
fn main() {
let mut buggy_map :HashMap<uint, &uint> =
HashMap::new::<uint, &uint>();
let mut buggy_map: HashMap<uint, &uint> = HashMap::new();
buggy_map.insert(42, &*~1); //~ ERROR borrowed value does not live long enough
// but it is ok if we use a temporary

View File

@ -14,8 +14,8 @@ use std::hashmap::HashMap;
// Test that trait types printed in error msgs include the type arguments.
fn main() {
let x: @Map<~str, ~str> = @HashMap::new::<~str, ~str>() as
@Map<~str, ~str>;
let x: @HashMap<~str, ~str> = @HashMap::new();
let x: @Map<~str, ~str> = x as @Map<~str, ~str>;
let y: @Map<uint, ~str> = @x;
//~^ ERROR expected trait std::container::Map but found @-ptr
}

View File

@ -1,4 +1,5 @@
// aux-build:private_variant_xc.rs
// xfail-test
extern mod private_variant_xc;

View File

@ -7,10 +7,10 @@ fn main() {
// normal method on struct
let _ = xc_private_method_lib::Struct{ x: 10 }.meth_struct(); //~ ERROR method `meth_struct` is private
// static method on struct
let _ = xc_private_method_lib::Struct::static_meth_struct(); //~ ERROR function `static_meth_struct` is private
let _ = xc_private_method_lib::Struct::static_meth_struct(); //~ ERROR method `static_meth_struct` is private
// normal method on enum
let _ = xc_private_method_lib::Variant1(20).meth_enum(); //~ ERROR method `meth_enum` is private
// static method on enum
let _ = xc_private_method_lib::Enum::static_meth_enum(); //~ ERROR function `static_meth_enum` is private
let _ = xc_private_method_lib::Enum::static_meth_enum(); //~ ERROR method `static_meth_enum` is private
}

View File

@ -13,7 +13,7 @@
use std::hashmap::HashMap;
pub fn main() {
let mut buggy_map: HashMap<uint, &uint> = HashMap::new::<uint, &uint>();
let mut buggy_map: HashMap<uint, &uint> = HashMap::new();
let x = ~1;
buggy_map.insert(42, &*x);
}