Skip to content

Commit 618558a

Browse files
committed
librustc: Allow adding static fn's in multiple impl's.
1 parent 88c318d commit 618558a

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

src/librustc/middle/resolve.rs

Lines changed: 27 additions & 17 deletions
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| {

0 commit comments

Comments
 (0)