@@ -102,7 +102,7 @@ use rustc_errors::ErrorGuaranteed;
102102use rustc_errors:: { DiagnosticMessage , SubdiagnosticMessage } ;
103103use rustc_hir as hir;
104104use rustc_hir:: Node ;
105- use rustc_infer:: infer:: { DefineOpaqueTypes , InferOk , TyCtxtInferExt } ;
105+ use rustc_infer:: infer:: TyCtxtInferExt ;
106106use rustc_macros:: fluent_messages;
107107use rustc_middle:: middle;
108108use rustc_middle:: ty:: query:: Providers ;
@@ -113,7 +113,7 @@ use rustc_span::def_id::{DefId, LocalDefId, CRATE_DEF_ID};
113113use rustc_span:: { symbol:: sym, Span , DUMMY_SP } ;
114114use rustc_target:: spec:: abi:: Abi ;
115115use rustc_trait_selection:: traits:: error_reporting:: TypeErrCtxtExt as _;
116- use rustc_trait_selection:: traits:: { self , ObligationCause , ObligationCauseCode } ;
116+ use rustc_trait_selection:: traits:: { self , ObligationCause , ObligationCauseCode , ObligationCtxt } ;
117117
118118use std:: ops:: Not ;
119119
@@ -160,24 +160,21 @@ fn require_c_abi_if_c_variadic(tcx: TyCtxt<'_>, decl: &hir::FnDecl<'_>, abi: Abi
160160fn require_same_types < ' tcx > (
161161 tcx : TyCtxt < ' tcx > ,
162162 cause : & ObligationCause < ' tcx > ,
163+ param_env : ty:: ParamEnv < ' tcx > ,
163164 expected : Ty < ' tcx > ,
164165 actual : Ty < ' tcx > ,
165- ) -> bool {
166+ ) {
166167 let infcx = & tcx. infer_ctxt ( ) . build ( ) ;
167- let param_env = ty:: ParamEnv :: empty ( ) ;
168- let errors = match infcx. at ( cause, param_env) . eq ( DefineOpaqueTypes :: No , expected, actual) {
169- Ok ( InferOk { obligations, .. } ) => traits:: fully_solve_obligations ( infcx, obligations) ,
168+ let ocx = ObligationCtxt :: new ( infcx) ;
169+ match ocx. eq ( cause, param_env, expected, actual) {
170+ Ok ( ( ) ) => {
171+ let errors = ocx. select_all_or_error ( ) ;
172+ if !errors. is_empty ( ) {
173+ infcx. err_ctxt ( ) . report_fulfillment_errors ( & errors) ;
174+ }
175+ }
170176 Err ( err) => {
171177 infcx. err_ctxt ( ) . report_mismatched_types ( cause, expected, actual, err) . emit ( ) ;
172- return false ;
173- }
174- } ;
175-
176- match & errors[ ..] {
177- [ ] => true ,
178- errors => {
179- infcx. err_ctxt ( ) . report_fulfillment_errors ( errors) ;
180- false
181178 }
182179 }
183180}
@@ -296,6 +293,8 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
296293 return ;
297294 }
298295
296+ // Main should have no WC, so empty param env is OK here.
297+ let param_env = ty:: ParamEnv :: empty ( ) ;
299298 let expected_return_type;
300299 if let Some ( term_did) = tcx. lang_items ( ) . termination ( ) {
301300 let return_ty = main_fnsig. output ( ) ;
@@ -306,8 +305,6 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
306305 }
307306 let return_ty = return_ty. skip_binder ( ) ;
308307 let infcx = tcx. infer_ctxt ( ) . build ( ) ;
309- // Main should have no WC, so empty param env is OK here.
310- let param_env = ty:: ParamEnv :: empty ( ) ;
311308 let cause = traits:: ObligationCause :: new (
312309 return_ty_span,
313310 main_diagnostics_def_id,
@@ -343,6 +340,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
343340 main_diagnostics_def_id,
344341 ObligationCauseCode :: MainFunctionType ,
345342 ) ,
343+ param_env,
346344 se_ty,
347345 tcx. mk_fn_ptr ( main_fnsig) ,
348346 ) ;
@@ -417,6 +415,7 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: DefId) {
417415 start_def_id,
418416 ObligationCauseCode :: StartFunctionType ,
419417 ) ,
418+ ty:: ParamEnv :: empty ( ) , // start should not have any where bounds.
420419 se_ty,
421420 tcx. mk_fn_ptr ( tcx. fn_sig ( start_def_id) . subst_identity ( ) ) ,
422421 ) ;
0 commit comments