@@ -2467,42 +2467,6 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
2467
2467
None
2468
2468
}
2469
2469
2470
- /// Determines whether the given type is inhabited. `None` means that we don't know.
2471
- fn ty_inhabited < ' tcx > ( cx : & LateContext < ' tcx > , ty : Ty < ' tcx > ) -> Option < bool > {
2472
- use rustc_type_ir:: sty:: TyKind :: * ;
2473
- if !cx. tcx . type_uninhabited_from ( cx. param_env . and ( ty) ) . is_empty ( ) {
2474
- // This is definitely uninhabited from some module.
2475
- return Some ( false ) ;
2476
- }
2477
- match ty. kind ( ) {
2478
- Never => Some ( false ) ,
2479
- Int ( _) | Uint ( _) | Float ( _) | Bool | Char | RawPtr ( _) => Some ( true ) ,
2480
- // Fallback for more complicated types. (Note that `&!` might be considered
2481
- // uninhabited so references are "complicated", too.)
2482
- _ => None ,
2483
- }
2484
- }
2485
- /// Determines whether a product type formed from a list of types is inhabited.
2486
- fn tys_inhabited < ' tcx > (
2487
- cx : & LateContext < ' tcx > ,
2488
- tys : impl Iterator < Item = Ty < ' tcx > > ,
2489
- ) -> Option < bool > {
2490
- let mut definitely_inhabited = true ; // with no fields, we are definitely inhabited.
2491
- for ty in tys {
2492
- match ty_inhabited ( cx, ty) {
2493
- // If any type is uninhabited, the product is uninhabited.
2494
- Some ( false ) => return Some ( false ) ,
2495
- // Otherwise go searching for a `None`.
2496
- None => {
2497
- // We don't know.
2498
- definitely_inhabited = false ;
2499
- }
2500
- Some ( true ) => { }
2501
- }
2502
- }
2503
- if definitely_inhabited { Some ( true ) } else { None }
2504
- }
2505
-
2506
2470
fn variant_find_init_error < ' tcx > (
2507
2471
cx : & LateContext < ' tcx > ,
2508
2472
variant : & VariantDef ,
@@ -2599,11 +2563,11 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
2599
2563
// And now, enums.
2600
2564
let span = cx. tcx . def_span ( adt_def. did ( ) ) ;
2601
2565
let mut potential_variants = adt_def. variants ( ) . iter ( ) . filter_map ( |variant| {
2602
- let inhabited = tys_inhabited (
2603
- cx ,
2604
- variant . fields . iter ( ) . map ( |field| field . ty ( cx. tcx , substs) ) ,
2605
- ) ;
2606
- let definitely_inhabited = match inhabited {
2566
+ let definitely_inhabited = match variant
2567
+ . inhabited_predicate ( cx . tcx , * adt_def )
2568
+ . subst ( cx. tcx , substs)
2569
+ . apply_any_module ( cx . tcx , cx . param_env )
2570
+ {
2607
2571
// Entirely skip uninhbaited variants.
2608
2572
Some ( false ) => return None ,
2609
2573
// Forward the others, but remember which ones are definitely inhabited.
0 commit comments