Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion compiler/rustc_typeck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ use rustc_middle::util;
use rustc_session::config::EntryFnType;
use rustc_span::{symbol::sym, Span, DUMMY_SP};
use rustc_target::spec::abi::Abi;
use rustc_trait_selection::infer::InferCtxtExt;
use rustc_trait_selection::traits::error_reporting::InferCtxtExt as _;
use rustc_trait_selection::traits::{
self, ObligationCause, ObligationCauseCode, TraitEngine, TraitEngineExt as _,
Expand Down Expand Up @@ -328,7 +329,26 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
ObligationCauseCode::MainFunctionType,
);
let mut fulfillment_cx = traits::FulfillmentContext::new();
fulfillment_cx.register_bound(&infcx, ty::ParamEnv::empty(), return_ty, term_id, cause);
// normalize any potential projections in the return type, then add
// any possible obligations to the fulfillment context.
// HACK(ThePuzzlemaker) this feels symptomatic of a problem within
// checking trait fulfillment, not this here. I'm not sure why it
// works in the example in `fn test()` given in #88609? This also
// probably isn't the best way to do this.
let InferOk { value: norm_return_ty, obligations } = infcx
.partially_normalize_associated_types_in(
cause.clone(),
ty::ParamEnv::empty(),
return_ty,
);
fulfillment_cx.register_predicate_obligations(&infcx, obligations);
fulfillment_cx.register_bound(
&infcx,
ty::ParamEnv::empty(),
norm_return_ty,
term_id,
cause,
);
if let Err(err) = fulfillment_cx.select_all_or_error(&infcx) {
infcx.report_fulfillment_errors(&err, None, false);
error = true;
Expand Down
19 changes: 19 additions & 0 deletions src/test/ui/typeck/issue-88609.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Regression test for #88609:
// The return type for `main` is not normalized while checking if it implements
// the trait `std::process::Termination`.

// build-pass

trait Same {
type Output;
}

impl<T> Same for T {
type Output = T;
}

type Unit = <() as Same>::Output;

fn main() -> Result<Unit, std::io::Error> {
unimplemented!()
}