Skip to content

Commit da59fa7

Browse files
Use ObligationCtxt in main fn return type check
1 parent 6f18f0a commit da59fa7

File tree

1 file changed

+7
-24
lines changed
  • compiler/rustc_typeck/src

1 file changed

+7
-24
lines changed

compiler/rustc_typeck/src/lib.rs

+7-24
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ use rustc_middle::util;
112112
use rustc_session::config::EntryFnType;
113113
use rustc_span::{symbol::sym, Span, DUMMY_SP};
114114
use rustc_target::spec::abi::Abi;
115-
use rustc_trait_selection::infer::InferCtxtExt;
116115
use rustc_trait_selection::traits::error_reporting::InferCtxtExt as _;
117116
use rustc_trait_selection::traits::{
118117
self, ObligationCause, ObligationCauseCode, TraitEngine, TraitEngineExt as _,
@@ -303,7 +302,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
303302
}
304303

305304
let expected_return_type;
306-
if let Some(term_id) = tcx.lang_items().termination() {
305+
if let Some(term_did) = tcx.lang_items().termination() {
307306
let return_ty = main_fnsig.output();
308307
let return_ty_span = main_fn_return_type_span(tcx, main_def_id).unwrap_or(main_span);
309308
if !return_ty.bound_vars().is_empty() {
@@ -314,33 +313,17 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
314313
}
315314
let return_ty = return_ty.skip_binder();
316315
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();
317318
let cause = traits::ObligationCause::new(
318319
return_ty_span,
319320
main_diagnostics_hir_id,
320321
ObligationCauseCode::MainFunctionType,
321322
);
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();
344327
if !errors.is_empty() {
345328
infcx.report_fulfillment_errors(&errors, None, false);
346329
error = true;

0 commit comments

Comments
 (0)