review, small cleanup
This commit is contained in:
parent
1b275d08ad
commit
09e6254496
1 changed files with 21 additions and 18 deletions
|
@ -30,24 +30,24 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
|
||||||
span: Span,
|
span: Span,
|
||||||
) -> Result<(), ErrorHandled> {
|
) -> Result<(), ErrorHandled> {
|
||||||
debug!("is_const_evaluatable({:?}, {:?})", def, substs);
|
debug!("is_const_evaluatable({:?}, {:?})", def, substs);
|
||||||
if infcx.tcx.features().const_evaluatable_checked {
|
// `AbstractConst::new` already returns `None` if `const_evaluatable_checked`
|
||||||
if let Some(ct) = AbstractConst::new(infcx.tcx, def, substs) {
|
// is not active, so we don't have to explicitly check for this here.
|
||||||
for pred in param_env.caller_bounds() {
|
if let Some(ct) = AbstractConst::new(infcx.tcx, def, substs) {
|
||||||
match pred.skip_binders() {
|
for pred in param_env.caller_bounds() {
|
||||||
ty::PredicateAtom::ConstEvaluatable(b_def, b_substs) => {
|
match pred.skip_binders() {
|
||||||
debug!("is_const_evaluatable: caller_bound={:?}, {:?}", b_def, b_substs);
|
ty::PredicateAtom::ConstEvaluatable(b_def, b_substs) => {
|
||||||
if b_def == def && b_substs == substs {
|
debug!("is_const_evaluatable: caller_bound={:?}, {:?}", b_def, b_substs);
|
||||||
debug!("is_const_evaluatable: caller_bound ~~> ok");
|
if b_def == def && b_substs == substs {
|
||||||
return Ok(());
|
debug!("is_const_evaluatable: caller_bound ~~> ok");
|
||||||
} else if AbstractConst::new(infcx.tcx, b_def, b_substs)
|
return Ok(());
|
||||||
.map_or(false, |b_ct| try_unify(infcx.tcx, ct, b_ct))
|
} else if AbstractConst::new(infcx.tcx, b_def, b_substs)
|
||||||
{
|
.map_or(false, |b_ct| try_unify(infcx.tcx, ct, b_ct))
|
||||||
debug!("is_const_evaluatable: abstract_const ~~> ok");
|
{
|
||||||
return Ok(());
|
debug!("is_const_evaluatable: abstract_const ~~> ok");
|
||||||
}
|
return Ok(());
|
||||||
}
|
}
|
||||||
_ => {} // don't care
|
|
||||||
}
|
}
|
||||||
|
_ => {} // don't care
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -394,14 +394,17 @@ pub(super) fn try_unify<'tcx>(
|
||||||
let a_ct = a_ct.subst(tcx, a.substs);
|
let a_ct = a_ct.subst(tcx, a.substs);
|
||||||
let b_ct = b_ct.subst(tcx, b.substs);
|
let b_ct = b_ct.subst(tcx, b.substs);
|
||||||
match (a_ct.val, b_ct.val) {
|
match (a_ct.val, b_ct.val) {
|
||||||
|
// We can just unify errors with everything to reduce the amount of
|
||||||
|
// emitted errors here.
|
||||||
|
(ty::ConstKind::Error(_), _) | (_, ty::ConstKind::Error(_)) => true,
|
||||||
(ty::ConstKind::Param(a_param), ty::ConstKind::Param(b_param)) => {
|
(ty::ConstKind::Param(a_param), ty::ConstKind::Param(b_param)) => {
|
||||||
a_param == b_param
|
a_param == b_param
|
||||||
}
|
}
|
||||||
(ty::ConstKind::Value(a_val), ty::ConstKind::Value(b_val)) => a_val == b_val,
|
(ty::ConstKind::Value(a_val), ty::ConstKind::Value(b_val)) => a_val == b_val,
|
||||||
// If we have `fn a<const N: usize>() -> [u8; N + 1]` and `fn b<const M: usize>() -> [u8; 1 + M]`
|
// If we have `fn a<const N: usize>() -> [u8; N + 1]` and `fn b<const M: usize>() -> [u8; 1 + M]`
|
||||||
// we do not want to use `assert_eq!(a(), b())` to infer that `N` and `M` have to be `1`. This
|
// we do not want to use `assert_eq!(a(), b())` to infer that `N` and `M` have to be `1`. This
|
||||||
// means that we can't do anything with inference variables here.
|
// means that we only allow inference variables if they are equal.
|
||||||
(ty::ConstKind::Infer(_), _) | (_, ty::ConstKind::Infer(_)) => false,
|
(ty::ConstKind::Infer(a_val), ty::ConstKind::Infer(b_val)) => a_val == b_val,
|
||||||
// FIXME(const_evaluatable_checked): We may want to either actually try
|
// FIXME(const_evaluatable_checked): We may want to either actually try
|
||||||
// to evaluate `a_ct` and `b_ct` if they are are fully concrete or something like
|
// to evaluate `a_ct` and `b_ct` if they are are fully concrete or something like
|
||||||
// this, for now we just return false here.
|
// this, for now we just return false here.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue