Skip to content

Re-exporting items using a glob breaks if the module imports another module #4865

Closed

Description

@z0w0
priv mod say {
    pub fn hello() { io::println(~"hello"); }
}

pub mod hello {
    use say;

    pub fn hello() {
        say::hello();
    }
}

pub use hello::*; // doesn't work - `pub use hello::hello;` does

fn main() {
    hello();
}

Results in this error when compiling:

error: failed to resolve imports
a.rs:13:8: 13:17 error: unresolved import
a.rs:13 pub use hello::*; // doesn't work - `pub use hello::hello;` does
                ^~~~~~~~~
a.rs:6:5: 6:9 error: unresolved import
a.rs:6  use say;
            ^~~~

As mentioned in the code, explicitly re-exporting items works but is not a good alternative for when you have hundreds of items (including variants) in a module. Changing the say module to public doesn't fix it.

Activity

  1. catamorphism commented on Apr 25, 2013

    @catamorphism
    Contributor

    Not critical for 0.7. Nominating for milestone 1, well-defined.

  2. graydon commented on May 2, 2013

    @graydon
    Contributor

    accepted for well defined - promises made by the resolve pass need to be written down

  3. Blei commented on Jul 9, 2013

    @Blei
    Contributor

    Still applies. Here's the updated source code:

    pub use hello::*; // doesn't work - `pub use hello::hello;` does
    
    pub mod say {
        pub fn hello() { println("hello"); }
    }
    
    pub mod hello {
        use say;
    
        pub fn hello() {
            say::hello();
        }
    }
    
    fn main() {
        hello();
    }

    The error is now:

    blerg2.rs:1:8: 1:17 error: unresolved import
    blerg2.rs:1 pub use hello::*; // doesn't work - `pub use hello::hello;` does
                        ^~~~~~~~~
    blerg2.rs:8:8: 8:11 error: unresolved import (maybe you meant `say::*`?)
    blerg2.rs:8     use say;
                        ^~~
    error: aborting due to 2 previous errors
    

    The error about say goes away when changing the glob to a single import.

  4. Blei commented on Jul 9, 2013

    @Blei
    Contributor

    And here's a failing cross-crate example that's very probably related, so I thought I'd add it here instead of opening a new issue.

    // foo.rs
    pub use foo::*;
    
    mod foo {
        pub fn foo() { println("foo"); }
    }
    // bar.rs
    extern mod foo;
    use foo::*;
    
    fn main() {
        foo();
    }

    Compilation:

    % rustc --lib foo.rs
    warning: missing crate link meta `name`, using `foo` as default
    warning: missing crate link meta `vers`, using `0.0` as default
    % rustc -L. bar.rs
    error: linking with `cc` failed with code 1
    note: cc arguments: -L/home/philipp/programming/rust/x86_64-unknown-linux-gnu/stage2/lib/rustc/x86_64-unknown-linux-gnu/lib -m64 -o bar bar.o -L/home/philipp/programming/rust/x86_64-unknown-linux-gnu/stage2/lib/rustc/x86_64-unknown-linux-gnu/lib -lstd-6c65cf4b443341b1-0.8-pre -L. -lfoo-15fb3a718ea23983-0.0 -lrustrt -lrt -lpthread -L. -lrt -ldl -lm -lmorestack -lrustrt -Wl,-rpath,$ORIGIN/../../programming/rust/x86_64-unknown-linux-gnu/stage2/lib/rustc/x86_64-unknown-linux-gnu/lib -Wl,-rpath,$ORIGIN/. -Wl,-rpath,/home/philipp/programming/rust/x86_64-unknown-linux-gnu/stage2/lib/rustc/x86_64-unknown-linux-gnu/lib -Wl,-rpath,/home/philipp/tmp/6477/. -Wl,-rpath,/usr/local/lib/rustc/x86_64-unknown-linux-gnu/lib
    note: bar.o: In function `main::_c6c3cd618d2fde1::_0$x2e0':
    bar.rc:(.text+0x2c): undefined reference to `foo::foo::_15bec6257b8bff78::_0$x2e0'
    collect2: Fehler: ld gab 1 als Ende-Status zurück
    
    error: aborting due to previous error
    
  5. thestinger commented on Aug 27, 2013

    @thestinger
    Contributor

    This is still an issue.

  6. alexcrichton commented on Oct 11, 2013

    @alexcrichton
    Member

    @Blei, your second test case (which fails with a linker error), I believe was fixed by #9791.

    Otherwise I believe that this is another facet of glob imports having circular references causing problems. The imports at the top level of the crate cannot be considered resolved until the glob is resolved, but the glob cannot get resolved until mod hello is resolved. Now this method can't quite get resolved because use say looks up imports in the global module, which is still waiting on being resolved, hence the circular dependency.

    This is one of the reasons why globs are currently behind a feature flag. Their behavior is subtle and unexpected in certain ways, along with them not always having the best error messages.

    Regardless, leaving open for now as it still reproduces.

  7. pcwalton commented on Nov 22, 2013

    @pcwalton
    Contributor

    Globs are feature gated. Nominating to remove from backcompat-lang.

  8. pnkfelix commented on Dec 19, 2013

    @pnkfelix
    Contributor

    revised Priority to P-low

  9. emberian commented on Jul 31, 2014

    @emberian
    Contributor

    Another example (stripped down) from gl-rs:

    #![crate_type = "lib"]
    
    #![feature(globs)]
    
    extern crate libc;
    
    use std::mem;
    
    use self::types::*;
    
    pub mod types {
        use libc;
    }
    
    mod storage {
        use libc;
    }
    
    mod failing {
        use libc;
        use super::types::*;
    }
  10. added a commit that references this issue on Jul 31, 2014
  11. steveklabnik commented on Feb 11, 2015

    @steveklabnik
    Contributor

    Triage: globs are un-feature gated, but this issue still persists.

  12. steveklabnik commented on Feb 11, 2015

    @steveklabnik
    Contributor

    Re-nominating because of that

  13. pnkfelix commented on Feb 12, 2015

    @pnkfelix
    Contributor

    polish issue, 1.0 P-high. (Note that we believe this and other glob bugs we know of are "only" rejecting valid programs, and thus the associated bug can be fixed backwards compatibly.)

    If someone knows of a case where an invalid program is accepted due to glob bugs, that would be much more severe.

  14. added this to the 1.0 milestone on Feb 12, 2015
  15. 4 remaining items

  16. modified the milestones: 1.1, 1.0 on Apr 2, 2015
  17. kali commented on May 3, 2015

    @kali
    Contributor

    I reached this point while reducing an issue, I think it is the same problem, and the testcase is somewhat simpler.

    pub mod a {
      use b::*;
    }
    
    pub mod b {
      use a::*;
    }
    
    use a::*;
    
    fn main() {
    }
  18. gbersac commented on May 3, 2015

    @gbersac

    Still apply. Spend two days getting mad because of this bug. Note that there is no need for the modules to reference each others directly :

    pub mod a {
        use b::fn_b;
        use c::*;
    
        pub fn fn_a(){
        }
    }
    
    pub mod b {
        use a::fn_a;
        use c::*;
    
        pub fn fn_b(){
        }
    }
    
    pub mod c{
        pub fn fn_c(){
        }
    }
    
    use a::fn_a;
    use b::fn_b;
    
    fn main() {
    }

    Here the star imports (mod::*) are not the modules themself, but another module, the module c.

  19. pnkfelix commented on May 15, 2015

    @pnkfelix
    Contributor

    @gbersac 's test case seems especially frustrating; as he noted, the reported error is for imports that are not glob imports, and yet for some reason the presence of the unrelated glob imports is causing the resolution of the circular non-glob imports to fail.

  20. removed this from the 1.1 milestone on May 21, 2015
  21. brson commented on Jun 12, 2015

    @brson
    Contributor

    The final case here is solved by #26242

  22. added a commit that references this issue on Mar 4, 2026
  23. added a commit that references this issue on Aug 21, 2026
    66e2266
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

    A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyP-mediumMedium priority

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions