@@ -112,7 +112,6 @@ use rustc_middle::util;
112
112
use rustc_session:: config:: EntryFnType ;
113
113
use rustc_span:: { symbol:: sym, Span , DUMMY_SP } ;
114
114
use rustc_target:: spec:: abi:: Abi ;
115
- use rustc_trait_selection:: infer:: InferCtxtExt ;
116
115
use rustc_trait_selection:: traits:: error_reporting:: InferCtxtExt as _;
117
116
use rustc_trait_selection:: traits:: {
118
117
self , ObligationCause , ObligationCauseCode , TraitEngine , TraitEngineExt as _,
@@ -303,7 +302,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
303
302
}
304
303
305
304
let expected_return_type;
306
- if let Some ( term_id ) = tcx. lang_items ( ) . termination ( ) {
305
+ if let Some ( term_did ) = tcx. lang_items ( ) . termination ( ) {
307
306
let return_ty = main_fnsig. output ( ) ;
308
307
let return_ty_span = main_fn_return_type_span ( tcx, main_def_id) . unwrap_or ( main_span) ;
309
308
if !return_ty. bound_vars ( ) . is_empty ( ) {
@@ -314,33 +313,17 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
314
313
}
315
314
let return_ty = return_ty. skip_binder ( ) ;
316
315
tcx. infer_ctxt ( ) . enter ( |infcx| {
316
+ // Main should have no WC, so empty param env is OK here.
317
+ let param_env = ty:: ParamEnv :: empty ( ) ;
317
318
let cause = traits:: ObligationCause :: new (
318
319
return_ty_span,
319
320
main_diagnostics_hir_id,
320
321
ObligationCauseCode :: MainFunctionType ,
321
322
) ;
322
- let mut fulfillment_cx = traits:: FulfillmentContext :: new ( ) ;
323
- // normalize any potential projections in the return type, then add
324
- // any possible obligations to the fulfillment context.
325
- // HACK(ThePuzzlemaker) this feels symptomatic of a problem within
326
- // checking trait fulfillment, not this here. I'm not sure why it
327
- // works in the example in `fn test()` given in #88609? This also
328
- // probably isn't the best way to do this.
329
- let InferOk { value : norm_return_ty, obligations } = infcx
330
- . partially_normalize_associated_types_in (
331
- cause. clone ( ) ,
332
- ty:: ParamEnv :: empty ( ) ,
333
- return_ty,
334
- ) ;
335
- fulfillment_cx. register_predicate_obligations ( & infcx, obligations) ;
336
- fulfillment_cx. register_bound (
337
- & infcx,
338
- ty:: ParamEnv :: empty ( ) ,
339
- norm_return_ty,
340
- term_id,
341
- cause,
342
- ) ;
343
- let errors = fulfillment_cx. select_all_or_error ( & infcx) ;
323
+ let ocx = traits:: ObligationCtxt :: new ( & infcx) ;
324
+ let norm_return_ty = ocx. normalize ( cause. clone ( ) , param_env, return_ty) ;
325
+ ocx. register_bound ( cause, param_env, norm_return_ty, term_did) ;
326
+ let errors = ocx. select_all_or_error ( ) ;
344
327
if !errors. is_empty ( ) {
345
328
infcx. report_fulfillment_errors ( & errors, None , false ) ;
346
329
error = true ;
0 commit comments