1
Fork 0

Rollup merge of #115744 - fmease:fix-e0401, r=compiler-errors

Improve diagnostic for generic params from outer items (E0401)

Generalize the wording of E0401 to talk about *outer items* instead of *outer functions* since the current phrasing is outdated. The outer item can be a function, constant, trait, ADT or impl block (see the new UI test for the more exotic examples).

Further, don't suggest introducing generic parameters to constant items unless the feature `generic_const_items` is enabled.

Lastly, make E0401 translatable while we're at it.

Fixes #115720.
This commit is contained in:
Matthias Krüger 2023-09-11 17:03:32 +02:00 committed by GitHub
commit 8b49731211
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
41 changed files with 306 additions and 183 deletions

View file

@ -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 {