From 64305174c9f2925dcbec3cf24ccc4be3a52e1ff6 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 15 Nov 2012 16:59:43 -0800 Subject: [PATCH] librustc: Fix cross-crate reexports. rs=blocking-servo --- src/libcore/float.rs | 18 ++++---- src/librustc/middle/resolve.rs | 46 ++++++++++++-------- src/test/auxiliary/pub_use_mods_xcrate.rs | 11 +++++ src/test/run-pass/pub_use_mods_xcrate_exe.rs | 8 ++++ 4 files changed, 56 insertions(+), 27 deletions(-) create mode 100644 src/test/auxiliary/pub_use_mods_xcrate.rs create mode 100644 src/test/run-pass/pub_use_mods_xcrate_exe.rs diff --git a/src/libcore/float.rs b/src/libcore/float.rs index dd46d30d6bad..726ea31e7daf 100644 --- a/src/libcore/float.rs +++ b/src/libcore/float.rs @@ -16,15 +16,15 @@ use m_float = f64; -use f64::{add, sub, mul, div, rem, lt, le, eq, ne, ge, gt}; -use f64::logarithm; -use f64::{acos, asin, atan2, cbrt, ceil, copysign, cosh, floor}; -use f64::{erf, erfc, exp, expm1, exp2, abs_sub}; -use f64::{mul_add, fmax, fmin, nextafter, frexp, hypot, ldexp}; -use f64::{lgamma, ln, log_radix, ln1p, log10, log2, ilog_radix}; -use f64::{modf, pow, round, sinh, tanh, tgamma, trunc}; -use f64::signbit; -use f64::{j0, j1, jn, y0, y1, yn}; +pub use f64::{add, sub, mul, div, rem, lt, le, eq, ne, ge, gt}; +pub use f64::logarithm; +pub use f64::{acos, asin, atan2, cbrt, ceil, copysign, cosh, floor}; +pub use f64::{erf, erfc, exp, expm1, exp2, abs_sub}; +pub use f64::{mul_add, fmax, fmin, nextafter, frexp, hypot, ldexp}; +pub use f64::{lgamma, ln, log_radix, ln1p, log10, log2, ilog_radix}; +pub use f64::{modf, pow, round, sinh, tanh, tgamma, trunc}; +pub use f64::signbit; +pub use f64::{j0, j1, jn, y0, y1, yn}; use cmp::{Eq, Ord}; use num::from_int; diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 4d435bea7a26..6f67b948aa40 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -1687,7 +1687,7 @@ impl Resolver { // avoid creating cycles in the // module graph. - let resolution = @ImportResolution(Private, dummy_sp()); + let resolution = @ImportResolution(Public, dummy_sp()); resolution.outstanding_references = 0; match existing_module.parent_link { @@ -3199,23 +3199,26 @@ impl Resolver { fn add_exports_of_namebindings(exports2: &mut ~[Export2], ident: ident, namebindings: @NameBindings, + ns: Namespace, reexport: bool) { - for [ TypeNS, ValueNS ].each |ns| { - match (namebindings.def_for_namespace(*ns), - namebindings.privacy_for_namespace(*ns)) { - (Some(d), Some(Public)) => { - debug!("(computing exports) YES: %s '%s' \ - => %?", - if reexport { ~"reexport" } else { ~"export"}, - self.session.str_of(ident), - def_id_of_def(d)); - exports2.push(Export2 { - reexport: reexport, - name: self.session.str_of(ident), - def_id: def_id_of_def(d) - }); - } - _ => () + match (namebindings.def_for_namespace(ns), + namebindings.privacy_for_namespace(ns)) { + (Some(d), Some(Public)) => { + debug!("(computing exports) YES: %s '%s' => %?", + if reexport { ~"reexport" } else { ~"export"}, + self.session.str_of(ident), + def_id_of_def(d)); + exports2.push(Export2 { + reexport: reexport, + name: self.session.str_of(ident), + def_id: def_id_of_def(d) + }); + } + (Some(_), Some(privacy)) => { + debug!("(computing reexports) NO: privacy %?", privacy); + } + (d_opt, p_opt) => { + debug!("(computing reexports) NO: %?, %?", d_opt, p_opt); } } } @@ -3227,7 +3230,13 @@ impl Resolver { self.add_exports_of_namebindings(exports2, *ident, *namebindings, - false) + TypeNS, + false); + self.add_exports_of_namebindings(exports2, + *ident, + *namebindings, + ValueNS, + false); } for module_.import_resolutions.each_ref |ident, importresolution| { @@ -3244,6 +3253,7 @@ impl Resolver { self.add_exports_of_namebindings(exports2, *ident, target.bindings, + *ns, true) } _ => () diff --git a/src/test/auxiliary/pub_use_mods_xcrate.rs b/src/test/auxiliary/pub_use_mods_xcrate.rs new file mode 100644 index 000000000000..99a85c66b4ff --- /dev/null +++ b/src/test/auxiliary/pub_use_mods_xcrate.rs @@ -0,0 +1,11 @@ +pub mod a { + pub mod b { + pub mod c { + fn f(){} + fn g(){} + } + } + + pub use b::c; +} + diff --git a/src/test/run-pass/pub_use_mods_xcrate_exe.rs b/src/test/run-pass/pub_use_mods_xcrate_exe.rs new file mode 100644 index 000000000000..ddba3e4a387c --- /dev/null +++ b/src/test/run-pass/pub_use_mods_xcrate_exe.rs @@ -0,0 +1,8 @@ +// xfail-fast +// aux-build:pub_use_mods_xcrate.rs + +extern mod pub_use_mods_xcrate; +use pub_use_mods_xcrate::a::c; + +fn main(){} +