Bail in combine if consts have different types
This commit is contained in:
parent
9574f39c2d
commit
f7146136d7
1 changed files with 15 additions and 7 deletions
|
@ -34,7 +34,6 @@ use rustc_hir::def_id::DefId;
|
|||
use rustc_middle::infer::canonical::OriginalQueryValues;
|
||||
use rustc_middle::infer::unify_key::{ConstVarValue, ConstVariableValue};
|
||||
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind};
|
||||
use rustc_middle::traits::query::NoSolution;
|
||||
use rustc_middle::traits::ObligationCause;
|
||||
use rustc_middle::ty::error::{ExpectedFound, TypeError};
|
||||
use rustc_middle::ty::relate::{self, Relate, RelateResult, TypeRelation};
|
||||
|
@ -161,9 +160,9 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
//
|
||||
// This probe is probably not strictly necessary but it seems better to be safe and not accidentally find
|
||||
// ourselves with a check to find bugs being required for code to compile because it made inference progress.
|
||||
self.probe(|_| {
|
||||
let compatible_types = self.probe(|_| {
|
||||
if a.ty() == b.ty() {
|
||||
return;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// We don't have access to trait solving machinery in `rustc_infer` so the logic for determining if the
|
||||
|
@ -173,15 +172,24 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
(relation.param_env(), a.ty(), b.ty()),
|
||||
&mut OriginalQueryValues::default(),
|
||||
);
|
||||
|
||||
if let Err(NoSolution) = self.tcx.check_tys_might_be_eq(canonical) {
|
||||
self.tcx.check_tys_might_be_eq(canonical).map_err(|_| {
|
||||
self.tcx.sess.delay_span_bug(
|
||||
DUMMY_SP,
|
||||
&format!("cannot relate consts of different types (a={:?}, b={:?})", a, b,),
|
||||
);
|
||||
}
|
||||
)
|
||||
})
|
||||
});
|
||||
|
||||
// If the consts have differing types, just bail with a const error with
|
||||
// the expected const's type. Specifically, we don't want const infer vars
|
||||
// to do any type shapeshifting before and after resolution.
|
||||
if let Err(guar) = compatible_types {
|
||||
return Ok(self.tcx.const_error_with_guaranteed(
|
||||
if relation.a_is_expected() { a.ty() } else { b.ty() },
|
||||
guar,
|
||||
));
|
||||
}
|
||||
|
||||
match (a.kind(), b.kind()) {
|
||||
(
|
||||
ty::ConstKind::Infer(InferConst::Var(a_vid)),
|
||||
|
|
Loading…
Add table
Reference in a new issue