@@ -102,7 +102,7 @@ use rustc_errors::ErrorGuaranteed;
102
102
use rustc_errors:: { DiagnosticMessage , SubdiagnosticMessage } ;
103
103
use rustc_hir as hir;
104
104
use rustc_hir:: Node ;
105
- use rustc_infer:: infer:: { DefineOpaqueTypes , InferOk , TyCtxtInferExt } ;
105
+ use rustc_infer:: infer:: TyCtxtInferExt ;
106
106
use rustc_macros:: fluent_messages;
107
107
use rustc_middle:: middle;
108
108
use rustc_middle:: ty:: query:: Providers ;
@@ -113,7 +113,7 @@ use rustc_span::def_id::{DefId, LocalDefId, CRATE_DEF_ID};
113
113
use rustc_span:: { symbol:: sym, Span , DUMMY_SP } ;
114
114
use rustc_target:: spec:: abi:: Abi ;
115
115
use 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 } ;
117
117
118
118
use std:: ops:: Not ;
119
119
@@ -160,24 +160,21 @@ fn require_c_abi_if_c_variadic(tcx: TyCtxt<'_>, decl: &hir::FnDecl<'_>, abi: Abi
160
160
fn require_same_types < ' tcx > (
161
161
tcx : TyCtxt < ' tcx > ,
162
162
cause : & ObligationCause < ' tcx > ,
163
+ param_env : ty:: ParamEnv < ' tcx > ,
163
164
expected : Ty < ' tcx > ,
164
165
actual : Ty < ' tcx > ,
165
- ) -> bool {
166
+ ) {
166
167
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
+ }
170
176
Err ( err) => {
171
177
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
181
178
}
182
179
}
183
180
}
@@ -296,6 +293,8 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
296
293
return ;
297
294
}
298
295
296
+ // Main should have no WC, so empty param env is OK here.
297
+ let param_env = ty:: ParamEnv :: empty ( ) ;
299
298
let expected_return_type;
300
299
if let Some ( term_did) = tcx. lang_items ( ) . termination ( ) {
301
300
let return_ty = main_fnsig. output ( ) ;
@@ -306,8 +305,6 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
306
305
}
307
306
let return_ty = return_ty. skip_binder ( ) ;
308
307
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 ( ) ;
311
308
let cause = traits:: ObligationCause :: new (
312
309
return_ty_span,
313
310
main_diagnostics_def_id,
@@ -343,6 +340,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
343
340
main_diagnostics_def_id,
344
341
ObligationCauseCode :: MainFunctionType ,
345
342
) ,
343
+ param_env,
346
344
se_ty,
347
345
tcx. mk_fn_ptr ( main_fnsig) ,
348
346
) ;
@@ -417,6 +415,7 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: DefId) {
417
415
start_def_id,
418
416
ObligationCauseCode :: StartFunctionType ,
419
417
) ,
418
+ ty:: ParamEnv :: empty ( ) , // start should not have any where bounds.
420
419
se_ty,
421
420
tcx. mk_fn_ptr ( tcx. fn_sig ( start_def_id) . subst_identity ( ) ) ,
422
421
) ;
0 commit comments