item_like_imports: Allow multiple glob imports of the same item.
This commit is contained in:
parent
245a0c5530
commit
f582fa327e
2 changed files with 53 additions and 5 deletions
|
@ -317,10 +317,17 @@ impl<'a> Resolver<'a> {
|
|||
where T: ToNameBinding<'a>
|
||||
{
|
||||
let binding = self.arenas.alloc_name_binding(binding.to_name_binding());
|
||||
self.update_resolution(module, name, ns, |_, resolution| {
|
||||
self.update_resolution(module, name, ns, |this, resolution| {
|
||||
if let Some(old_binding) = resolution.binding {
|
||||
if binding.is_glob_import() {
|
||||
if !this.new_import_semantics || !old_binding.is_glob_import() {
|
||||
resolution.duplicate_globs.push(binding);
|
||||
} else if binding.def() != old_binding.def() {
|
||||
resolution.duplicate_globs.push(binding);
|
||||
} else if !old_binding.vis.is_at_least(binding.vis, this) {
|
||||
// We are glob-importing the same item but with greater visibility.
|
||||
resolution.binding = Some(binding);
|
||||
}
|
||||
} else if old_binding.is_glob_import() {
|
||||
resolution.duplicate_globs.push(old_binding);
|
||||
resolution.binding = Some(binding);
|
||||
|
@ -344,14 +351,17 @@ impl<'a> Resolver<'a> {
|
|||
// during which the resolution might end up getting re-defined via a glob cycle.
|
||||
let (binding, t) = {
|
||||
let mut resolution = &mut *self.resolution(module, name, ns).borrow_mut();
|
||||
let was_known = resolution.binding().is_some();
|
||||
let old_binding = resolution.binding();
|
||||
|
||||
let t = f(self, resolution);
|
||||
|
||||
if was_known { return t; }
|
||||
match resolution.binding() {
|
||||
Some(binding) => (binding, t),
|
||||
_ if !self.new_import_semantics && old_binding.is_some() => return t,
|
||||
None => return t,
|
||||
Some(binding) => match old_binding {
|
||||
Some(old_binding) if old_binding as *const _ == binding as *const _ => return t,
|
||||
_ => (binding, t),
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
38
src/test/compile-fail/imports/duplicate.rs
Normal file
38
src/test/compile-fail/imports/duplicate.rs
Normal file
|
@ -0,0 +1,38 @@
|
|||
// 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.
|
||||
|
||||
#![feature(item_like_imports)]
|
||||
|
||||
mod a {
|
||||
pub fn foo() {}
|
||||
}
|
||||
|
||||
mod b {
|
||||
pub fn foo() {}
|
||||
}
|
||||
|
||||
mod c {
|
||||
pub use a::foo;
|
||||
}
|
||||
|
||||
mod d {
|
||||
use a::foo; //~ NOTE previous import
|
||||
use a::foo; //~ ERROR `foo` has already been imported
|
||||
//~| NOTE already imported
|
||||
}
|
||||
|
||||
mod e {
|
||||
pub use a::*;
|
||||
pub use c::*; // ok
|
||||
}
|
||||
|
||||
fn main() {
|
||||
e::foo();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue