Skip to content

Commit 024bb8c

Browse files
Pass ParamEnv down instead of using ParamEnv of a module
1 parent 1e7f6a7 commit 024bb8c

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

compiler/rustc_hir_typeck/src/generator_interior/drop_ranges/cfg_build.rs

+15-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_index::vec::IndexVec;
1212
use rustc_infer::infer::InferCtxt;
1313
use rustc_middle::{
1414
hir::map::Map,
15-
ty::{TyCtxt, TypeVisitable, TypeckResults},
15+
ty::{ParamEnv, TyCtxt, TypeVisitable, TypeckResults},
1616
};
1717
use std::mem::swap;
1818

@@ -24,12 +24,18 @@ use std::mem::swap;
2424
pub(super) fn build_control_flow_graph<'tcx>(
2525
infcx: &InferCtxt<'tcx>,
2626
typeck_results: &TypeckResults<'tcx>,
27+
param_env: ParamEnv<'tcx>,
2728
consumed_borrowed_places: ConsumedAndBorrowedPlaces,
2829
body: &'tcx Body<'tcx>,
2930
num_exprs: usize,
3031
) -> (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+
);
3339
intravisit::walk_body(&mut drop_range_visitor, body);
3440

3541
drop_range_visitor.drop_ranges.process_deferred_edges();
@@ -88,6 +94,7 @@ pub(super) fn build_control_flow_graph<'tcx>(
8894
struct DropRangeVisitor<'a, 'tcx> {
8995
typeck_results: &'a TypeckResults<'tcx>,
9096
infcx: &'a InferCtxt<'tcx>,
97+
param_env: ParamEnv<'tcx>,
9198
places: ConsumedAndBorrowedPlaces,
9299
drop_ranges: DropRangesBuilder,
93100
expr_index: PostOrderId,
@@ -98,6 +105,7 @@ impl<'a, 'tcx> DropRangeVisitor<'a, 'tcx> {
98105
fn new(
99106
infcx: &'a InferCtxt<'tcx>,
100107
typeck_results: &'a TypeckResults<'tcx>,
108+
param_env: ParamEnv<'tcx>,
101109
places: ConsumedAndBorrowedPlaces,
102110
num_exprs: usize,
103111
) -> Self {
@@ -110,6 +118,7 @@ impl<'a, 'tcx> DropRangeVisitor<'a, 'tcx> {
110118
Self {
111119
infcx,
112120
typeck_results,
121+
param_env,
113122
places,
114123
drop_ranges,
115124
expr_index: PostOrderId::from_u32(0),
@@ -220,15 +229,14 @@ impl<'a, 'tcx> DropRangeVisitor<'a, 'tcx> {
220229
fn handle_uninhabited_return(&mut self, expr: &Expr<'tcx>) {
221230
let ty = self.typeck_results.expr_ty(expr);
222231
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());
226232
if ty.has_non_region_infer() {
227233
self.tcx()
228234
.sess
229235
.delay_span_bug(expr.span, format!("could not resolve infer vars in `{ty}`"));
230236
}
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) {
232240
// This function will not return. We model this fact as an infinite loop.
233241
self.drop_ranges.add_control_edge(self.expr_index + 1, self.expr_index + 1);
234242
}

compiler/rustc_hir_typeck/src/generator_interior/drop_ranges/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub fn compute_drop_ranges<'a, 'tcx>(
4545
let (mut drop_ranges, borrowed_temporaries) = build_control_flow_graph(
4646
&fcx,
4747
typeck_results,
48+
fcx.param_env,
4849
consumed_borrowed_places,
4950
body,
5051
num_exprs,

0 commit comments

Comments
 (0)