@@ -16,6 +16,7 @@ pub use self::IntVarValue::*;
1616pub use self :: LvaluePreference :: * ;
1717pub use self :: fold:: TypeFoldable ;
1818
19+ use std:: collections:: { hash_map, HashMap } ;
1920use dep_graph:: { self , DepNode } ;
2021use hir:: map as ast_map;
2122use middle;
@@ -1389,6 +1390,20 @@ impl<'tcx> serialize::UseSpecializedEncodable for AdtDef<'tcx> {
13891390
13901391impl < ' tcx > serialize:: UseSpecializedDecodable for AdtDef < ' tcx > { }
13911392
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+
13921407#[ derive( Copy , Clone , Debug , Eq , PartialEq ) ]
13931408pub enum AdtKind { Struct , Union , Enum }
13941409
@@ -1531,11 +1546,6 @@ impl<'a, 'gcx, 'tcx, 'container> AdtDefData<'gcx, 'container> {
15311546 self . variants . iter ( ) . flat_map ( VariantDefData :: fields_iter)
15321547 }
15331548
1534- #[ inline]
1535- pub fn is_empty ( & self ) -> bool {
1536- self . variants . is_empty ( )
1537- }
1538-
15391549 #[ inline]
15401550 pub fn is_univariant ( & self ) -> bool {
15411551 self . variants . len ( ) == 1
@@ -1795,6 +1805,21 @@ impl<'tcx, 'container> VariantDefData<'tcx, 'container> {
17951805 }
17961806}
17971807
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+
17981823impl < ' a , ' gcx , ' tcx , ' container > FieldDefData < ' tcx , ' container > {
17991824 pub fn new ( did : DefId ,
18001825 name : Name ,
@@ -1820,6 +1845,16 @@ impl<'a, 'gcx, 'tcx, 'container> FieldDefData<'tcx, 'container> {
18201845 }
18211846}
18221847
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+
18231858/// Records the substitutions used to translate the polytype for an
18241859/// item into the monotype of an item reference.
18251860#[ derive( Clone , RustcEncodable , RustcDecodable ) ]
0 commit comments