Rollup merge of #152106 - JonathanBrouwer:convert_ast_passes, r=jdonszelmann

Convert to inline diagnostics in `rustc_ast_passes`

For https://github.com/rust-lang/rust/issues/151366
r? @jdonszelmann
This commit is contained in:
Jonathan Brouwer
2026-02-05 12:16:59 +01:00
committed by GitHub
8 changed files with 329 additions and 554 deletions
-2
View File
@@ -3514,7 +3514,6 @@ dependencies = [
"rustc_data_structures",
"rustc_errors",
"rustc_feature",
"rustc_fluent_macro",
"rustc_macros",
"rustc_session",
"rustc_span",
@@ -3772,7 +3771,6 @@ dependencies = [
"libc",
"rustc_abi",
"rustc_ast",
"rustc_ast_passes",
"rustc_ast_pretty",
"rustc_borrowck",
"rustc_builtin_macros",
-1
View File
@@ -13,7 +13,6 @@ rustc_attr_parsing = { path = "../rustc_attr_parsing" }
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_errors = { path = "../rustc_errors" }
rustc_feature = { path = "../rustc_feature" }
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
rustc_macros = { path = "../rustc_macros" }
rustc_session = { path = "../rustc_session" }
rustc_span = { path = "../rustc_span" }
-342
View File
@@ -1,342 +0,0 @@
ast_passes_abi_cannot_be_coroutine =
functions with the {$abi} ABI cannot be `{$coroutine_kind_str}`
.suggestion = remove the `{$coroutine_kind_str}` keyword from this definition
ast_passes_abi_custom_safe_foreign_function =
foreign functions with the "custom" ABI cannot be safe
.suggestion = remove the `safe` keyword from this definition
ast_passes_abi_custom_safe_function =
functions with the "custom" ABI must be unsafe
.suggestion = add the `unsafe` keyword to this definition
ast_passes_abi_must_not_have_parameters_or_return_type=
invalid signature for `extern {$abi}` function
.note = functions with the {$abi} ABI cannot have any parameters or return type
.suggestion = remove the parameters and return type
ast_passes_abi_must_not_have_return_type=
invalid signature for `extern {$abi}` function
.note = functions with the {$abi} ABI cannot have a return type
.help = remove the return type
ast_passes_abi_x86_interrupt =
invalid signature for `extern "x86-interrupt"` function
.note = functions with the "x86-interrupt" ABI must be have either 1 or 2 parameters (but found {$param_count})
ast_passes_assoc_const_without_body =
associated constant in `impl` without body
.suggestion = provide a definition for the constant
ast_passes_assoc_fn_without_body =
associated function in `impl` without body
.suggestion = provide a definition for the function
ast_passes_assoc_type_without_body =
associated type in `impl` without body
.suggestion = provide a definition for the type
ast_passes_async_fn_in_const_trait_or_trait_impl =
async functions are not allowed in `const` {$context ->
[trait_impl] trait impls
[impl] impls
*[trait] traits
}
.label = associated functions of `const` cannot be declared `async`
ast_passes_at_least_one_trait = at least one trait must be specified
ast_passes_auto_generic = auto traits cannot have generic parameters
.label = auto trait cannot have generic parameters
.suggestion = remove the parameters
ast_passes_auto_items = auto traits cannot have associated items
.label = {ast_passes_auto_items}
.suggestion = remove the associated items
ast_passes_auto_super_lifetime = auto traits cannot have super traits or lifetime bounds
.label = {ast_passes_auto_super_lifetime}
.suggestion = remove the super traits or lifetime bounds
ast_passes_body_in_extern = incorrect `{$kind}` inside `extern` block
.cannot_have = cannot have a body
.invalid = the invalid body
.existing = `extern` blocks define existing foreign {$kind}s and {$kind}s inside of them cannot have a body
ast_passes_bound_in_context = bounds on `type`s in {$ctx} have no effect
ast_passes_c_variadic_bad_extern = `...` is not supported for `extern "{$abi}"` functions
.label = `extern "{$abi}"` because of this
.help = only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
ast_passes_c_variadic_bad_naked_extern = `...` is not supported for `extern "{$abi}"` naked functions
.label = `extern "{$abi}"` because of this
.help = C-variadic function must have a compatible calling convention
ast_passes_c_variadic_must_be_unsafe =
functions with a C variable argument list must be unsafe
.suggestion = add the `unsafe` keyword to this definition
ast_passes_c_variadic_no_extern = `...` is not supported for non-extern functions
.help = only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
ast_passes_c_variadic_not_supported = the `{$target}` target does not support c-variadic functions
ast_passes_const_and_c_variadic = functions cannot be both `const` and C-variadic
.const = `const` because of this
.variadic = C-variadic because of this
ast_passes_const_and_coroutine = functions cannot be both `const` and `{$coroutine_kind}`
.const = `const` because of this
.coroutine = `{$coroutine_kind}` because of this
.label = {""}
ast_passes_const_auto_trait = auto traits cannot be const
.help = remove the `const` keyword
ast_passes_const_bound_trait_object = const trait bounds are not allowed in trait object types
ast_passes_const_without_body =
free constant item without body
.suggestion = provide a definition for the constant
ast_passes_constraint_on_negative_bound =
associated type constraints not allowed on negative bounds
ast_passes_coroutine_and_c_variadic = functions cannot be both `{$coroutine_kind}` and C-variadic
.const = `{$coroutine_kind}` because of this
.variadic = C-variadic because of this
ast_passes_equality_in_where = equality constraints are not yet supported in `where` clauses
.label = not supported
.suggestion = if `{$ident}` is an associated type you're trying to set, use the associated type binding syntax
.suggestion_path = if `{$trait_segment}::{$potential_assoc}` is an associated type you're trying to set, use the associated type binding syntax
.note = see issue #20041 <https://github.com/rust-lang/rust/issues/20041> for more information
ast_passes_extern_block_suggestion = if you meant to declare an externally defined function, use an `extern` block
ast_passes_extern_fn_qualifiers = functions in `extern` blocks cannot have `{$kw}` qualifier
.label = in this `extern` block
.suggestion = remove the `{$kw}` qualifier
ast_passes_extern_invalid_safety = items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
.suggestion = add `unsafe` to this `extern` block
ast_passes_extern_item_ascii = items in `extern` blocks cannot use non-ascii identifiers
.label = in this `extern` block
.note = this limitation may be lifted in the future; see issue #83942 <https://github.com/rust-lang/rust/issues/83942> for more information
ast_passes_extern_keyword_link = for more information, visit https://doc.rust-lang.org/std/keyword.extern.html
ast_passes_extern_types_cannot = `type`s inside `extern` blocks cannot have {$descr}
.suggestion = remove the {$remove_descr}
.label = `extern` block begins here
ast_passes_extern_without_abi = `extern` declarations without an explicit ABI are disallowed
.suggestion = specify an ABI
.help = prior to Rust 2024, a default ABI was inferred
ast_passes_extern_without_abi_sugg = `extern` declarations without an explicit ABI are deprecated
.label = ABI should be specified here
.suggestion = explicitly specify the {$default_abi} ABI
ast_passes_feature_on_non_nightly = `#![feature]` may not be used on the {$channel} release channel
.suggestion = remove the attribute
.stable_since = the feature `{$name}` has been stable since `{$since}` and no longer requires an attribute to enable
ast_passes_fieldless_union = unions cannot have zero fields
ast_passes_fn_body_extern = incorrect function inside `extern` block
.cannot_have = cannot have a body
.suggestion = remove the invalid body
.help = you might have meant to write a function accessible through FFI, which can be done by writing `extern fn` outside of the `extern` block
.label = `extern` blocks define existing foreign functions and functions inside of them cannot have a body
ast_passes_fn_param_c_var_args_not_last =
`...` must be the last argument of a C-variadic function
ast_passes_fn_param_doc_comment =
documentation comments cannot be applied to function parameters
.label = doc comments are not allowed here
ast_passes_fn_param_forbidden_attr =
allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
ast_passes_fn_param_forbidden_self =
`self` parameter is only allowed in associated functions
.label = not semantically valid as function parameter
.note = associated functions are those in `impl` or `trait` definitions
ast_passes_fn_param_too_many =
function can not have more than {$max_num_args} arguments
ast_passes_fn_ptr_invalid_safety = function pointers cannot be declared with `safe` safety qualifier
.suggestion = remove safe from this item
ast_passes_fn_without_body =
free function without a body
.suggestion = provide a definition for the function
ast_passes_forbidden_bound =
bounds cannot be used in this context
ast_passes_forbidden_const_param =
late-bound const parameters cannot be used currently
ast_passes_forbidden_default =
`default` is only allowed on items in trait impls
.label = `default` because of this
ast_passes_forbidden_non_lifetime_param =
only lifetime parameters can be used in this context
ast_passes_generic_before_constraints = generic arguments must come before the first constraint
.constraints = {$constraint_len ->
[one] constraint
*[other] constraints
}
.args = generic {$args_len ->
[one] argument
*[other] arguments
}
.empty_string = {""},
.suggestion = move the {$constraint_len ->
[one] constraint
*[other] constraints
} after the generic {$args_len ->
[one] argument
*[other] arguments
}
ast_passes_generic_default_trailing = generic parameters with a default must be trailing
ast_passes_impl_fn_const =
redundant `const` fn marker in const impl
.parent_constness = this declares all associated functions implicitly const
.label = remove the `const`
ast_passes_incompatible_features = `{$f1}` and `{$f2}` are incompatible, using them at the same time is not allowed
.help = remove one of these features
ast_passes_item_invalid_safety = items outside of `unsafe extern {"{ }"}` cannot be declared with `safe` safety qualifier
.suggestion = remove safe from this item
ast_passes_item_underscore = `{$kind}` items in this context need a name
.label = `_` is not a valid name for this `{$kind}` item
ast_passes_match_arm_with_no_body =
`match` arm with no body
.suggestion = add a body after the pattern
ast_passes_missing_unsafe_on_extern = extern blocks must be unsafe
.suggestion = needs `unsafe` before the extern keyword
ast_passes_missing_unsafe_on_extern_lint = extern blocks should be unsafe
.suggestion = needs `unsafe` before the extern keyword
ast_passes_module_nonascii = trying to load file for module `{$name}` with non-ascii identifier name
.help = consider using the `#[path]` attribute to specify filesystem path
ast_passes_negative_bound_not_supported =
negative bounds are not supported
ast_passes_negative_bound_with_parenthetical_notation =
parenthetical notation may not be used for negative bounds
ast_passes_nested_impl_trait = nested `impl Trait` is not allowed
.outer = outer `impl Trait`
.inner = nested `impl Trait` here
ast_passes_nested_lifetimes = nested quantification of lifetimes
ast_passes_nomangle_ascii = `#[no_mangle]` requires ASCII identifier
ast_passes_obsolete_auto = `impl Trait for .. {"{}"}` is an obsolete syntax
.help = use `auto trait Trait {"{}"}` instead
ast_passes_out_of_order_params = {$param_ord} parameters must be declared prior to {$max_param} parameters
.suggestion = reorder the parameters: lifetimes, then consts and types
ast_passes_pattern_in_bodiless = patterns aren't allowed in functions without bodies
.label = pattern not allowed in function without body
ast_passes_pattern_in_fn_pointer = patterns aren't allowed in function pointer types
ast_passes_pattern_in_foreign = patterns aren't allowed in foreign function declarations
.label = pattern not allowed in foreign function
ast_passes_precise_capturing_duplicated = duplicate `use<...>` precise capturing syntax
.label = second `use<...>` here
ast_passes_precise_capturing_not_allowed_here = `use<...>` precise capturing syntax not allowed in {$loc}
ast_passes_scalable_vector_not_tuple_struct = scalable vectors must be tuple structs
ast_passes_static_without_body =
free static item without body
.suggestion = provide a definition for the static
ast_passes_tilde_const_disallowed = `[const]` is not allowed here
.closure = closures cannot have `[const]` trait bounds
.function = this function is not `const`, so it cannot have `[const]` trait bounds
.trait = this trait is not `const`, so it cannot have `[const]` trait bounds
.trait_impl = this impl is not `const`, so it cannot have `[const]` trait bounds
.impl = inherent impls cannot have `[const]` trait bounds
.trait_assoc_ty = associated types in non-`const` traits cannot have `[const]` trait bounds
.trait_impl_assoc_ty = associated types in non-const impls cannot have `[const]` trait bounds
.inherent_assoc_ty = inherent associated types cannot have `[const]` trait bounds
.struct = structs cannot have `[const]` trait bounds
.enum = enums cannot have `[const]` trait bounds
.union = unions cannot have `[const]` trait bounds
.anon_const = anonymous constants cannot have `[const]` trait bounds
.object = trait objects cannot have `[const]` trait bounds
.item = this item cannot have `[const]` trait bounds
ast_passes_trait_fn_const =
functions in {$in_impl ->
[true] trait impls
*[false] traits
} cannot be declared const
.label = functions in {$in_impl ->
[true] trait impls
*[false] traits
} cannot be const
.const_context_label = this declares all associated functions implicitly const
.remove_const_sugg = remove the `const`{$requires_multiple_changes ->
[true] {" ..."}
*[false] {""}
}
.make_impl_const_sugg = ... and declare the impl to be const instead
.make_trait_const_sugg = ... and declare the trait to be const instead
ast_passes_trait_object_single_bound = only a single explicit lifetime bound is permitted
ast_passes_ty_alias_without_body =
free type alias without body
.suggestion = provide a definition for the type
ast_passes_unsafe_item = {$kind} cannot be declared unsafe
ast_passes_unsafe_negative_impl = negative impls cannot be unsafe
.negative = negative because of this
.unsafe = unsafe because of this
ast_passes_unsafe_static =
static items cannot be declared with `unsafe` safety qualifier outside of `extern` block
ast_passes_visibility_not_permitted =
visibility qualifiers are not permitted here
.enum_variant = enum variants and their fields always share the visibility of the enum they are in
.trait_impl = trait items always share the visibility of their trait
.individual_impl_items = place qualifiers on individual impl items instead
.individual_foreign_items = place qualifiers on individual foreign items instead
.remove_qualifier_sugg = remove the qualifier
ast_passes_where_clause_after_type_alias = where clauses are not allowed after the type for type aliases
.note = see issue #112792 <https://github.com/rust-lang/rust/issues/112792> for more information
.help = add `#![feature(lazy_type_alias)]` to the crate attributes to enable
ast_passes_where_clause_before_type_alias = where clauses are not allowed before the type for type aliases
.note = see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information
.remove_suggestion = remove this `where`
.move_suggestion = move it to the end of the type declaration
+327 -204
View File
@@ -3,68 +3,76 @@
use rustc_abi::ExternAbi;
use rustc_ast::ParamKindOrd;
use rustc_errors::codes::*;
use rustc_errors::{Applicability, Diag, EmissionGuarantee, Subdiagnostic};
use rustc_errors::{Applicability, Diag, EmissionGuarantee, Subdiagnostic, inline_fluent};
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
use rustc_span::{Ident, Span, Symbol};
use crate::fluent_generated as fluent;
#[derive(Diagnostic)]
#[diag(ast_passes_visibility_not_permitted, code = E0449)]
#[diag("visibility qualifiers are not permitted here", code = E0449)]
pub(crate) struct VisibilityNotPermitted {
#[primary_span]
pub span: Span,
#[subdiagnostic]
pub note: VisibilityNotPermittedNote,
#[suggestion(
ast_passes_remove_qualifier_sugg,
code = "",
applicability = "machine-applicable"
)]
#[suggestion("remove the qualifier", code = "", applicability = "machine-applicable")]
pub remove_qualifier_sugg: Span,
}
#[derive(Subdiagnostic)]
pub(crate) enum VisibilityNotPermittedNote {
#[note(ast_passes_enum_variant)]
#[note("enum variants and their fields always share the visibility of the enum they are in")]
EnumVariant,
#[note(ast_passes_trait_impl)]
#[note("trait items always share the visibility of their trait")]
TraitImpl,
#[note(ast_passes_individual_impl_items)]
#[note("place qualifiers on individual impl items instead")]
IndividualImplItems,
#[note(ast_passes_individual_foreign_items)]
#[note("place qualifiers on individual foreign items instead")]
IndividualForeignItems,
}
#[derive(Diagnostic)]
#[diag(ast_passes_impl_fn_const)]
#[diag("redundant `const` fn marker in const impl")]
pub(crate) struct ImplFnConst {
#[primary_span]
#[suggestion(ast_passes_label, code = "", applicability = "machine-applicable")]
#[suggestion("remove the `const`", code = "", applicability = "machine-applicable")]
pub span: Span,
#[label(ast_passes_parent_constness)]
#[label("this declares all associated functions implicitly const")]
pub parent_constness: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_trait_fn_const, code = E0379)]
#[diag("functions in {$in_impl ->
[true] trait impls
*[false] traits
} cannot be declared const", code = E0379)]
pub(crate) struct TraitFnConst {
#[primary_span]
#[label]
#[label(
"functions in {$in_impl ->
[true] trait impls
*[false] traits
} cannot be const"
)]
pub span: Span,
pub in_impl: bool,
#[label(ast_passes_const_context_label)]
#[label("this declares all associated functions implicitly const")]
pub const_context_label: Option<Span>,
#[suggestion(ast_passes_remove_const_sugg, code = "")]
#[suggestion(
"remove the `const`{$requires_multiple_changes ->
[true] {\" ...\"}
*[false] {\"\"}
}",
code = ""
)]
pub remove_const_sugg: (Span, Applicability),
pub requires_multiple_changes: bool,
#[suggestion(
ast_passes_make_impl_const_sugg,
"... and declare the impl to be const instead",
code = "const ",
applicability = "maybe-incorrect"
)]
pub make_impl_const_sugg: Option<Span>,
#[suggestion(
ast_passes_make_trait_const_sugg,
"... and declare the trait to be const instead",
code = "const ",
applicability = "maybe-incorrect"
)]
@@ -72,31 +80,37 @@ pub(crate) struct TraitFnConst {
}
#[derive(Diagnostic)]
#[diag(ast_passes_async_fn_in_const_trait_or_trait_impl)]
#[diag(
"async functions are not allowed in `const` {$context ->
[trait_impl] trait impls
[impl] impls
*[trait] traits
}"
)]
pub(crate) struct AsyncFnInConstTraitOrTraitImpl {
#[primary_span]
pub async_keyword: Span,
pub context: &'static str,
#[label]
#[label("associated functions of `const` cannot be declared `async`")]
pub const_keyword: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_forbidden_bound)]
#[diag("bounds cannot be used in this context")]
pub(crate) struct ForbiddenBound {
#[primary_span]
pub spans: Vec<Span>,
}
#[derive(Diagnostic)]
#[diag(ast_passes_forbidden_const_param)]
#[diag("late-bound const parameters cannot be used currently")]
pub(crate) struct ForbiddenConstParam {
#[primary_span]
pub const_param_spans: Vec<Span>,
}
#[derive(Diagnostic)]
#[diag(ast_passes_fn_param_too_many)]
#[diag("function can not have more than {$max_num_args} arguments")]
pub(crate) struct FnParamTooMany {
#[primary_span]
pub span: Span,
@@ -104,105 +118,135 @@ pub(crate) struct FnParamTooMany {
}
#[derive(Diagnostic)]
#[diag(ast_passes_fn_param_c_var_args_not_last)]
#[diag("`...` must be the last argument of a C-variadic function")]
pub(crate) struct FnParamCVarArgsNotLast {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_fn_param_doc_comment)]
#[diag("documentation comments cannot be applied to function parameters")]
pub(crate) struct FnParamDocComment {
#[primary_span]
#[label]
#[label("doc comments are not allowed here")]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_fn_param_forbidden_attr)]
#[diag(
"allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters"
)]
pub(crate) struct FnParamForbiddenAttr {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_fn_param_forbidden_self)]
#[note]
#[diag("`self` parameter is only allowed in associated functions")]
#[note("associated functions are those in `impl` or `trait` definitions")]
pub(crate) struct FnParamForbiddenSelf {
#[primary_span]
#[label]
#[label("not semantically valid as function parameter")]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_forbidden_default)]
#[diag("`default` is only allowed on items in trait impls")]
pub(crate) struct ForbiddenDefault {
#[primary_span]
pub span: Span,
#[label]
#[label("`default` because of this")]
pub def_span: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_assoc_const_without_body)]
#[diag("associated constant in `impl` without body")]
pub(crate) struct AssocConstWithoutBody {
#[primary_span]
pub span: Span,
#[suggestion(code = " = <expr>;", applicability = "has-placeholders")]
#[suggestion(
"provide a definition for the constant",
code = " = <expr>;",
applicability = "has-placeholders"
)]
pub replace_span: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_assoc_fn_without_body)]
#[diag("associated function in `impl` without body")]
pub(crate) struct AssocFnWithoutBody {
#[primary_span]
pub span: Span,
#[suggestion(code = " {{ <body> }}", applicability = "has-placeholders")]
#[suggestion(
"provide a definition for the function",
code = " {{ <body> }}",
applicability = "has-placeholders"
)]
pub replace_span: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_assoc_type_without_body)]
#[diag("associated type in `impl` without body")]
pub(crate) struct AssocTypeWithoutBody {
#[primary_span]
pub span: Span,
#[suggestion(code = " = <type>;", applicability = "has-placeholders")]
#[suggestion(
"provide a definition for the type",
code = " = <type>;",
applicability = "has-placeholders"
)]
pub replace_span: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_const_without_body)]
#[diag("free constant item without body")]
pub(crate) struct ConstWithoutBody {
#[primary_span]
pub span: Span,
#[suggestion(code = " = <expr>;", applicability = "has-placeholders")]
#[suggestion(
"provide a definition for the constant",
code = " = <expr>;",
applicability = "has-placeholders"
)]
pub replace_span: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_static_without_body)]
#[diag("free static item without body")]
pub(crate) struct StaticWithoutBody {
#[primary_span]
pub span: Span,
#[suggestion(code = " = <expr>;", applicability = "has-placeholders")]
#[suggestion(
"provide a definition for the static",
code = " = <expr>;",
applicability = "has-placeholders"
)]
pub replace_span: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_ty_alias_without_body)]
#[diag("free type alias without body")]
pub(crate) struct TyAliasWithoutBody {
#[primary_span]
pub span: Span,
#[suggestion(code = " = <type>;", applicability = "has-placeholders")]
#[suggestion(
"provide a definition for the type",
code = " = <type>;",
applicability = "has-placeholders"
)]
pub replace_span: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_fn_without_body)]
#[diag("free function without a body")]
pub(crate) struct FnWithoutBody {
#[primary_span]
pub span: Span,
#[suggestion(code = " {{ <body> }}", applicability = "has-placeholders")]
#[suggestion(
"provide a definition for the function",
code = " {{ <body> }}",
applicability = "has-placeholders"
)]
pub replace_span: Span,
#[subdiagnostic]
pub extern_block_suggestion: Option<ExternBlockSuggestion>,
@@ -210,14 +254,20 @@ pub(crate) struct FnWithoutBody {
#[derive(Subdiagnostic)]
pub(crate) enum ExternBlockSuggestion {
#[multipart_suggestion(ast_passes_extern_block_suggestion, applicability = "maybe-incorrect")]
#[multipart_suggestion(
"if you meant to declare an externally defined function, use an `extern` block",
applicability = "maybe-incorrect"
)]
Implicit {
#[suggestion_part(code = "extern {{")]
start_span: Span,
#[suggestion_part(code = " }}")]
end_span: Span,
},
#[multipart_suggestion(ast_passes_extern_block_suggestion, applicability = "maybe-incorrect")]
#[multipart_suggestion(
"if you meant to declare an externally defined function, use an `extern` block",
applicability = "maybe-incorrect"
)]
Explicit {
#[suggestion_part(code = "extern \"{abi}\" {{")]
start_span: Span,
@@ -228,37 +278,44 @@ pub(crate) enum ExternBlockSuggestion {
}
#[derive(Diagnostic)]
#[diag(ast_passes_extern_invalid_safety)]
#[diag("items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers")]
pub(crate) struct InvalidSafetyOnExtern {
#[primary_span]
pub item_span: Span,
#[suggestion(code = "unsafe ", applicability = "machine-applicable", style = "verbose")]
#[suggestion(
"add `unsafe` to this `extern` block",
code = "unsafe ",
applicability = "machine-applicable",
style = "verbose"
)]
pub block: Option<Span>,
}
#[derive(Diagnostic)]
#[diag(ast_passes_item_invalid_safety)]
#[diag(
"items outside of `unsafe extern {\"{ }\"}` cannot be declared with `safe` safety qualifier"
)]
pub(crate) struct InvalidSafetyOnItem {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_fn_ptr_invalid_safety)]
#[diag("function pointers cannot be declared with `safe` safety qualifier")]
pub(crate) struct InvalidSafetyOnFnPtr {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_unsafe_static)]
#[diag("static items cannot be declared with `unsafe` safety qualifier outside of `extern` block")]
pub(crate) struct UnsafeStatic {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_bound_in_context)]
#[diag("bounds on `type`s in {$ctx} have no effect")]
pub(crate) struct BoundInContext<'a> {
#[primary_span]
pub span: Span,
@@ -266,83 +323,93 @@ pub(crate) struct BoundInContext<'a> {
}
#[derive(Diagnostic)]
#[diag(ast_passes_extern_types_cannot)]
#[note(ast_passes_extern_keyword_link)]
#[diag("`type`s inside `extern` blocks cannot have {$descr}")]
#[note("for more information, visit https://doc.rust-lang.org/std/keyword.extern.html")]
pub(crate) struct ExternTypesCannotHave<'a> {
#[primary_span]
#[suggestion(code = "", applicability = "maybe-incorrect")]
#[suggestion("remove the {$remove_descr}", code = "", applicability = "maybe-incorrect")]
pub span: Span,
pub descr: &'a str,
pub remove_descr: &'a str,
#[label]
#[label("`extern` block begins here")]
pub block_span: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_body_in_extern)]
#[note(ast_passes_extern_keyword_link)]
#[diag("incorrect `{$kind}` inside `extern` block")]
#[note("for more information, visit https://doc.rust-lang.org/std/keyword.extern.html")]
pub(crate) struct BodyInExtern<'a> {
#[primary_span]
#[label(ast_passes_cannot_have)]
#[label("cannot have a body")]
pub span: Span,
#[label(ast_passes_invalid)]
#[label("the invalid body")]
pub body: Span,
#[label(ast_passes_existing)]
#[label(
"`extern` blocks define existing foreign {$kind}s and {$kind}s inside of them cannot have a body"
)]
pub block: Span,
pub kind: &'a str,
}
#[derive(Diagnostic)]
#[diag(ast_passes_fn_body_extern)]
#[help]
#[note(ast_passes_extern_keyword_link)]
#[diag("incorrect function inside `extern` block")]
#[help(
"you might have meant to write a function accessible through FFI, which can be done by writing `extern fn` outside of the `extern` block"
)]
#[note("for more information, visit https://doc.rust-lang.org/std/keyword.extern.html")]
pub(crate) struct FnBodyInExtern {
#[primary_span]
#[label(ast_passes_cannot_have)]
#[label("cannot have a body")]
pub span: Span,
#[suggestion(code = ";", applicability = "maybe-incorrect")]
#[suggestion("remove the invalid body", code = ";", applicability = "maybe-incorrect")]
pub body: Span,
#[label]
#[label(
"`extern` blocks define existing foreign functions and functions inside of them cannot have a body"
)]
pub block: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_extern_fn_qualifiers)]
#[diag("functions in `extern` blocks cannot have `{$kw}` qualifier")]
pub(crate) struct FnQualifierInExtern {
#[primary_span]
#[suggestion(code = "", applicability = "maybe-incorrect")]
#[suggestion("remove the `{$kw}` qualifier", code = "", applicability = "maybe-incorrect")]
pub span: Span,
#[label]
#[label("in this `extern` block")]
pub block: Span,
pub kw: &'static str,
}
#[derive(Diagnostic)]
#[diag(ast_passes_extern_item_ascii)]
#[note]
#[diag("items in `extern` blocks cannot use non-ascii identifiers")]
#[note(
"this limitation may be lifted in the future; see issue #83942 <https://github.com/rust-lang/rust/issues/83942> for more information"
)]
pub(crate) struct ExternItemAscii {
#[primary_span]
pub span: Span,
#[label]
#[label("in this `extern` block")]
pub block: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_c_variadic_no_extern)]
#[help]
#[diag("`...` is not supported for non-extern functions")]
#[help(
"only `extern \"C\"` and `extern \"C-unwind\"` functions may have a C variable argument list"
)]
pub(crate) struct CVariadicNoExtern {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_c_variadic_must_be_unsafe)]
#[diag("functions with a C variable argument list must be unsafe")]
pub(crate) struct CVariadicMustBeUnsafe {
#[primary_span]
pub span: Span,
#[suggestion(
ast_passes_suggestion,
"add the `unsafe` keyword to this definition",
applicability = "maybe-incorrect",
code = "unsafe ",
style = "verbose"
@@ -351,46 +418,48 @@ pub(crate) struct CVariadicMustBeUnsafe {
}
#[derive(Diagnostic)]
#[diag(ast_passes_c_variadic_bad_extern)]
#[help]
#[diag("`...` is not supported for `extern \"{$abi}\"` functions")]
#[help(
"only `extern \"C\"` and `extern \"C-unwind\"` functions may have a C variable argument list"
)]
pub(crate) struct CVariadicBadExtern {
#[primary_span]
pub span: Span,
pub abi: &'static str,
#[label]
#[label("`extern \"{$abi}\"` because of this")]
pub extern_span: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_c_variadic_bad_naked_extern)]
#[help]
#[diag("`...` is not supported for `extern \"{$abi}\"` naked functions")]
#[help("C-variadic function must have a compatible calling convention")]
pub(crate) struct CVariadicBadNakedExtern {
#[primary_span]
pub span: Span,
pub abi: &'static str,
#[label]
#[label("`extern \"{$abi}\"` because of this")]
pub extern_span: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_item_underscore)]
#[diag("`{$kind}` items in this context need a name")]
pub(crate) struct ItemUnderscore<'a> {
#[primary_span]
#[label]
#[label("`_` is not a valid name for this `{$kind}` item")]
pub span: Span,
pub kind: &'a str,
}
#[derive(Diagnostic)]
#[diag(ast_passes_nomangle_ascii, code = E0754)]
#[diag("`#[no_mangle]` requires ASCII identifier", code = E0754)]
pub(crate) struct NoMangleAscii {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_module_nonascii, code = E0754)]
#[help]
#[diag("trying to load file for module `{$name}` with non-ascii identifier name", code = E0754)]
#[help("consider using the `#[path]` attribute to specify filesystem path")]
pub(crate) struct ModuleNonAscii {
#[primary_span]
pub span: Span,
@@ -398,55 +467,91 @@ pub(crate) struct ModuleNonAscii {
}
#[derive(Diagnostic)]
#[diag(ast_passes_auto_generic, code = E0567)]
#[diag("auto traits cannot have generic parameters", code = E0567)]
pub(crate) struct AutoTraitGeneric {
#[primary_span]
#[suggestion(code = "", applicability = "machine-applicable", style = "tool-only")]
#[suggestion(
"remove the parameters",
code = "",
applicability = "machine-applicable",
style = "tool-only"
)]
pub span: Span,
#[label]
#[label("auto trait cannot have generic parameters")]
pub ident: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_auto_super_lifetime, code = E0568)]
#[diag("auto traits cannot have super traits or lifetime bounds", code = E0568)]
pub(crate) struct AutoTraitBounds {
#[primary_span]
pub span: Vec<Span>,
#[suggestion(code = "", applicability = "machine-applicable", style = "tool-only")]
#[suggestion(
"remove the super traits or lifetime bounds",
code = "",
applicability = "machine-applicable",
style = "tool-only"
)]
pub removal: Span,
#[label]
#[label("auto traits cannot have super traits or lifetime bounds")]
pub ident: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_auto_items, code = E0380)]
#[diag("auto traits cannot have associated items", code = E0380)]
pub(crate) struct AutoTraitItems {
#[primary_span]
pub spans: Vec<Span>,
#[suggestion(code = "", applicability = "machine-applicable", style = "tool-only")]
#[suggestion(
"remove the super traits or lifetime bounds",
code = "",
applicability = "machine-applicable",
style = "tool-only"
)]
pub total: Span,
#[label]
#[label("auto traits cannot have associated items")]
pub ident: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_const_auto_trait)]
#[help]
#[diag("auto traits cannot be const")]
#[help("remove the `const` keyword")]
pub(crate) struct ConstAutoTrait {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_generic_before_constraints)]
#[diag("generic arguments must come before the first constraint")]
pub(crate) struct ArgsBeforeConstraint {
#[primary_span]
pub arg_spans: Vec<Span>,
#[label(ast_passes_constraints)]
#[label(
"{$constraint_len ->
[one] constraint
*[other] constraints
}"
)]
pub constraints: Span,
#[label(ast_passes_args)]
#[label(
"generic {$args_len ->
[one] argument
*[other] arguments
}"
)]
pub args: Span,
#[suggestion(code = "{suggestion}", applicability = "machine-applicable", style = "verbose")]
#[suggestion(
"move the {$constraint_len ->
[one] constraint
*[other] constraints
} after the generic {$args_len ->
[one] argument
*[other] arguments
}",
code = "{suggestion}",
applicability = "machine-applicable",
style = "verbose"
)]
pub data: Span,
pub suggestion: String,
pub constraint_len: usize,
@@ -467,43 +572,47 @@ fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
}
#[derive(Diagnostic)]
#[diag(ast_passes_pattern_in_fn_pointer, code = E0561)]
#[diag("patterns aren't allowed in function pointer types", code = E0561)]
pub(crate) struct PatternFnPointer {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_trait_object_single_bound, code = E0226)]
#[diag("only a single explicit lifetime bound is permitted", code = E0226)]
pub(crate) struct TraitObjectBound {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_nested_impl_trait, code = E0666)]
#[diag("nested `impl Trait` is not allowed", code = E0666)]
pub(crate) struct NestedImplTrait {
#[primary_span]
pub span: Span,
#[label(ast_passes_outer)]
#[label("outer `impl Trait`")]
pub outer: Span,
#[label(ast_passes_inner)]
#[label("nested `impl Trait` here")]
pub inner: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_at_least_one_trait)]
#[diag("at least one trait must be specified")]
pub(crate) struct AtLeastOneTrait {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_out_of_order_params)]
#[diag("{$param_ord} parameters must be declared prior to {$max_param} parameters")]
pub(crate) struct OutOfOrderParams<'a> {
#[primary_span]
pub spans: Vec<Span>,
#[suggestion(code = "{ordered_params}", applicability = "machine-applicable")]
#[suggestion(
"reorder the parameters: lifetimes, then consts and types",
code = "{ordered_params}",
applicability = "machine-applicable"
)]
pub sugg_span: Span,
pub param_ord: &'a ParamKindOrd,
pub max_param: &'a ParamKindOrd,
@@ -511,26 +620,26 @@ pub(crate) struct OutOfOrderParams<'a> {
}
#[derive(Diagnostic)]
#[diag(ast_passes_obsolete_auto)]
#[help]
#[diag("`impl Trait for .. {\"{}\"}` is an obsolete syntax")]
#[help("use `auto trait Trait {\"{}\"}` instead")]
pub(crate) struct ObsoleteAuto {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_unsafe_negative_impl, code = E0198)]
#[diag("negative impls cannot be unsafe", code = E0198)]
pub(crate) struct UnsafeNegativeImpl {
#[primary_span]
pub span: Span,
#[label(ast_passes_negative)]
#[label("negative because of this")]
pub negative: Span,
#[label(ast_passes_unsafe)]
#[label("unsafe because of this")]
pub r#unsafe: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_unsafe_item)]
#[diag("{$kind} cannot be declared unsafe")]
pub(crate) struct UnsafeItem {
#[primary_span]
pub span: Span,
@@ -538,39 +647,43 @@ pub(crate) struct UnsafeItem {
}
#[derive(Diagnostic)]
#[diag(ast_passes_missing_unsafe_on_extern)]
#[diag("extern blocks must be unsafe")]
pub(crate) struct MissingUnsafeOnExtern {
#[primary_span]
pub span: Span,
}
#[derive(LintDiagnostic)]
#[diag(ast_passes_missing_unsafe_on_extern_lint)]
#[diag("extern blocks should be unsafe")]
pub(crate) struct MissingUnsafeOnExternLint {
#[suggestion(code = "unsafe ", applicability = "machine-applicable")]
#[suggestion(
"needs `unsafe` before the extern keyword",
code = "unsafe ",
applicability = "machine-applicable"
)]
pub suggestion: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_fieldless_union)]
#[diag("unions cannot have zero fields")]
pub(crate) struct FieldlessUnion {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_where_clause_after_type_alias)]
#[note]
#[diag("where clauses are not allowed after the type for type aliases")]
#[note("see issue #112792 <https://github.com/rust-lang/rust/issues/112792> for more information")]
pub(crate) struct WhereClauseAfterTypeAlias {
#[primary_span]
pub span: Span,
#[help]
#[help("add `#![feature(lazy_type_alias)]` to the crate attributes to enable")]
pub help: bool,
}
#[derive(Diagnostic)]
#[diag(ast_passes_where_clause_before_type_alias)]
#[note]
#[diag("where clauses are not allowed before the type for type aliases")]
#[note("see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information")]
pub(crate) struct WhereClauseBeforeTypeAlias {
#[primary_span]
pub span: Span,
@@ -580,13 +693,13 @@ pub(crate) struct WhereClauseBeforeTypeAlias {
#[derive(Subdiagnostic)]
pub(crate) enum WhereClauseBeforeTypeAliasSugg {
#[suggestion(ast_passes_remove_suggestion, applicability = "machine-applicable", code = "")]
#[suggestion("remove this `where`", applicability = "machine-applicable", code = "")]
Remove {
#[primary_span]
span: Span,
},
#[multipart_suggestion(
ast_passes_move_suggestion,
"move it to the end of the type declaration",
applicability = "machine-applicable",
style = "verbose"
)]
@@ -600,21 +713,21 @@ pub(crate) enum WhereClauseBeforeTypeAliasSugg {
}
#[derive(Diagnostic)]
#[diag(ast_passes_generic_default_trailing)]
#[diag("generic parameters with a default must be trailing")]
pub(crate) struct GenericDefaultTrailing {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_nested_lifetimes, code = E0316)]
#[diag("nested quantification of lifetimes", code = E0316)]
pub(crate) struct NestedLifetimes {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_const_bound_trait_object)]
#[diag("const trait bounds are not allowed in trait object types")]
pub(crate) struct ConstBoundTraitObject {
#[primary_span]
pub span: Span,
@@ -623,7 +736,7 @@ pub(crate) struct ConstBoundTraitObject {
// FIXME(const_trait_impl): Consider making the note/reason the message of the diagnostic.
// FIXME(const_trait_impl): Provide structured suggestions (e.g., add `const` here).
#[derive(Diagnostic)]
#[diag(ast_passes_tilde_const_disallowed)]
#[diag("`[const]` is not allowed here")]
pub(crate) struct TildeConstDisallowed {
#[primary_span]
pub span: Span,
@@ -633,108 +746,108 @@ pub(crate) struct TildeConstDisallowed {
#[derive(Subdiagnostic, Copy, Clone)]
pub(crate) enum TildeConstReason {
#[note(ast_passes_closure)]
#[note("closures cannot have `[const]` trait bounds")]
Closure,
#[note(ast_passes_function)]
#[note("this function is not `const`, so it cannot have `[const]` trait bounds")]
Function {
#[primary_span]
ident: Span,
},
#[note(ast_passes_trait)]
#[note("this trait is not `const`, so it cannot have `[const]` trait bounds")]
Trait {
#[primary_span]
span: Span,
},
#[note(ast_passes_trait_impl)]
#[note("this impl is not `const`, so it cannot have `[const]` trait bounds")]
TraitImpl {
#[primary_span]
span: Span,
},
#[note(ast_passes_impl)]
#[note("inherent impls cannot have `[const]` trait bounds")]
Impl {
#[primary_span]
span: Span,
},
#[note(ast_passes_trait_assoc_ty)]
#[note("associated types in non-`const` traits cannot have `[const]` trait bounds")]
TraitAssocTy {
#[primary_span]
span: Span,
},
#[note(ast_passes_trait_impl_assoc_ty)]
#[note("associated types in non-const impls cannot have `[const]` trait bounds")]
TraitImplAssocTy {
#[primary_span]
span: Span,
},
#[note(ast_passes_inherent_assoc_ty)]
#[note("inherent associated types cannot have `[const]` trait bounds")]
InherentAssocTy {
#[primary_span]
span: Span,
},
#[note(ast_passes_struct)]
#[note("structs cannot have `[const]` trait bounds")]
Struct {
#[primary_span]
span: Span,
},
#[note(ast_passes_enum)]
#[note("enums cannot have `[const]` trait bounds")]
Enum {
#[primary_span]
span: Span,
},
#[note(ast_passes_union)]
#[note("unions cannot have `[const]` trait bounds")]
Union {
#[primary_span]
span: Span,
},
#[note(ast_passes_anon_const)]
#[note("anonymous constants cannot have `[const]` trait bounds")]
AnonConst {
#[primary_span]
span: Span,
},
#[note(ast_passes_object)]
#[note("trait objects cannot have `[const]` trait bounds")]
TraitObject,
#[note(ast_passes_item)]
#[note("this item cannot have `[const]` trait bounds")]
Item,
}
#[derive(Diagnostic)]
#[diag(ast_passes_const_and_coroutine)]
#[diag("functions cannot be both `const` and `{$coroutine_kind}`")]
pub(crate) struct ConstAndCoroutine {
#[primary_span]
pub spans: Vec<Span>,
#[label(ast_passes_const)]
#[label("`const` because of this")]
pub const_span: Span,
#[label(ast_passes_coroutine)]
#[label("`{$coroutine_kind}` because of this")]
pub coroutine_span: Span,
#[label]
#[label("{\"\"}")]
pub span: Span,
pub coroutine_kind: &'static str,
}
#[derive(Diagnostic)]
#[diag(ast_passes_const_and_c_variadic)]
#[diag("functions cannot be both `const` and C-variadic")]
pub(crate) struct ConstAndCVariadic {
#[primary_span]
pub spans: Vec<Span>,
#[label(ast_passes_const)]
#[label("`const` because of this")]
pub const_span: Span,
#[label(ast_passes_variadic)]
#[label("C-variadic because of this")]
pub variadic_span: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_coroutine_and_c_variadic)]
#[diag("functions cannot be both `{$coroutine_kind}` and C-variadic")]
pub(crate) struct CoroutineAndCVariadic {
#[primary_span]
pub spans: Vec<Span>,
pub coroutine_kind: &'static str,
#[label(ast_passes_const)]
#[label("`{$coroutine_kind}` because of this")]
pub coroutine_span: Span,
#[label(ast_passes_variadic)]
#[label("C-variadic because of this")]
pub variadic_span: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_c_variadic_not_supported)]
#[diag("the `{$target}` target does not support c-variadic functions")]
pub(crate) struct CVariadicNotSupported<'a> {
#[primary_span]
pub variadic_span: Span,
@@ -742,29 +855,29 @@ pub(crate) struct CVariadicNotSupported<'a> {
}
#[derive(Diagnostic)]
#[diag(ast_passes_pattern_in_foreign, code = E0130)]
#[diag("patterns aren't allowed in foreign function declarations", code = E0130)]
// FIXME: deduplicate with rustc_lint (`BuiltinLintDiag::PatternsInFnsWithoutBody`)
pub(crate) struct PatternInForeign {
#[primary_span]
#[label]
#[label("pattern not allowed in foreign function")]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_pattern_in_bodiless, code = E0642)]
#[diag("patterns aren't allowed in functions without bodies", code = E0642)]
// FIXME: deduplicate with rustc_lint (`BuiltinLintDiag::PatternsInFnsWithoutBody`)
pub(crate) struct PatternInBodiless {
#[primary_span]
#[label]
#[label("pattern not allowed in function without body")]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_equality_in_where)]
#[note]
#[diag("equality constraints are not yet supported in `where` clauses")]
#[note("see issue #20041 <https://github.com/rust-lang/rust/issues/20041> for more information")]
pub(crate) struct EqualityInWhere {
#[primary_span]
#[label]
#[label("not supported")]
pub span: Span,
#[subdiagnostic]
pub assoc: Option<AssociatedSuggestion>,
@@ -774,7 +887,7 @@ pub(crate) struct EqualityInWhere {
#[derive(Subdiagnostic)]
#[suggestion(
ast_passes_suggestion,
"if `{$ident}` is an associated type you're trying to set, use the associated type binding syntax",
code = "{param}: {path}",
style = "verbose",
applicability = "maybe-incorrect"
@@ -788,7 +901,10 @@ pub(crate) struct AssociatedSuggestion {
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(ast_passes_suggestion_path, applicability = "maybe-incorrect")]
#[multipart_suggestion(
"if `{$trait_segment}::{$potential_assoc}` is an associated type you're trying to set, use the associated type binding syntax",
applicability = "maybe-incorrect"
)]
pub(crate) struct AssociatedSuggestion2 {
#[suggestion_part(code = "{args}")]
pub span: Span,
@@ -800,14 +916,14 @@ pub(crate) struct AssociatedSuggestion2 {
}
#[derive(Diagnostic)]
#[diag(ast_passes_feature_on_non_nightly, code = E0554)]
#[diag("`#![feature]` may not be used on the {$channel} release channel", code = E0554)]
pub(crate) struct FeatureOnNonNightly {
#[primary_span]
pub span: Span,
pub channel: &'static str,
#[subdiagnostic]
pub stable_features: Vec<StableFeature>,
#[suggestion(code = "", applicability = "machine-applicable")]
#[suggestion("remove the attribute", code = "", applicability = "machine-applicable")]
pub sugg: Option<Span>,
}
@@ -820,13 +936,13 @@ impl Subdiagnostic for StableFeature {
fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
diag.arg("name", self.name);
diag.arg("since", self.since);
diag.help(fluent::ast_passes_stable_since);
diag.help(inline_fluent!("the feature `{$name}` has been stable since `{$since}` and no longer requires an attribute to enable"));
}
}
#[derive(Diagnostic)]
#[diag(ast_passes_incompatible_features)]
#[help]
#[diag("`{$f1}` and `{$f2}` are incompatible, using them at the same time is not allowed")]
#[help("remove one of these features")]
pub(crate) struct IncompatibleFeatures {
#[primary_span]
pub spans: Vec<Span>,
@@ -835,28 +951,28 @@ pub(crate) struct IncompatibleFeatures {
}
#[derive(Diagnostic)]
#[diag(ast_passes_negative_bound_not_supported)]
#[diag("negative bounds are not supported")]
pub(crate) struct NegativeBoundUnsupported {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_constraint_on_negative_bound)]
#[diag("associated type constraints not allowed on negative bounds")]
pub(crate) struct ConstraintOnNegativeBound {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_negative_bound_with_parenthetical_notation)]
#[diag("parenthetical notation may not be used for negative bounds")]
pub(crate) struct NegativeBoundWithParentheticalNotation {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_match_arm_with_no_body)]
#[diag("`match` arm with no body")]
pub(crate) struct MatchArmWithNoBody {
#[primary_span]
pub span: Span,
@@ -864,6 +980,7 @@ pub(crate) struct MatchArmWithNoBody {
// any logic looking at the arm being replaced if there was a comma already or not for the
// resulting code to be correct.
#[suggestion(
"add a body after the pattern",
code = " => {{ todo!() }}",
applicability = "has-placeholders",
style = "verbose"
@@ -872,7 +989,7 @@ pub(crate) struct MatchArmWithNoBody {
}
#[derive(Diagnostic)]
#[diag(ast_passes_precise_capturing_not_allowed_here)]
#[diag("`use<...>` precise capturing syntax not allowed in {$loc}")]
pub(crate) struct PreciseCapturingNotAllowedHere {
#[primary_span]
pub span: Span,
@@ -880,39 +997,43 @@ pub(crate) struct PreciseCapturingNotAllowedHere {
}
#[derive(Diagnostic)]
#[diag(ast_passes_precise_capturing_duplicated)]
#[diag("duplicate `use<...>` precise capturing syntax")]
pub(crate) struct DuplicatePreciseCapturing {
#[primary_span]
pub bound1: Span,
#[label]
#[label("second `use<...>` here")]
pub bound2: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_extern_without_abi)]
#[help]
#[diag("`extern` declarations without an explicit ABI are disallowed")]
#[help("prior to Rust 2024, a default ABI was inferred")]
pub(crate) struct MissingAbi {
#[primary_span]
#[suggestion(code = "extern \"<abi>\"", applicability = "has-placeholders")]
#[suggestion("specify an ABI", code = "extern \"<abi>\"", applicability = "has-placeholders")]
pub span: Span,
}
#[derive(LintDiagnostic)]
#[diag(ast_passes_extern_without_abi_sugg)]
#[diag("`extern` declarations without an explicit ABI are deprecated")]
pub(crate) struct MissingAbiSugg {
#[suggestion(code = "extern {default_abi}", applicability = "machine-applicable")]
#[suggestion(
"explicitly specify the {$default_abi} ABI",
code = "extern {default_abi}",
applicability = "machine-applicable"
)]
pub span: Span,
pub default_abi: ExternAbi,
}
#[derive(Diagnostic)]
#[diag(ast_passes_abi_custom_safe_foreign_function)]
#[diag("foreign functions with the \"custom\" ABI cannot be safe")]
pub(crate) struct AbiCustomSafeForeignFunction {
#[primary_span]
pub span: Span,
#[suggestion(
ast_passes_suggestion,
"remove the `safe` keyword from this definition",
applicability = "maybe-incorrect",
code = "",
style = "verbose"
@@ -921,14 +1042,14 @@ pub(crate) struct AbiCustomSafeForeignFunction {
}
#[derive(Diagnostic)]
#[diag(ast_passes_abi_custom_safe_function)]
#[diag("functions with the \"custom\" ABI must be unsafe")]
pub(crate) struct AbiCustomSafeFunction {
#[primary_span]
pub span: Span,
pub abi: ExternAbi,
#[suggestion(
ast_passes_suggestion,
"add the `unsafe` keyword to this definition",
applicability = "maybe-incorrect",
code = "unsafe ",
style = "verbose"
@@ -937,14 +1058,14 @@ pub(crate) struct AbiCustomSafeFunction {
}
#[derive(Diagnostic)]
#[diag(ast_passes_abi_cannot_be_coroutine)]
#[diag("functions with the {$abi} ABI cannot be `{$coroutine_kind_str}`")]
pub(crate) struct AbiCannotBeCoroutine {
#[primary_span]
pub span: Span,
pub abi: ExternAbi,
#[suggestion(
ast_passes_suggestion,
"remove the `{$coroutine_kind_str}` keyword from this definition",
applicability = "maybe-incorrect",
code = "",
style = "verbose"
@@ -954,15 +1075,15 @@ pub(crate) struct AbiCannotBeCoroutine {
}
#[derive(Diagnostic)]
#[diag(ast_passes_abi_must_not_have_parameters_or_return_type)]
#[note]
#[diag("invalid signature for `extern {$abi}` function")]
#[note("functions with the {$abi} ABI cannot have any parameters or return type")]
pub(crate) struct AbiMustNotHaveParametersOrReturnType {
#[primary_span]
pub spans: Vec<Span>,
pub abi: ExternAbi,
#[suggestion(
ast_passes_suggestion,
"remove the parameters and return type",
applicability = "maybe-incorrect",
code = "{padding}fn {symbol}()",
style = "verbose"
@@ -973,18 +1094,20 @@ pub(crate) struct AbiMustNotHaveParametersOrReturnType {
}
#[derive(Diagnostic)]
#[diag(ast_passes_abi_must_not_have_return_type)]
#[note]
#[diag("invalid signature for `extern {$abi}` function")]
#[note("functions with the {$abi} ABI cannot have a return type")]
pub(crate) struct AbiMustNotHaveReturnType {
#[primary_span]
#[help]
#[help("remove the return type")]
pub span: Span,
pub abi: ExternAbi,
}
#[derive(Diagnostic)]
#[diag(ast_passes_abi_x86_interrupt)]
#[note]
#[diag("invalid signature for `extern \"x86-interrupt\"` function")]
#[note(
"functions with the \"x86-interrupt\" ABI must be have either 1 or 2 parameters (but found {$param_count})"
)]
pub(crate) struct AbiX86Interrupt {
#[primary_span]
pub spans: Vec<Span>,
@@ -992,7 +1115,7 @@ pub(crate) struct AbiX86Interrupt {
}
#[derive(Diagnostic)]
#[diag(ast_passes_scalable_vector_not_tuple_struct)]
#[diag("scalable vectors must be tuple structs")]
pub(crate) struct ScalableVectorNotTupleStruct {
#[primary_span]
pub span: Span,
@@ -1,5 +1,6 @@
use rustc_ast::visit::{self, AssocCtxt, FnCtxt, FnKind, Visitor};
use rustc_ast::{self as ast, AttrVec, NodeId, PatKind, attr, token};
use rustc_errors::inline_fluent;
use rustc_feature::{AttributeGate, BUILTIN_ATTRIBUTE_MAP, BuiltinAttribute, Features};
use rustc_session::Session;
use rustc_session::parse::{feature_err, feature_warn};
@@ -124,7 +125,7 @@ fn check_late_bound_lifetime_defs(&self, params: &[ast::GenericParam]) {
&self,
non_lifetime_binders,
non_lt_param_spans,
crate::fluent_generated::ast_passes_forbidden_non_lifetime_param
inline_fluent!("only lifetime parameters can be used in this context")
);
// FIXME(non_lifetime_binders): Const bound params are pretty broken.
-2
View File
@@ -11,5 +11,3 @@
pub mod ast_validation;
mod errors;
pub mod feature_gate;
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
-1
View File
@@ -9,7 +9,6 @@ anstyle = "1.0.13"
jiff = { version = "0.2.5", default-features = false, features = ["std"] }
rustc_abi = { path = "../rustc_abi" }
rustc_ast = { path = "../rustc_ast" }
rustc_ast_passes = { path = "../rustc_ast_passes" }
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
rustc_borrowck = { path = "../rustc_borrowck" }
rustc_builtin_macros = { path = "../rustc_builtin_macros" }
-1
View File
@@ -114,7 +114,6 @@ pub fn default_translator() -> Translator {
pub static DEFAULT_LOCALE_RESOURCES: &[&str] = &[
// tidy-alphabetical-start
rustc_ast_passes::DEFAULT_LOCALE_RESOURCE,
rustc_borrowck::DEFAULT_LOCALE_RESOURCE,
rustc_builtin_macros::DEFAULT_LOCALE_RESOURCE,
rustc_const_eval::DEFAULT_LOCALE_RESOURCE,