@@ -98,7 +98,7 @@ mod outlives;
9898pub mod structured_errors;
9999mod variance;
100100
101- use rustc_errors:: { struct_span_err , ErrorGuaranteed } ;
101+ use rustc_errors:: ErrorGuaranteed ;
102102use rustc_errors:: { DiagnosticMessage , SubdiagnosticMessage } ;
103103use rustc_hir as hir;
104104use rustc_hir:: Node ;
@@ -123,7 +123,6 @@ use bounds::Bounds;
123123fluent_messages ! { "../locales/en-US.ftl" }
124124
125125fn require_c_abi_if_c_variadic ( tcx : TyCtxt < ' _ > , decl : & hir:: FnDecl < ' _ > , abi : Abi , span : Span ) {
126- const ERROR_HEAD : & str = "C-variadic function must have a compatible calling convention" ;
127126 const CONVENTIONS_UNSTABLE : & str = "`C`, `cdecl`, `win64`, `sysv64` or `efiapi`" ;
128127 const CONVENTIONS_STABLE : & str = "`C` or `cdecl`" ;
129128 const UNSTABLE_EXPLAIN : & str =
@@ -155,8 +154,7 @@ fn require_c_abi_if_c_variadic(tcx: TyCtxt<'_>, decl: &hir::FnDecl<'_>, abi: Abi
155154 ( true , false ) => CONVENTIONS_UNSTABLE ,
156155 } ;
157156
158- let mut err = struct_span_err ! ( tcx. sess, span, E0045 , "{}, like {}" , ERROR_HEAD , conventions) ;
159- err. span_label ( span, ERROR_HEAD ) . emit ( ) ;
157+ tcx. sess . emit_err ( errors:: VariadicFunctionCompatibleConvention { span, conventions } ) ;
160158}
161159
162160fn require_same_types < ' tcx > (
@@ -258,15 +256,10 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
258256 let main_fn_predicates = tcx. predicates_of ( main_def_id) ;
259257 if main_fn_generics. count ( ) != 0 || !main_fnsig. bound_vars ( ) . is_empty ( ) {
260258 let generics_param_span = main_fn_generics_params_span ( tcx, main_def_id) ;
261- let msg = "`main` function is not allowed to have generic \
262- parameters";
263- let mut diag =
264- struct_span_err ! ( tcx. sess, generics_param_span. unwrap_or( main_span) , E0131 , "{}" , msg) ;
265- if let Some ( generics_param_span) = generics_param_span {
266- let label = "`main` cannot have generic parameters" ;
267- diag. span_label ( generics_param_span, label) ;
268- }
269- diag. emit ( ) ;
259+ tcx. sess . emit_err ( errors:: MainFunctionGenericParameters {
260+ span : generics_param_span. unwrap_or ( main_span) ,
261+ label_span : generics_param_span,
262+ } ) ;
270263 error = true ;
271264 } else if !main_fn_predicates. predicates . is_empty ( ) {
272265 // generics may bring in implicit predicates, so we skip this check if generics is present.
@@ -280,17 +273,8 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
280273
281274 let main_asyncness = tcx. asyncness ( main_def_id) ;
282275 if let hir:: IsAsync :: Async = main_asyncness {
283- let mut diag = struct_span_err ! (
284- tcx. sess,
285- main_span,
286- E0752 ,
287- "`main` function is not allowed to be `async`"
288- ) ;
289276 let asyncness_span = main_fn_asyncness_span ( tcx, main_def_id) ;
290- if let Some ( asyncness_span) = asyncness_span {
291- diag. span_label ( asyncness_span, "`main` function is not allowed to be `async`" ) ;
292- }
293- diag. emit ( ) ;
277+ tcx. sess . emit_err ( errors:: MainFunctionAsync { span : main_span, asyncness : asyncness_span } ) ;
294278 error = true ;
295279 }
296280
@@ -308,9 +292,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
308292 let return_ty = main_fnsig. output ( ) ;
309293 let return_ty_span = main_fn_return_type_span ( tcx, main_def_id) . unwrap_or ( main_span) ;
310294 if !return_ty. bound_vars ( ) . is_empty ( ) {
311- let msg = "`main` function return type is not allowed to have generic \
312- parameters";
313- struct_span_err ! ( tcx. sess, return_ty_span, E0131 , "{}" , msg) . emit ( ) ;
295+ tcx. sess . emit_err ( errors:: MainFunctionReturnTypeGeneric { span : return_ty_span } ) ;
314296 error = true ;
315297 }
316298 let return_ty = return_ty. skip_binder ( ) ;
@@ -367,56 +349,28 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: DefId) {
367349 if let hir:: ItemKind :: Fn ( sig, generics, _) = & it. kind {
368350 let mut error = false ;
369351 if !generics. params . is_empty ( ) {
370- struct_span_err ! (
371- tcx. sess,
372- generics. span,
373- E0132 ,
374- "start function is not allowed to have type parameters"
375- )
376- . span_label ( generics. span , "start function cannot have type parameters" )
377- . emit ( ) ;
352+ tcx. sess . emit_err ( errors:: StartFunctionParameters { span : generics. span } ) ;
378353 error = true ;
379354 }
380355 if generics. has_where_clause_predicates {
381- struct_span_err ! (
382- tcx. sess,
383- generics. where_clause_span,
384- E0647 ,
385- "start function is not allowed to have a `where` clause"
386- )
387- . span_label (
388- generics. where_clause_span ,
389- "start function cannot have a `where` clause" ,
390- )
391- . emit ( ) ;
356+ tcx. sess . emit_err ( errors:: StartFunctionWhere {
357+ span : generics. where_clause_span ,
358+ } ) ;
392359 error = true ;
393360 }
394361 if let hir:: IsAsync :: Async = sig. header . asyncness {
395362 let span = tcx. def_span ( it. owner_id ) ;
396- struct_span_err ! (
397- tcx. sess,
398- span,
399- E0752 ,
400- "`start` is not allowed to be `async`"
401- )
402- . span_label ( span, "`start` is not allowed to be `async`" )
403- . emit ( ) ;
363+ tcx. sess . emit_err ( errors:: StartAsync { span : span } ) ;
404364 error = true ;
405365 }
406366
407367 let attrs = tcx. hir ( ) . attrs ( start_id) ;
408368 for attr in attrs {
409369 if attr. has_name ( sym:: track_caller) {
410- tcx. sess
411- . struct_span_err (
412- attr. span ,
413- "`start` is not allowed to be `#[track_caller]`" ,
414- )
415- . span_label (
416- start_span,
417- "`start` is not allowed to be `#[track_caller]`" ,
418- )
419- . emit ( ) ;
370+ tcx. sess . emit_err ( errors:: StartTrackCaller {
371+ span : attr. span ,
372+ start : start_span,
373+ } ) ;
420374 error = true ;
421375 }
422376 }
0 commit comments