Skip to content
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

Resolve: an unresolved glob needlessly halts imports resolution progress #31444

Closed
jseyfried opened this issue Feb 6, 2016 · 1 comment
Closed
Labels
A-resolve Area: Name/path resolution done by `rustc_resolve` specifically

Comments

@jseyfried
Copy link
Contributor

Example:

mod foo {
    pub mod bar {}
    pub use self::bar as baz; // This cannot be resolved because of the glob
    pub use self::baz::*;
}

EDIT: Another more realistic example:

mod foo {
    pub mod bar {}
    pub use baz::bar::*;
}

mod baz {
    pub use foo::bar;
}

Without the glob, they resolve.

@jseyfried
Copy link
Contributor Author

Also, adding a function bar to foo allows it to resolve (EDIT: in both cases), for example:

mod foo {
    pub fn bar() {}
    pub mod bar {}
    pub use self::bar as baz; // Now this resolves
    pub use self::baz::*;
}

@steveklabnik steveklabnik added the A-resolve Area: Name/path resolution done by `rustc_resolve` specifically label Feb 8, 2016
bors added a commit that referenced this issue Mar 5, 2016
…sakis

This PR improves the import resolution algorithm.

First, it records that an import succeeded or failed for one namespace (by calling `decrement_outstanding_references_for` and `try_define_child` if successful) even if it is still indeterminate in the other namespace, fixing #31444.

Second, it starts importing bindings from globs as soon as the glob path is determined.
It maintains links from imported modules to their importers so that when a resolution becomes successful in an imported module, a corresponding binding will be added to the importer module.
It also maintains links from importer modules to imported modules so that we can determine if an undefined name is indeterminate or failing by recursively checking this in the imported modules.
This allows, for example:
```rust
mod foo {
    pub mod baz {}
    pub use bar::baz::*;
}

mod bar {
    pub use foo::*;
}
```
It also allows cycles of pub glob imports, although by to the current shadowing rules, the only way for such a cycle to compile is if each participating module defines no names. Incidentally, this PR lays the groundwork for more permissive feature-gated shadowing rules.

Finally, this PR encapsulates almost all implementation details of import resolution in `resolve_imports` (some of which used to be in `lib.rs`) and refactors reexport recording, shadowed trait collecting, some duplicate checking, and the `private_in_public` lint out of the core import resolution algorithm and into a post-processing pass in `resolve_imports`.

r? @nrc
@bors bors closed this as completed in 064f17c Mar 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-resolve Area: Name/path resolution done by `rustc_resolve` specifically
Projects
None yet
Development

No branches or pull requests

2 participants