Skip to content

Glob importing causes unrelated compiler error #19179

Closed
@dylanmckay

Description

@dylanmckay

When using globs to import everything from a module where the module itself imports things from the global namespace causes an error:

error: unresolved import
...
error: unresolved import (maybe you meant `std::*`?)

That is to say, if some_mod.rs glob imports other_mod and other_mod imports something from :: (say, std), the module cannot be found. If the glob import is replaced by manually importing every type, compilation succeeds.

The error occurs on the line in the imported module that tries to import the module.

Test Case (link to Playpen):

#![feature(globs)]

// Import everything from `test_module`
// This causes an error.
use self::test_module::*;

// Import what we want from `test_module`
// This succeeds.
// TODO: uncomment this line
//use self::test_module::Dummy;


mod test_module
{
    // Fails on this line, but only if `test_module` is glob imported.
    // Compilation is successful if globs are not used.
    use std;

    pub struct Dummy;
}

fn main() { }

Several months ago when I started learning Rust, this was actually the error that made modules so confusing to me in the beginning - I couldn't understand why sometimes (apparently when I used globs) I couldn't import std but instead I had to import every function and trait I wanted to use into my module's namespace.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-resolveArea: Name/path resolution done by `rustc_resolve` specifically

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions