Skip to content

Commit b9fe8a5

Browse files
Filter nested obligations during HIR coercion
1 parent f63ccaf commit b9fe8a5

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

compiler/rustc_hir_typeck/src/coercion.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ use rustc_span::{self, BytePos, DesugaringKind, Span};
6262
use rustc_target::spec::abi::Abi;
6363
use rustc_trait_selection::infer::InferCtxtExt as _;
6464
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt as _;
65+
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
6566
use rustc_trait_selection::traits::{
6667
self, NormalizeExt, ObligationCause, ObligationCauseCode, ObligationCtxt,
6768
};
@@ -144,12 +145,22 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
144145
debug!("unify(a: {:?}, b: {:?}, use_lub: {})", a, b, self.use_lub);
145146
self.commit_if_ok(|_| {
146147
let at = self.at(&self.cause, self.fcx.param_env).define_opaque_types(true);
147-
if self.use_lub {
148+
let result = if self.use_lub {
148149
at.lub(b, a)
149150
} else {
150151
at.sup(b, a)
151152
.map(|InferOk { value: (), obligations }| InferOk { value: a, obligations })
153+
}?;
154+
155+
if self.tcx.trait_solver_next() {
156+
for obligation in &result.obligations {
157+
if !self.predicate_may_hold(obligation) {
158+
return Err(TypeError::Mismatch);
159+
}
160+
}
152161
}
162+
163+
Ok(result)
153164
})
154165
}
155166

0 commit comments

Comments
 (0)