Skip to content

Commit

Permalink
librustc: Fix problem with cross-crate reexported static methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
pcwalton committed Aug 28, 2013
1 parent 6c37e3b commit 2bd46e7
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/libextra/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
56 changes: 50 additions & 6 deletions src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}
}

Expand Down Expand Up @@ -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
};
Expand Down
8 changes: 6 additions & 2 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
22 changes: 18 additions & 4 deletions src/librustc/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand All @@ -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",
Expand All @@ -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) => {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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, _) => {
Expand Down
18 changes: 13 additions & 5 deletions src/libstd/rt/uv/uvio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1303,15 +1303,17 @@ 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
assert!(maybe_socket.is_ok());

// 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| {
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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];
Expand All @@ -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) };
Expand Down
3 changes: 1 addition & 2 deletions src/test/compile-fail/borrowck-borrowed-uniq-rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/test/compile-fail/map-types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 1 addition & 0 deletions src/test/compile-fail/private-variant-xc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// aux-build:private_variant_xc.rs
// xfail-test

extern mod private_variant_xc;

Expand Down
4 changes: 2 additions & 2 deletions src/test/compile-fail/xc-private-method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion src/test/run-pass/issue-3026.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 2bd46e7

Please sign in to comment.