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

glob imports ignore private items #23157

Closed
nrc opened this issue Mar 8, 2015 · 7 comments · Fixed by #37127
Closed

glob imports ignore private items #23157

nrc opened this issue Mar 8, 2015 · 7 comments · Fixed by #37127
Labels
A-resolve Area: Name/path resolution done by `rustc_resolve` specifically E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@nrc
Copy link
Member

nrc commented Mar 8, 2015

This is a bug if the importing module should be able to see the private items. E.g.,

struct Foo;

mod sub {
    import super::*;

    type Bar = Foo; // Error: use of undeclared type name Foo
}

I think there is a backwards compatibility hazard here, because if there is already an item called Foo in sub then we currently get no error, but we ought to get a name clash (unless we allow shadowing in this case).

triage: I-nominated

@rust-highfive rust-highfive added this to the 1.0 beta milestone Mar 8, 2015
@nrc nrc added A-resolve Area: Name/path resolution done by `rustc_resolve` specifically A-globs labels Mar 8, 2015
@nrc nrc removed this from the 1.0 beta milestone Mar 8, 2015
@alexcrichton
Copy link
Member

This is currently intentional, there is specific code in resolve to reject any imports of private items. The reason for this is that if an import itself is considered a private item the semantics get really weird very quickly.

For example, all modules import the prelude, so can I import Option from any module? (yes I'll get an error, but those seem like unusual semantics). I believe this is also done to assuage the implementation of cyclically importing everything from a module to another, although I'm less sure about this.

@nrc
Copy link
Member Author

nrc commented Mar 9, 2015

That seems reasonable in general, but I think the rule ought to be that globs only import accessible items, rather than public items, so that if a module imports a glob and has access to a private item it is still imported. I kind of see the argument for weirdness - but nothing that doesn't apply to pub use (I think).

Since there are no cycles in the 'can access private member' graph, it doesn't seem like it should make a difference wrt cyclicity.

@pnkfelix
Copy link
Member

P-high, not 1.0.

@pnkfelix pnkfelix added P-medium Medium priority and removed I-nominated labels Mar 12, 2015
@bltavares
Copy link
Contributor

Updating the code on the example:

struct Foo;

mod sub {
    use super::*;

    type Bar = Foo; // Error: use of undeclared type name Foo
}

@brson
Copy link
Contributor

brson commented Aug 25, 2016

@jseyfried Does #35894 fix this?

@brson brson added I-wrong T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. labels Aug 25, 2016
@jseyfried
Copy link
Contributor

@brson Yeah, once #![feature(item_like_imports)] is stable, that is.

@brson
Copy link
Contributor

brson commented Aug 29, 2016

Depends on #35120.

bors added a commit that referenced this issue Nov 21, 2016
marmistrz added a commit to marmistrz/nix that referenced this issue Jul 31, 2017
marmistrz added a commit to marmistrz/nix that referenced this issue Aug 4, 2017
marmistrz added a commit to marmistrz/nix that referenced this issue Aug 7, 2017
justinas added a commit to justinas/gettext that referenced this issue Nov 1, 2018
The test would not compile with 1.13 due to this bug:
rust-lang/rust#23157
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-resolve Area: Name/path resolution done by `rustc_resolve` specifically E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants