Skip to content

Commit 3b9de6b

Browse files
committed
dont try to unify unevaluated constants that contain infer vars
1 parent ac0458a commit 3b9de6b

File tree

1 file changed

+15
-1
lines changed
  • compiler/rustc_infer/src/infer

1 file changed

+15
-1
lines changed

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,14 +687,23 @@ pub struct CombinedSnapshot<'a, 'tcx> {
687687
impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
688688
/// calls `tcx.try_unify_abstract_consts` after
689689
/// canonicalizing the consts.
690+
#[instrument(skip(self), level = "debug")]
690691
pub fn try_unify_abstract_consts(
691692
&self,
692693
a: ty::Unevaluated<'tcx, ()>,
693694
b: ty::Unevaluated<'tcx, ()>,
694695
param_env: ty::ParamEnv<'tcx>,
695696
) -> bool {
697+
// Reject any attempt to unify two unevaluated constants that contain inference
698+
// variables.
699+
// FIXME `TyCtxt::const_eval_resolve` already rejects the resolution of those
700+
// constants early, but the canonicalization below messes with that mechanism.
701+
if a.substs.has_infer_types_or_consts() || b.substs.has_infer_types_or_consts() {
702+
debug!("a or b contain infer vars in its substs -> cannot unify");
703+
return false;
704+
}
705+
696706
let canonical = self.canonicalize_query((a, b), &mut OriginalQueryValues::default());
697-
debug!("canonical consts: {:?}", &canonical.value);
698707

699708
self.tcx.try_unify_abstract_consts(param_env.and(canonical.value))
700709
}
@@ -1599,22 +1608,27 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
15991608
///
16001609
/// This handles inferences variables within both `param_env` and `substs` by
16011610
/// performing the operation on their respective canonical forms.
1611+
#[instrument(skip(self), level = "debug")]
16021612
pub fn const_eval_resolve(
16031613
&self,
16041614
param_env: ty::ParamEnv<'tcx>,
16051615
unevaluated: ty::Unevaluated<'tcx>,
16061616
span: Option<Span>,
16071617
) -> EvalToConstValueResult<'tcx> {
16081618
let substs = self.resolve_vars_if_possible(unevaluated.substs);
1619+
debug!(?substs);
16091620

16101621
// Postpone the evaluation of constants whose substs depend on inference
16111622
// variables
16121623
if substs.has_infer_types_or_consts() {
1624+
debug!("has infer types or consts");
16131625
return Err(ErrorHandled::TooGeneric);
16141626
}
16151627

16161628
let param_env_erased = self.tcx.erase_regions(param_env);
16171629
let substs_erased = self.tcx.erase_regions(substs);
1630+
debug!(?param_env_erased);
1631+
debug!(?substs_erased);
16181632

16191633
let unevaluated = ty::Unevaluated {
16201634
def: unevaluated.def,

0 commit comments

Comments
 (0)