-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Unexpected warning with use statement #30159
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
Comments
cc @petrochenkov, it's related to privacy |
@sanxiyn You mentioned on IRC that you would like to see this nominated, can you leave a comment describing why? |
I find it worrying that glob import is not equivalent to explicitly named import. |
This is some fun bug in glob imports (in name resolution, not in privacy, strictly speaking).
Slight variations like
or
or even
fail with The incorrect |
@sanxiyn @petrochenkov the incorrect pub fn f() {}
pub mod foo {
fn f() {}
}
mod bar {
pub use f;
pub use f as g;
use foo::*; // This makes first import private but does not affect the second import.
}
mod baz {
use f;
pub use foo::*; // This makes the above import public
} In the original example, the visibility of the first import This problem is due to a bug in I fixed this problem in PR #30294 while fixing a very closely related issue. |
…to avoid breakage.
r? @nrc Since PR #30294 unintentionally fixed issue #30159, it can cause breakage for a different reason than I originally stated in the PR (see #30159, I characterized the issue precisely there). This commit limits the scope of the breakage to what I originally stated in the PR by "unfixing" the backwards incompatible part of #30159. I think fixing #30159 has enough potential for breakage to warrant a crater run. If you disagree, I can cancel this PR, leaving it fixed.
… can make preceding imports public (fixes rust-lang#30159).
This reverts PR #30324, fixing bug #30159 in which a public a glob import makes public any preceding imports that share a name with an item in the module being glob imported from. For example, ```rust pub fn f() {} pub mod foo { fn f() {} } mod bar { use f; use f as g; pub use foo::*; // This makes the first import public but does not affect the second import. } ``` This is a [breaking-change].
Playground link for all of the examples.
Using this code:
Gives me this warning:
But, removing that line gives me this error:
Switching the code to use these
use
statements:GIves me:
And my last attempt:
Gives me:
So it seems that
use
ing a private item followed bypub use super::*
will export the private item publicly. I could be misunderstanding something here, but where I'm running into this,test_level_1
is actually a plugin that doespub use super::*
, so the warning version is the only one that will compile. In other words, I can't just write the mods as:The text was updated successfully, but these errors were encountered: