Make E0401 translatable
This commit is contained in:
parent
b00e408e61
commit
9b36252477
3 changed files with 65 additions and 35 deletions
|
@ -64,9 +64,6 @@ resolve_cannot_find_ident_in_this_scope =
|
|||
resolve_cannot_glob_import_possible_crates =
|
||||
cannot glob-import all possible crates
|
||||
|
||||
resolve_cannot_use_self_type_here =
|
||||
can't use `Self` here
|
||||
|
||||
resolve_change_import_binding =
|
||||
you can use `as` to change the binding name of the import
|
||||
|
||||
|
@ -86,9 +83,6 @@ resolve_const_not_member_of_trait =
|
|||
const `{$const_}` is not a member of trait `{$trait_}`
|
||||
.label = not a member of trait `{$trait_}`
|
||||
|
||||
resolve_const_param_from_outer_fn =
|
||||
const parameter from outer function
|
||||
|
||||
resolve_const_param_in_enum_discriminant =
|
||||
const parameters may not be used in enum discriminant values
|
||||
|
||||
|
@ -115,10 +109,19 @@ resolve_forward_declared_generic_param =
|
|||
generic parameters with a default cannot use forward declared identifiers
|
||||
.label = defaulted generic parameters cannot be forward declared
|
||||
|
||||
resolve_generic_params_from_outer_function =
|
||||
can't use generic parameters from outer function
|
||||
.label = use of generic parameter from outer function
|
||||
.suggestion = try using a local generic parameter instead
|
||||
resolve_generic_params_from_outer_item =
|
||||
can't use generic parameters from outer item
|
||||
.label = use of generic parameter from outer item
|
||||
.refer_to_type_directly = refer to the type directly here instead
|
||||
.suggestion = try introducing a local generic parameter here
|
||||
|
||||
resolve_generic_params_from_outer_item_const_param = const parameter from outer item
|
||||
|
||||
resolve_generic_params_from_outer_item_self_ty_alias = `Self` type implicitly declared here, by this `impl`
|
||||
|
||||
resolve_generic_params_from_outer_item_self_ty_param = can't use `Self` here
|
||||
|
||||
resolve_generic_params_from_outer_item_ty_param = type parameter from outer item
|
||||
|
||||
resolve_glob_import_doesnt_reexport =
|
||||
glob import doesn't reexport anything because no candidate is public enough
|
||||
|
@ -273,9 +276,6 @@ resolve_type_not_member_of_trait =
|
|||
type `{$type_}` is not a member of trait `{$trait_}`
|
||||
.label = not a member of trait `{$trait_}`
|
||||
|
||||
resolve_type_param_from_outer_fn =
|
||||
type parameter from outer function
|
||||
|
||||
resolve_type_param_in_enum_discriminant =
|
||||
type parameters may not be used in enum discriminant values
|
||||
|
||||
|
@ -311,9 +311,6 @@ resolve_unreachable_label_suggestion_use_similarly_named =
|
|||
resolve_unreachable_label_with_similar_name_exists =
|
||||
a label with a similar name exists but is unreachable
|
||||
|
||||
resolve_use_a_type_here_instead =
|
||||
use a type here instead
|
||||
|
||||
resolve_variable_bound_with_different_mode =
|
||||
variable `{$variable_name}` is bound inconsistently across alternatives separated by `|`
|
||||
.label = bound in different ways
|
||||
|
|
|
@ -554,34 +554,34 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
|
||||
match resolution_error {
|
||||
ResolutionError::GenericParamsFromOuterItem(outer_res, has_generic_params) => {
|
||||
let mut err = struct_span_err!(
|
||||
self.tcx.sess,
|
||||
use errs::GenericParamsFromOuterItemLabel as Label;
|
||||
let mut err = errs::GenericParamsFromOuterItem {
|
||||
span,
|
||||
E0401,
|
||||
"can't use generic parameters from outer item",
|
||||
);
|
||||
err.span_label(span, "use of generic parameter from outer item");
|
||||
label: None,
|
||||
refer_to_type_directly: None,
|
||||
sugg: None,
|
||||
};
|
||||
|
||||
let sm = self.tcx.sess.source_map();
|
||||
let def_id = match outer_res {
|
||||
Res::SelfTyParam { .. } => {
|
||||
err.span_label(span, "can't use `Self` here");
|
||||
return err;
|
||||
err.label = Some(Label::SelfTyParam(span));
|
||||
return self.tcx.sess.create_err(err);
|
||||
}
|
||||
Res::SelfTyAlias { alias_to: def_id, .. } => {
|
||||
err.span_label(
|
||||
reduce_impl_span_to_impl_keyword(sm, self.def_span(def_id)),
|
||||
"`Self` type implicitly declared here, by this `impl`",
|
||||
);
|
||||
err.span_label(span, "refer to the type directly here instead");
|
||||
return err;
|
||||
err.label = Some(Label::SelfTyAlias(reduce_impl_span_to_impl_keyword(
|
||||
sm,
|
||||
self.def_span(def_id),
|
||||
)));
|
||||
err.refer_to_type_directly = Some(span);
|
||||
return self.tcx.sess.create_err(err);
|
||||
}
|
||||
Res::Def(DefKind::TyParam, def_id) => {
|
||||
err.span_label(self.def_span(def_id), "type parameter from outer item");
|
||||
err.label = Some(Label::TyParam(self.def_span(def_id)));
|
||||
def_id
|
||||
}
|
||||
Res::Def(DefKind::ConstParam, def_id) => {
|
||||
err.span_label(self.def_span(def_id), "const parameter from outer item");
|
||||
err.label = Some(Label::ConstParam(self.def_span(def_id)));
|
||||
def_id
|
||||
}
|
||||
_ => {
|
||||
|
@ -594,7 +594,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
};
|
||||
|
||||
if let HasGenericParams::Yes(span) = has_generic_params {
|
||||
let sugg_msg = "try introducing a local generic parameter here";
|
||||
let name = self.tcx.item_name(def_id);
|
||||
let (span, snippet) = if span.is_empty() {
|
||||
let snippet = format!("<{name}>");
|
||||
|
@ -604,10 +603,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
let snippet = format!("{name}, ");
|
||||
(span, snippet)
|
||||
};
|
||||
err.span_suggestion(span, sugg_msg, snippet, Applicability::MaybeIncorrect);
|
||||
err.sugg = Some(errs::GenericParamsFromOuterItemSugg { span, snippet });
|
||||
}
|
||||
|
||||
err
|
||||
self.tcx.sess.create_err(err)
|
||||
}
|
||||
ResolutionError::NameAlreadyUsedInParameterList(name, first_use_span) => self
|
||||
.tcx
|
||||
|
|
|
@ -32,6 +32,40 @@ pub(crate) struct CrateRootNamesMustBeNamedExplicitly(#[primary_span] pub(crate)
|
|||
#[diag(resolve_crate_root_imports_must_be_named_explicitly)]
|
||||
pub(crate) struct ResolutionError(#[primary_span] pub(crate) Span);
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(resolve_generic_params_from_outer_item, code = "E0401")]
|
||||
pub(crate) struct GenericParamsFromOuterItem {
|
||||
#[primary_span]
|
||||
#[label]
|
||||
pub(crate) span: Span,
|
||||
#[subdiagnostic]
|
||||
pub(crate) label: Option<GenericParamsFromOuterItemLabel>,
|
||||
#[label(resolve_refer_to_type_directly)]
|
||||
pub(crate) refer_to_type_directly: Option<Span>,
|
||||
#[subdiagnostic]
|
||||
pub(crate) sugg: Option<GenericParamsFromOuterItemSugg>,
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
pub(crate) enum GenericParamsFromOuterItemLabel {
|
||||
#[label(resolve_generic_params_from_outer_item_self_ty_param)]
|
||||
SelfTyParam(#[primary_span] Span),
|
||||
#[label(resolve_generic_params_from_outer_item_self_ty_alias)]
|
||||
SelfTyAlias(#[primary_span] Span),
|
||||
#[label(resolve_generic_params_from_outer_item_ty_param)]
|
||||
TyParam(#[primary_span] Span),
|
||||
#[label(resolve_generic_params_from_outer_item_const_param)]
|
||||
ConstParam(#[primary_span] Span),
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
#[suggestion(resolve_suggestion, code = "{snippet}", applicability = "maybe-incorrect")]
|
||||
pub(crate) struct GenericParamsFromOuterItemSugg {
|
||||
#[primary_span]
|
||||
pub(crate) span: Span,
|
||||
pub(crate) snippet: String,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(resolve_name_is_already_used_as_generic_parameter, code = "E0403")]
|
||||
pub(crate) struct NameAlreadyUsedInParameterList {
|
||||
|
|
Loading…
Add table
Reference in a new issue