Skip to content

Wildcard imports from super omit non-public constants and statics. #37434

New issue

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

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

Already on GitHub? # to your account

Closed
koute opened this issue Oct 27, 2016 · 4 comments
Closed

Wildcard imports from super omit non-public constants and statics. #37434

koute opened this issue Oct 27, 2016 · 4 comments

Comments

@koute
Copy link
Member

koute commented Oct 27, 2016

Please consider the following code:

const CONSTANT: usize = 0;

mod ok {
    use super::CONSTANT;
    fn foobar() -> usize {
        CONSTANT
    }
}

mod error {
    use super::*;
    fn foobar() -> usize {
        CONSTANT
    }
}

The ok::foobar compiles fine while error::foobar generates the following error:

error[E0425]: unresolved name `CONSTANT`
  --> test.rs:13:9
   |
13 |         CONSTANT
   |         ^^^^^^^^ unresolved name

This also affects static.

Marking the constant pub makes it compile as expected.

Meta

rustc 1.14.0-nightly (c59cb71d9 2016-10-26)
binary: rustc
commit-hash: c59cb71d976ceabf00c7da0224a795fab530601e
commit-date: 2016-10-26
host: x86_64-unknown-linux-gnu
release: 1.14.0-nightly
LLVM version: 3.9

1.12.1 is also affected.

@koute
Copy link
Member Author

koute commented Oct 27, 2016

Actually, sorry, it seems that this isn't specific to constants; a wildcard doesn't import anything non-public.

Is this intended? I'd expect a * to expand to everything that is importable from a given scope, not only what is public.

@petrochenkov
Copy link
Contributor

The code will compile if you add #![feature(item_like_imports)] to the crate root.

After #37127 lands, item_like_imports will become a default and the code will work without any features.

@koute
Copy link
Member Author

koute commented Oct 27, 2016

@petrochenkov I see; thanks!

Sorry for the duplicate bug! I did try to search for duplicates, but it seems that my search-fu wasn't strong enough.

@sanmai-NL
Copy link

@koute: you can still close it. 🙂

@koute koute closed this as completed Oct 30, 2016
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants