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: Improve duplicate glob detection #32814

Merged
merged 4 commits into from
Apr 13, 2016

Conversation

jseyfried
Copy link
Contributor

This fixes a bug introduced in #31726 in which we erroneously allow multiple imports of the same item under some circumstances.

More specifically, we erroneously allow a module that is in a cycle of glob re-exports to have other re-exports (besides the glob from the cycle).
For example,

pub fn f() {}
mod foo {
    pub use f; // (1) This defines `foo::f`.
    pub use bar::*; // (3) This also defines `foo::f`, which should be a duplicate error but is currently allowed.
}
mod bar {
    pub use foo::*; // (2) This defines `bar::f`.
}

A module in a glob re-export cycle can still have pub items after this PR. For example,

mod foo {
    pub fn f() {}; // (1) This defines `foo::f`.
    pub use bar::*; // (3) This is not a duplicate error since items shadow glob-imported re-exports (cf #31337).
}
mod bar {
    pub use foo::*; // (2) This defines `bar::f`.
}

r? @nikomatsakis

@jseyfried
Copy link
Contributor Author

The bug isn't in beta yet, but it landed a month ago so it still might be a good idea to do a crater run.

@@ -275,7 +275,6 @@ impl<'a> ::ModuleS<'a> {
// Define the name or return the existing binding if there is a collision.
pub fn try_define_child(&self, name: Name, ns: Namespace, binding: NameBinding<'a>)
-> Result<(), &'a NameBinding<'a>> {
if self.resolutions.borrow_state() != ::std::cell::BorrowState::Unused { return Ok(()); }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This line was preventing the duplicate errors from being reported.

@jseyfried jseyfried mentioned this pull request Apr 11, 2016
@nikomatsakis
Copy link
Contributor

r=me w/ comments

@bors
Copy link
Contributor

bors commented Apr 11, 2016

📌 Commit c0b3bb9 has been approved by nikomatsakis

@jseyfried jseyfried force-pushed the improve_duplicate_glob_detection branch from c0b3bb9 to bc6daea Compare April 11, 2016 19:45
@jseyfried
Copy link
Contributor Author

@bors r=nikomatsakis

@bors
Copy link
Contributor

bors commented Apr 11, 2016

📌 Commit bc6daea has been approved by nikomatsakis

@bluss
Copy link
Member

bluss commented Apr 11, 2016

This needs backport if it wants to get in Rust 1.9 beta

@nikomatsakis nikomatsakis added the beta-nominated Nominated for backporting to the compiler in the beta channel. label Apr 12, 2016
@bors
Copy link
Contributor

bors commented Apr 13, 2016

⌛ Testing commit bc6daea with merge 4b71f8d...

bors added a commit that referenced this pull request Apr 13, 2016
…nikomatsakis

resolve: Improve duplicate glob detection

This fixes a bug introduced in #31726 in which we erroneously allow multiple imports of the same item under some circumstances.

More specifically, we erroneously allow a module that is in a cycle of glob re-exports to have other re-exports (besides the glob from the cycle).
For example,
```rust
pub fn f() {}
mod foo {
    pub use f; // (1) This defines `foo::f`.
    pub use bar::*; // (3) This also defines `foo::f`, which should be a duplicate error but is currently allowed.
}
mod bar {
    pub use foo::*; // (2) This defines `bar::f`.
}
```

A module in a glob re-export cycle can still have `pub` items after this PR. For example,
```rust
mod foo {
    pub fn f() {}; // (1) This defines `foo::f`.
    pub use bar::*; // (3) This is not a duplicate error since items shadow glob-imported re-exports (cf #31337).
}
mod bar {
    pub use foo::*; // (2) This defines `bar::f`.
}
```
r? @nikomatsakis
@bors bors merged commit bc6daea into rust-lang:master Apr 13, 2016
@nikomatsakis nikomatsakis added the beta-accepted Accepted for backporting to the compiler in the beta channel. label Apr 21, 2016
@nikomatsakis
Copy link
Contributor

Fixes a regression, small patch. Approved for beta.

@brson brson removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label May 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta-accepted Accepted for backporting to the compiler in the beta channel.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants