@@ -42,7 +42,6 @@ use crate::formats::item_type::ItemType;
4242use crate :: html:: render:: Context ;
4343use crate :: passes:: collect_intra_doc_links:: UrlFragment ;
4444
45- pub ( crate ) use self :: FnRetTy :: * ;
4645pub ( crate ) use self :: ItemKind :: * ;
4746pub ( crate ) use self :: SelfTy :: * ;
4847pub ( crate ) use self :: Type :: {
@@ -1353,7 +1352,7 @@ pub(crate) struct Function {
13531352#[ derive( Clone , PartialEq , Eq , Debug , Hash ) ]
13541353pub ( crate ) struct FnDecl {
13551354 pub ( crate ) inputs : Arguments ,
1356- pub ( crate ) output : FnRetTy ,
1355+ pub ( crate ) output : Type ,
13571356 pub ( crate ) c_variadic : bool ,
13581357}
13591358
@@ -1371,18 +1370,16 @@ impl FnDecl {
13711370 ///
13721371 /// This function will panic if the return type does not match the expected sugaring for async
13731372 /// functions.
1374- pub ( crate ) fn sugared_async_return_type ( & self ) -> FnRetTy {
1375- match & self . output {
1376- FnRetTy :: Return ( Type :: ImplTrait ( bounds) ) => match & bounds[ 0 ] {
1377- GenericBound :: TraitBound ( PolyTrait { trait_, .. } , ..) => {
1378- let bindings = trait_. bindings ( ) . unwrap ( ) ;
1379- let ret_ty = bindings[ 0 ] . term ( ) ;
1380- let ty = ret_ty. ty ( ) . expect ( "Unexpected constant return term" ) ;
1381- FnRetTy :: Return ( ty. clone ( ) )
1382- }
1383- _ => panic ! ( "unexpected desugaring of async function" ) ,
1384- } ,
1385- _ => panic ! ( "unexpected desugaring of async function" ) ,
1373+ pub ( crate ) fn sugared_async_return_type ( & self ) -> Type {
1374+ if let Type :: ImplTrait ( v) = & self . output &&
1375+ let [ GenericBound :: TraitBound ( PolyTrait { trait_, .. } , _ ) ] = & v[ ..]
1376+ {
1377+ let bindings = trait_. bindings ( ) . unwrap ( ) ;
1378+ let ret_ty = bindings[ 0 ] . term ( ) ;
1379+ let ty = ret_ty. ty ( ) . expect ( "Unexpected constant return term" ) ;
1380+ ty. clone ( )
1381+ } else {
1382+ panic ! ( "unexpected desugaring of async function" )
13861383 }
13871384 }
13881385}
@@ -1425,21 +1422,6 @@ impl Argument {
14251422 }
14261423}
14271424
1428- #[ derive( Clone , PartialEq , Eq , Debug , Hash ) ]
1429- pub ( crate ) enum FnRetTy {
1430- Return ( Type ) ,
1431- DefaultReturn ,
1432- }
1433-
1434- impl FnRetTy {
1435- pub ( crate ) fn as_return ( & self ) -> Option < & Type > {
1436- match self {
1437- Return ( ret) => Some ( ret) ,
1438- DefaultReturn => None ,
1439- }
1440- }
1441- }
1442-
14431425#[ derive( Clone , Debug ) ]
14441426pub ( crate ) struct Trait {
14451427 pub ( crate ) def_id : DefId ,
@@ -1641,6 +1623,10 @@ impl Type {
16411623 matches ! ( self , Type :: ImplTrait ( _) )
16421624 }
16431625
1626+ pub ( crate ) fn is_unit ( & self ) -> bool {
1627+ matches ! ( self , Type :: Tuple ( v) if v. is_empty( ) )
1628+ }
1629+
16441630 pub ( crate ) fn projection ( & self ) -> Option < ( & Type , DefId , PathSegment ) > {
16451631 if let QPath ( box QPathData { self_type, trait_, assoc, .. } ) = self {
16461632 Some ( ( self_type, trait_. as_ref ( ) ?. def_id ( ) , assoc. clone ( ) ) )
0 commit comments