@@ -92,24 +92,6 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
92
92
93
93
let mut error = false ;
94
94
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
- }
113
95
114
96
let main_asyncness = tcx. asyncness ( main_def_id) ;
115
97
if main_asyncness. is_async ( ) {
@@ -142,10 +124,6 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
142
124
if let Some ( term_did) = tcx. lang_items ( ) . termination ( ) {
143
125
let return_ty = main_fnsig. output ( ) ;
144
126
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
- }
149
127
let return_ty = return_ty. skip_binder ( ) ;
150
128
let infcx = tcx. infer_ctxt ( ) . build ( ) ;
151
129
let cause = traits:: ObligationCause :: new (
@@ -180,7 +158,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
180
158
Abi :: Rust ,
181
159
) ) ;
182
160
183
- check_function_signature (
161
+ if check_function_signature (
184
162
tcx,
185
163
ObligationCause :: new (
186
164
main_span,
@@ -189,7 +167,28 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
189
167
) ,
190
168
main_def_id,
191
169
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
+ }
193
192
}
194
193
195
194
fn 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) {
255
254
Abi :: Rust ,
256
255
) ) ;
257
256
258
- check_function_signature (
257
+ let _ = check_function_signature (
259
258
tcx,
260
259
ObligationCause :: new (
261
260
start_span,
0 commit comments