@@ -34,10 +34,9 @@ use thin_vec::ThinVec;
34
34
use { rustc_ast as ast, rustc_hir as hir} ;
35
35
36
36
pub ( crate ) use self :: ItemKind :: * ;
37
- pub ( crate ) use self :: SelfTy :: * ;
38
37
pub ( crate ) use self :: Type :: {
39
38
Array , BareFunction , BorrowedRef , DynTrait , Generic , ImplTrait , Infer , Primitive , QPath ,
40
- RawPointer , Slice , Tuple ,
39
+ RawPointer , SelfTy , Slice , Tuple ,
41
40
} ;
42
41
use crate :: clean:: cfg:: Cfg ;
43
42
use crate :: clean:: clean_middle_path;
@@ -1384,8 +1383,8 @@ pub(crate) struct FnDecl {
1384
1383
}
1385
1384
1386
1385
impl FnDecl {
1387
- pub ( crate ) fn self_type ( & self ) -> Option < SelfTy > {
1388
- self . inputs . values . get ( 0 ) . and_then ( |v| v. to_self ( ) )
1386
+ pub ( crate ) fn receiver_type ( & self ) -> Option < & Type > {
1387
+ self . inputs . values . get ( 0 ) . and_then ( |v| v. to_receiver ( ) )
1389
1388
}
1390
1389
}
1391
1390
@@ -1403,27 +1402,9 @@ pub(crate) struct Argument {
1403
1402
pub ( crate ) is_const : bool ,
1404
1403
}
1405
1404
1406
- #[ derive( Clone , PartialEq , Debug ) ]
1407
- pub ( crate ) enum SelfTy {
1408
- SelfValue ,
1409
- SelfBorrowed ( Option < Lifetime > , Mutability ) ,
1410
- SelfExplicit ( Type ) ,
1411
- }
1412
-
1413
1405
impl Argument {
1414
- pub ( crate ) fn to_self ( & self ) -> Option < SelfTy > {
1415
- if self . name != kw:: SelfLower {
1416
- return None ;
1417
- }
1418
- if self . type_ . is_self_type ( ) {
1419
- return Some ( SelfValue ) ;
1420
- }
1421
- match self . type_ {
1422
- BorrowedRef { ref lifetime, mutability, ref type_ } if type_. is_self_type ( ) => {
1423
- Some ( SelfBorrowed ( lifetime. clone ( ) , mutability) )
1424
- }
1425
- _ => Some ( SelfExplicit ( self . type_ . clone ( ) ) ) ,
1426
- }
1406
+ pub ( crate ) fn to_receiver ( & self ) -> Option < & Type > {
1407
+ if self . name == kw:: SelfLower { Some ( & self . type_ ) } else { None }
1427
1408
}
1428
1409
}
1429
1410
@@ -1477,6 +1458,8 @@ pub(crate) enum Type {
1477
1458
DynTrait ( Vec < PolyTrait > , Option < Lifetime > ) ,
1478
1459
/// A type parameter.
1479
1460
Generic ( Symbol ) ,
1461
+ /// The `Self` type.
1462
+ SelfTy ,
1480
1463
/// A primitive (aka, builtin) type.
1481
1464
Primitive ( PrimitiveType ) ,
1482
1465
/// A function pointer: `extern "ABI" fn(...) -> ...`
@@ -1571,6 +1554,8 @@ impl Type {
1571
1554
// If both sides are generic, this returns true.
1572
1555
( _, Type :: Generic ( _) ) => true ,
1573
1556
( Type :: Generic ( _) , _) => false ,
1557
+ // `Self` only matches itself.
1558
+ ( Type :: SelfTy , Type :: SelfTy ) => true ,
1574
1559
// Paths account for both the path itself and its generics.
1575
1560
( Type :: Path { path : a } , Type :: Path { path : b } ) => {
1576
1561
a. def_id ( ) == b. def_id ( )
@@ -1642,7 +1627,7 @@ impl Type {
1642
1627
1643
1628
pub ( crate ) fn is_self_type ( & self ) -> bool {
1644
1629
match * self {
1645
- Generic ( name ) => name == kw :: SelfUpper ,
1630
+ SelfTy => true ,
1646
1631
_ => false ,
1647
1632
}
1648
1633
}
@@ -1700,7 +1685,7 @@ impl Type {
1700
1685
Type :: Pat ( ..) => PrimitiveType :: Pat ,
1701
1686
RawPointer ( ..) => PrimitiveType :: RawPointer ,
1702
1687
QPath ( box QPathData { ref self_type, .. } ) => return self_type. def_id ( cache) ,
1703
- Generic ( _) | Infer | ImplTrait ( _) => return None ,
1688
+ Generic ( _) | SelfTy | Infer | ImplTrait ( _) => return None ,
1704
1689
} ;
1705
1690
Primitive ( t) . def_id ( cache)
1706
1691
}
0 commit comments