Skip to content

Commit 2e563a4

Browse files
committed
lint: port clashing extern diagnostics
Signed-off-by: David Wood <[email protected]>
1 parent 157cbbc commit 2e563a4

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,3 +386,10 @@ lint-builtin-explicit-outlives = outlives requirements can be inferred
386386
lint-builtin-incomplete-features = the feature `{$name}` is incomplete and may not be safe to use and/or cause compiler crashes
387387
.note = see issue #{$n} <https://github.com/rust-lang/rust/issues/{$n}> for more information
388388
.help = consider using `min_{$name}` instead, which is more stable and complete
389+
390+
lint-builtin-clashing-extern-same-name = `{$this_fi}` redeclared with a different signature
391+
.previous-decl-label = `{$orig}` previously declared here
392+
.mismatch-label = this signature doesn't match the previous declaration
393+
lint-builtin-clashing-extern-diff-name = `{$this_fi}` redeclares `{$orig}` with a different signature
394+
.previous-decl-label = `{$orig}` previously declared here
395+
.mismatch-label = this signature doesn't match the previous declaration

compiler/rustc_lint/src/builtin.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2972,23 +2972,19 @@ impl<'tcx> LateLintPass<'tcx> for ClashingExternDeclarations {
29722972
let mut found_str = DiagnosticStyledString::new();
29732973
found_str.push(this_decl_ty.fn_sig(tcx).to_string(), true);
29742974

2975-
lint.build(&format!(
2976-
"`{}` redeclare{} with a different signature",
2977-
this_fi.ident.name,
2978-
if orig.get_name() == this_fi.ident.name {
2979-
"d".to_string()
2980-
} else {
2981-
format!("s `{}`", orig.get_name())
2982-
}
2983-
))
2975+
lint.build(if orig.get_name() == this_fi.ident.name {
2976+
fluent::lint::builtin_clashing_extern_same_name
2977+
} else {
2978+
fluent::lint::builtin_clashing_extern_diff_name
2979+
})
2980+
.set_arg("this_fi", this_fi.ident.name)
2981+
.set_arg("orig", orig.get_name())
29842982
.span_label(
29852983
get_relevant_span(orig_fi),
2986-
&format!("`{}` previously declared here", orig.get_name()),
2987-
)
2988-
.span_label(
2989-
get_relevant_span(this_fi),
2990-
"this signature doesn't match the previous declaration",
2984+
fluent::lint::previous_decl_label,
29912985
)
2986+
.span_label(get_relevant_span(this_fi), fluent::lint::mismatch_label)
2987+
// FIXME(davidtwco): translatable expected/found
29922988
.note_expected_found(&"", expected_str, &"", found_str)
29932989
.emit();
29942990
},

0 commit comments

Comments
 (0)