@@ -12,7 +12,7 @@ use rustc_index::vec::IndexVec;
12
12
use rustc_infer:: infer:: InferCtxt ;
13
13
use rustc_middle:: {
14
14
hir:: map:: Map ,
15
- ty:: { TyCtxt , TypeVisitable , TypeckResults } ,
15
+ ty:: { ParamEnv , TyCtxt , TypeVisitable , TypeckResults } ,
16
16
} ;
17
17
use std:: mem:: swap;
18
18
@@ -24,12 +24,18 @@ use std::mem::swap;
24
24
pub ( super ) fn build_control_flow_graph < ' tcx > (
25
25
infcx : & InferCtxt < ' tcx > ,
26
26
typeck_results : & TypeckResults < ' tcx > ,
27
+ param_env : ParamEnv < ' tcx > ,
27
28
consumed_borrowed_places : ConsumedAndBorrowedPlaces ,
28
29
body : & ' tcx Body < ' tcx > ,
29
30
num_exprs : usize ,
30
31
) -> ( DropRangesBuilder , FxHashSet < HirId > ) {
31
- let mut drop_range_visitor =
32
- DropRangeVisitor :: new ( infcx, typeck_results, consumed_borrowed_places, num_exprs) ;
32
+ let mut drop_range_visitor = DropRangeVisitor :: new (
33
+ infcx,
34
+ typeck_results,
35
+ param_env,
36
+ consumed_borrowed_places,
37
+ num_exprs,
38
+ ) ;
33
39
intravisit:: walk_body ( & mut drop_range_visitor, body) ;
34
40
35
41
drop_range_visitor. drop_ranges . process_deferred_edges ( ) ;
@@ -88,6 +94,7 @@ pub(super) fn build_control_flow_graph<'tcx>(
88
94
struct DropRangeVisitor < ' a , ' tcx > {
89
95
typeck_results : & ' a TypeckResults < ' tcx > ,
90
96
infcx : & ' a InferCtxt < ' tcx > ,
97
+ param_env : ParamEnv < ' tcx > ,
91
98
places : ConsumedAndBorrowedPlaces ,
92
99
drop_ranges : DropRangesBuilder ,
93
100
expr_index : PostOrderId ,
@@ -98,6 +105,7 @@ impl<'a, 'tcx> DropRangeVisitor<'a, 'tcx> {
98
105
fn new (
99
106
infcx : & ' a InferCtxt < ' tcx > ,
100
107
typeck_results : & ' a TypeckResults < ' tcx > ,
108
+ param_env : ParamEnv < ' tcx > ,
101
109
places : ConsumedAndBorrowedPlaces ,
102
110
num_exprs : usize ,
103
111
) -> Self {
@@ -110,6 +118,7 @@ impl<'a, 'tcx> DropRangeVisitor<'a, 'tcx> {
110
118
Self {
111
119
infcx,
112
120
typeck_results,
121
+ param_env,
113
122
places,
114
123
drop_ranges,
115
124
expr_index : PostOrderId :: from_u32 ( 0 ) ,
@@ -220,15 +229,14 @@ impl<'a, 'tcx> DropRangeVisitor<'a, 'tcx> {
220
229
fn handle_uninhabited_return ( & mut self , expr : & Expr < ' tcx > ) {
221
230
let ty = self . typeck_results . expr_ty ( expr) ;
222
231
let ty = self . infcx . resolve_vars_if_possible ( ty) ;
223
- let ty = self . tcx ( ) . erase_regions ( ty) ;
224
- let m = self . tcx ( ) . parent_module ( expr. hir_id ) . to_def_id ( ) ;
225
- let param_env = self . tcx ( ) . param_env ( m. expect_local ( ) ) ;
226
232
if ty. has_non_region_infer ( ) {
227
233
self . tcx ( )
228
234
. sess
229
235
. delay_span_bug ( expr. span , format ! ( "could not resolve infer vars in `{ty}`" ) ) ;
230
236
}
231
- if !ty. is_inhabited_from ( self . tcx ( ) , m, param_env) {
237
+ let ty = self . tcx ( ) . erase_regions ( ty) ;
238
+ let m = self . tcx ( ) . parent_module ( expr. hir_id ) . to_def_id ( ) ;
239
+ if !ty. is_inhabited_from ( self . tcx ( ) , m, self . param_env ) {
232
240
// This function will not return. We model this fact as an infinite loop.
233
241
self . drop_ranges . add_control_edge ( self . expr_index + 1 , self . expr_index + 1 ) ;
234
242
}
0 commit comments