@@ -34,10 +34,9 @@ use thin_vec::ThinVec;
3434use { rustc_ast as ast, rustc_hir as hir} ;
3535
3636pub ( crate ) use self :: ItemKind :: * ;
37- pub ( crate ) use self :: SelfTy :: * ;
3837pub ( crate ) use self :: Type :: {
3938 Array , BareFunction , BorrowedRef , DynTrait , Generic , ImplTrait , Infer , Primitive , QPath ,
40- RawPointer , Slice , Tuple ,
39+ RawPointer , SelfTy , Slice , Tuple ,
4140} ;
4241use crate :: clean:: cfg:: Cfg ;
4342use crate :: clean:: clean_middle_path;
@@ -1384,8 +1383,8 @@ pub(crate) struct FnDecl {
13841383}
13851384
13861385impl 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 ( ) )
13891388 }
13901389}
13911390
@@ -1403,27 +1402,9 @@ pub(crate) struct Argument {
14031402 pub ( crate ) is_const : bool ,
14041403}
14051404
1406- #[ derive( Clone , PartialEq , Debug ) ]
1407- pub ( crate ) enum SelfTy {
1408- SelfValue ,
1409- SelfBorrowed ( Option < Lifetime > , Mutability ) ,
1410- SelfExplicit ( Type ) ,
1411- }
1412-
14131405impl 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 }
14271408 }
14281409}
14291410
@@ -1477,6 +1458,8 @@ pub(crate) enum Type {
14771458 DynTrait ( Vec < PolyTrait > , Option < Lifetime > ) ,
14781459 /// A type parameter.
14791460 Generic ( Symbol ) ,
1461+ /// The `Self` type.
1462+ SelfTy ,
14801463 /// A primitive (aka, builtin) type.
14811464 Primitive ( PrimitiveType ) ,
14821465 /// A function pointer: `extern "ABI" fn(...) -> ...`
@@ -1571,6 +1554,8 @@ impl Type {
15711554 // If both sides are generic, this returns true.
15721555 ( _, Type :: Generic ( _) ) => true ,
15731556 ( Type :: Generic ( _) , _) => false ,
1557+ // `Self` only matches itself.
1558+ ( Type :: SelfTy , Type :: SelfTy ) => true ,
15741559 // Paths account for both the path itself and its generics.
15751560 ( Type :: Path { path : a } , Type :: Path { path : b } ) => {
15761561 a. def_id ( ) == b. def_id ( )
@@ -1642,7 +1627,7 @@ impl Type {
16421627
16431628 pub ( crate ) fn is_self_type ( & self ) -> bool {
16441629 match * self {
1645- Generic ( name ) => name == kw :: SelfUpper ,
1630+ SelfTy => true ,
16461631 _ => false ,
16471632 }
16481633 }
@@ -1700,7 +1685,7 @@ impl Type {
17001685 Type :: Pat ( ..) => PrimitiveType :: Pat ,
17011686 RawPointer ( ..) => PrimitiveType :: RawPointer ,
17021687 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 ,
17041689 } ;
17051690 Primitive ( t) . def_id ( cache)
17061691 }
0 commit comments