Skip to content

Commit b483816

Browse files
committed
hir-analysis: make one diagnostic translatable
1 parent 3200982 commit b483816

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

compiler/rustc_error_messages/locales/en-US/hir_analysis.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,6 @@ hir_analysis_linkage_type =
124124
hir_analysis_auto_deref_reached_recursion_limit = reached the recursion limit while auto-dereferencing `{$ty}`
125125
.label = deref recursion limit reached
126126
.help = consider increasing the recursion limit by adding a `#![recursion_limit = "{$suggested_limit}"]` attribute to your crate (`{$crate_name}`)
127+
128+
hir_analysis_track_caller_on_main = `main` function is not allowed to be `#[track_caller]`
129+
.label = `main` function is not allowed to be `#[track_caller]`

compiler/rustc_hir_analysis/src/errors.rs

+9
Original file line numberDiff line numberDiff line change
@@ -312,3 +312,12 @@ pub struct AutoDerefReachedRecursionLimit<'a> {
312312
pub suggested_limit: rustc_session::Limit,
313313
pub crate_name: Symbol,
314314
}
315+
316+
#[derive(Diagnostic)]
317+
#[diag(hir_analysis_track_caller_on_main)]
318+
pub(crate) struct TrackCallerOnMain {
319+
#[primary_span]
320+
pub span: Span,
321+
#[label]
322+
pub annotated: Span,
323+
}

compiler/rustc_hir_analysis/src/lib.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
297297
}
298298

299299
for attr in tcx.get_attrs(main_def_id, sym::track_caller) {
300-
tcx.sess
301-
.struct_span_err(attr.span, "`main` function is not allowed to be `#[track_caller]`")
302-
.span_label(main_span, "`main` function is not allowed to be `#[track_caller]`")
303-
.emit();
300+
tcx.sess.emit_err(errors::TrackCallerOnMain { span: attr.span, annotated: main_span });
304301
error = true;
305302
}
306303

0 commit comments

Comments
 (0)