deal with const_evaluatable_checked
in ConstEquate
This commit is contained in:
parent
1773f14a24
commit
412e0404c0
7 changed files with 80 additions and 6 deletions
|
@ -6,7 +6,7 @@ use rustc_errors::ErrorReported;
|
|||
use rustc_infer::traits::{SelectionError, TraitEngine, TraitEngineExt as _, TraitObligation};
|
||||
use rustc_middle::mir::abstract_const::NotConstEvaluatable;
|
||||
use rustc_middle::mir::interpret::ErrorHandled;
|
||||
use rustc_middle::ty::error::ExpectedFound;
|
||||
use rustc_middle::ty::error::{ExpectedFound, TypeError};
|
||||
use rustc_middle::ty::subst::SubstsRef;
|
||||
use rustc_middle::ty::ToPredicate;
|
||||
use rustc_middle::ty::{self, Binder, Const, Ty, TypeFoldable};
|
||||
|
@ -591,7 +591,16 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
|
|||
)
|
||||
}
|
||||
(Err(ErrorHandled::TooGeneric), _) | (_, Err(ErrorHandled::TooGeneric)) => {
|
||||
ProcessResult::Unchanged
|
||||
if c1.has_infer_types_or_consts() || c2.has_infer_types_or_consts() {
|
||||
ProcessResult::Unchanged
|
||||
} else {
|
||||
// Two different constants using generic parameters ~> error.
|
||||
let expected_found = ExpectedFound::new(true, c1, c2);
|
||||
ProcessResult::Error(FulfillmentErrorCode::CodeConstEquateError(
|
||||
expected_found,
|
||||
TypeError::ConstMismatch(expected_found),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -557,6 +557,23 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
ty::PredicateKind::ConstEquate(c1, c2) => {
|
||||
debug!(?c1, ?c2, "evaluate_predicate_recursively: equating consts");
|
||||
|
||||
if self.tcx().features().const_evaluatable_checked {
|
||||
// FIXME: we probably should only try to unify abstract constants
|
||||
// if the constants depend on generic parameters.
|
||||
//
|
||||
// Let's just see where this breaks :shrug:
|
||||
if let (ty::ConstKind::Unevaluated(a), ty::ConstKind::Unevaluated(b)) =
|
||||
(c1.val, c2.val)
|
||||
{
|
||||
if self
|
||||
.tcx()
|
||||
.try_unify_abstract_consts(((a.def, a.substs), (b.def, b.substs)))
|
||||
{
|
||||
return Ok(EvaluatedToOk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let evaluate = |c: &'tcx ty::Const<'tcx>| {
|
||||
if let ty::ConstKind::Unevaluated(unevaluated) = c.val {
|
||||
self.infcx
|
||||
|
@ -591,7 +608,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
)
|
||||
}
|
||||
(Err(ErrorHandled::TooGeneric), _) | (_, Err(ErrorHandled::TooGeneric)) => {
|
||||
Ok(EvaluatedToAmbig)
|
||||
if c1.has_infer_types_or_consts() || c2.has_infer_types_or_consts() {
|
||||
Ok(EvaluatedToAmbig)
|
||||
} else {
|
||||
// Two different constants using generic parameters ~> error.
|
||||
Ok(EvaluatedToErr)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue