avoid string dispatch in fluent
This commit is contained in:
parent
8e07a85ad7
commit
57eba4f535
@ -533,11 +533,27 @@ passes_no_main_function =
|
||||
.non_function_main = non-function item at `crate::main` is found
|
||||
|
||||
passes_duplicate_lang_item =
|
||||
{$message ->
|
||||
*[duplicate] found duplicate lang item `{$lang_item_name}`
|
||||
[duplicate_in_crate] duplicate lang item in crate `{$crate_name}`: `{$lang_item_name}`.
|
||||
[duplicate_in_crate_depends] duplicate lang item in crate `{$crate_name}` (which `{$dependency_of}` depends on): `{$lang_item_name}`.
|
||||
}
|
||||
found duplicate lang item `{$lang_item_name}`
|
||||
.first_defined_span = the lang item is first defined here
|
||||
.first_defined_crate_depends = the lang item is first defined in crate `{$orig_crate_name}` (which `{$orig_dependency_of}` depends on)
|
||||
.first_defined_crate = the lang item is first defined in crate `{$orig_crate_name}`.
|
||||
.first_definition_local = first definition in the local crate (`{$orig_crate_name}`)
|
||||
.second_definition_local = second definition in the local crate (`{$crate_name}`)
|
||||
.first_definition_path = first definition in `{$orig_crate_name}` loaded from {$orig_path}
|
||||
.second_definition_path = second definition in `{$crate_name}` loaded from {$path}
|
||||
|
||||
passes_duplicate_lang_item_crate =
|
||||
duplicate lang item in crate `{$crate_name}`: `{$lang_item_name}`.
|
||||
.first_defined_span = the lang item is first defined here
|
||||
.first_defined_crate_depends = the lang item is first defined in crate `{$orig_crate_name}` (which `{$orig_dependency_of}` depends on)
|
||||
.first_defined_crate = the lang item is first defined in crate `{$orig_crate_name}`.
|
||||
.first_definition_local = first definition in the local crate (`{$orig_crate_name}`)
|
||||
.second_definition_local = second definition in the local crate (`{$crate_name}`)
|
||||
.first_definition_path = first definition in `{$orig_crate_name}` loaded from {$orig_path}
|
||||
.second_definition_path = second definition in `{$crate_name}` loaded from {$path}
|
||||
|
||||
passes_duplicate_lang_item_crate_depends =
|
||||
duplicate lang item in crate `{$crate_name}` (which `{$dependency_of}` depends on): `{$lang_item_name}`.
|
||||
.first_defined_span = the lang item is first defined here
|
||||
.first_defined_crate_depends = the lang item is first defined in crate `{$orig_crate_name}` (which `{$orig_dependency_of}` depends on)
|
||||
.first_defined_crate = the lang item is first defined in crate `{$orig_crate_name}`.
|
||||
|
@ -10,6 +10,8 @@ use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
|
||||
use rustc_middle::ty::{MainDefinition, Ty};
|
||||
use rustc_span::{Span, Symbol, DUMMY_SP};
|
||||
|
||||
use crate::lang_items::Duplicate;
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(passes::outer_crate_level_attr)]
|
||||
pub struct OuterCrateLevelAttr;
|
||||
@ -1175,7 +1177,7 @@ impl<'a> IntoDiagnostic<'a> for NoMainErr {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct DuplicateLangItem<'a> {
|
||||
pub struct DuplicateLangItem {
|
||||
pub local_span: Option<Span>,
|
||||
pub lang_item_name: Symbol,
|
||||
pub crate_name: Symbol,
|
||||
@ -1187,16 +1189,23 @@ pub struct DuplicateLangItem<'a> {
|
||||
pub orig_dependency_of: Symbol,
|
||||
pub orig_is_local: bool,
|
||||
pub orig_path: String,
|
||||
pub message: &'a str,
|
||||
pub(crate) duplicate: Duplicate,
|
||||
}
|
||||
|
||||
impl<'a, 'b> IntoDiagnostic<'a> for DuplicateLangItem<'b> {
|
||||
impl IntoDiagnostic<'_> for DuplicateLangItem {
|
||||
fn into_diagnostic(
|
||||
self,
|
||||
handler: &'a rustc_errors::Handler,
|
||||
) -> rustc_errors::DiagnosticBuilder<'a, ErrorGuaranteed> {
|
||||
handler: &rustc_errors::Handler,
|
||||
) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
|
||||
let mut diag = handler.struct_err_with_code(
|
||||
rustc_errors::fluent::passes::duplicate_lang_item,
|
||||
match self.duplicate {
|
||||
Duplicate::Plain => rustc_errors::fluent::passes::duplicate_lang_item,
|
||||
|
||||
Duplicate::Crate => rustc_errors::fluent::passes::duplicate_lang_item_crate,
|
||||
Duplicate::CrateDepends => {
|
||||
rustc_errors::fluent::passes::duplicate_lang_item_crate_depends
|
||||
}
|
||||
},
|
||||
error_code!(E0152),
|
||||
);
|
||||
diag.set_arg("lang_item_name", self.lang_item_name);
|
||||
@ -1206,7 +1215,6 @@ impl<'a, 'b> IntoDiagnostic<'a> for DuplicateLangItem<'b> {
|
||||
diag.set_arg("orig_crate_name", self.orig_crate_name);
|
||||
diag.set_arg("orig_dependency_of", self.orig_dependency_of);
|
||||
diag.set_arg("orig_path", self.orig_path);
|
||||
diag.set_arg("message", self.message);
|
||||
if let Some(span) = self.local_span {
|
||||
diag.set_span(span);
|
||||
}
|
||||
|
@ -24,6 +24,12 @@ use rustc_span::{symbol::kw::Empty, Span};
|
||||
|
||||
use rustc_middle::ty::query::Providers;
|
||||
|
||||
pub(crate) enum Duplicate {
|
||||
Plain,
|
||||
Crate,
|
||||
CrateDepends,
|
||||
}
|
||||
|
||||
struct LanguageItemCollector<'tcx> {
|
||||
items: LanguageItems,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
@ -103,15 +109,15 @@ impl<'tcx> LanguageItemCollector<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
let message = if local_span.is_some() {
|
||||
"duplicate"
|
||||
let duplicate = if local_span.is_some() {
|
||||
Duplicate::Plain
|
||||
} else {
|
||||
match self.tcx.extern_crate(item_def_id) {
|
||||
Some(ExternCrate { dependency_of: inner_dependency_of, .. }) => {
|
||||
dependency_of = self.tcx.crate_name(*inner_dependency_of);
|
||||
"duplicate_in_crate_depends"
|
||||
Duplicate::CrateDepends
|
||||
}
|
||||
_ => "duplicate_in_crate",
|
||||
_ => Duplicate::Crate,
|
||||
}
|
||||
};
|
||||
|
||||
@ -127,7 +133,7 @@ impl<'tcx> LanguageItemCollector<'tcx> {
|
||||
orig_dependency_of,
|
||||
orig_is_local,
|
||||
orig_path,
|
||||
message,
|
||||
duplicate,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user