@@ -63,7 +63,7 @@ use syntax::ast::{PolyTraitRef, PrimTy, Public, SelfExplicit, SelfStatic};
63
63
use syntax:: ast:: { RegionTyParamBound , StmtDecl , StructField } ;
64
64
use syntax:: ast:: { StructVariantKind , TraitRef , TraitTyParamBound } ;
65
65
use syntax:: ast:: { TupleVariantKind , Ty , TyBool , TyChar , TyClosure , TyF32 } ;
66
- use syntax:: ast:: { TyF64 , TyFloat , TyI , TyI8 , TyI16 , TyI32 , TyI64 , TyInt } ;
66
+ use syntax:: ast:: { TyF64 , TyFloat , TyI , TyI8 , TyI16 , TyI32 , TyI64 , TyInt , TyObjectSum } ;
67
67
use syntax:: ast:: { TyParam , TyParamBound , TyPath , TyPtr , TyPolyTraitRef , TyProc , TyQPath } ;
68
68
use syntax:: ast:: { TyRptr , TyStr , TyU , TyU8 , TyU16 , TyU32 , TyU64 , TyUint } ;
69
69
use syntax:: ast:: { TypeImplItem , UnnamedField } ;
@@ -1392,29 +1392,53 @@ impl<'a> Resolver<'a> {
1392
1392
// methods within to a new module, if the type was defined
1393
1393
// within this module.
1394
1394
1395
- // Create the module and add all methods.
1396
- match ty. node {
1397
- TyPath ( ref path, _, _) if path. segments . len ( ) == 1 => {
1395
+ let mod_name = match ty. node {
1396
+ TyPath ( ref path, _) if path. segments . len ( ) == 1 => {
1398
1397
// FIXME(18446) we should distinguish between the name of
1399
1398
// a trait and the name of an impl of that trait.
1400
- let mod_name = path. segments . last ( ) . unwrap ( ) . identifier . name ;
1399
+ Some ( path. segments . last ( ) . unwrap ( ) . identifier . name )
1400
+ }
1401
+ TyObjectSum ( ref lhs_ty, _) => {
1402
+ match lhs_ty. node {
1403
+ TyPath ( ref path, _) if path. segments . len ( ) == 1 => {
1404
+ Some ( path. segments . last ( ) . unwrap ( ) . identifier . name )
1405
+ }
1406
+ _ => {
1407
+ None
1408
+ }
1409
+ }
1410
+ }
1411
+ _ => {
1412
+ None
1413
+ }
1414
+ } ;
1401
1415
1416
+ match mod_name {
1417
+ None => {
1418
+ self . resolve_error ( ty. span ,
1419
+ "inherent implementations may \
1420
+ only be implemented in the same \
1421
+ module as the type they are \
1422
+ implemented for")
1423
+ }
1424
+ Some ( mod_name) => {
1425
+ // Create the module and add all methods.
1402
1426
let parent_opt = parent. module ( ) . children . borrow ( )
1403
- . get ( & mod_name) . cloned ( ) ;
1427
+ . get ( & mod_name) . cloned ( ) ;
1404
1428
let new_parent = match parent_opt {
1405
1429
// It already exists
1406
1430
Some ( ref child) if child. get_module_if_available ( )
1407
- . is_some ( ) &&
1408
- ( child. get_module ( ) . kind . get ( ) == ImplModuleKind ||
1409
- child. get_module ( ) . kind . get ( ) == TraitModuleKind ) => {
1410
- ModuleReducedGraphParent ( child. get_module ( ) )
1411
- }
1431
+ . is_some ( ) &&
1432
+ ( child. get_module ( ) . kind . get ( ) == ImplModuleKind ||
1433
+ child. get_module ( ) . kind . get ( ) == TraitModuleKind ) => {
1434
+ ModuleReducedGraphParent ( child. get_module ( ) )
1435
+ }
1412
1436
Some ( ref child) if child. get_module_if_available ( )
1413
- . is_some ( ) &&
1414
- child. get_module ( ) . kind . get ( ) ==
1415
- EnumModuleKind => {
1416
- ModuleReducedGraphParent ( child. get_module ( ) )
1417
- }
1437
+ . is_some ( ) &&
1438
+ child. get_module ( ) . kind . get ( ) ==
1439
+ EnumModuleKind => {
1440
+ ModuleReducedGraphParent ( child. get_module ( ) )
1441
+ }
1418
1442
// Create the module
1419
1443
_ => {
1420
1444
let name_bindings =
@@ -1429,7 +1453,7 @@ impl<'a> Resolver<'a> {
1429
1453
let ns = TypeNS ;
1430
1454
let is_public =
1431
1455
!name_bindings. defined_in_namespace ( ns) ||
1432
- name_bindings. defined_in_public_namespace ( ns) ;
1456
+ name_bindings. defined_in_public_namespace ( ns) ;
1433
1457
1434
1458
name_bindings. define_module ( parent_link,
1435
1459
Some ( def_id) ,
@@ -1455,21 +1479,21 @@ impl<'a> Resolver<'a> {
1455
1479
ForbidDuplicateValues ,
1456
1480
method. span ) ;
1457
1481
let def = match method. pe_explicit_self ( )
1458
- . node {
1459
- SelfStatic => {
1460
- // Static methods become
1461
- // `DefStaticMethod`s.
1462
- DefStaticMethod ( local_def ( method. id ) ,
1463
- FromImpl ( local_def ( item. id ) ) )
1464
- }
1465
- _ => {
1466
- // Non-static methods become
1467
- // `DefMethod`s.
1468
- DefMethod ( local_def ( method. id ) ,
1469
- None ,
1470
- FromImpl ( local_def ( item. id ) ) )
1471
- }
1472
- } ;
1482
+ . node {
1483
+ SelfStatic => {
1484
+ // Static methods become
1485
+ // `DefStaticMethod`s.
1486
+ DefStaticMethod ( local_def ( method. id ) ,
1487
+ FromImpl ( local_def ( item. id ) ) )
1488
+ }
1489
+ _ => {
1490
+ // Non-static methods become
1491
+ // `DefMethod`s.
1492
+ DefMethod ( local_def ( method. id ) ,
1493
+ None ,
1494
+ FromImpl ( local_def ( item. id ) ) )
1495
+ }
1496
+ } ;
1473
1497
1474
1498
// NB: not IMPORTABLE
1475
1499
let modifiers = if method. pe_vis ( ) == ast:: Public {
@@ -1492,7 +1516,7 @@ impl<'a> Resolver<'a> {
1492
1516
ForbidDuplicateTypesAndModules ,
1493
1517
typedef. span ) ;
1494
1518
let def = DefAssociatedTy ( local_def (
1495
- typedef. id ) ) ;
1519
+ typedef. id ) ) ;
1496
1520
// NB: not IMPORTABLE
1497
1521
let modifiers = if typedef. vis == ast:: Public {
1498
1522
PUBLIC
@@ -1507,13 +1531,6 @@ impl<'a> Resolver<'a> {
1507
1531
}
1508
1532
}
1509
1533
}
1510
- _ => {
1511
- self . resolve_error ( ty. span ,
1512
- "inherent implementations may \
1513
- only be implemented in the same \
1514
- module as the type they are \
1515
- implemented for")
1516
- }
1517
1534
}
1518
1535
1519
1536
parent
@@ -4721,7 +4738,7 @@ impl<'a> Resolver<'a> {
4721
4738
// type, the result will be that the type name resolves to a module but not
4722
4739
// a type (shadowing any imported modules or types with this name), leading
4723
4740
// to weird user-visible bugs. So we ward this off here. See #15060.
4724
- TyPath ( ref path, _ , path_id) => {
4741
+ TyPath ( ref path, path_id) => {
4725
4742
match self . def_map . borrow ( ) . get ( & path_id) {
4726
4743
// FIXME: should we catch other options and give more precise errors?
4727
4744
Some ( & DefMod ( _) ) => {
@@ -4887,7 +4904,7 @@ impl<'a> Resolver<'a> {
4887
4904
// Like path expressions, the interpretation of path types depends
4888
4905
// on whether the path has multiple elements in it or not.
4889
4906
4890
- TyPath ( ref path, ref bounds , path_id) => {
4907
+ TyPath ( ref path, path_id) => {
4891
4908
// This is a path in the type namespace. Walk through scopes
4892
4909
// looking for it.
4893
4910
let mut result_def = None ;
@@ -4957,11 +4974,12 @@ impl<'a> Resolver<'a> {
4957
4974
self . resolve_error ( ty. span , msg. as_slice ( ) ) ;
4958
4975
}
4959
4976
}
4977
+ }
4960
4978
4961
- bounds. as_ref ( ) . map ( |bound_vec| {
4962
- self . resolve_type_parameter_bounds ( ty. id , bound_vec,
4979
+ TyObjectSum ( ref ty, ref bound_vec) => {
4980
+ self . resolve_type ( & * * ty) ;
4981
+ self . resolve_type_parameter_bounds ( ty. id , bound_vec,
4963
4982
TraitBoundingTypeParameter ) ;
4964
- } ) ;
4965
4983
}
4966
4984
4967
4985
TyQPath ( ref qpath) => {
@@ -5598,7 +5616,7 @@ impl<'a> Resolver<'a> {
5598
5616
fn extract_path_and_node_id ( t : & Ty , allow : FallbackChecks )
5599
5617
-> Option < ( Path , NodeId , FallbackChecks ) > {
5600
5618
match t. node {
5601
- TyPath ( ref path, _ , node_id) => Some ( ( path. clone ( ) , node_id, allow) ) ,
5619
+ TyPath ( ref path, node_id) => Some ( ( path. clone ( ) , node_id, allow) ) ,
5602
5620
TyPtr ( ref mut_ty) => extract_path_and_node_id ( & * mut_ty. ty , OnlyTraitAndStatics ) ,
5603
5621
TyRptr ( _, ref mut_ty) => extract_path_and_node_id ( & * mut_ty. ty , allow) ,
5604
5622
// This doesn't handle the remaining `Ty` variants as they are not
0 commit comments