Remove redundant method with const variable resolution

This commit is contained in:
varkor 2019-07-31 01:51:20 +01:00
parent 04b88a9eba
commit 87e73c1f82
3 changed files with 10 additions and 31 deletions

View File

@ -693,7 +693,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
const_var: &'tcx ty::Const<'tcx> const_var: &'tcx ty::Const<'tcx>
) -> &'tcx ty::Const<'tcx> { ) -> &'tcx ty::Const<'tcx> {
let infcx = self.infcx.expect("encountered const-var without infcx"); let infcx = self.infcx.expect("encountered const-var without infcx");
let bound_to = infcx.resolve_const_var(const_var); let bound_to = infcx.shallow_resolve(const_var);
if bound_to != const_var { if bound_to != const_var {
self.fold_const(bound_to) self.fold_const(bound_to)
} else { } else {

View File

@ -1351,23 +1351,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
} }
} }
pub fn resolve_const_var(
&self,
ct: &'tcx ty::Const<'tcx>
) -> &'tcx ty::Const<'tcx> {
if let ty::Const { val: ConstValue::Infer(InferConst::Var(v)), .. } = ct {
self.const_unification_table
.borrow_mut()
.probe_value(*v)
.val
.known()
.map(|c| self.resolve_const_var(c))
.unwrap_or(ct)
} else {
ct
}
}
pub fn fully_resolve<T: TypeFoldable<'tcx>>(&self, value: &T) -> FixupResult<'tcx, T> { pub fn fully_resolve<T: TypeFoldable<'tcx>>(&self, value: &T) -> FixupResult<'tcx, T> {
/*! /*!
* Attempts to resolve all type/region/const variables in * Attempts to resolve all type/region/const variables in
@ -1586,7 +1569,7 @@ impl<'a, 'tcx> ShallowResolver<'a, 'tcx> {
// it can be resolved to an int/float variable, which // it can be resolved to an int/float variable, which
// can then be recursively resolved, hence the // can then be recursively resolved, hence the
// recursion. Note though that we prevent type // recursion. Note though that we prevent type
// variables from unifyxing to other type variables // variables from unifying to other type variables
// directly (though they may be embedded // directly (though they may be embedded
// structurally), and we prevent cycles in any case, // structurally), and we prevent cycles in any case,
// so this recursion should always be of very limited // so this recursion should always be of very limited
@ -1626,17 +1609,15 @@ impl<'a, 'tcx> TypeFolder<'tcx> for ShallowResolver<'a, 'tcx> {
} }
fn fold_const(&mut self, ct: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> { fn fold_const(&mut self, ct: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
match ct { if let ty::Const { val: ConstValue::Infer(InferConst::Var(vid)), .. } = ct {
ty::Const { val: ConstValue::Infer(InferConst::Var(vid)), .. } => {
self.infcx.const_unification_table self.infcx.const_unification_table
.borrow_mut() .borrow_mut()
.probe_value(*vid) .probe_value(*vid)
.val .val
.known() .known()
.map(|c| self.fold_const(c))
.unwrap_or(ct) .unwrap_or(ct)
} } else {
_ => ct, ct
} }
} }
} }

View File

@ -594,13 +594,11 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
ty: a.ty, ty: a.ty,
})) }))
} }
(ConstValue::ByRef { .. }, _) => {
bug!( // FIXME(const_generics): we should either handle `Scalar::Ptr` or add a comment
"non-Scalar ConstValue encountered in super_relate_consts {:?} {:?}", // saying that we're not handling it intentionally.
a,
b, // FIXME(const_generics): handle `ConstValue::ByRef` and `ConstValue::Slice`.
);
}
// FIXME(const_generics): this is wrong, as it is a projection // FIXME(const_generics): this is wrong, as it is a projection
(ConstValue::Unevaluated(a_def_id, a_substs), (ConstValue::Unevaluated(a_def_id, a_substs),