Skip to content

Commit b2b4c79

Browse files
committed
resolve -- rewrite conflict closure into method
1 parent 949e1c7 commit b2b4c79

File tree

1 file changed

+50
-41
lines changed

1 file changed

+50
-41
lines changed

src/librustc/middle/resolve.rs

Lines changed: 50 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2567,52 +2567,15 @@ impl Resolver {
25672567
}
25682568
}
25692569

2570-
let merge_import_resolution = |name, name_bindings: @NameBindings| {
2571-
let dest_import_resolution;
2572-
let mut import_resolutions = module_.import_resolutions
2573-
.borrow_mut();
2574-
match import_resolutions.get().find(&name) {
2575-
None => {
2576-
// Create a new import resolution from this child.
2577-
dest_import_resolution =
2578-
@ImportResolution::new(id, is_public);
2579-
import_resolutions.get().insert(name,
2580-
dest_import_resolution);
2581-
}
2582-
Some(&existing_import_resolution) => {
2583-
dest_import_resolution = existing_import_resolution;
2584-
}
2585-
}
2586-
2587-
debug!("(resolving glob import) writing resolution `{}` in `{}` \
2588-
to `{}`",
2589-
token::get_ident(name).get().to_str(),
2590-
self.module_to_str(containing_module),
2591-
self.module_to_str(module_));
2592-
2593-
// Merge the child item into the import resolution.
2594-
if name_bindings.defined_in_public_namespace(ValueNS) {
2595-
debug!("(resolving glob import) ... for value target");
2596-
dest_import_resolution.value_target.set(
2597-
Some(Target::new(containing_module, name_bindings)));
2598-
dest_import_resolution.value_id.set(id);
2599-
}
2600-
if name_bindings.defined_in_public_namespace(TypeNS) {
2601-
debug!("(resolving glob import) ... for type target");
2602-
dest_import_resolution.type_target.set(
2603-
Some(Target::new(containing_module, name_bindings)));
2604-
dest_import_resolution.type_id.set(id);
2605-
}
2606-
dest_import_resolution.is_public.set(is_public);
2607-
};
2608-
26092570
// Add all children from the containing module.
26102571
self.populate_module_if_necessary(containing_module);
26112572

26122573
{
26132574
let children = containing_module.children.borrow();
26142575
for (&name, name_bindings) in children.get().iter() {
2615-
merge_import_resolution(name, *name_bindings);
2576+
self.merge_import_resolution(module_, containing_module,
2577+
id, is_public,
2578+
name, *name_bindings);
26162579
}
26172580
}
26182581

@@ -2623,7 +2586,9 @@ impl Resolver {
26232586
for (&name, module) in external_module_children.get().iter() {
26242587
let name_bindings =
26252588
@Resolver::create_name_bindings_from_module(*module);
2626-
merge_import_resolution(name, name_bindings);
2589+
self.merge_import_resolution(module_, containing_module,
2590+
id, is_public,
2591+
name, name_bindings);
26272592
}
26282593
}
26292594

@@ -2641,6 +2606,50 @@ impl Resolver {
26412606
return Success(());
26422607
}
26432608

2609+
fn merge_import_resolution(&mut self,
2610+
module_: @Module,
2611+
containing_module: @Module,
2612+
id: NodeId,
2613+
is_public: bool,
2614+
name: Name,
2615+
name_bindings: @NameBindings) {
2616+
let dest_import_resolution;
2617+
let mut import_resolutions = module_.import_resolutions.borrow_mut();
2618+
match import_resolutions.get().find(&name) {
2619+
None => {
2620+
// Create a new import resolution from this child.
2621+
dest_import_resolution =
2622+
@ImportResolution::new(id, is_public);
2623+
import_resolutions.get().insert(name,
2624+
dest_import_resolution);
2625+
}
2626+
Some(&existing_import_resolution) => {
2627+
dest_import_resolution = existing_import_resolution;
2628+
}
2629+
}
2630+
2631+
debug!("(resolving glob import) writing resolution `{}` in `{}` \
2632+
to `{}`",
2633+
token::get_ident(name).get().to_str(),
2634+
self.module_to_str(containing_module),
2635+
self.module_to_str(module_));
2636+
2637+
// Merge the child item into the import resolution.
2638+
if name_bindings.defined_in_public_namespace(ValueNS) {
2639+
debug!("(resolving glob import) ... for value target");
2640+
dest_import_resolution.value_target.set(
2641+
Some(Target::new(containing_module, name_bindings)));
2642+
dest_import_resolution.value_id.set(id);
2643+
}
2644+
if name_bindings.defined_in_public_namespace(TypeNS) {
2645+
debug!("(resolving glob import) ... for type target");
2646+
dest_import_resolution.type_target.set(
2647+
Some(Target::new(containing_module, name_bindings)));
2648+
dest_import_resolution.type_id.set(id);
2649+
}
2650+
dest_import_resolution.is_public.set(is_public);
2651+
}
2652+
26442653
/// Resolves the given module path from the given root `module_`.
26452654
fn resolve_module_path_from_root(&mut self,
26462655
module_: @Module,

0 commit comments

Comments
 (0)