about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-02-21 23:02:02 +0100
committerGitHub <noreply@github.com>2023-02-21 23:02:02 +0100
commitd39fc2111bd16f78d7ad79c06ce1eb774a4bfa2e (patch)
treef5c5fed47c3aa3fa3edbd87da0c611fd0c3b79f7
parent82dc2ebfe3696705a3aa6f6375ea26ba944a1d5e (diff)
parentb483816d88ebea5890f4810617ef5f2fabb25494 (diff)
downloadrust-d39fc2111bd16f78d7ad79c06ce1eb774a4bfa2e.tar.gz
rust-d39fc2111bd16f78d7ad79c06ce1eb774a4bfa2e.zip
Rollup merge of #108323 - tshepang:translatable-hir-analysis, r=compiler-errors
hir-analysis: make one diagnostic translatable
-rw-r--r--compiler/rustc_error_messages/locales/en-US/hir_analysis.ftl3
-rw-r--r--compiler/rustc_hir_analysis/src/errors.rs9
-rw-r--r--compiler/rustc_hir_analysis/src/lib.rs5
3 files changed, 13 insertions, 4 deletions
diff --git a/compiler/rustc_error_messages/locales/en-US/hir_analysis.ftl b/compiler/rustc_error_messages/locales/en-US/hir_analysis.ftl
index 41f458f6c17..f8d28817fec 100644
--- a/compiler/rustc_error_messages/locales/en-US/hir_analysis.ftl
+++ b/compiler/rustc_error_messages/locales/en-US/hir_analysis.ftl
@@ -124,3 +124,6 @@ hir_analysis_linkage_type =
 hir_analysis_auto_deref_reached_recursion_limit = reached the recursion limit while auto-dereferencing `{$ty}`
     .label = deref recursion limit reached
     .help = consider increasing the recursion limit by adding a `#![recursion_limit = "{$suggested_limit}"]` attribute to your crate (`{$crate_name}`)
+
+hir_analysis_track_caller_on_main = `main` function is not allowed to be `#[track_caller]`
+    .label = `main` function is not allowed to be `#[track_caller]`
diff --git a/compiler/rustc_hir_analysis/src/errors.rs b/compiler/rustc_hir_analysis/src/errors.rs
index 04f5f3f6276..f3c3c02a05f 100644
--- a/compiler/rustc_hir_analysis/src/errors.rs
+++ b/compiler/rustc_hir_analysis/src/errors.rs
@@ -312,3 +312,12 @@ pub struct AutoDerefReachedRecursionLimit<'a> {
     pub suggested_limit: rustc_session::Limit,
     pub crate_name: Symbol,
 }
+
+#[derive(Diagnostic)]
+#[diag(hir_analysis_track_caller_on_main)]
+pub(crate) struct TrackCallerOnMain {
+    #[primary_span]
+    pub span: Span,
+    #[label]
+    pub annotated: Span,
+}
diff --git a/compiler/rustc_hir_analysis/src/lib.rs b/compiler/rustc_hir_analysis/src/lib.rs
index 11240cf22e4..73a71376662 100644
--- a/compiler/rustc_hir_analysis/src/lib.rs
+++ b/compiler/rustc_hir_analysis/src/lib.rs
@@ -297,10 +297,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
     }
 
     for attr in tcx.get_attrs(main_def_id, sym::track_caller) {
-        tcx.sess
-            .struct_span_err(attr.span, "`main` function is not allowed to be `#[track_caller]`")
-            .span_label(main_span, "`main` function is not allowed to be `#[track_caller]`")
-            .emit();
+        tcx.sess.emit_err(errors::TrackCallerOnMain { span: attr.span, annotated: main_span });
         error = true;
     }