@@ -42,7 +42,6 @@ use crate::formats::item_type::ItemType;
42
42
use crate :: html:: render:: Context ;
43
43
use crate :: passes:: collect_intra_doc_links:: UrlFragment ;
44
44
45
- pub ( crate ) use self :: FnRetTy :: * ;
46
45
pub ( crate ) use self :: ItemKind :: * ;
47
46
pub ( crate ) use self :: SelfTy :: * ;
48
47
pub ( crate ) use self :: Type :: {
@@ -1353,7 +1352,7 @@ pub(crate) struct Function {
1353
1352
#[ derive( Clone , PartialEq , Eq , Debug , Hash ) ]
1354
1353
pub ( crate ) struct FnDecl {
1355
1354
pub ( crate ) inputs : Arguments ,
1356
- pub ( crate ) output : FnRetTy ,
1355
+ pub ( crate ) output : Type ,
1357
1356
pub ( crate ) c_variadic : bool ,
1358
1357
}
1359
1358
@@ -1371,18 +1370,16 @@ impl FnDecl {
1371
1370
///
1372
1371
/// This function will panic if the return type does not match the expected sugaring for async
1373
1372
/// 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" )
1386
1383
}
1387
1384
}
1388
1385
}
@@ -1425,21 +1422,6 @@ impl Argument {
1425
1422
}
1426
1423
}
1427
1424
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
-
1443
1425
#[ derive( Clone , Debug ) ]
1444
1426
pub ( crate ) struct Trait {
1445
1427
pub ( crate ) def_id : DefId ,
@@ -1641,6 +1623,10 @@ impl Type {
1641
1623
matches ! ( self , Type :: ImplTrait ( _) )
1642
1624
}
1643
1625
1626
+ pub ( crate ) fn is_unit ( & self ) -> bool {
1627
+ matches ! ( self , Type :: Tuple ( v) if v. is_empty( ) )
1628
+ }
1629
+
1644
1630
pub ( crate ) fn projection ( & self ) -> Option < ( & Type , DefId , PathSegment ) > {
1645
1631
if let QPath ( box QPathData { self_type, trait_, assoc, .. } ) = self {
1646
1632
Some ( ( self_type, trait_. as_ref ( ) ?. def_id ( ) , assoc. clone ( ) ) )
0 commit comments