diff options
| author | bors <bors@rust-lang.org> | 2016-04-12 22:21:23 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2016-04-12 22:21:23 -0700 |
| commit | 4b71f8d1417423d933dfd4f74d5d4d167b85f77e (patch) | |
| tree | 0dbbc205324310a16be1d2e283f6e08146ea0651 /src/test | |
| parent | 7c27cce9e59bbbc1e556de257de85122dad88dcd (diff) | |
| parent | bc6daea2db6d5b5686e857b93c1f71a94268dddb (diff) | |
| download | rust-4b71f8d1417423d933dfd4f74d5d4d167b85f77e.tar.gz rust-4b71f8d1417423d933dfd4f74d5d4d167b85f77e.zip | |
Auto merge of #32814 - jseyfried:improve_duplicate_glob_detection, r=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
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/compile-fail/glob-cycles.rs | 26 | ||||
| -rw-r--r-- | src/test/compile-fail/issue-32797.rs | 21 |
2 files changed, 47 insertions, 0 deletions
diff --git a/src/test/compile-fail/glob-cycles.rs b/src/test/compile-fail/glob-cycles.rs new file mode 100644 index 00000000000..077ae19b4cb --- /dev/null +++ b/src/test/compile-fail/glob-cycles.rs @@ -0,0 +1,26 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +mod foo { + pub use bar::*; + pub use main as f; //~ ERROR has already been imported +} + +mod bar { + pub use foo::*; +} + +pub use foo::*; +pub use baz::*; //~ ERROR has already been imported +mod baz { + pub use super::*; +} + +pub fn main() {} diff --git a/src/test/compile-fail/issue-32797.rs b/src/test/compile-fail/issue-32797.rs new file mode 100644 index 00000000000..af75783a710 --- /dev/null +++ b/src/test/compile-fail/issue-32797.rs @@ -0,0 +1,21 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +pub use bar::*; +mod bar { + pub use super::*; +} + +pub use baz::*; //~ ERROR already been imported +mod baz { + pub use main as f; +} + +pub fn main() {} |
