Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can pub use "reexport" priv items from the current module? #9678

Closed
pnkfelix opened this issue Oct 2, 2013 · 3 comments
Closed

Can pub use "reexport" priv items from the current module? #9678

pnkfelix opened this issue Oct 2, 2013 · 3 comments

Comments

@pnkfelix
Copy link
Member

pnkfelix commented Oct 2, 2013

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)]
pub use sum = self::sigma;

pub use t = m::n::t;

fn sigma(x:int, y:int) -> int { x + y }

mod m {
    pub use self::n::t;
    mod n {
        pub type t = int;
    }

    pub fn f(x: n::t) -> n::t { x + 1 }
}

mod o {
    #[cfg(not(o_workaround))]
    pub use s = self::tau;
    #[cfg(not(o_workaround))]
    pub use f = self::g;

    #[cfg(o_workaround)]
    pub type s = tau;

    #[cfg(o_workaround)]
    pub fn f(x: tau) -> tau { g(x) }

    type tau = int;
    fn g(x: tau) -> tau { x + 1 }
}

fn main() {
    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
@pnkfelix
Copy link
Member Author

pnkfelix commented Oct 2, 2013

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.

@alexcrichton
Copy link
Member

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.

@alexcrichton
Copy link
Member

This has since been closed, and there are many tests which exercise this functionality. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants