Skip to content

Commit fe87b6a

Browse files
committed
Use infcx.at(..).normalize() in const eval to deal with inference
variables.
1 parent 77a6e85 commit fe87b6a

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

src/librustc_mir/interpret/eval_context.rs

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc::mir::interpret::{
99
};
1010
use rustc::ty::layout::{self, Align, HasDataLayout, LayoutOf, Size, TyLayout};
1111
use rustc::ty::query::TyCtxtAt;
12-
use rustc::ty::subst::SubstsRef;
12+
use rustc::ty::subst::{Subst, SubstsRef};
1313
use rustc::ty::{self, Instance, Ty, TyCtxt, TypeFoldable};
1414
use rustc_data_structures::fx::FxHashMap;
1515
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@@ -25,6 +25,7 @@ use super::{
2525
};
2626
use rustc::infer::canonical::OriginalQueryValues;
2727
use rustc::infer::InferCtxt;
28+
use rustc::traits::ObligationCause;
2829

2930
pub struct InterpCx<'infcx, 'mir, 'tcx, M: Machine<'mir, 'tcx>> {
3031
/// Stores the `Machine` instance.
@@ -345,26 +346,18 @@ impl<'infcx, 'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'infcx, 'mir, 'tcx, M>
345346
&self,
346347
value: T,
347348
) -> T {
348-
let mut param_env = self.param_env;
349-
param_env.caller_bounds =
350-
self.tcx.mk_predicates(param_env.caller_bounds.iter().filter(|predicate| {
351-
match *predicate {
352-
ty::Predicate::Trait(..)
353-
| ty::Predicate::Subtype(..)
354-
| ty::Predicate::Projection(..)
355-
| ty::Predicate::WellFormed(..)
356-
| ty::Predicate::ObjectSafe(..)
357-
| ty::Predicate::ClosureKind(..)
358-
| ty::Predicate::ConstEvaluatable(..) => true,
359-
ty::Predicate::TypeOutlives(..) | ty::Predicate::RegionOutlives(..) => false,
360-
}
361-
}));
362-
363-
self.tcx.subst_and_normalize_erasing_regions(
364-
self.frame().instance.substs,
365-
param_env,
366-
&value,
367-
)
349+
let substituted = value.subst(*self.tcx, self.frame().instance.substs);
350+
let erased_value = self.tcx.erase_regions(&substituted);
351+
352+
// TODO handle normalization failure and obligations
353+
let normalized_value = self
354+
.infcx
355+
.at(&ObligationCause::dummy(), self.param_env)
356+
.normalize(&erased_value)
357+
.unwrap()
358+
.value;
359+
let normalized_value = self.infcx.resolve_vars_if_possible(&normalized_value);
360+
self.tcx.erase_regions(&normalized_value)
368361
}
369362

370363
/// The `substs` are assumed to already be in our interpreter "universe" (param_env).

0 commit comments

Comments
 (0)