diff options
| author | bors <bors@rust-lang.org> | 2013-06-09 14:46:24 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-06-09 14:46:24 -0700 |
| commit | 9bcf9119d86d0484b48e7a5efb7aefee88e11134 (patch) | |
| tree | f943bf1cc0918bc5637ef5d3ed05b5cd1c7d00d8 | |
| parent | 94f72dd73699701d7354e16950b9a547e11e015b (diff) | |
| parent | 0bf6d9e9ef0140bdf30ab7814bfac1e6f5157335 (diff) | |
| download | rust-9bcf9119d86d0484b48e7a5efb7aefee88e11134.tar.gz rust-9bcf9119d86d0484b48e7a5efb7aefee88e11134.zip | |
auto merge of #7029 : luqmana/rust/issue-4228, r=catamorphism
Fixes #4228
| -rw-r--r-- | src/librustc/middle/resolve.rs | 44 | ||||
| -rw-r--r-- | src/test/run-pass/issue-4228.rs | 23 |
2 files changed, 50 insertions, 17 deletions
diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 184ed441694..ec821ab2c71 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -409,6 +409,7 @@ pub enum ParentLink { } /// The type of module this is. +#[deriving(Eq)] pub enum ModuleKind { NormalModuleKind, ExternModuleKind, @@ -1228,25 +1229,34 @@ impl Resolver { match (trait_ref_opt, ty) { (None, @Ty { node: ty_path(path, _), _ }) if has_static_methods && path.idents.len() == 1 => { - // Create the module. let name = path_to_ident(path); - let (name_bindings, new_parent) = - self.add_child(name, - parent, - ForbidDuplicateModules, - sp); - - let parent_link = self.get_parent_link(new_parent, - ident); - let def_id = local_def(item.id); - name_bindings.define_module(Public, - parent_link, - Some(def_id), - ImplModuleKind, - sp); - let new_parent = ModuleReducedGraphParent( - name_bindings.get_module()); + let new_parent = match parent.children.find(&name) { + // It already exists + Some(&child) if child.get_module_if_available().is_some() && + child.get_module().kind == ImplModuleKind => { + ModuleReducedGraphParent(child.get_module()) + } + // Create the module + _ => { + let (name_bindings, new_parent) = + self.add_child(name, + parent, + ForbidDuplicateModules, + sp); + + let parent_link = self.get_parent_link(new_parent, + ident); + let def_id = local_def(item.id); + name_bindings.define_module(Public, + parent_link, + Some(def_id), + ImplModuleKind, + sp); + + ModuleReducedGraphParent(name_bindings.get_module()) + } + }; // For each static method... for methods.each |method| { diff --git a/src/test/run-pass/issue-4228.rs b/src/test/run-pass/issue-4228.rs new file mode 100644 index 00000000000..8cae8dd7915 --- /dev/null +++ b/src/test/run-pass/issue-4228.rs @@ -0,0 +1,23 @@ +// Copyright 2013 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. + +struct Foo; + +impl Foo { + fn first() {} +} +impl Foo { + fn second() {} +} + +pub fn main() { + Foo::first(); + Foo::second(); +} |
