Skip to content

Commit 9bcf911

Browse files
committed
auto merge of #7029 : luqmana/rust/issue-4228, r=catamorphism
Fixes #4228
2 parents 94f72dd + 0bf6d9e commit 9bcf911

File tree

2 files changed

+50
-17
lines changed

2 files changed

+50
-17
lines changed

src/librustc/middle/resolve.rs

+27-17
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ pub enum ParentLink {
409409
}
410410

411411
/// The type of module this is.
412+
#[deriving(Eq)]
412413
pub enum ModuleKind {
413414
NormalModuleKind,
414415
ExternModuleKind,
@@ -1228,25 +1229,34 @@ impl Resolver {
12281229
match (trait_ref_opt, ty) {
12291230
(None, @Ty { node: ty_path(path, _), _ }) if
12301231
has_static_methods && path.idents.len() == 1 => {
1231-
// Create the module.
12321232
let name = path_to_ident(path);
1233-
let (name_bindings, new_parent) =
1234-
self.add_child(name,
1235-
parent,
1236-
ForbidDuplicateModules,
1237-
sp);
1238-
1239-
let parent_link = self.get_parent_link(new_parent,
1240-
ident);
1241-
let def_id = local_def(item.id);
1242-
name_bindings.define_module(Public,
1243-
parent_link,
1244-
Some(def_id),
1245-
ImplModuleKind,
1246-
sp);
12471233

1248-
let new_parent = ModuleReducedGraphParent(
1249-
name_bindings.get_module());
1234+
let new_parent = match parent.children.find(&name) {
1235+
// It already exists
1236+
Some(&child) if child.get_module_if_available().is_some() &&
1237+
child.get_module().kind == ImplModuleKind => {
1238+
ModuleReducedGraphParent(child.get_module())
1239+
}
1240+
// Create the module
1241+
_ => {
1242+
let (name_bindings, new_parent) =
1243+
self.add_child(name,
1244+
parent,
1245+
ForbidDuplicateModules,
1246+
sp);
1247+
1248+
let parent_link = self.get_parent_link(new_parent,
1249+
ident);
1250+
let def_id = local_def(item.id);
1251+
name_bindings.define_module(Public,
1252+
parent_link,
1253+
Some(def_id),
1254+
ImplModuleKind,
1255+
sp);
1256+
1257+
ModuleReducedGraphParent(name_bindings.get_module())
1258+
}
1259+
};
12501260

12511261
// For each static method...
12521262
for methods.each |method| {

src/test/run-pass/issue-4228.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
struct Foo;
12+
13+
impl Foo {
14+
fn first() {}
15+
}
16+
impl Foo {
17+
fn second() {}
18+
}
19+
20+
pub fn main() {
21+
Foo::first();
22+
Foo::second();
23+
}

0 commit comments

Comments
 (0)