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

Block import resolution only on 'pub' imports #27547

Merged
merged 5 commits into from
Aug 10, 2015

Conversation

elinorbgr
Copy link
Contributor

As noted in my previous PR #27439 , the import resolution algorithm has two cases where it bails out:

  • The algorithm will delay an import if the module containing the target of the import still has unresolved glob imports
  • The algorithm will delay a glob import of the target module still has unresolved imports

This PR alters the behaviour to only bail out when the above described unresolved imports are pub, as non-pub imports don't affect the result anyway.

It is still possible to fail the algorithm with examples like

pub mod a {
    pub use b::*;
}

pub mod b {
    pub use a::*;
}

but such configurations cannot be resolved in any meaningful way, as these are cyclic imports.

Closes #4865

When resolving 'use' statements, only consider pub imports of the
target module as blocking.

Closes rust-lang#4865
@rust-highfive
Copy link
Collaborator

r? @Aatch

(rust_highfive has picked a reviewer for you, use r? to override)

@elinorbgr elinorbgr changed the title More perseverant resolve Block import resolution only on 'pub' imports Aug 5, 2015
@elinorbgr
Copy link
Contributor Author

r? @nrc , cc @retep998

@rust-highfive rust-highfive assigned nrc and unassigned Aatch Aug 5, 2015
@nrc
Copy link
Member

nrc commented Aug 5, 2015

Does this change work in the case of non-public, but visible imports? (i.e., in a nested module). I think it does because glob imports only import public items, not visible ones.

Does this have a backwards compatibility hazard there? I.e., will this prevent us making globs import visible items in the future if we want to?

// except according to those terms.

pub mod a {
use b::*;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: indent

@elinorbgr
Copy link
Contributor Author

About visible items, yeah, there might be a compatibility hazard.

This change rely on the fact that item imported by non-pub use statements are not visible out of the module. This allows to not wait for these import to be resolved to continue, and avoid some deadlock-like situations in the resolution.

However, I will possibly make it harder to introduce help messages in a kind of "maybe you forgot to add pub before this import ?". But one could argue that the generic message "There is no foo in bar." is already quite a good hind about what is wrong.

I'll address your nits tomorrow, it's almost midnight for me. 😉

@elinorbgr
Copy link
Contributor Author

@nrc For the case of importing a module into itself, is it enough to just add an help message, like this:

error: unresolved import `self::*`. cannot glob-import a module into itself [E0432]

or should I make a specific error (and add en error code ?)

@nrc
Copy link
Member

nrc commented Aug 6, 2015

@vberger I don't think you can have different messages for the same error code. Probably the easiest thing to do is to add the extra detail as a note.

@elinorbgr
Copy link
Contributor Author

@nrc well, the error message E0432 already have several messages on it, but they all are a variation on "Unresolved import":

error: unresolved import `foo::bar`. Maybe a missing `extern crate foo`? [E0432]
error: unresolved import `foo::bar`. There is no `bar` in `foo`. [E0432]
...

The second half of the error message is actually fully-customizable, and I already have the code working to generate the message

error: unresolved import `self::*`. Cannot glob-import a module into itself. [E0432]

So, would that be fine ?

@elinorbgr
Copy link
Contributor Author

@nrc see my last commit for the implementation

@nrc
Copy link
Member

nrc commented Aug 9, 2015

The diagnostics stuff just checks the string literal, so if the second part is just {} in there then it can change however you like. Otherwise, it needs a different code.

@nrc
Copy link
Member

nrc commented Aug 9, 2015

lgtm, thanks for the changes!

@bors: r+

@bors
Copy link
Contributor

bors commented Aug 9, 2015

📌 Commit 5847ea7 has been approved by nrc

@bors
Copy link
Contributor

bors commented Aug 9, 2015

⌛ Testing commit 5847ea7 with merge 8d6a10d...

@bors
Copy link
Contributor

bors commented Aug 9, 2015

💔 Test failed - auto-linux-32-opt

@TimNN
Copy link
Contributor

TimNN commented Aug 10, 2015

Looks like #27619

@dotdash
Copy link
Contributor

dotdash commented Aug 10, 2015

@bors retry

bors added a commit that referenced this pull request Aug 10, 2015
As noted in my previous PR #27439 , the import resolution algorithm has two cases where it bails out:

- The algorithm will delay an import if the module containing the target of the import still has unresolved glob imports
- The algorithm will delay a glob import of the target module still has unresolved imports

This PR alters the behaviour to only bail out when the above described unresolved imports are `pub`, as non-pub imports don't affect the result anyway.

It is still possible to fail the algorithm with examples like
```rust
pub mod a {
    pub use b::*;
}

pub mod b {
    pub use a::*;
}
```
but such configurations cannot be resolved in any meaningful way, as these are cyclic imports.

Closes #4865
@bors
Copy link
Contributor

bors commented Aug 10, 2015

⌛ Testing commit 5847ea7 with merge 1db1417...

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 this pull request may close these issues.

Re-exporting items using a glob breaks if the module imports another module
7 participants