Skip to content

Commit f7d69bd

Browse files
ivarflakstadizagawd
authored andcommitted
Turn predicate 'erased lifetimes into 'static
1 parent c55d874 commit f7d69bd

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
@@ -8,11 +8,12 @@ use std::assert_matches::assert_matches;
88

99
use rustc_abi::{FIRST_VARIANT, FieldIdx, HasDataLayout, Size, VariantIdx};
1010
use rustc_apfloat::ieee::{Double, Half, Quad, Single};
11+
use rustc_hir::def_id::CRATE_DEF_ID;
1112
use rustc_infer::infer::TyCtxtInferExt;
1213
use rustc_middle::mir::interpret::{CTFE_ALLOC_SALT, read_target_uint, write_target_uint};
1314
use rustc_middle::mir::{self, BinOp, ConstValue, NonDivergingIntrinsic};
1415
use rustc_middle::ty::layout::TyAndLayout;
15-
use rustc_middle::ty::{FloatTy, Ty, TyCtxt, Upcast};
16+
use rustc_middle::ty::{FloatTy, Ty, TyCtxt, Upcast, TypeFoldable};
1617
use rustc_middle::{bug, span_bug, ty};
1718
use rustc_span::{Symbol, sym};
1819
use rustc_trait_selection::traits::{Obligation, ObligationCause, ObligationCtxt};
@@ -240,12 +241,22 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
240241
let ocx = ObligationCtxt::new(&infcx);
241242
ocx.register_obligations(preds.iter().map(|pred| {
242243
let pred = pred.with_self_ty(tcx, tp_ty);
243-
let pred = tcx.erase_regions(pred);
244+
// Lifetimes can only be 'static because of the bound on T
245+
let pred = pred.fold_with(&mut ty::BottomUpFolder {
246+
tcx,
247+
ty_op: |ty| ty,
248+
lt_op: |lt| {
249+
if lt == tcx.lifetimes.re_erased { tcx.lifetimes.re_static } else { lt }
250+
},
251+
ct_op: |ct| ct,
252+
});
244253
Obligation::new(tcx, ObligationCause::dummy(), param_env, pred)
245254
}));
246255
let type_impls_trait = ocx.select_all_or_error().is_empty();
256+
// Since `assumed_wf_tys=[]` the choice of LocalDefId is irrelevant, so using the "default"
257+
let regions_are_valid = ocx.resolve_regions(CRATE_DEF_ID, param_env, []).is_empty();
247258

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

0 commit comments

Comments
 (0)