@@ -100,14 +100,16 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
100
100
/// This code should only compile in modules where the uninhabitedness of Foo is
101
101
/// visible.
102
102
pub fn is_ty_uninhabited_from ( self , module : DefId , ty : Ty < ' tcx > ) -> bool {
103
- let forest = ty. uninhabited_from ( & mut FxHashMap ( ) , self ) ;
104
-
105
103
// To check whether this type is uninhabited at all (not just from the
106
104
// given node) you could check whether the forest is empty.
107
105
// ```
108
106
// forest.is_empty()
109
107
// ```
110
- forest. contains ( self , module)
108
+ self . ty_inhabitedness_forest ( ty) . contains ( self , module)
109
+ }
110
+
111
+ fn ty_inhabitedness_forest ( self , ty : Ty < ' tcx > ) -> DefIdForest {
112
+ ty. uninhabited_from ( & mut FxHashMap ( ) , self )
111
113
}
112
114
113
115
pub fn is_enum_variant_uninhabited_from ( self ,
@@ -116,17 +118,25 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
116
118
substs : & ' tcx Substs < ' tcx > )
117
119
-> bool
118
120
{
119
- let adt_kind = AdtKind :: Enum ;
120
- variant. uninhabited_from ( & mut FxHashMap ( ) , self , substs, adt_kind) . contains ( self , module)
121
+ self . variant_inhabitedness_forest ( variant, substs) . contains ( self , module)
121
122
}
122
123
123
124
pub fn is_variant_uninhabited_from_all_modules ( self ,
124
125
variant : & ' tcx VariantDef ,
125
- substs : & ' tcx Substs < ' tcx > ,
126
- adt_kind : AdtKind )
126
+ substs : & ' tcx Substs < ' tcx > )
127
127
-> bool
128
128
{
129
- !variant. uninhabited_from ( & mut FxHashMap ( ) , self , substs, adt_kind) . is_empty ( )
129
+ !self . variant_inhabitedness_forest ( variant, substs) . is_empty ( )
130
+ }
131
+
132
+ fn variant_inhabitedness_forest ( self , variant : & ' tcx VariantDef , substs : & ' tcx Substs < ' tcx > )
133
+ -> DefIdForest {
134
+ // Determine the ADT kind:
135
+ let adt_def_id = self . adt_def_id_of_variant ( variant) ;
136
+ let adt_kind = self . adt_def ( adt_def_id) . adt_kind ( ) ;
137
+
138
+ // Compute inhabitedness forest:
139
+ variant. uninhabited_from ( & mut FxHashMap ( ) , self , substs, adt_kind)
130
140
}
131
141
}
132
142
@@ -210,31 +220,6 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
210
220
& self ,
211
221
visited : & mut FxHashMap < DefId , FxHashSet < & ' tcx Substs < ' tcx > > > ,
212
222
tcx : TyCtxt < ' a , ' gcx , ' tcx > ) -> DefIdForest
213
- {
214
- match tcx. lift_to_global ( & self ) {
215
- Some ( global_ty) => {
216
- {
217
- let cache = tcx. inhabitedness_cache . borrow ( ) ;
218
- if let Some ( forest) = cache. get ( & global_ty) {
219
- return forest. clone ( ) ;
220
- }
221
- }
222
- let forest = global_ty. uninhabited_from_inner ( visited, tcx) ;
223
- let mut cache = tcx. inhabitedness_cache . borrow_mut ( ) ;
224
- cache. insert ( global_ty, forest. clone ( ) ) ;
225
- forest
226
- } ,
227
- None => {
228
- let forest = self . uninhabited_from_inner ( visited, tcx) ;
229
- forest
230
- } ,
231
- }
232
- }
233
-
234
- fn uninhabited_from_inner (
235
- & self ,
236
- visited : & mut FxHashMap < DefId , FxHashSet < & ' tcx Substs < ' tcx > > > ,
237
- tcx : TyCtxt < ' a , ' gcx , ' tcx > ) -> DefIdForest
238
223
{
239
224
match self . sty {
240
225
TyAdt ( def, substs) => {
0 commit comments