Skip to content

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

Closed

Description

@koute

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.

Activity

  1. koute commented on Oct 27, 2016

    @koute
    ContributorAuthor

    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.

  2. petrochenkov commented on Oct 27, 2016

    @petrochenkov
    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.

  3. koute commented on Oct 27, 2016

    @koute
    ContributorAuthor

    @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.

  4. sanmai-NL commented on Oct 30, 2016

    @sanmai-NL
    Contributor

    @koute: you can still close it. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions