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 leaves import resolutions in an inconsistent state #31403

Closed
jseyfried opened this issue Feb 4, 2016 · 1 comment · Fixed by #31461
Closed

Resolve leaves import resolutions in an inconsistent state #31403

jseyfried opened this issue Feb 4, 2016 · 1 comment · Fixed by #31461

Comments

@jseyfried
Copy link
Contributor

For example,

mod foo {
    pub mod bar {} // This defines bar in the type namespace
    pub use alpha::bar; // This defines bar in the value namespace

    // This should define baz in both namespaces, but it only defines `baz` in the type namespace.
    pub use self::bar as baz;
    pub fn baz() {} // This should collide with the imported `baz`, but now it does not.
}

pub fn f() {}
mod alpha {
    pub use self::f as bar; // Changing this to `pub fn bar() {}` makes the imports consistent
    pub use super::*;
}

fn main() {
    foo::bar();
    foo::baz(); // This errors
}
@jseyfried jseyfried changed the title Resolves leaves import resolutions in an inconsistent state Resolve leaves import resolutions in an inconsistent state Feb 4, 2016
@jseyfried
Copy link
Contributor Author

This is caused by this code, which incorrectly reports that the import of bar as baz fails in the type namespace.

jseyfried referenced this issue in jseyfried/rust Feb 8, 2016
…valued map.

Refactor away resolve_name_in_module in resolve_imports.rs

Rewrite and improve the core name resolution procedure in NameResolution::result and Module::resolve_name

Refactor the duplicate checking code into NameResolution::try_define
bors added a commit that referenced this issue Feb 11, 2016
This PR adds to `NameBinding` so it can more fully represent bindings from imports as well from items, refactors away `Target`, generalizes `ImportResolution` to a simpler type `NameResolution`, and uses a single `NameResolution`-valued map in place the existing maps `children` and `import_resolutions` (of `NameBinding`s and `ImportResolution`s, respectively), simplifying duplicate checking and name resolution.

It also unifies the `resolve_name_in_module` in `lib.rs` with its namesake in `resolve_imports.rs`, clarifying and improving the core logic (fixes #31403 and fixes #31404) while maintaining clear future-comparability with shadowable globs (i.e., never reporting that a resolution is a `Success` or is `Failing` unless this would also be knowable with shadowable globs).

Since it fixes #31403, this is technically a [breaking-change], but it is exceedingly unlikely to cause breakage in practice. The following is an example of code that would break:
```rust
mod foo {
    pub mod bar {} // This defines bar in the type namespace
    pub use alpha::bar; // This defines bar in the value namespace

    // This should define baz in both namespaces, but it only defines baz in the type namespace.
    pub use self::bar as baz;
    pub fn baz() {} // This should collide with baz, but now it does not.
}

pub fn f() {}
mod alpha {
    pub use self::f as bar; // Changing this to `pub fn bar() {}` causes the collision right now.
    pub use super::*;
}
```

r? @nrc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant