@@ -92,24 +92,6 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
9292
9393 let mut error = false ;
9494 let main_diagnostics_def_id = main_fn_diagnostics_def_id ( tcx, main_def_id, main_span) ;
95- let main_fn_generics = tcx. generics_of ( main_def_id) ;
96- let main_fn_predicates = tcx. predicates_of ( main_def_id) ;
97- if main_fn_generics. count ( ) != 0 || !main_fnsig. bound_vars ( ) . is_empty ( ) {
98- let generics_param_span = main_fn_generics_params_span ( tcx, main_def_id) ;
99- tcx. sess . emit_err ( errors:: MainFunctionGenericParameters {
100- span : generics_param_span. unwrap_or ( main_span) ,
101- label_span : generics_param_span,
102- } ) ;
103- error = true ;
104- } else if !main_fn_predicates. predicates . is_empty ( ) {
105- // generics may bring in implicit predicates, so we skip this check if generics is present.
106- let generics_where_clauses_span = main_fn_where_clauses_span ( tcx, main_def_id) ;
107- tcx. sess . emit_err ( errors:: WhereClauseOnMain {
108- span : generics_where_clauses_span. unwrap_or ( main_span) ,
109- generics_span : generics_where_clauses_span,
110- } ) ;
111- error = true ;
112- }
11395
11496 let main_asyncness = tcx. asyncness ( main_def_id) ;
11597 if main_asyncness. is_async ( ) {
@@ -142,10 +124,6 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
142124 if let Some ( term_did) = tcx. lang_items ( ) . termination ( ) {
143125 let return_ty = main_fnsig. output ( ) ;
144126 let return_ty_span = main_fn_return_type_span ( tcx, main_def_id) . unwrap_or ( main_span) ;
145- if !return_ty. bound_vars ( ) . is_empty ( ) {
146- tcx. sess . emit_err ( errors:: MainFunctionReturnTypeGeneric { span : return_ty_span } ) ;
147- error = true ;
148- }
149127 let return_ty = return_ty. skip_binder ( ) ;
150128 let infcx = tcx. infer_ctxt ( ) . build ( ) ;
151129 let cause = traits:: ObligationCause :: new (
@@ -180,7 +158,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
180158 Abi :: Rust ,
181159 ) ) ;
182160
183- check_function_signature (
161+ if check_function_signature (
184162 tcx,
185163 ObligationCause :: new (
186164 main_span,
@@ -189,7 +167,28 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
189167 ) ,
190168 main_def_id,
191169 expected_sig,
192- ) ;
170+ )
171+ . is_err ( )
172+ {
173+ return ;
174+ }
175+
176+ let main_fn_generics = tcx. generics_of ( main_def_id) ;
177+ let main_fn_predicates = tcx. predicates_of ( main_def_id) ;
178+ if main_fn_generics. count ( ) != 0 || !main_fnsig. bound_vars ( ) . is_empty ( ) {
179+ let generics_param_span = main_fn_generics_params_span ( tcx, main_def_id) ;
180+ tcx. sess . emit_err ( errors:: MainFunctionGenericParameters {
181+ span : generics_param_span. unwrap_or ( main_span) ,
182+ label_span : generics_param_span,
183+ } ) ;
184+ } else if !main_fn_predicates. predicates . is_empty ( ) {
185+ // generics may bring in implicit predicates, so we skip this check if generics is present.
186+ let generics_where_clauses_span = main_fn_where_clauses_span ( tcx, main_def_id) ;
187+ tcx. sess . emit_err ( errors:: WhereClauseOnMain {
188+ span : generics_where_clauses_span. unwrap_or ( main_span) ,
189+ generics_span : generics_where_clauses_span,
190+ } ) ;
191+ }
193192}
194193
195194fn check_start_fn_ty ( tcx : TyCtxt < ' _ > , start_def_id : DefId ) {
@@ -255,7 +254,7 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: DefId) {
255254 Abi :: Rust ,
256255 ) ) ;
257256
258- check_function_signature (
257+ let _ = check_function_signature (
259258 tcx,
260259 ObligationCause :: new (
261260 start_span,
0 commit comments