Implement fold_const for BoundVarReplacer

This commit is contained in:
varkor 2019-03-09 16:54:50 +00:00
parent fa394c2283
commit cf1a719c19
4 changed files with 81 additions and 18 deletions

View file

@ -70,6 +70,13 @@ where
}
};
tcx.replace_escaping_bound_vars(value, fld_r, fld_t).0
let fld_c = |bound_ct: ty::BoundVar, _| {
match var_values.var_values[bound_ct].unpack() {
UnpackedKind::Const(ct) => ct,
c => bug!("{:?} is a const but value is {:?}", bound_ct, c),
}
};
tcx.replace_escaping_bound_vars(value, fld_r, fld_t, fld_c).0
}
}

View file

@ -4,10 +4,12 @@
use super::combine::CombineFields;
use super::{HigherRankedType, InferCtxt, PlaceholderMap};
use crate::infer::CombinedSnapshot;
use crate::infer::{CombinedSnapshot, ConstVariableOrigin};
use crate::ty::relate::{Relate, RelateResult, TypeRelation};
use crate::ty::{self, Binder, TypeFoldable};
use syntax_pos::DUMMY_SP;
impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
pub fn higher_ranked_sub<T>(
&mut self,
@ -99,7 +101,16 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
}))
};
let (result, map) = self.tcx.replace_bound_vars(binder, fld_r, fld_t);
let fld_c = |_: ty::BoundVar, ty| {
self.next_const_var_in_universe(
ty,
// FIXME(const_generics): do we want a placeholder const?
ConstVariableOrigin::MiscVariable(DUMMY_SP),
next_universe,
)
};
let (result, map) = self.tcx.replace_bound_vars(binder, fld_r, fld_t, fld_c);
debug!(
"replace_bound_vars_with_placeholders(\

View file

@ -1476,7 +1476,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
{
let fld_r = |br| self.next_region_var(LateBoundRegion(span, br, lbrct));
let fld_t = |_| self.next_ty_var(TypeVariableOrigin::MiscVariable(span));
self.tcx.replace_bound_vars(value, fld_r, fld_t)
let fld_c = |_, ty| self.next_const_var(ty, ConstVariableOrigin::MiscVariable(span));
self.tcx.replace_bound_vars(value, fld_r, fld_t, fld_c)
}
/// See the [`region_constraints::verify_generic_bound`] method.