@@ -90,30 +90,46 @@ impl<'tcx> TyCtxt<'tcx> {
9090/// ``` 
9191/// This code should only compile in modules where the uninhabitedness of Foo is 
9292/// visible. 
93- pub  fn  is_ty_uninhabited_from ( self ,  module :  DefId ,  ty :  Ty < ' tcx > )  -> bool  { 
93+ pub  fn  is_ty_uninhabited_from ( 
94+         self , 
95+         module :  DefId , 
96+         ty :  Ty < ' tcx > , 
97+         param_env :  ty:: ParamEnv < ' tcx > , 
98+     )  -> bool  { 
9499        // To check whether this type is uninhabited at all (not just from the 
95100        // given node), you could check whether the forest is empty. 
96101        // ``` 
97102        // forest.is_empty() 
98103        // ``` 
99-         ty. uninhabited_from ( self ) . contains ( self ,  module) 
104+         ty. uninhabited_from ( self ,  param_env ) . contains ( self ,  module) 
100105    } 
101106
102-     pub  fn  is_ty_uninhabited_from_any_module ( self ,  ty :  Ty < ' tcx > )  -> bool  { 
103-         !ty. uninhabited_from ( self ) . is_empty ( ) 
107+     pub  fn  is_ty_uninhabited_from_any_module ( 
108+         self , 
109+         ty :  Ty < ' tcx > , 
110+         param_env :  ty:: ParamEnv < ' tcx > , 
111+     )  -> bool  { 
112+         !ty. uninhabited_from ( self ,  param_env) . is_empty ( ) 
104113    } 
105114} 
106115
107116impl < ' tcx >  AdtDef  { 
108117    /// Calculates the forest of `DefId`s from which this ADT is visibly uninhabited. 
109- fn  uninhabited_from ( & self ,  tcx :  TyCtxt < ' tcx > ,  substs :  SubstsRef < ' tcx > )  -> DefIdForest  { 
118+ fn  uninhabited_from ( 
119+         & self , 
120+         tcx :  TyCtxt < ' tcx > , 
121+         substs :  SubstsRef < ' tcx > , 
122+         param_env :  ty:: ParamEnv < ' tcx > , 
123+     )  -> DefIdForest  { 
110124        // Non-exhaustive ADTs from other crates are always considered inhabited. 
111125        if  self . is_variant_list_non_exhaustive ( )  && !self . did . is_local ( )  { 
112126            DefIdForest :: empty ( ) 
113127        }  else  { 
114128            DefIdForest :: intersection ( 
115129                tcx, 
116-                 self . variants . iter ( ) . map ( |v| v. uninhabited_from ( tcx,  substs,  self . adt_kind ( ) ) ) , 
130+                 self . variants 
131+                     . iter ( ) 
132+                     . map ( |v| v. uninhabited_from ( tcx,  substs,  self . adt_kind ( ) ,  param_env) ) , 
117133            ) 
118134        } 
119135    } 
@@ -126,6 +142,7 @@ impl<'tcx> VariantDef {
126142        tcx :  TyCtxt < ' tcx > , 
127143        substs :  SubstsRef < ' tcx > , 
128144        adt_kind :  AdtKind , 
145+         param_env :  ty:: ParamEnv < ' tcx > , 
129146    )  -> DefIdForest  { 
130147        let  is_enum = match  adt_kind { 
131148            // For now, `union`s are never considered uninhabited. 
@@ -140,7 +157,7 @@ impl<'tcx> VariantDef {
140157        }  else  { 
141158            DefIdForest :: union ( 
142159                tcx, 
143-                 self . fields . iter ( ) . map ( |f| f. uninhabited_from ( tcx,  substs,  is_enum) ) , 
160+                 self . fields . iter ( ) . map ( |f| f. uninhabited_from ( tcx,  substs,  is_enum,  param_env ) ) , 
144161            ) 
145162        } 
146163    } 
@@ -153,8 +170,9 @@ impl<'tcx> FieldDef {
153170        tcx :  TyCtxt < ' tcx > , 
154171        substs :  SubstsRef < ' tcx > , 
155172        is_enum :  bool , 
173+         param_env :  ty:: ParamEnv < ' tcx > , 
156174    )  -> DefIdForest  { 
157-         let  data_uninhabitedness = move  || self . ty ( tcx,  substs) . uninhabited_from ( tcx) ; 
175+         let  data_uninhabitedness = move  || self . ty ( tcx,  substs) . uninhabited_from ( tcx,  param_env ) ; 
158176        // FIXME(canndrew): Currently enum fields are (incorrectly) stored with 
159177        // `Visibility::Invisible` so we need to override `self.vis` if we're 
160178        // dealing with an enum. 
@@ -176,20 +194,21 @@ impl<'tcx> FieldDef {
176194
177195impl < ' tcx >  TyS < ' tcx >  { 
178196    /// Calculates the forest of `DefId`s from which this type is visibly uninhabited. 
179- fn  uninhabited_from ( & self ,  tcx :  TyCtxt < ' tcx > )  -> DefIdForest  { 
197+ fn  uninhabited_from ( & self ,  tcx :  TyCtxt < ' tcx > ,   param_env :  ty :: ParamEnv < ' tcx > )  -> DefIdForest  { 
180198        match  self . kind  { 
181-             Adt ( def,  substs)  => def. uninhabited_from ( tcx,  substs) , 
199+             Adt ( def,  substs)  => def. uninhabited_from ( tcx,  substs,  param_env ) , 
182200
183201            Never  => DefIdForest :: full ( tcx) , 
184202
185-             Tuple ( ref  tys)  => { 
186-                 DefIdForest :: union ( tcx,  tys. iter ( ) . map ( |ty| ty. expect_ty ( ) . uninhabited_from ( tcx) ) ) 
187-             } 
203+             Tuple ( ref  tys)  => DefIdForest :: union ( 
204+                 tcx, 
205+                 tys. iter ( ) . map ( |ty| ty. expect_ty ( ) . uninhabited_from ( tcx,  param_env) ) , 
206+             ) , 
188207
189-             Array ( ty,  len)  => match  len. try_eval_usize ( tcx,  ty :: ParamEnv :: empty ( ) )  { 
208+             Array ( ty,  len)  => match  len. try_eval_usize ( tcx,  param_env )  { 
190209                // If the array is definitely non-empty, it's uninhabited if 
191210                // the type of its elements is uninhabited. 
192-                 Some ( n)  if  n != 0  => ty. uninhabited_from ( tcx) , 
211+                 Some ( n)  if  n != 0  => ty. uninhabited_from ( tcx,  param_env ) , 
193212                _ => DefIdForest :: empty ( ) , 
194213            } , 
195214
0 commit comments