@@ -16,6 +16,7 @@ pub use self::IntVarValue::*;
16
16
pub use self :: LvaluePreference :: * ;
17
17
pub use self :: fold:: TypeFoldable ;
18
18
19
+ use std:: collections:: { hash_map, HashMap } ;
19
20
use dep_graph:: { self , DepNode } ;
20
21
use hir:: map as ast_map;
21
22
use middle;
@@ -1389,6 +1390,20 @@ impl<'tcx> serialize::UseSpecializedEncodable for AdtDef<'tcx> {
1389
1390
1390
1391
impl < ' tcx > serialize:: UseSpecializedDecodable for AdtDef < ' tcx > { }
1391
1392
1393
+ impl < ' a , ' gcx , ' tcx > AdtDefData < ' tcx , ' static > {
1394
+ #[ inline]
1395
+ pub fn is_uninhabited_recurse ( & ' tcx self ,
1396
+ visited : & mut HashMap < ( DefId , & ' tcx Substs < ' tcx > ) , ( ) > ,
1397
+ cx : TyCtxt < ' a , ' gcx , ' tcx > ,
1398
+ substs : & ' tcx Substs < ' tcx > ) -> bool {
1399
+ match visited. entry ( ( self . did , substs) ) {
1400
+ hash_map:: Entry :: Occupied ( _) => return true ,
1401
+ hash_map:: Entry :: Vacant ( ve) => ve. insert ( ( ) ) ,
1402
+ } ;
1403
+ self . variants . iter ( ) . all ( |v| v. is_uninhabited_recurse ( visited, cx, substs, self . is_union ( ) ) )
1404
+ }
1405
+ }
1406
+
1392
1407
#[ derive( Copy , Clone , Debug , Eq , PartialEq ) ]
1393
1408
pub enum AdtKind { Struct , Union , Enum }
1394
1409
@@ -1531,11 +1546,6 @@ impl<'a, 'gcx, 'tcx, 'container> AdtDefData<'gcx, 'container> {
1531
1546
self . variants . iter ( ) . flat_map ( VariantDefData :: fields_iter)
1532
1547
}
1533
1548
1534
- #[ inline]
1535
- pub fn is_empty ( & self ) -> bool {
1536
- self . variants . is_empty ( )
1537
- }
1538
-
1539
1549
#[ inline]
1540
1550
pub fn is_univariant ( & self ) -> bool {
1541
1551
self . variants . len ( ) == 1
@@ -1795,6 +1805,21 @@ impl<'tcx, 'container> VariantDefData<'tcx, 'container> {
1795
1805
}
1796
1806
}
1797
1807
1808
+ impl < ' a , ' gcx , ' tcx > VariantDefData < ' tcx , ' static > {
1809
+ #[ inline]
1810
+ pub fn is_uninhabited_recurse ( & ' tcx self ,
1811
+ visited : & mut HashMap < ( DefId , & ' tcx Substs < ' tcx > ) , ( ) > ,
1812
+ cx : TyCtxt < ' a , ' gcx , ' tcx > ,
1813
+ substs : & ' tcx Substs < ' tcx > ,
1814
+ is_union : bool ) -> bool {
1815
+ if is_union {
1816
+ self . fields . iter ( ) . all ( |f| f. is_uninhabited_recurse ( visited, cx, substs) )
1817
+ } else {
1818
+ self . fields . iter ( ) . any ( |f| f. is_uninhabited_recurse ( visited, cx, substs) )
1819
+ }
1820
+ }
1821
+ }
1822
+
1798
1823
impl < ' a , ' gcx , ' tcx , ' container > FieldDefData < ' tcx , ' container > {
1799
1824
pub fn new ( did : DefId ,
1800
1825
name : Name ,
@@ -1820,6 +1845,16 @@ impl<'a, 'gcx, 'tcx, 'container> FieldDefData<'tcx, 'container> {
1820
1845
}
1821
1846
}
1822
1847
1848
+ impl < ' a , ' gcx , ' tcx > FieldDefData < ' tcx , ' static > {
1849
+ #[ inline]
1850
+ pub fn is_uninhabited_recurse ( & ' tcx self ,
1851
+ visited : & mut HashMap < ( DefId , & ' tcx Substs < ' tcx > ) , ( ) > ,
1852
+ tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
1853
+ substs : & ' tcx Substs < ' tcx > ) -> bool {
1854
+ self . ty ( tcx, substs) . is_uninhabited_recurse ( visited, tcx)
1855
+ }
1856
+ }
1857
+
1823
1858
/// Records the substitutions used to translate the polytype for an
1824
1859
/// item into the monotype of an item reference.
1825
1860
#[ derive( Clone , RustcEncodable , RustcDecodable ) ]
0 commit comments