Skip to content

Commit bdced83

Browse files
Use ObligationCtxt in expected_inputs_for_expected_outputs
1 parent cc9b259 commit bdced83

File tree

1 file changed

+7
-26
lines changed
  • compiler/rustc_hir_typeck/src/fn_ctxt

1 file changed

+7
-26
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+7-26
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use rustc_infer::infer::canonical::{Canonical, OriginalQueryValues, QueryRespons
1818
use rustc_infer::infer::error_reporting::TypeAnnotationNeeded::E0282;
1919
use rustc_infer::infer::{InferOk, InferResult};
2020
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, AutoBorrowMutability};
21+
use rustc_middle::ty::error::TypeError;
2122
use rustc_middle::ty::fold::TypeFoldable;
2223
use rustc_middle::ty::visit::TypeVisitable;
2324
use rustc_middle::ty::{
@@ -32,9 +33,7 @@ use rustc_span::symbol::{kw, sym, Ident};
3233
use rustc_span::{Span, DUMMY_SP};
3334
use rustc_trait_selection::infer::InferCtxtExt as _;
3435
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt as _;
35-
use rustc_trait_selection::traits::{
36-
self, ObligationCause, ObligationCauseCode, TraitEngine, TraitEngineExt,
37-
};
36+
use rustc_trait_selection::traits::{self, ObligationCause, ObligationCauseCode, ObligationCtxt};
3837

3938
use std::collections::hash_map::Entry;
4039
use std::slice;
@@ -766,34 +765,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
766765

767766
let expect_args = self
768767
.fudge_inference_if_ok(|| {
768+
let ocx = ObligationCtxt::new(self);
769+
769770
// Attempt to apply a subtyping relationship between the formal
770771
// return type (likely containing type variables if the function
771772
// is polymorphic) and the expected return type.
772773
// No argument expectations are produced if unification fails.
773774
let origin = self.misc(call_span);
774-
let ures = self.at(&origin, self.param_env).sup(ret_ty, formal_ret);
775-
776-
// FIXME(#27336) can't use ? here, Try::from_error doesn't default
777-
// to identity so the resulting type is not constrained.
778-
match ures {
779-
Ok(ok) => {
780-
// Process any obligations locally as much as
781-
// we can. We don't care if some things turn
782-
// out unconstrained or ambiguous, as we're
783-
// just trying to get hints here.
784-
let errors = self.save_and_restore_in_snapshot_flag(|_| {
785-
let mut fulfill = <dyn TraitEngine<'_>>::new(self.tcx);
786-
for obligation in ok.obligations {
787-
fulfill.register_predicate_obligation(self, obligation);
788-
}
789-
fulfill.select_where_possible(self)
790-
});
791-
792-
if !errors.is_empty() {
793-
return Err(());
794-
}
795-
}
796-
Err(_) => return Err(()),
775+
ocx.sup(&origin, self.param_env, ret_ty, formal_ret)?;
776+
if !ocx.select_where_possible().is_empty() {
777+
return Err(TypeError::Mismatch);
797778
}
798779

799780
// Record all the argument types, with the substitutions

0 commit comments

Comments
 (0)