Skip to content

Can't define pub fn in child module if it uses a type defined in the parent module #30070

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

Closed
4xrsJCr9 opened this issue Nov 26, 2015 · 4 comments

Comments

@4xrsJCr9
Copy link

mod parent {
    mod child {
        use super::Test;
        pub fn child_fn(test: Test) {
        }
    }
    struct Test(u32);
}

The above fails to compile on rustc 1.6.0-nightly (2ba44607f 2015-11-22) (Playground link: http://is.gd/kngh6n).

I want to be able to use child_fn from within the parent module. Since the child module and its types are completely private to the parent module, shouldn't this work?

@oli-obk
Copy link
Contributor

oli-obk commented Nov 26, 2015

duplicate of #27608

works as expected

@petrochenkov
Copy link
Contributor

Since the child module and its types are completely private to the parent module, shouldn't this work?

And then you add pub use self::child::child_fn; in the parent module and private Test leaks outside of parent. So, this is by design, yes.

@oli-obk
Copy link
Contributor

oli-obk commented Nov 26, 2015

The idea is that every module can be checked on its own, instead of having to check the entire crate.

@4xrsJCr9
Copy link
Author

@oli-obk:
I should have found that issue; sorry for the duplication.

The idea is that every module can be checked on its own, instead of having to check the entire crate.

Fair enough.

@petrochenkov:

And then you add pub use self::child::child_fn; in the parent module and private Test leaks outside of parent. So, this is by design, yes.

Perhaps the compiler should wait till I actually leak Test before it starts complaining. Having said that, I can appreciate how much simpler/faster it would be to implement the design from the RFC linked to #27608.

Thank you both for your replies.

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

3 participants