@@ -18,6 +18,7 @@ use rustc_infer::infer::canonical::{Canonical, OriginalQueryValues, QueryRespons
18
18
use rustc_infer:: infer:: error_reporting:: TypeAnnotationNeeded :: E0282 ;
19
19
use rustc_infer:: infer:: { InferOk , InferResult } ;
20
20
use rustc_middle:: ty:: adjustment:: { Adjust , Adjustment , AutoBorrow , AutoBorrowMutability } ;
21
+ use rustc_middle:: ty:: error:: TypeError ;
21
22
use rustc_middle:: ty:: fold:: TypeFoldable ;
22
23
use rustc_middle:: ty:: visit:: TypeVisitable ;
23
24
use rustc_middle:: ty:: {
@@ -32,9 +33,7 @@ use rustc_span::symbol::{kw, sym, Ident};
32
33
use rustc_span:: { Span , DUMMY_SP } ;
33
34
use rustc_trait_selection:: infer:: InferCtxtExt as _;
34
35
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 } ;
38
37
39
38
use std:: collections:: hash_map:: Entry ;
40
39
use std:: slice;
@@ -766,34 +765,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
766
765
767
766
let expect_args = self
768
767
. fudge_inference_if_ok ( || {
768
+ let ocx = ObligationCtxt :: new ( self ) ;
769
+
769
770
// Attempt to apply a subtyping relationship between the formal
770
771
// return type (likely containing type variables if the function
771
772
// is polymorphic) and the expected return type.
772
773
// No argument expectations are produced if unification fails.
773
774
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 ) ;
797
778
}
798
779
799
780
// Record all the argument types, with the substitutions
0 commit comments