@@ -167,23 +167,15 @@ impl<'a, 'gcx, 'tcx> VariantDef {
167
167
substs : & ' tcx Substs < ' tcx > ,
168
168
adt_kind : AdtKind ) -> DefIdForest
169
169
{
170
- match adt_kind {
171
- AdtKind :: Union => {
172
- DefIdForest :: intersection ( tcx, self . fields . iter ( ) . map ( |f| {
173
- f. uninhabited_from ( visited, tcx, substs, false )
174
- } ) )
175
- } ,
176
- AdtKind :: Struct => {
177
- DefIdForest :: union ( tcx, self . fields . iter ( ) . map ( |f| {
178
- f. uninhabited_from ( visited, tcx, substs, false )
179
- } ) )
180
- } ,
181
- AdtKind :: Enum => {
182
- DefIdForest :: union ( tcx, self . fields . iter ( ) . map ( |f| {
183
- f. uninhabited_from ( visited, tcx, substs, true )
184
- } ) )
185
- } ,
186
- }
170
+ let is_enum = match adt_kind {
171
+ // For now, `union`s are never considered uninhabited.
172
+ AdtKind :: Union => return DefIdForest :: empty ( ) ,
173
+ AdtKind :: Enum => true ,
174
+ AdtKind :: Struct => false ,
175
+ } ;
176
+ DefIdForest :: union ( tcx, self . fields . iter ( ) . map ( |f| {
177
+ f. uninhabited_from ( visited, tcx, substs, is_enum)
178
+ } ) )
187
179
}
188
180
}
189
181
@@ -194,8 +186,8 @@ impl<'a, 'gcx, 'tcx> FieldDef {
194
186
visited : & mut FxHashMap < DefId , FxHashSet < & ' tcx Substs < ' tcx > > > ,
195
187
tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
196
188
substs : & ' tcx Substs < ' tcx > ,
197
- is_enum : bool ) -> DefIdForest
198
- {
189
+ is_enum : bool ,
190
+ ) -> DefIdForest {
199
191
let mut data_uninhabitedness = move || {
200
192
self . ty ( tcx, substs) . uninhabited_from ( visited, tcx)
201
193
} ;
@@ -253,14 +245,16 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
253
245
let substs_set = visited. get_mut ( & def. did ) . unwrap ( ) ;
254
246
substs_set. remove ( substs) ;
255
247
ret
256
- } ,
248
+ }
257
249
258
250
Never => DefIdForest :: full ( tcx) ,
251
+
259
252
Tuple ( ref tys) => {
260
253
DefIdForest :: union ( tcx, tys. iter ( ) . map ( |ty| {
261
254
ty. uninhabited_from ( visited, tcx)
262
255
} ) )
263
- } ,
256
+ }
257
+
264
258
Array ( ty, len) => {
265
259
match len. assert_usize ( tcx) {
266
260
// If the array is definitely non-empty, it's uninhabited if
@@ -269,9 +263,11 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
269
263
_ => DefIdForest :: empty ( )
270
264
}
271
265
}
272
- Ref ( _, ty, _) => {
273
- ty. uninhabited_from ( visited, tcx)
274
- }
266
+
267
+ // References to uninitialised memory is valid for any type, including
268
+ // uninhabited types, in unsafe code, so we treat all references as
269
+ // inhabited.
270
+ Ref ( ..) => DefIdForest :: empty ( ) ,
275
271
276
272
_ => DefIdForest :: empty ( ) ,
277
273
}
0 commit comments