@@ -412,118 +412,118 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
412
412
}
413
413
};
414
414
415
- match mod_name {
415
+ let mod_name = match mod_name {
416
+ Some(mod_name) => mod_name,
416
417
None => {
417
418
self.resolve_error(ty.span,
418
419
"inherent implementations may \
419
420
only be implemented in the same \
420
421
module as the type they are \
421
- implemented for")
422
+ implemented for");
423
+ return parent.clone();
422
424
}
423
- Some(mod_name) => {
424
- // Create the module and add all methods.
425
- let parent_opt = parent.children.borrow().get(&mod_name).cloned();
426
- let new_parent = match parent_opt {
427
- // It already exists
428
- Some(ref child) if child.get_module_if_available()
429
- .is_some() &&
430
- (child.get_module().kind.get() == ImplModuleKind ||
431
- child.get_module().kind.get() == TraitModuleKind) => {
432
- child.get_module()
433
- }
434
- Some(ref child) if child.get_module_if_available()
435
- .is_some() &&
436
- child.get_module().kind.get() ==
437
- EnumModuleKind => child.get_module(),
438
- // Create the module
439
- _ => {
440
- let name_bindings =
441
- self.add_child(mod_name, parent, ForbidDuplicateModules, sp);
442
-
443
- let parent_link = self.get_parent_link(parent, name);
444
- let def_id = local_def(item.id);
445
- let ns = TypeNS;
446
- let is_public =
447
- !name_bindings.defined_in_namespace(ns) ||
448
- name_bindings.defined_in_public_namespace(ns);
449
-
450
- name_bindings.define_module(parent_link,
451
- Some(def_id),
452
- ImplModuleKind,
453
- false,
454
- is_public,
455
- sp);
456
-
457
- name_bindings.get_module()
458
- }
459
- };
425
+ };
460
426
461
- // For each implementation item...
462
- for impl_item in impl_items.iter() {
463
- match *impl_item {
464
- MethodImplItem(ref method) => {
465
- // Add the method to the module.
466
- let name = method.pe_ident().name;
467
- let method_name_bindings =
468
- self.add_child(name,
469
- &new_parent,
470
- ForbidDuplicateValues,
471
- method.span);
472
- let def = match method.pe_explicit_self()
473
- .node {
474
- SelfStatic => {
475
- // Static methods become
476
- // `DefStaticMethod`s.
477
- DefStaticMethod(local_def(method.id),
478
- FromImpl(local_def(item.id)))
479
- }
480
- _ => {
481
- // Non-static methods become
482
- // `DefMethod`s.
483
- DefMethod(local_def(method.id),
484
- None,
485
- FromImpl(local_def(item.id)))
486
- }
487
- };
427
+ // Create the module and add all methods.
428
+ let parent_opt = parent.children.borrow().get(&mod_name).cloned();
429
+ let new_parent = match parent_opt {
430
+ // It already exists
431
+ Some(ref child) if child.get_module_if_available()
432
+ .is_some() &&
433
+ (child.get_module().kind.get() == ImplModuleKind ||
434
+ child.get_module().kind.get() == TraitModuleKind) => {
435
+ child.get_module()
436
+ }
437
+ Some(ref child) if child.get_module_if_available()
438
+ .is_some() &&
439
+ child.get_module().kind.get() ==
440
+ EnumModuleKind => child.get_module(),
441
+ // Create the module
442
+ _ => {
443
+ let name_bindings =
444
+ self.add_child(mod_name, parent, ForbidDuplicateModules, sp);
445
+
446
+ let parent_link = self.get_parent_link(parent, name);
447
+ let def_id = local_def(item.id);
448
+ let ns = TypeNS;
449
+ let is_public =
450
+ !name_bindings.defined_in_namespace(ns) ||
451
+ name_bindings.defined_in_public_namespace(ns);
452
+
453
+ name_bindings.define_module(parent_link,
454
+ Some(def_id),
455
+ ImplModuleKind,
456
+ false,
457
+ is_public,
458
+ sp);
488
459
489
- // NB: not IMPORTABLE
490
- let modifiers = if method.pe_vis() == ast::Public {
491
- PUBLIC
492
- } else {
493
- DefModifiers::empty()
494
- };
495
- method_name_bindings.define_value(
496
- def,
497
- method.span,
498
- modifiers);
499
- }
500
- TypeImplItem(ref typedef) => {
501
- // Add the typedef to the module.
502
- let name = typedef.ident.name;
503
- let typedef_name_bindings =
504
- self.add_child(
505
- name,
506
- &new_parent,
507
- ForbidDuplicateTypesAndModules,
508
- typedef.span);
509
- let def = DefAssociatedTy(local_def(
510
- typedef.id));
511
- // NB: not IMPORTABLE
512
- let modifiers = if typedef.vis == ast::Public {
513
- PUBLIC
514
- } else {
515
- DefModifiers::empty()
516
- };
517
- typedef_name_bindings.define_type(
518
- def,
519
- typedef.span,
520
- modifiers);
521
- }
522
- }
460
+ name_bindings.get_module()
461
+ }
462
+ };
463
+
464
+ // For each implementation item...
465
+ for impl_item in impl_items.iter() {
466
+ match *impl_item {
467
+ MethodImplItem(ref method) => {
468
+ // Add the method to the module.
469
+ let name = method.pe_ident().name;
470
+ let method_name_bindings =
471
+ self.add_child(name,
472
+ &new_parent,
473
+ ForbidDuplicateValues,
474
+ method.span);
475
+ let def = match method.pe_explicit_self()
476
+ .node {
477
+ SelfStatic => {
478
+ // Static methods become
479
+ // `DefStaticMethod`s.
480
+ DefStaticMethod(local_def(method.id),
481
+ FromImpl(local_def(item.id)))
482
+ }
483
+ _ => {
484
+ // Non-static methods become
485
+ // `DefMethod`s.
486
+ DefMethod(local_def(method.id),
487
+ None,
488
+ FromImpl(local_def(item.id)))
489
+ }
490
+ };
491
+
492
+ // NB: not IMPORTABLE
493
+ let modifiers = if method.pe_vis() == ast::Public {
494
+ PUBLIC
495
+ } else {
496
+ DefModifiers::empty()
497
+ };
498
+ method_name_bindings.define_value(
499
+ def,
500
+ method.span,
501
+ modifiers);
502
+ }
503
+ TypeImplItem(ref typedef) => {
504
+ // Add the typedef to the module.
505
+ let name = typedef.ident.name;
506
+ let typedef_name_bindings =
507
+ self.add_child(
508
+ name,
509
+ &new_parent,
510
+ ForbidDuplicateTypesAndModules,
511
+ typedef.span);
512
+ let def = DefAssociatedTy(local_def(
513
+ typedef.id));
514
+ // NB: not IMPORTABLE
515
+ let modifiers = if typedef.vis == ast::Public {
516
+ PUBLIC
517
+ } else {
518
+ DefModifiers::empty()
519
+ };
520
+ typedef_name_bindings.define_type(
521
+ def,
522
+ typedef.span,
523
+ modifiers);
523
524
}
524
525
}
525
526
}
526
-
527
527
parent.clone()
528
528
}
529
529
0 commit comments