You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So, out of personal curiosity, I tried to recreate the effect of the old export lists via pub use, since the Rust manual claims that pub use serves to re-export a name. (And the manual says that it can redirect "even a definition with a private canonical path")
But apparently one cannot use pub use in this manner.
Is that intentional? If so, I think the manual's language on this point could be improved.
(Also, when one attempts this in the outermost scope of the source file, the error message uses ??? for the module name.)
Sample source code:
#[cfg(outer_version1)]pubuse sum = self::sigma;pubuse t = m::n::t;fnsigma(x:int,y:int) -> int{ x + y }mod m {pubuseself::n::t;mod n {pubtypet = int;}pubfnf(x: n::t) -> n::t{ x + 1}}mod o {#[cfg(not(o_workaround))]pubuse s = self::tau;#[cfg(not(o_workaround))]pubuse f = self::g;#[cfg(o_workaround)]pubtypes = tau;#[cfg(o_workaround)]pubfnf(x:tau) -> tau{g(x)}typetau = int;fng(x:tau) -> tau{ x + 1}}fnmain(){let a : m::t = 4;let _y = m::f(a);let b : o::s = 5;let _z = o::f(b);}
Out of the box run (illustrates reasonable error messages from o):
% rustc /tmp/pu.rs
/tmp/pu.rs:19:12: 19:26 error: unresolved import: found `tau` in `o` but it is private
/tmp/pu.rs:19 pub use s = self::tau;
^~~~~~~~~~~~~~
/tmp/pu.rs:19:12: 19:26 error: failed to resolve import `self::tau`
/tmp/pu.rs:19 pub use s = self::tau;
^~~~~~~~~~~~~~
/tmp/pu.rs:21:12: 21:24 error: unresolved import: found `g` in `o` but it is private
/tmp/pu.rs:21 pub use f = self::g;
^~~~~~~~~~~~
/tmp/pu.rs:21:12: 21:24 error: failed to resolve import `self::g`
/tmp/pu.rs:21 pub use f = self::g;
^~~~~~~~~~~~
error: aborting due to 4 previous errors
Run focusing on the outermost error (illustrating poor error message):
% rustc --cfg outer_version1 --cfg o_workaround /tmp/pu.rs
/tmp/pu.rs:2:8: 2:26 error: unresolved import: found `sigma` in `???` but it is private
/tmp/pu.rs:2 pub use sum = self::sigma;
^~~~~~~~~~~~~~~~~~
/tmp/pu.rs:2:8: 2:26 error: failed to resolve import `self::sigma`
/tmp/pu.rs:2 pub use sum = self::sigma;
^~~~~~~~~~~~~~~~~~
error: aborting due to 2 previous errors
The text was updated successfully, but these errors were encountered:
By the way, I did read the discussion on #1893 which is the RFC on replacing export lists with pub/priv, so its entirely possible that this behavior of pub use is entirely deliberate. If so, then I guess I should just try to come up with some refinement of the text in rust.md.
This may be resolved by my work in #8215, but I'm going to leave this open because it's not clear to me that it's a relative of that. I'll attempt to resolve this during that though.
So, out of personal curiosity, I tried to recreate the effect of the old export lists via
pub use
, since the Rust manual claims thatpub use
serves to re-export a name. (And the manual says that it can redirect "even a definition with a private canonical path")But apparently one cannot use
pub use
in this manner.Is that intentional? If so, I think the manual's language on this point could be improved.
(Also, when one attempts this in the outermost scope of the source file, the error message uses
???
for the module name.)Sample source code:
Out of the box run (illustrates reasonable error messages from
o
):Run focusing on the outermost error (illustrating poor error message):
The text was updated successfully, but these errors were encountered: