File tree Expand file tree Collapse file tree 3 files changed +16
-10
lines changed
compiler/rustc_hir_analysis Expand file tree Collapse file tree 3 files changed +16
-10
lines changed Original file line number Diff line number Diff line change @@ -127,5 +127,8 @@ hir_analysis_auto_deref_reached_recursion_limit = reached the recursion limit wh
127127 .label = deref recursion limit reached
128128 .help = consider increasing the recursion limit by adding a `#![recursion_limit = "{ $suggested_limit } "]` attribute to your crate (`{ $crate_name } `)
129129
130+ hir_analysis_where_clause_on_main = `main` function is not allowed to have a `where` clause
131+ .label = `main` cannot have a `where` clause
132+
130133hir_analysis_track_caller_on_main = `main` function is not allowed to be `#[track_caller]`
131134 .label = `main` function is not allowed to be `#[track_caller]`
Original file line number Diff line number Diff line change @@ -316,6 +316,15 @@ pub struct AutoDerefReachedRecursionLimit<'a> {
316316 pub crate_name : Symbol ,
317317}
318318
319+ #[ derive( Diagnostic ) ]
320+ #[ diag( hir_analysis_where_clause_on_main, code = "E0646" ) ]
321+ pub ( crate ) struct WhereClauseOnMain {
322+ #[ primary_span]
323+ pub span : Span ,
324+ #[ label]
325+ pub generics_span : Option < Span > ,
326+ }
327+
319328#[ derive( Diagnostic ) ]
320329#[ diag( hir_analysis_track_caller_on_main) ]
321330pub ( crate ) struct TrackCallerOnMain {
Original file line number Diff line number Diff line change @@ -271,16 +271,10 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
271271 } else if !main_fn_predicates. predicates . is_empty ( ) {
272272 // generics may bring in implicit predicates, so we skip this check if generics is present.
273273 let generics_where_clauses_span = main_fn_where_clauses_span ( tcx, main_def_id) ;
274- let mut diag = struct_span_err ! (
275- tcx. sess,
276- generics_where_clauses_span. unwrap_or( main_span) ,
277- E0646 ,
278- "`main` function is not allowed to have a `where` clause"
279- ) ;
280- if let Some ( generics_where_clauses_span) = generics_where_clauses_span {
281- diag. span_label ( generics_where_clauses_span, "`main` cannot have a `where` clause" ) ;
282- }
283- diag. emit ( ) ;
274+ tcx. sess . emit_err ( errors:: WhereClauseOnMain {
275+ span : generics_where_clauses_span. unwrap_or ( main_span) ,
276+ generics_span : generics_where_clauses_span,
277+ } ) ;
284278 error = true ;
285279 }
286280
You can’t perform that action at this time.
0 commit comments