Skip to content

Commit 5b438f8

Browse files
committed
Turn predicate 'erased lifetimes into 'static
1 parent 8e9b17b commit 5b438f8

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

compiler/rustc_const_eval/src/interpret/intrinsics.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ use std::assert_matches::assert_matches;
66

77
use rustc_abi::{FIRST_VARIANT, FieldIdx, HasDataLayout, Size};
88
use rustc_apfloat::ieee::{Double, Half, Quad, Single};
9+
use rustc_hir::def_id::CRATE_DEF_ID;
910
use rustc_infer::infer::TyCtxtInferExt;
1011
use rustc_middle::mir::interpret::{CTFE_ALLOC_SALT, read_target_uint, write_target_uint};
1112
use rustc_middle::mir::{self, BinOp, ConstValue, NonDivergingIntrinsic};
1213
use rustc_middle::ty::layout::TyAndLayout;
13-
use rustc_middle::ty::{Ty, TyCtxt};
14+
use rustc_middle::ty::{Ty, TyCtxt, TypeFoldable};
1415
use rustc_middle::{bug, span_bug, ty};
1516
use rustc_span::{Symbol, sym};
1617
use rustc_trait_selection::traits::{Obligation, ObligationCause, ObligationCtxt};
@@ -170,12 +171,22 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
170171
let ocx = ObligationCtxt::new(&infcx);
171172
ocx.register_obligations(preds.iter().map(|pred| {
172173
let pred = pred.with_self_ty(tcx, tp_ty);
173-
let pred = tcx.erase_regions(pred);
174+
// Lifetimes can only be 'static because of the bound on T
175+
let pred = pred.fold_with(&mut ty::BottomUpFolder {
176+
tcx,
177+
ty_op: |ty| ty,
178+
lt_op: |lt| {
179+
if lt == tcx.lifetimes.re_erased { tcx.lifetimes.re_static } else { lt }
180+
},
181+
ct_op: |ct| ct,
182+
});
174183
Obligation::new(tcx, ObligationCause::dummy(), param_env, pred)
175184
}));
176185
let type_impls_trait = ocx.select_all_or_error().is_empty();
186+
// Since `assumed_wf_tys=[]` the choice of LocalDefId is irrelevant, so using the "default"
187+
let regions_are_valid = ocx.resolve_regions(CRATE_DEF_ID, param_env, []).is_empty();
177188

178-
if type_impls_trait {
189+
if regions_are_valid && type_impls_trait {
179190
let vtable_ptr = self.get_vtable_ptr(tp_ty, preds)?;
180191
// Writing a non-null pointer into an `Option<NonNull>` will automatically make it `Some`.
181192
self.write_pointer(vtable_ptr, dest)?;

0 commit comments

Comments
 (0)