diff --git a/Cargo.lock b/Cargo.lock index 9c98946c9d390..23abc6626aaba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3514,7 +3514,6 @@ dependencies = [ "rustc_data_structures", "rustc_errors", "rustc_feature", - "rustc_fluent_macro", "rustc_macros", "rustc_session", "rustc_span", @@ -3600,7 +3599,6 @@ dependencies = [ "rustc_errors", "rustc_expand", "rustc_feature", - "rustc_fluent_macro", "rustc_hir", "rustc_index", "rustc_lexer", @@ -3772,10 +3770,8 @@ dependencies = [ "libc", "rustc_abi", "rustc_ast", - "rustc_ast_passes", "rustc_ast_pretty", "rustc_borrowck", - "rustc_builtin_macros", "rustc_codegen_ssa", "rustc_const_eval", "rustc_data_structures", @@ -3796,7 +3792,6 @@ dependencies = [ "rustc_mir_transform", "rustc_parse", "rustc_passes", - "rustc_pattern_analysis", "rustc_public", "rustc_resolve", "rustc_session", @@ -3846,7 +3841,6 @@ dependencies = [ "rustc_data_structures", "rustc_error_codes", "rustc_error_messages", - "rustc_fluent_macro", "rustc_hashes", "rustc_index", "rustc_lint_defs", @@ -4262,7 +4256,6 @@ dependencies = [ "rustc_error_messages", "rustc_errors", "rustc_feature", - "rustc_fluent_macro", "rustc_graphviz", "rustc_hashes", "rustc_hir", @@ -4451,7 +4444,6 @@ dependencies = [ "rustc_arena", "rustc_data_structures", "rustc_errors", - "rustc_fluent_macro", "rustc_hir", "rustc_index", "rustc_macros", diff --git a/compiler/rustc_ast_passes/Cargo.toml b/compiler/rustc_ast_passes/Cargo.toml index 3e04f8b11ec9d..fdc735fa8d4ff 100644 --- a/compiler/rustc_ast_passes/Cargo.toml +++ b/compiler/rustc_ast_passes/Cargo.toml @@ -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" } diff --git a/compiler/rustc_ast_passes/messages.ftl b/compiler/rustc_ast_passes/messages.ftl deleted file mode 100644 index b9117c83ae2f6..0000000000000 --- a/compiler/rustc_ast_passes/messages.ftl +++ /dev/null @@ -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 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 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 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 for more information - .remove_suggestion = remove this `where` - .move_suggestion = move it to the end of the type declaration diff --git a/compiler/rustc_ast_passes/src/errors.rs b/compiler/rustc_ast_passes/src/errors.rs index 22adaae8c6f2f..baf6f6beaeed7 100644 --- a/compiler/rustc_ast_passes/src/errors.rs +++ b/compiler/rustc_ast_passes/src/errors.rs @@ -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, - #[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, #[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, } #[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, } #[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 = " = ;", applicability = "has-placeholders")] + #[suggestion( + "provide a definition for the constant", + code = " = ;", + 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 = " {{ }}", applicability = "has-placeholders")] + #[suggestion( + "provide a definition for the function", + code = " {{ }}", + 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 = " = ;", applicability = "has-placeholders")] + #[suggestion( + "provide a definition for the type", + code = " = ;", + 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 = " = ;", applicability = "has-placeholders")] + #[suggestion( + "provide a definition for the constant", + code = " = ;", + 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 = " = ;", applicability = "has-placeholders")] + #[suggestion( + "provide a definition for the static", + code = " = ;", + 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 = " = ;", applicability = "has-placeholders")] + #[suggestion( + "provide a definition for the type", + code = " = ;", + 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 = " {{ }}", applicability = "has-placeholders")] + #[suggestion( + "provide a definition for the function", + code = " {{ }}", + applicability = "has-placeholders" + )] pub replace_span: Span, #[subdiagnostic] pub extern_block_suggestion: Option, @@ -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, } #[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 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, - #[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, - #[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, - #[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 @@ impl Subdiagnostic for EmptyLabelManySpans { } #[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, - #[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 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 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, - #[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, - #[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, 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 for more information")] pub(crate) struct EqualityInWhere { #[primary_span] - #[label] + #[label("not supported")] pub span: Span, #[subdiagnostic] pub assoc: Option, @@ -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, - #[suggestion(code = "", applicability = "machine-applicable")] + #[suggestion("remove the attribute", code = "", applicability = "machine-applicable")] pub sugg: Option, } @@ -820,13 +936,13 @@ impl Subdiagnostic for StableFeature { fn add_to_diag(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, @@ -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 \"\"", applicability = "has-placeholders")] + #[suggestion("specify an ABI", code = "extern \"\"", 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, 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, @@ -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, diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index 6376cab364db1..1b1bbb1564c46 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -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 @@ impl<'a> PostExpansionVisitor<'a> { &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. diff --git a/compiler/rustc_ast_passes/src/lib.rs b/compiler/rustc_ast_passes/src/lib.rs index 06795a6be81ef..2630348c49c1f 100644 --- a/compiler/rustc_ast_passes/src/lib.rs +++ b/compiler/rustc_ast_passes/src/lib.rs @@ -11,5 +11,3 @@ pub mod ast_validation; mod errors; pub mod feature_gate; - -rustc_fluent_macro::fluent_messages! { "../messages.ftl" } diff --git a/compiler/rustc_builtin_macros/Cargo.toml b/compiler/rustc_builtin_macros/Cargo.toml index ce9a3ce3f248e..dd84a2c1802d5 100644 --- a/compiler/rustc_builtin_macros/Cargo.toml +++ b/compiler/rustc_builtin_macros/Cargo.toml @@ -15,7 +15,6 @@ rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } rustc_expand = { path = "../rustc_expand" } rustc_feature = { path = "../rustc_feature" } -rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_hir = { path = "../rustc_hir" } rustc_index = { path = "../rustc_index" } rustc_lexer = { path = "../rustc_lexer" } diff --git a/compiler/rustc_builtin_macros/messages.ftl b/compiler/rustc_builtin_macros/messages.ftl deleted file mode 100644 index f9ffddf790847..0000000000000 --- a/compiler/rustc_builtin_macros/messages.ftl +++ /dev/null @@ -1,320 +0,0 @@ -builtin_macros_alloc_error_must_be_fn = alloc_error_handler must be a function -builtin_macros_alloc_must_statics = allocators must be statics - -builtin_macros_asm_attribute_not_supported = - this attribute is not supported on assembly - -builtin_macros_asm_clobber_abi = clobber_abi -builtin_macros_asm_clobber_no_reg = asm with `clobber_abi` must specify explicit registers for outputs -builtin_macros_asm_clobber_outputs = generic outputs - -builtin_macros_asm_duplicate_arg = duplicate argument named `{$name}` - .label = previously here - .arg = duplicate argument - -builtin_macros_asm_explicit_register_name = explicit register arguments cannot have names - -builtin_macros_asm_mayunwind = asm labels are not allowed with the `may_unwind` option - -builtin_macros_asm_modifier_invalid = asm template modifier must be a single character - -builtin_macros_asm_mutually_exclusive = the `{$opt1}` and `{$opt2}` options are mutually exclusive - -builtin_macros_asm_no_matched_argument_name = there is no argument named `{$name}` - -builtin_macros_asm_noreturn = asm outputs are not allowed with the `noreturn` option - -builtin_macros_asm_opt_already_provided = the `{$symbol}` option was already provided - .label = this option was already provided - .suggestion = remove this option - -builtin_macros_asm_pos_after = positional arguments cannot follow named arguments or explicit register arguments - .pos = positional argument - .named = named argument - .explicit = explicit register argument - -builtin_macros_asm_pure_combine = the `pure` option must be combined with either `nomem` or `readonly` - -builtin_macros_asm_pure_no_output = asm with the `pure` option must have at least one output - -builtin_macros_asm_unsupported_clobber_abi = `clobber_abi` cannot be used with `{$macro_name}!` - -builtin_macros_asm_unsupported_option = the `{$symbol}` option cannot be used with `{$macro_name}!` - .label = the `{$symbol}` option is not meaningful for global-scoped inline assembly - .suggestion = remove this option - -builtin_macros_assert_missing_comma = unexpected string literal - .suggestion = try adding a comma - -builtin_macros_assert_requires_boolean = macro requires a boolean expression as an argument - .label = boolean expression required - -builtin_macros_assert_requires_expression = macro requires an expression as an argument - .suggestion = try removing semicolon - -builtin_macros_autodiff = autodiff must be applied to function -builtin_macros_autodiff_missing_config = autodiff requires at least a name and mode -builtin_macros_autodiff_mode_activity = {$act} can not be used in {$mode} Mode -builtin_macros_autodiff_number_activities = expected {$expected} activities, but found {$found} -builtin_macros_autodiff_ret_activity = invalid return activity {$act} in {$mode} Mode -builtin_macros_autodiff_ty_activity = {$act} can not be used for this type -builtin_macros_autodiff_unknown_activity = did not recognize Activity: `{$act}` - -builtin_macros_autodiff_width = autodiff width must fit u32, but is {$width} - -builtin_macros_avoid_att_syntax = avoid using `.att_syntax`, prefer using `options(att_syntax)` instead - -builtin_macros_avoid_intel_syntax = avoid using `.intel_syntax`, Intel syntax is the default - -builtin_macros_bad_derive_target = `derive` may only be applied to `struct`s, `enum`s and `union`s - .label = not applicable here - .label2 = not a `struct`, `enum` or `union` - -builtin_macros_bench_sig = functions used as benches must have signature `fn(&mut Bencher) -> impl Termination` - - -builtin_macros_cannot_derive_union = this trait cannot be derived for unions - -builtin_macros_cfg_accessible_has_args = `cfg_accessible` path cannot accept arguments - -builtin_macros_cfg_accessible_indeterminate = cannot determine whether the path is accessible or not - -builtin_macros_cfg_accessible_literal_path = `cfg_accessible` path cannot be a literal -builtin_macros_cfg_accessible_multiple_paths = multiple `cfg_accessible` paths are specified -builtin_macros_cfg_accessible_unspecified_path = `cfg_accessible` path is not specified - -builtin_macros_cfg_select_no_matches = none of the predicates in this `cfg_select` evaluated to true - -builtin_macros_cfg_select_unreachable = unreachable predicate - .label = always matches - .label2 = this predicate is never reached - -builtin_macros_coerce_pointee_requires_maybe_sized = `derive(CoercePointee)` requires `{$name}` to be marked `?Sized` - -builtin_macros_coerce_pointee_requires_one_field = `CoercePointee` can only be derived on `struct`s with at least one field - -builtin_macros_coerce_pointee_requires_one_generic = `CoercePointee` can only be derived on `struct`s that are generic over at least one type - -builtin_macros_coerce_pointee_requires_one_pointee = exactly one generic type parameter must be marked as `#[pointee]` to derive `CoercePointee` traits - -builtin_macros_coerce_pointee_requires_transparent = `CoercePointee` can only be derived on `struct`s with `#[repr(transparent)]` - -builtin_macros_coerce_pointee_too_many_pointees = only one type parameter can be marked as `#[pointee]` when deriving `CoercePointee` traits - .label = here another type parameter is marked as `#[pointee]` - - -builtin_macros_concat_bytes_array = cannot concatenate doubly nested array - .note = byte strings are treated as arrays of bytes - .help = try flattening the array - -builtin_macros_concat_bytes_bad_repeat = repeat count is not a positive number - -builtin_macros_concat_bytes_invalid = cannot concatenate {$lit_kind} literals - .byte_char = try using a byte character - .byte_str = try using a byte string - .c_str = try using a null-terminated byte string - .c_str_note = concatenating C strings is ambiguous about including the '\0' - .number_array = try wrapping the number in an array - -builtin_macros_concat_bytes_missing_literal = expected a byte literal - .note = only byte literals (like `b"foo"`, `b's'` and `[3, 4, 5]`) can be passed to `concat_bytes!()` - -builtin_macros_concat_bytes_non_u8 = numeric literal is not a `u8` - -builtin_macros_concat_bytes_oob = numeric literal is out of bounds - -builtin_macros_concat_bytestr = cannot concatenate a byte string literal -builtin_macros_concat_c_str_lit = cannot concatenate a C string literal - -builtin_macros_concat_missing_literal = expected a literal - .note = only literals (like `"foo"`, `-42` and `3.14`) can be passed to `concat!()` - -builtin_macros_default_arg = `#[default]` attribute does not accept a value - .suggestion = try using `#[default]` - -builtin_macros_derive_from_usage_note = `#[derive(From)]` can only be used on structs with exactly one field - -builtin_macros_derive_from_wrong_field_count = `#[derive(From)]` used on a struct with {$multiple_fields -> - [true] multiple fields - *[false] no fields -} - -builtin_macros_derive_from_wrong_target = `#[derive(From)]` used on {$kind} - -builtin_macros_derive_macro_call = `derive` cannot be used on items with type macros - -builtin_macros_derive_path_args_list = traits in `#[derive(...)]` don't accept arguments - .suggestion = remove the arguments - -builtin_macros_derive_path_args_value = traits in `#[derive(...)]` don't accept values - .suggestion = remove the value - -builtin_macros_duplicate_macro_attribute = duplicated attribute - -builtin_macros_eii_declaration_expected_list = `#[eii_declaration(...)]` expects a list of one or two elements -builtin_macros_eii_declaration_expected_macro = `#[eii_declaration(...)]` is only valid on macros -builtin_macros_eii_declaration_expected_unsafe = expected this argument to be "unsafe" - .note = the second argument is optional - -builtin_macros_eii_only_once = `#[{$name}]` can only be specified once - .note = specified again here - -builtin_macros_eii_shared_macro_expected_function = `#[{$name}]` is only valid on functions -builtin_macros_eii_shared_macro_expected_max_one_argument = `#[{$name}]` expected no arguments or a single argument: `#[{$name}(default)]` -builtin_macros_eii_shared_macro_in_statement_position = `#[{$name}]` can only be used on functions inside a module - .label = `#[{$name}]` is used on this item, which is part of another item's local scope - -builtin_macros_env_not_defined = environment variable `{$var}` not defined at compile time - .cargo = Cargo sets build script variables at run time. Use `std::env::var({$var_expr})` instead - .cargo_typo = there is a similar Cargo environment variable: `{$suggested_var}` - .custom = use `std::env::var({$var_expr})` to read the variable at run time - -builtin_macros_env_not_unicode = environment variable `{$var}` is not a valid Unicode string - -builtin_macros_env_takes_args = `env!()` takes 1 or 2 arguments - -builtin_macros_expected_comma_in_list = expected token: `,` - -builtin_macros_expected_one_cfg_pattern = expected 1 cfg-pattern - -builtin_macros_expected_other = expected operand, {$is_inline_asm -> - [false] options - *[true] clobber_abi, options - }, or additional template string - -builtin_macros_export_macro_rules = cannot export macro_rules! macros from a `proc-macro` crate type currently - -builtin_macros_format_add_missing_colon = add a colon before the format specifier - -builtin_macros_format_duplicate_arg = duplicate argument named `{$ident}` - .label1 = previously here - .label2 = duplicate argument - -builtin_macros_format_no_arg_named = there is no argument named `{$name}` - .note = did you intend to capture a variable `{$name}` from the surrounding scope? - .note2 = to avoid ambiguity, `format_args!` cannot capture variables when the format string is expanded from a macro - -builtin_macros_format_pos_mismatch = {$n} positional {$n -> - [one] argument - *[more] arguments - } in format string, but {$desc} - -builtin_macros_format_positional_after_named = positional arguments cannot follow named arguments - .label = positional arguments must be before named arguments - .named_args = named argument - -builtin_macros_format_redundant_args = redundant {$n -> - [one] argument - *[more] arguments - } - .help = {$n -> - [one] the formatting string already captures the binding directly, it doesn't need to be included in the argument list - *[more] the formatting strings already captures the bindings directly, they don't need to be included in the argument list - } - .note = {$n -> - [one] the formatting specifier is referencing the binding already - *[more] the formatting specifiers are referencing the bindings already - } - .suggestion = this can be removed - -builtin_macros_format_remove_raw_ident = remove the `r#` - -builtin_macros_format_reorder_format_parameter = did you mean `{$replacement}`? - -builtin_macros_format_requires_string = requires at least a format string argument - -builtin_macros_format_string_invalid = invalid format string: {$desc} - .label = {$label1} in format string - .note = {$note} - .second_label = {$label} - -builtin_macros_format_unknown_trait = unknown format trait `{$ty}` - .note = the only appropriate formatting traits are: - - ``, which uses the `Display` trait - - `?`, which uses the `Debug` trait - - `e`, which uses the `LowerExp` trait - - `E`, which uses the `UpperExp` trait - - `o`, which uses the `Octal` trait - - `p`, which uses the `Pointer` trait - - `b`, which uses the `Binary` trait - - `x`, which uses the `LowerHex` trait - - `X`, which uses the `UpperHex` trait - .suggestion = use the `{$trait_name}` trait - -builtin_macros_format_unused_arg = {$named -> - [true] named argument - *[false] argument - } never used - -builtin_macros_format_unused_args = multiple unused formatting arguments - .label = multiple missing formatting specifiers - -builtin_macros_format_use_positional = consider using a positional formatting argument instead - -builtin_macros_incomplete_include = include macro expected single expression in source - -builtin_macros_multiple_default_attrs = multiple `#[default]` attributes - .note = only one `#[default]` attribute is needed - .label = `#[default]` used here - .label_again = `#[default]` used again here - .help = try removing {$only_one -> - [true] this - *[false] these - } - -builtin_macros_multiple_defaults = multiple declared defaults - .label = first default - .additional = additional default - .note = only one variant can be default - .suggestion = make `{$ident}` default - -builtin_macros_naked_functions_testing_attribute = - cannot use `#[unsafe(naked)]` with testing attributes - .label = function marked with testing attribute here - .naked_attribute = `#[unsafe(naked)]` is incompatible with testing attributes - -builtin_macros_no_default_variant = `#[derive(Default)]` on enum with no `#[default]` - .label = this enum needs a unit variant marked with `#[default]` - .suggestion = make this unit variant default by placing `#[default]` on it - -builtin_macros_non_exhaustive_default = default variant must be exhaustive - .label = declared `#[non_exhaustive]` here - .help = consider a manual implementation of `Default` - -builtin_macros_non_generic_pointee = the `#[pointee]` attribute may only be used on generic parameters - -builtin_macros_non_unit_default = the `#[default]` attribute may only be used on unit enum variants{$post} - .help = consider a manual implementation of `Default` - -builtin_macros_only_one_argument = {$name} takes 1 argument - -builtin_macros_proc_macro = `proc-macro` crate types currently cannot export any items other than functions tagged with `#[proc_macro]`, `#[proc_macro_derive]`, or `#[proc_macro_attribute]` - -builtin_macros_proc_macro_attribute_only_usable_with_crate_type = the `#[{$path}]` attribute is only usable with crates of the `proc-macro` crate type - -builtin_macros_requires_cfg_pattern = - macro requires a cfg-pattern as an argument - .label = cfg-pattern required - -builtin_macros_source_utils_expected_item = expected item, found `{$token}` - -builtin_macros_takes_no_arguments = {$name} takes no arguments - -builtin_macros_test_bad_fn = {$kind} functions cannot be used for tests - .label = `{$kind}` because of this - -builtin_macros_test_case_non_item = `#[test_case]` attribute is only allowed on items - -builtin_macros_test_runner_invalid = `test_runner` argument must be a path -builtin_macros_test_runner_nargs = `#![test_runner(..)]` accepts exactly 1 argument - -builtin_macros_tests_not_support = building tests with panic=abort is not supported without `-Zpanic_abort_tests` - -builtin_macros_trace_macros = trace_macros! accepts only `true` or `false` - -builtin_macros_unexpected_lit = expected path to a trait, found literal - .label = not a trait - .str_lit = try using `#[derive({$sym})]` - .other = for example, write `#[derive(Debug)]` for `Debug` - -builtin_macros_unnameable_test_items = cannot test inner items diff --git a/compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs b/compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs index d6fdf088b0d19..8984e51c08447 100644 --- a/compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs +++ b/compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs @@ -463,44 +463,44 @@ impl<'a, 'b> rustc_ast::visit::Visitor<'a> for AlwaysErrorOnGenericParam<'a, 'b> } #[derive(Diagnostic)] -#[diag(builtin_macros_coerce_pointee_requires_transparent, code = E0802)] +#[diag("`CoercePointee` can only be derived on `struct`s with `#[repr(transparent)]`", code = E0802)] struct RequireTransparent { #[primary_span] span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_coerce_pointee_requires_one_field, code = E0802)] +#[diag("`CoercePointee` can only be derived on `struct`s with at least one field", code = E0802)] struct RequireOneField { #[primary_span] span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_coerce_pointee_requires_one_generic, code = E0802)] +#[diag("`CoercePointee` can only be derived on `struct`s that are generic over at least one type", code = E0802)] struct RequireOneGeneric { #[primary_span] span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_coerce_pointee_requires_one_pointee, code = E0802)] +#[diag("exactly one generic type parameter must be marked as `#[pointee]` to derive `CoercePointee` traits", code = E0802)] struct RequireOnePointee { #[primary_span] span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_coerce_pointee_too_many_pointees, code = E0802)] +#[diag("only one type parameter can be marked as `#[pointee]` when deriving `CoercePointee` traits", code = E0802)] struct TooManyPointees { #[primary_span] one: Span, - #[label] + #[label("here another type parameter is marked as `#[pointee]`")] another: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_coerce_pointee_requires_maybe_sized, code = E0802)] +#[diag("`derive(CoercePointee)` requires `{$name}` to be marked `?Sized`", code = E0802)] struct RequiresMaybeSized { #[primary_span] span: Span, diff --git a/compiler/rustc_builtin_macros/src/errors.rs b/compiler/rustc_builtin_macros/src/errors.rs index 0aaa8cf558c43..d3f7e1c5d8e36 100644 --- a/compiler/rustc_builtin_macros/src/errors.rs +++ b/compiler/rustc_builtin_macros/src/errors.rs @@ -1,150 +1,157 @@ use rustc_errors::codes::*; use rustc_errors::{ Diag, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level, MultiSpan, SingleLabelManySpans, - Subdiagnostic, + Subdiagnostic, inline_fluent, }; use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic}; use rustc_span::{Ident, Span, Symbol}; #[derive(LintDiagnostic)] -#[diag(builtin_macros_avoid_intel_syntax)] +#[diag("avoid using `.intel_syntax`, Intel syntax is the default")] pub(crate) struct AvoidIntelSyntax; #[derive(LintDiagnostic)] -#[diag(builtin_macros_avoid_att_syntax)] +#[diag("avoid using `.att_syntax`, prefer using `options(att_syntax)` instead")] pub(crate) struct AvoidAttSyntax; #[derive(LintDiagnostic)] -#[diag(builtin_macros_incomplete_include)] +#[diag("include macro expected single expression in source")] pub(crate) struct IncompleteInclude; #[derive(LintDiagnostic)] -#[diag(builtin_macros_unnameable_test_items)] +#[diag("cannot test inner items")] pub(crate) struct UnnameableTestItems; #[derive(LintDiagnostic)] -#[diag(builtin_macros_duplicate_macro_attribute)] +#[diag("duplicated attribute")] pub(crate) struct DuplicateMacroAttribute; #[derive(Diagnostic)] -#[diag(builtin_macros_requires_cfg_pattern)] +#[diag("macro requires a cfg-pattern as an argument")] pub(crate) struct RequiresCfgPattern { #[primary_span] - #[label] + #[label("cfg-pattern required")] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_expected_one_cfg_pattern)] +#[diag("expected 1 cfg-pattern")] pub(crate) struct OneCfgPattern { #[primary_span] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_alloc_error_must_be_fn)] +#[diag("alloc_error_handler must be a function")] pub(crate) struct AllocErrorMustBeFn { #[primary_span] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_assert_requires_boolean)] +#[diag("macro requires a boolean expression as an argument")] pub(crate) struct AssertRequiresBoolean { #[primary_span] - #[label] + #[label("boolean expression required")] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_assert_requires_expression)] +#[diag("macro requires an expression as an argument")] pub(crate) struct AssertRequiresExpression { #[primary_span] pub(crate) span: Span, - #[suggestion(code = "", applicability = "maybe-incorrect")] + #[suggestion("try removing semicolon", code = "", applicability = "maybe-incorrect")] pub(crate) token: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_assert_missing_comma)] +#[diag("unexpected string literal")] pub(crate) struct AssertMissingComma { #[primary_span] pub(crate) span: Span, - #[suggestion(code = ", ", applicability = "maybe-incorrect", style = "short")] + #[suggestion( + "try adding a comma", + code = ", ", + applicability = "maybe-incorrect", + style = "short" + )] pub(crate) comma: Span, } #[derive(Diagnostic)] pub(crate) enum CfgAccessibleInvalid { - #[diag(builtin_macros_cfg_accessible_unspecified_path)] + #[diag("`cfg_accessible` path is not specified")] UnspecifiedPath(#[primary_span] Span), - #[diag(builtin_macros_cfg_accessible_multiple_paths)] + #[diag("multiple `cfg_accessible` paths are specified")] MultiplePaths(#[primary_span] Span), - #[diag(builtin_macros_cfg_accessible_literal_path)] + #[diag("`cfg_accessible` path cannot be a literal")] LiteralPath(#[primary_span] Span), - #[diag(builtin_macros_cfg_accessible_has_args)] + #[diag("`cfg_accessible` path cannot accept arguments")] HasArguments(#[primary_span] Span), } #[derive(Diagnostic)] -#[diag(builtin_macros_cfg_accessible_indeterminate)] +#[diag("cannot determine whether the path is accessible or not")] pub(crate) struct CfgAccessibleIndeterminate { #[primary_span] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_concat_missing_literal)] -#[note] +#[diag("expected a literal")] +#[note("only literals (like `\"foo\"`, `-42` and `3.14`) can be passed to `concat!()`")] pub(crate) struct ConcatMissingLiteral { #[primary_span] pub(crate) spans: Vec, } #[derive(Diagnostic)] -#[diag(builtin_macros_concat_bytestr)] +#[diag("cannot concatenate a byte string literal")] pub(crate) struct ConcatBytestr { #[primary_span] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_concat_c_str_lit)] +#[diag("cannot concatenate a C string literal")] pub(crate) struct ConcatCStrLit { #[primary_span] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_export_macro_rules)] +#[diag("cannot export macro_rules! macros from a `proc-macro` crate type currently")] pub(crate) struct ExportMacroRules { #[primary_span] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_proc_macro)] +#[diag( + "`proc-macro` crate types currently cannot export any items other than functions tagged with `#[proc_macro]`, `#[proc_macro_derive]`, or `#[proc_macro_attribute]`" +)] pub(crate) struct ProcMacro { #[primary_span] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_trace_macros)] +#[diag("trace_macros! accepts only `true` or `false`")] pub(crate) struct TraceMacros { #[primary_span] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_bench_sig)] +#[diag("functions used as benches must have signature `fn(&mut Bencher) -> impl Termination`")] pub(crate) struct BenchSig { #[primary_span] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_alloc_must_statics)] +#[diag("allocators must be statics")] pub(crate) struct AllocMustStatics { #[primary_span] pub(crate) span: Span, @@ -155,27 +162,27 @@ pub(crate) use autodiff::*; mod autodiff { use super::*; #[derive(Diagnostic)] - #[diag(builtin_macros_autodiff_missing_config)] + #[diag("autodiff requires at least a name and mode")] pub(crate) struct AutoDiffMissingConfig { #[primary_span] pub(crate) span: Span, } #[derive(Diagnostic)] - #[diag(builtin_macros_autodiff_unknown_activity)] + #[diag("did not recognize Activity: `{$act}`")] pub(crate) struct AutoDiffUnknownActivity { #[primary_span] pub(crate) span: Span, pub(crate) act: String, } #[derive(Diagnostic)] - #[diag(builtin_macros_autodiff_ty_activity)] + #[diag("{$act} can not be used for this type")] pub(crate) struct AutoDiffInvalidTypeForActivity { #[primary_span] pub(crate) span: Span, pub(crate) act: String, } #[derive(Diagnostic)] - #[diag(builtin_macros_autodiff_number_activities)] + #[diag("expected {$expected} activities, but found {$found}")] pub(crate) struct AutoDiffInvalidNumberActivities { #[primary_span] pub(crate) span: Span, @@ -183,7 +190,7 @@ mod autodiff { pub(crate) found: usize, } #[derive(Diagnostic)] - #[diag(builtin_macros_autodiff_mode_activity)] + #[diag("{$act} can not be used in {$mode} Mode")] pub(crate) struct AutoDiffInvalidApplicationModeAct { #[primary_span] pub(crate) span: Span, @@ -192,7 +199,7 @@ mod autodiff { } #[derive(Diagnostic)] - #[diag(builtin_macros_autodiff_ret_activity)] + #[diag("invalid return activity {$act} in {$mode} Mode")] pub(crate) struct AutoDiffInvalidRetAct { #[primary_span] pub(crate) span: Span, @@ -201,7 +208,7 @@ mod autodiff { } #[derive(Diagnostic)] - #[diag(builtin_macros_autodiff_width)] + #[diag("autodiff width must fit u32, but is {$width}")] pub(crate) struct AutoDiffInvalidWidth { #[primary_span] pub(crate) span: Span, @@ -209,7 +216,7 @@ mod autodiff { } #[derive(Diagnostic)] - #[diag(builtin_macros_autodiff)] + #[diag("autodiff must be applied to function")] pub(crate) struct AutoDiffInvalidApplication { #[primary_span] pub(crate) span: Span, @@ -217,21 +224,21 @@ mod autodiff { } #[derive(Diagnostic)] -#[diag(builtin_macros_concat_bytes_invalid)] +#[diag("cannot concatenate {$lit_kind} literals")] pub(crate) struct ConcatBytesInvalid { #[primary_span] pub(crate) span: Span, pub(crate) lit_kind: &'static str, #[subdiagnostic] pub(crate) sugg: Option, - #[note(builtin_macros_c_str_note)] + #[note("concatenating C strings is ambiguous about including the '\\0'")] pub(crate) cs_note: Option<()>, } #[derive(Subdiagnostic)] pub(crate) enum ConcatBytesInvalidSuggestion { #[suggestion( - builtin_macros_byte_char, + "try using a byte character", code = "b{snippet}", applicability = "machine-applicable" )] @@ -241,7 +248,7 @@ pub(crate) enum ConcatBytesInvalidSuggestion { snippet: String, }, #[suggestion( - builtin_macros_byte_str, + "try using a byte string", code = "b{snippet}", applicability = "machine-applicable" )] @@ -250,15 +257,19 @@ pub(crate) enum ConcatBytesInvalidSuggestion { span: Span, snippet: String, }, - #[note(builtin_macros_c_str_note)] - #[suggestion(builtin_macros_c_str, code = "{as_bstr}", applicability = "machine-applicable")] + #[note("concatenating C strings is ambiguous about including the '\\0'")] + #[suggestion( + "try using a null-terminated byte string", + code = "{as_bstr}", + applicability = "machine-applicable" + )] CStrLit { #[primary_span] span: Span, as_bstr: String, }, #[suggestion( - builtin_macros_number_array, + "try wrapping the number in an array", code = "[{snippet}]", applicability = "machine-applicable" )] @@ -270,63 +281,65 @@ pub(crate) enum ConcatBytesInvalidSuggestion { } #[derive(Diagnostic)] -#[diag(builtin_macros_concat_bytes_oob)] +#[diag("numeric literal is out of bounds")] pub(crate) struct ConcatBytesOob { #[primary_span] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_concat_bytes_non_u8)] +#[diag("numeric literal is not a `u8`")] pub(crate) struct ConcatBytesNonU8 { #[primary_span] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_concat_bytes_missing_literal)] -#[note] +#[diag("expected a byte literal")] +#[note( + "only byte literals (like `b\"foo\"`, `b's'` and `[3, 4, 5]`) can be passed to `concat_bytes!()`" +)] pub(crate) struct ConcatBytesMissingLiteral { #[primary_span] pub(crate) spans: Vec, } #[derive(Diagnostic)] -#[diag(builtin_macros_concat_bytes_array)] +#[diag("cannot concatenate doubly nested array")] pub(crate) struct ConcatBytesArray { #[primary_span] pub(crate) span: Span, - #[note] - #[help] + #[note("byte strings are treated as arrays of bytes")] + #[help("try flattening the array")] pub(crate) bytestr: bool, } #[derive(Diagnostic)] -#[diag(builtin_macros_concat_bytes_bad_repeat)] +#[diag("repeat count is not a positive number")] pub(crate) struct ConcatBytesBadRepeat { #[primary_span] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_bad_derive_target, code = E0774)] +#[diag("`derive` may only be applied to `struct`s, `enum`s and `union`s", code = E0774)] pub(crate) struct BadDeriveTarget { #[primary_span] - #[label] + #[label("not applicable here")] pub(crate) span: Span, - #[label(builtin_macros_label2)] + #[label("not a `struct`, `enum` or `union`")] pub(crate) item: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_tests_not_support)] +#[diag("building tests with panic=abort is not supported without `-Zpanic_abort_tests`")] pub(crate) struct TestsNotSupport {} #[derive(Diagnostic)] -#[diag(builtin_macros_unexpected_lit, code = E0777)] +#[diag("expected path to a trait, found literal", code = E0777)] pub(crate) struct BadDeriveLit { #[primary_span] - #[label] + #[label("not a trait")] pub(crate) span: Span, #[subdiagnostic] pub help: BadDeriveLitHelp, @@ -334,55 +347,59 @@ pub(crate) struct BadDeriveLit { #[derive(Subdiagnostic)] pub(crate) enum BadDeriveLitHelp { - #[help(builtin_macros_str_lit)] + #[help("try using `#[derive({$sym})]`")] StrLit { sym: Symbol }, - #[help(builtin_macros_other)] + #[help("for example, write `#[derive(Debug)]` for `Debug`")] Other, } #[derive(Diagnostic)] -#[diag(builtin_macros_derive_path_args_list)] +#[diag("traits in `#[derive(...)]` don't accept arguments")] pub(crate) struct DerivePathArgsList { - #[suggestion(code = "", applicability = "machine-applicable")] + #[suggestion("remove the arguments", code = "", applicability = "machine-applicable")] #[primary_span] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_derive_path_args_value)] +#[diag("traits in `#[derive(...)]` don't accept values")] pub(crate) struct DerivePathArgsValue { - #[suggestion(code = "", applicability = "machine-applicable")] + #[suggestion("remove the value", code = "", applicability = "machine-applicable")] #[primary_span] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_no_default_variant, code = E0665)] +#[diag("`#[derive(Default)]` on enum with no `#[default]`", code = E0665)] pub(crate) struct NoDefaultVariant { #[primary_span] pub(crate) span: Span, - #[label] + #[label("this enum needs a unit variant marked with `#[default]`")] pub(crate) item_span: Span, #[subdiagnostic] pub(crate) suggs: Vec, } #[derive(Subdiagnostic)] -#[suggestion(builtin_macros_suggestion, code = "#[default] ", applicability = "maybe-incorrect")] +#[suggestion( + "make this unit variant default by placing `#[default]` on it", + code = "#[default] ", + applicability = "maybe-incorrect" +)] pub(crate) struct NoDefaultVariantSugg { #[primary_span] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_multiple_defaults)] -#[note] +#[diag("multiple declared defaults")] +#[note("only one variant can be default")] pub(crate) struct MultipleDefaults { #[primary_span] pub(crate) span: Span, - #[label] + #[label("first default")] pub(crate) first: Span, - #[label(builtin_macros_additional)] + #[label("additional default")] pub additional: Vec, #[subdiagnostic] pub suggs: Vec, @@ -390,7 +407,7 @@ pub(crate) struct MultipleDefaults { #[derive(Subdiagnostic)] #[multipart_suggestion( - builtin_macros_suggestion, + "make `{$ident}` default", applicability = "maybe-incorrect", style = "tool-only" )] @@ -401,8 +418,8 @@ pub(crate) struct MultipleDefaultsSugg { } #[derive(Diagnostic)] -#[diag(builtin_macros_non_unit_default)] -#[help] +#[diag("the `#[default]` attribute may only be used on unit enum variants{$post}")] +#[help("consider a manual implementation of `Default`")] pub(crate) struct NonUnitDefault { #[primary_span] pub(crate) span: Span, @@ -410,26 +427,31 @@ pub(crate) struct NonUnitDefault { } #[derive(Diagnostic)] -#[diag(builtin_macros_non_exhaustive_default)] -#[help] +#[diag("default variant must be exhaustive")] +#[help("consider a manual implementation of `Default`")] pub(crate) struct NonExhaustiveDefault { #[primary_span] pub(crate) span: Span, - #[label] + #[label("declared `#[non_exhaustive]` here")] pub(crate) non_exhaustive: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_multiple_default_attrs)] -#[note] +#[diag("multiple `#[default]` attributes")] +#[note("only one `#[default]` attribute is needed")] pub(crate) struct MultipleDefaultAttrs { #[primary_span] pub(crate) span: Span, - #[label] + #[label("`#[default]` used here")] pub(crate) first: Span, - #[label(builtin_macros_label_again)] + #[label("`#[default]` used again here")] pub(crate) first_rest: Span, - #[help] + #[help( + "try removing {$only_one -> + [true] this + *[false] these + }" + )] pub(crate) rest: MultiSpan, pub(crate) only_one: bool, #[subdiagnostic] @@ -438,7 +460,7 @@ pub(crate) struct MultipleDefaultAttrs { #[derive(Subdiagnostic)] #[multipart_suggestion( - builtin_macros_help, + "consider a manual implementation of `Default`", applicability = "machine-applicable", style = "tool-only" )] @@ -448,16 +470,21 @@ pub(crate) struct MultipleDefaultAttrsSugg { } #[derive(Diagnostic)] -#[diag(builtin_macros_default_arg)] +#[diag("`#[default]` attribute does not accept a value")] pub(crate) struct DefaultHasArg { #[primary_span] - #[suggestion(code = "#[default]", style = "hidden", applicability = "maybe-incorrect")] + #[suggestion( + "try using `#[default]`", + code = "#[default]", + style = "hidden", + applicability = "maybe-incorrect" + )] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_derive_from_wrong_target)] -#[note(builtin_macros_derive_from_usage_note)] +#[diag("`#[derive(From)]` used on {$kind}")] +#[note("`#[derive(From)]` can only be used on structs with exactly one field")] pub(crate) struct DeriveFromWrongTarget<'a> { #[primary_span] pub(crate) span: MultiSpan, @@ -465,8 +492,13 @@ pub(crate) struct DeriveFromWrongTarget<'a> { } #[derive(Diagnostic)] -#[diag(builtin_macros_derive_from_wrong_field_count)] -#[note(builtin_macros_derive_from_usage_note)] +#[diag( + "`#[derive(From)]` used on a struct with {$multiple_fields -> + [true] multiple fields + *[false] no fields + }" +)] +#[note("`#[derive(From)]` can only be used on structs with exactly one field")] pub(crate) struct DeriveFromWrongFieldCount { #[primary_span] pub(crate) span: MultiSpan, @@ -474,21 +506,21 @@ pub(crate) struct DeriveFromWrongFieldCount { } #[derive(Diagnostic)] -#[diag(builtin_macros_derive_macro_call)] +#[diag("`derive` cannot be used on items with type macros")] pub(crate) struct DeriveMacroCall { #[primary_span] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_cannot_derive_union)] +#[diag("this trait cannot be derived for unions")] pub(crate) struct DeriveUnion { #[primary_span] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_env_takes_args)] +#[diag("`env!()` takes 1 or 2 arguments")] pub(crate) struct EnvTakesArgs { #[primary_span] pub(crate) span: Span, @@ -511,24 +543,26 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for EnvNotDefinedWithUserMessag #[derive(Diagnostic)] pub(crate) enum EnvNotDefined<'a> { - #[diag(builtin_macros_env_not_defined)] - #[help(builtin_macros_cargo)] + #[diag("environment variable `{$var}` not defined at compile time")] + #[help( + "Cargo sets build script variables at run time. Use `std::env::var({$var_expr})` instead" + )] CargoEnvVar { #[primary_span] span: Span, var: Symbol, var_expr: &'a rustc_ast::Expr, }, - #[diag(builtin_macros_env_not_defined)] - #[help(builtin_macros_cargo_typo)] + #[diag("environment variable `{$var}` not defined at compile time")] + #[help("there is a similar Cargo environment variable: `{$suggested_var}`")] CargoEnvVarTypo { #[primary_span] span: Span, var: Symbol, suggested_var: Symbol, }, - #[diag(builtin_macros_env_not_defined)] - #[help(builtin_macros_custom)] + #[diag("environment variable `{$var}` not defined at compile time")] + #[help("use `std::env::var({$var_expr})` to read the variable at run time")] CustomEnvVar { #[primary_span] span: Span, @@ -538,7 +572,7 @@ pub(crate) enum EnvNotDefined<'a> { } #[derive(Diagnostic)] -#[diag(builtin_macros_env_not_unicode)] +#[diag("environment variable `{$var}` is not a valid Unicode string")] pub(crate) struct EnvNotUnicode { #[primary_span] pub(crate) span: Span, @@ -546,39 +580,39 @@ pub(crate) struct EnvNotUnicode { } #[derive(Diagnostic)] -#[diag(builtin_macros_format_requires_string)] +#[diag("requires at least a format string argument")] pub(crate) struct FormatRequiresString { #[primary_span] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_format_duplicate_arg)] +#[diag("duplicate argument named `{$ident}`")] pub(crate) struct FormatDuplicateArg { #[primary_span] pub(crate) span: Span, - #[label(builtin_macros_label1)] + #[label("previously here")] pub(crate) prev: Span, - #[label(builtin_macros_label2)] + #[label("duplicate argument")] pub(crate) duplicate: Span, pub(crate) ident: Ident, } #[derive(Diagnostic)] -#[diag(builtin_macros_format_positional_after_named)] +#[diag("positional arguments cannot follow named arguments")] pub(crate) struct PositionalAfterNamed { #[primary_span] - #[label] + #[label("positional arguments must be before named arguments")] pub(crate) span: Span, - #[label(builtin_macros_named_args)] + #[label("named argument")] pub(crate) args: Vec, } #[derive(Diagnostic)] -#[diag(builtin_macros_format_string_invalid)] +#[diag("invalid format string: {$desc}")] pub(crate) struct InvalidFormatString { #[primary_span] - #[label] + #[label("{$label1} in format string")] pub(crate) span: Span, pub(crate) desc: String, pub(crate) label1: String, @@ -591,13 +625,13 @@ pub(crate) struct InvalidFormatString { } #[derive(Subdiagnostic)] -#[note(builtin_macros_note)] +#[note("{$note}")] pub(crate) struct InvalidFormatStringNote { pub(crate) note: String, } #[derive(Subdiagnostic)] -#[label(builtin_macros_second_label)] +#[label("{$label}")] pub(crate) struct InvalidFormatStringLabel { #[primary_span] pub(crate) span: Span, @@ -607,7 +641,7 @@ pub(crate) struct InvalidFormatStringLabel { #[derive(Subdiagnostic)] pub(crate) enum InvalidFormatStringSuggestion { #[multipart_suggestion( - builtin_macros_format_use_positional, + "consider using a positional formatting argument instead", style = "verbose", applicability = "machine-applicable" )] @@ -619,17 +653,13 @@ pub(crate) enum InvalidFormatStringSuggestion { span: Span, arg: String, }, - #[suggestion( - builtin_macros_format_remove_raw_ident, - code = "", - applicability = "machine-applicable" - )] + #[suggestion("remove the `r#`", code = "", applicability = "machine-applicable")] RemoveRawIdent { #[primary_span] span: Span, }, #[suggestion( - builtin_macros_format_reorder_format_parameter, + "did you mean `{$replacement}`?", code = "{replacement}", style = "verbose", applicability = "machine-applicable" @@ -640,7 +670,7 @@ pub(crate) enum InvalidFormatStringSuggestion { replacement: String, }, #[suggestion( - builtin_macros_format_add_missing_colon, + "add a colon before the format specifier", code = ":?", applicability = "machine-applicable" )] @@ -651,9 +681,11 @@ pub(crate) enum InvalidFormatStringSuggestion { } #[derive(Diagnostic)] -#[diag(builtin_macros_format_no_arg_named)] -#[note] -#[note(builtin_macros_note2)] +#[diag("there is no argument named `{$name}`")] +#[note("did you intend to capture a variable `{$name}` from the surrounding scope?")] +#[note( + "to avoid ambiguity, `format_args!` cannot capture variables when the format string is expanded from a macro" +)] pub(crate) struct FormatNoArgNamed { #[primary_span] pub(crate) span: Span, @@ -661,8 +693,19 @@ pub(crate) struct FormatNoArgNamed { } #[derive(Diagnostic)] -#[diag(builtin_macros_format_unknown_trait)] -#[note] +#[diag("unknown format trait `{$ty}`")] +#[note( + "the only appropriate formatting traits are: + - ``, which uses the `Display` trait + - `?`, which uses the `Debug` trait + - `e`, which uses the `LowerExp` trait + - `E`, which uses the `UpperExp` trait + - `o`, which uses the `Octal` trait + - `p`, which uses the `Pointer` trait + - `b`, which uses the `Binary` trait + - `x`, which uses the `LowerHex` trait + - `X`, which uses the `UpperHex` trait" +)] pub(crate) struct FormatUnknownTrait<'a> { #[primary_span] pub(crate) span: Span, @@ -673,7 +716,7 @@ pub(crate) struct FormatUnknownTrait<'a> { #[derive(Subdiagnostic)] #[suggestion( - builtin_macros_suggestion, + "use the `{$trait_name}` trait", code = "{fmt}", style = "tool-only", applicability = "maybe-incorrect" @@ -686,10 +729,20 @@ pub(crate) struct FormatUnknownTraitSugg { } #[derive(Diagnostic)] -#[diag(builtin_macros_format_unused_arg)] +#[diag( + "{$named -> + [true] named argument + *[false] argument + } never used" +)] pub(crate) struct FormatUnusedArg { #[primary_span] - #[label(builtin_macros_format_unused_arg)] + #[label( + "{$named -> + [true] named argument + *[false] argument + } never used" + )] pub(crate) span: Span, pub(crate) named: bool, } @@ -699,25 +752,35 @@ pub(crate) struct FormatUnusedArg { impl Subdiagnostic for FormatUnusedArg { fn add_to_diag(self, diag: &mut Diag<'_, G>) { diag.arg("named", self.named); - let msg = diag.eagerly_translate(crate::fluent_generated::builtin_macros_format_unused_arg); + let msg = diag.eagerly_translate(inline_fluent!( + "{$named -> + [true] named argument + *[false] argument + } never used" + )); diag.remove_arg("named"); diag.span_label(self.span, msg); } } #[derive(Diagnostic)] -#[diag(builtin_macros_format_unused_args)] +#[diag("multiple unused formatting arguments")] pub(crate) struct FormatUnusedArgs { #[primary_span] pub(crate) unused: Vec, - #[label] + #[label("multiple missing formatting specifiers")] pub(crate) fmt: Span, #[subdiagnostic] pub(crate) unused_labels: Vec, } #[derive(Diagnostic)] -#[diag(builtin_macros_format_pos_mismatch)] +#[diag( + "{$n} positional {$n -> + [one] argument + *[more] arguments + } in format string, but {$desc}" +)] pub(crate) struct FormatPositionalMismatch { #[primary_span] pub(crate) span: MultiSpan, @@ -728,13 +791,23 @@ pub(crate) struct FormatPositionalMismatch { } #[derive(Diagnostic)] -#[diag(builtin_macros_format_redundant_args)] +#[diag( + "redundant {$n -> + [one] argument + *[more] arguments + }" +)] pub(crate) struct FormatRedundantArgs { #[primary_span] pub(crate) span: MultiSpan, pub(crate) n: usize, - #[note] + #[note( + "{$n -> + [one] the formatting specifier is referencing the binding already + *[more] the formatting specifiers are referencing the bindings already + }" + )] pub(crate) note: MultiSpan, #[subdiagnostic] @@ -742,38 +815,38 @@ pub(crate) struct FormatRedundantArgs { } #[derive(Subdiagnostic)] -#[multipart_suggestion(builtin_macros_suggestion, applicability = "machine-applicable")] +#[multipart_suggestion("this can be removed", applicability = "machine-applicable")] pub(crate) struct FormatRedundantArgsSugg { #[suggestion_part(code = "")] pub(crate) spans: Vec, } #[derive(Diagnostic)] -#[diag(builtin_macros_test_case_non_item)] +#[diag("`#[test_case]` attribute is only allowed on items")] pub(crate) struct TestCaseNonItem { #[primary_span] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_test_bad_fn)] +#[diag("{$kind} functions cannot be used for tests")] pub(crate) struct TestBadFn { #[primary_span] pub(crate) span: Span, - #[label] + #[label("`{$kind}` because of this")] pub(crate) cause: Span, pub(crate) kind: &'static str, } #[derive(Diagnostic)] -#[diag(builtin_macros_asm_explicit_register_name)] +#[diag("explicit register arguments cannot have names")] pub(crate) struct AsmExplicitRegisterName { #[primary_span] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_asm_mutually_exclusive)] +#[diag("the `{$opt1}` and `{$opt2}` options are mutually exclusive")] pub(crate) struct AsmMutuallyExclusive { #[primary_span] pub(crate) spans: Vec, @@ -782,65 +855,65 @@ pub(crate) struct AsmMutuallyExclusive { } #[derive(Diagnostic)] -#[diag(builtin_macros_asm_pure_combine)] +#[diag("the `pure` option must be combined with either `nomem` or `readonly`")] pub(crate) struct AsmPureCombine { #[primary_span] pub(crate) spans: Vec, } #[derive(Diagnostic)] -#[diag(builtin_macros_asm_pure_no_output)] +#[diag("asm with the `pure` option must have at least one output")] pub(crate) struct AsmPureNoOutput { #[primary_span] pub(crate) spans: Vec, } #[derive(Diagnostic)] -#[diag(builtin_macros_asm_modifier_invalid)] +#[diag("asm template modifier must be a single character")] pub(crate) struct AsmModifierInvalid { #[primary_span] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_asm_attribute_not_supported)] +#[diag("this attribute is not supported on assembly")] pub(crate) struct AsmAttributeNotSupported { #[primary_span] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_asm_duplicate_arg)] +#[diag("duplicate argument named `{$name}`")] pub(crate) struct AsmDuplicateArg { #[primary_span] - #[label(builtin_macros_arg)] + #[label("duplicate argument")] pub(crate) span: Span, - #[label] + #[label("previously here")] pub(crate) prev: Span, pub(crate) name: Symbol, } #[derive(Diagnostic)] -#[diag(builtin_macros_asm_pos_after)] +#[diag("positional arguments cannot follow named arguments or explicit register arguments")] pub(crate) struct AsmPositionalAfter { #[primary_span] - #[label(builtin_macros_pos)] + #[label("positional argument")] pub(crate) span: Span, - #[label(builtin_macros_named)] + #[label("named argument")] pub(crate) named: Vec, - #[label(builtin_macros_explicit)] + #[label("explicit register argument")] pub(crate) explicit: Vec, } #[derive(Diagnostic)] -#[diag(builtin_macros_asm_noreturn)] +#[diag("asm outputs are not allowed with the `noreturn` option")] pub(crate) struct AsmNoReturn { #[primary_span] pub(crate) outputs_sp: Vec, } #[derive(Diagnostic)] -#[diag(builtin_macros_asm_no_matched_argument_name)] +#[diag("there is no argument named `{$name}`")] pub(crate) struct AsmNoMatchedArgumentName { pub(crate) name: String, #[primary_span] @@ -848,7 +921,7 @@ pub(crate) struct AsmNoMatchedArgumentName { } #[derive(Diagnostic)] -#[diag(builtin_macros_asm_mayunwind)] +#[diag("asm labels are not allowed with the `may_unwind` option")] pub(crate) struct AsmMayUnwind { #[primary_span] pub(crate) labels_sp: Vec, @@ -862,46 +935,55 @@ pub(crate) struct AsmClobberNoReg { impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for AsmClobberNoReg { fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> { // eager translation as `span_labels` takes `AsRef` - let lbl1 = dcx.eagerly_translate_to_string( - crate::fluent_generated::builtin_macros_asm_clobber_abi, - [].into_iter(), - ); - let lbl2 = dcx.eagerly_translate_to_string( - crate::fluent_generated::builtin_macros_asm_clobber_outputs, - [].into_iter(), - ); - Diag::new(dcx, level, crate::fluent_generated::builtin_macros_asm_clobber_no_reg) - .with_span(self.spans.clone()) - .with_span_labels(self.clobbers, &lbl1) - .with_span_labels(self.spans, &lbl2) + let lbl1 = dcx.eagerly_translate_to_string(inline_fluent!("clobber_abi"), [].into_iter()); + let lbl2 = + dcx.eagerly_translate_to_string(inline_fluent!("generic outputs"), [].into_iter()); + Diag::new( + dcx, + level, + inline_fluent!("asm with `clobber_abi` must specify explicit registers for outputs"), + ) + .with_span(self.spans.clone()) + .with_span_labels(self.clobbers, &lbl1) + .with_span_labels(self.spans, &lbl2) } } #[derive(Diagnostic)] -#[diag(builtin_macros_asm_opt_already_provided)] +#[diag("the `{$symbol}` option was already provided")] pub(crate) struct AsmOptAlreadyprovided { #[primary_span] - #[label] + #[label("this option was already provided")] pub(crate) span: Span, pub(crate) symbol: Symbol, - #[suggestion(code = "", applicability = "machine-applicable", style = "tool-only")] + #[suggestion( + "remove this option", + code = "", + applicability = "machine-applicable", + style = "tool-only" + )] pub(crate) span_with_comma: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_asm_unsupported_option)] +#[diag("the `{$symbol}` option cannot be used with `{$macro_name}!`")] pub(crate) struct AsmUnsupportedOption { #[primary_span] - #[label] + #[label("the `{$symbol}` option is not meaningful for global-scoped inline assembly")] pub(crate) span: Span, pub(crate) symbol: Symbol, - #[suggestion(code = "", applicability = "machine-applicable", style = "tool-only")] + #[suggestion( + "remove this option", + code = "", + applicability = "machine-applicable", + style = "tool-only" + )] pub(crate) span_with_comma: Span, pub(crate) macro_name: &'static str, } #[derive(Diagnostic)] -#[diag(builtin_macros_asm_unsupported_clobber_abi)] +#[diag("`clobber_abi` cannot be used with `{$macro_name}!`")] pub(crate) struct AsmUnsupportedClobberAbi { #[primary_span] pub(crate) spans: Vec, @@ -909,28 +991,28 @@ pub(crate) struct AsmUnsupportedClobberAbi { } #[derive(Diagnostic)] -#[diag(builtin_macros_test_runner_invalid)] +#[diag("`test_runner` argument must be a path")] pub(crate) struct TestRunnerInvalid { #[primary_span] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_test_runner_nargs)] +#[diag("`#![test_runner(..)]` accepts exactly 1 argument")] pub(crate) struct TestRunnerNargs { #[primary_span] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_expected_comma_in_list)] +#[diag("expected token: `,`")] pub(crate) struct ExpectedCommaInList { #[primary_span] pub span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_only_one_argument)] +#[diag("{$name} takes 1 argument")] pub(crate) struct OnlyOneArgument<'a> { #[primary_span] pub span: Span, @@ -938,7 +1020,7 @@ pub(crate) struct OnlyOneArgument<'a> { } #[derive(Diagnostic)] -#[diag(builtin_macros_takes_no_arguments)] +#[diag("{$name} takes no arguments")] pub(crate) struct TakesNoArguments<'a> { #[primary_span] pub span: Span, @@ -946,7 +1028,7 @@ pub(crate) struct TakesNoArguments<'a> { } #[derive(Diagnostic)] -#[diag(builtin_macros_proc_macro_attribute_only_usable_with_crate_type)] +#[diag("the `#[{$path}]` attribute is only usable with crates of the `proc-macro` crate type")] pub(crate) struct AttributeOnlyUsableWithCrateType<'a> { #[primary_span] pub span: Span, @@ -954,7 +1036,7 @@ pub(crate) struct AttributeOnlyUsableWithCrateType<'a> { } #[derive(Diagnostic)] -#[diag(builtin_macros_source_utils_expected_item)] +#[diag("expected item, found `{$token}`")] pub(crate) struct ExpectedItem<'a> { #[primary_span] pub span: Span, @@ -962,73 +1044,83 @@ pub(crate) struct ExpectedItem<'a> { } #[derive(Diagnostic)] -#[diag(builtin_macros_naked_functions_testing_attribute, code = E0736)] +#[diag("cannot use `#[unsafe(naked)]` with testing attributes", code = E0736)] pub(crate) struct NakedFunctionTestingAttribute { #[primary_span] - #[label(builtin_macros_naked_attribute)] + #[label("`#[unsafe(naked)]` is incompatible with testing attributes")] pub naked_span: Span, - #[label] + #[label("function marked with testing attribute here")] pub testing_span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_non_generic_pointee)] +#[diag("the `#[pointee]` attribute may only be used on generic parameters")] pub(crate) struct NonGenericPointee { #[primary_span] pub span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_expected_other)] +#[diag( + "expected operand, {$is_inline_asm -> + [false] options + *[true] clobber_abi, options + }, or additional template string" +)] pub(crate) struct AsmExpectedOther { #[primary_span] - #[label(builtin_macros_expected_other)] + #[label( + "expected operand, {$is_inline_asm -> + [false] options + *[true] clobber_abi, options + }, or additional template string" + )] pub(crate) span: Span, pub(crate) is_inline_asm: bool, } #[derive(Diagnostic)] -#[diag(builtin_macros_cfg_select_no_matches)] +#[diag("none of the predicates in this `cfg_select` evaluated to true")] pub(crate) struct CfgSelectNoMatches { #[primary_span] pub span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_cfg_select_unreachable)] +#[diag("unreachable predicate")] pub(crate) struct CfgSelectUnreachable { #[primary_span] - #[label(builtin_macros_label2)] + #[label("this predicate is never reached")] pub span: Span, - #[label] + #[label("always matches")] pub wildcard_span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_eii_declaration_expected_macro)] +#[diag("`#[eii_declaration(...)]` is only valid on macros")] pub(crate) struct EiiExternTargetExpectedMacro { #[primary_span] pub span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_eii_declaration_expected_list)] +#[diag("`#[eii_declaration(...)]` expects a list of one or two elements")] pub(crate) struct EiiExternTargetExpectedList { #[primary_span] pub span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_eii_declaration_expected_unsafe)] +#[diag("expected this argument to be \"unsafe\"")] pub(crate) struct EiiExternTargetExpectedUnsafe { #[primary_span] - #[note] + #[note("the second argument is optional")] pub span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_eii_shared_macro_expected_function)] +#[diag("`#[{$name}]` is only valid on functions")] pub(crate) struct EiiSharedMacroExpectedFunction { #[primary_span] pub span: Span, @@ -1036,27 +1128,27 @@ pub(crate) struct EiiSharedMacroExpectedFunction { } #[derive(Diagnostic)] -#[diag(builtin_macros_eii_shared_macro_in_statement_position)] +#[diag("`#[{$name}]` can only be used on functions inside a module")] pub(crate) struct EiiSharedMacroInStatementPosition { #[primary_span] pub span: Span, pub name: String, - #[label] + #[label("`#[{$name}]` is used on this item, which is part of another item's local scope")] pub item_span: Span, } #[derive(Diagnostic)] -#[diag(builtin_macros_eii_only_once)] +#[diag("`#[{$name}]` can only be specified once")] pub(crate) struct EiiOnlyOnce { #[primary_span] pub span: Span, - #[note] + #[note("specified again here")] pub first_span: Span, pub name: String, } #[derive(Diagnostic)] -#[diag(builtin_macros_eii_shared_macro_expected_max_one_argument)] +#[diag("`#[{$name}]` expected no arguments or a single argument: `#[{$name}(default)]`")] pub(crate) struct EiiMacroExpectedMaxOneArgument { #[primary_span] pub span: Span, diff --git a/compiler/rustc_builtin_macros/src/lib.rs b/compiler/rustc_builtin_macros/src/lib.rs index 120e3f849ff63..8ac15ceb4bbe1 100644 --- a/compiler/rustc_builtin_macros/src/lib.rs +++ b/compiler/rustc_builtin_macros/src/lib.rs @@ -57,8 +57,6 @@ pub mod standard_library_imports; pub mod test_harness; pub mod util; -rustc_fluent_macro::fluent_messages! { "../messages.ftl" } - pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) { let mut register = |name, kind| resolver.register_builtin_macro(name, kind); macro register_bang($($name:ident: $f:expr,)*) { diff --git a/compiler/rustc_codegen_llvm/src/va_arg.rs b/compiler/rustc_codegen_llvm/src/va_arg.rs index c7da2457ada5c..a491f30fd9161 100644 --- a/compiler/rustc_codegen_llvm/src/va_arg.rs +++ b/compiler/rustc_codegen_llvm/src/va_arg.rs @@ -131,7 +131,7 @@ fn emit_ptr_va_arg<'ll, 'tcx>( ); if indirect { let tmp_ret = bx.load(llty, addr, addr_align); - bx.load(bx.cx.layout_of(target_ty).llvm_type(bx.cx), tmp_ret, align.abi) + bx.load(layout.llvm_type(bx.cx), tmp_ret, align.abi) } else { bx.load(llty, addr, addr_align) } @@ -1007,6 +1007,8 @@ fn emit_xtensa_va_arg<'ll, 'tcx>( /// Determine the va_arg implementation to use. The LLVM va_arg instruction /// is lacking in some instances, so we should only use it as a fallback. +/// +/// pub(super) fn emit_va_arg<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, addr: OperandRef<'tcx, &'ll Value>, @@ -1015,6 +1017,10 @@ pub(super) fn emit_va_arg<'ll, 'tcx>( let layout = bx.cx.layout_of(target_ty); let target_ty_size = layout.layout.size().bytes(); + // Some ABIs have special behavior for zero-sized types. currently `VaArgSafe` is not + // implemented for any zero-sized types, so this assert should always hold. + assert!(!bx.layout_of(target_ty).is_zst()); + let target = &bx.cx.tcx.sess.target; match target.arch { Arch::X86 => emit_ptr_va_arg( @@ -1026,17 +1032,24 @@ pub(super) fn emit_va_arg<'ll, 'tcx>( if target.is_like_windows { AllowHigherAlign::No } else { AllowHigherAlign::Yes }, ForceRightAdjust::No, ), - Arch::AArch64 | Arch::Arm64EC if target.is_like_windows || target.is_like_darwin => { - emit_ptr_va_arg( - bx, - addr, - target_ty, - PassMode::Direct, - SlotSize::Bytes8, - if target.is_like_windows { AllowHigherAlign::No } else { AllowHigherAlign::Yes }, - ForceRightAdjust::No, - ) - } + Arch::Arm64EC => emit_ptr_va_arg( + bx, + addr, + target_ty, + PassMode::Direct, + SlotSize::Bytes8, + if target.is_like_windows { AllowHigherAlign::No } else { AllowHigherAlign::Yes }, + ForceRightAdjust::No, + ), + Arch::AArch64 if target.is_like_windows || target.is_like_darwin => emit_ptr_va_arg( + bx, + addr, + target_ty, + PassMode::Direct, + SlotSize::Bytes8, + if target.is_like_windows { AllowHigherAlign::No } else { AllowHigherAlign::Yes }, + ForceRightAdjust::No, + ), Arch::AArch64 => emit_aapcs_va_arg(bx, addr, target_ty), Arch::Arm => { // Types wider than 16 bytes are not currently supported. Clang has special logic for @@ -1064,7 +1077,16 @@ pub(super) fn emit_va_arg<'ll, 'tcx>( AllowHigherAlign::Yes, ForceRightAdjust::Yes, ), - Arch::LoongArch32 => emit_ptr_va_arg( + Arch::RiscV32 if target.abi == Abi::Ilp32e => { + // FIXME: clang manually adjusts the alignment for this ABI. It notes: + // + // > To be compatible with GCC's behaviors, we force arguments with + // > 2×XLEN-bit alignment and size at most 2×XLEN bits like `long long`, + // > `unsigned long long` and `double` to have 4-byte alignment. This + // > behavior may be changed when RV32E/ILP32E is ratified. + bug!("c-variadic calls with ilp32e use a custom ABI and are not currently implemented"); + } + Arch::RiscV32 | Arch::LoongArch32 => emit_ptr_va_arg( bx, addr, target_ty, @@ -1073,7 +1095,7 @@ pub(super) fn emit_va_arg<'ll, 'tcx>( AllowHigherAlign::Yes, ForceRightAdjust::No, ), - Arch::LoongArch64 => emit_ptr_va_arg( + Arch::RiscV64 | Arch::LoongArch64 => emit_ptr_va_arg( bx, addr, target_ty, @@ -1140,16 +1162,34 @@ pub(super) fn emit_va_arg<'ll, 'tcx>( // This includes `target.is_like_darwin`, which on x86_64 targets is like sysv64. Arch::X86_64 => emit_x86_64_sysv64_va_arg(bx, addr, target_ty), Arch::Xtensa => emit_xtensa_va_arg(bx, addr, target_ty), - Arch::Hexagon => { - if target.env == Env::Musl { - emit_hexagon_va_arg_musl(bx, addr, target_ty) - } else { - emit_hexagon_va_arg_bare_metal(bx, addr, target_ty) - } + Arch::Hexagon => match target.env { + Env::Musl => emit_hexagon_va_arg_musl(bx, addr, target_ty), + _ => emit_hexagon_va_arg_bare_metal(bx, addr, target_ty), + }, + Arch::Sparc64 => emit_ptr_va_arg( + bx, + addr, + target_ty, + if target_ty_size > 2 * 8 { PassMode::Indirect } else { PassMode::Direct }, + SlotSize::Bytes8, + AllowHigherAlign::Yes, + ForceRightAdjust::No, + ), + + Arch::Bpf => bug!("bpf does not support c-variadic functions"), + Arch::SpirV => bug!("spirv does not support c-variadic functions"), + + Arch::Mips | Arch::Mips32r6 | Arch::Mips64 | Arch::Mips64r6 => { + // FIXME: port MipsTargetLowering::lowerVAARG. + bx.va_arg(addr.immediate(), bx.cx.layout_of(target_ty).llvm_type(bx.cx)) + } + Arch::Sparc | Arch::Avr | Arch::M68k | Arch::Msp430 => { + // Clang uses the LLVM implementation for these architectures. + bx.va_arg(addr.immediate(), bx.cx.layout_of(target_ty).llvm_type(bx.cx)) + } + Arch::Other(_) => { + // For custom targets, use the LLVM va_arg instruction as a fallback. + bx.va_arg(addr.immediate(), bx.cx.layout_of(target_ty).llvm_type(bx.cx)) } - // For all other architecture/OS combinations fall back to using - // the LLVM va_arg instruction. - // https://llvm.org/docs/LangRef.html#va-arg-instruction - _ => bx.va_arg(addr.immediate(), bx.cx.layout_of(target_ty).llvm_type(bx.cx)), } } diff --git a/compiler/rustc_driver_impl/Cargo.toml b/compiler/rustc_driver_impl/Cargo.toml index c24a4ca532194..39e512be6820f 100644 --- a/compiler/rustc_driver_impl/Cargo.toml +++ b/compiler/rustc_driver_impl/Cargo.toml @@ -9,10 +9,8 @@ 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" } rustc_codegen_ssa = { path = "../rustc_codegen_ssa" } rustc_const_eval = { path = "../rustc_const_eval" } rustc_data_structures = { path = "../rustc_data_structures" } @@ -33,7 +31,6 @@ rustc_mir_build = { path = "../rustc_mir_build" } rustc_mir_transform = { path = "../rustc_mir_transform" } rustc_parse = { path = "../rustc_parse" } rustc_passes = { path = "../rustc_passes" } -rustc_pattern_analysis = { path = "../rustc_pattern_analysis" } rustc_public = { path = "../rustc_public", features = ["rustc_internal"] } rustc_resolve = { path = "../rustc_resolve" } rustc_session = { path = "../rustc_session" } diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs index 02298dbf82670..2e97b4fed245d 100644 --- a/compiler/rustc_driver_impl/src/lib.rs +++ b/compiler/rustc_driver_impl/src/lib.rs @@ -114,18 +114,13 @@ 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, - rustc_errors::DEFAULT_LOCALE_RESOURCE, rustc_hir_analysis::DEFAULT_LOCALE_RESOURCE, rustc_lint::DEFAULT_LOCALE_RESOURCE, - rustc_middle::DEFAULT_LOCALE_RESOURCE, rustc_mir_build::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE, rustc_passes::DEFAULT_LOCALE_RESOURCE, - rustc_pattern_analysis::DEFAULT_LOCALE_RESOURCE, rustc_trait_selection::DEFAULT_LOCALE_RESOURCE, // tidy-alphabetical-end ]; diff --git a/compiler/rustc_errors/Cargo.toml b/compiler/rustc_errors/Cargo.toml index 81eecca3199f4..a81fc496c8288 100644 --- a/compiler/rustc_errors/Cargo.toml +++ b/compiler/rustc_errors/Cargo.toml @@ -14,7 +14,6 @@ rustc_ast = { path = "../rustc_ast" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_error_codes = { path = "../rustc_error_codes" } rustc_error_messages = { path = "../rustc_error_messages" } -rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_hashes = { path = "../rustc_hashes" } rustc_index = { path = "../rustc_index" } rustc_lint_defs = { path = "../rustc_lint_defs" } diff --git a/compiler/rustc_errors/messages.ftl b/compiler/rustc_errors/messages.ftl deleted file mode 100644 index ad2e206260d57..0000000000000 --- a/compiler/rustc_errors/messages.ftl +++ /dev/null @@ -1,48 +0,0 @@ -errors_delayed_at_with_newline = - delayed at {$emitted_at} - {$note} - -errors_delayed_at_without_newline = - delayed at {$emitted_at} - {$note} - -errors_expected_lifetime_parameter = - expected lifetime {$count -> - [1] parameter - *[other] parameters - } - -errors_indicate_anonymous_lifetime = - indicate the anonymous {$count -> - [1] lifetime - *[other] lifetimes - } - -errors_invalid_flushed_delayed_diagnostic_level = - `flushed_delayed` got diagnostic with level {$level}, instead of the expected `DelayedBug` - -errors_target_inconsistent_architecture = - inconsistent target specification: "data-layout" claims architecture is {$dl}-endian, while "target-endian" is `{$target}` - -errors_target_inconsistent_pointer_width = - inconsistent target specification: "data-layout" claims pointers are {$pointer_size}-bit, while "target-pointer-width" is `{$target}` - -errors_target_invalid_address_space = - invalid address space `{$addr_space}` for `{$cause}` in "data-layout": {$err} - -errors_target_invalid_alignment = - invalid alignment for `{$cause}` in "data-layout": `{$align}` is {$err_kind -> - [not_power_of_two] not a power of 2 - [too_large] too large - *[other] {""} - } - -errors_target_invalid_bits = - invalid {$kind} `{$bit}` for `{$cause}` in "data-layout": {$err} - -errors_target_invalid_bits_size = {$err} - -errors_target_invalid_datalayout_pointer_spec = - unknown pointer specification `{$err}` in datalayout string - -errors_target_missing_alignment = - missing alignment for `{$cause}` in "data-layout" diff --git a/compiler/rustc_errors/src/diagnostic_impls.rs b/compiler/rustc_errors/src/diagnostic_impls.rs index 435d16a838065..c36afc6fc8897 100644 --- a/compiler/rustc_errors/src/diagnostic_impls.rs +++ b/compiler/rustc_errors/src/diagnostic_impls.rs @@ -7,8 +7,7 @@ use rustc_span::{Span, Symbol}; use crate::diagnostic::DiagLocation; use crate::{ - Diag, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level, Subdiagnostic, - fluent_generated as fluent, + Diag, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level, Subdiagnostic, inline_fluent, }; impl IntoDiagArg for DiagLocation { @@ -44,43 +43,48 @@ impl Diagnostic<'_, G> for TargetDataLayoutErrors<'_> { fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> { match self { TargetDataLayoutErrors::InvalidAddressSpace { addr_space, err, cause } => { - Diag::new(dcx, level, fluent::errors_target_invalid_address_space) + Diag::new(dcx, level, inline_fluent!("invalid address space `{$addr_space}` for `{$cause}` in \"data-layout\": {$err}")) .with_arg("addr_space", addr_space) .with_arg("cause", cause) .with_arg("err", err) } TargetDataLayoutErrors::InvalidBits { kind, bit, cause, err } => { - Diag::new(dcx, level, fluent::errors_target_invalid_bits) + Diag::new(dcx, level, inline_fluent!("invalid {$kind} `{$bit}` for `{$cause}` in \"data-layout\": {$err}")) .with_arg("kind", kind) .with_arg("bit", bit) .with_arg("cause", cause) .with_arg("err", err) } TargetDataLayoutErrors::MissingAlignment { cause } => { - Diag::new(dcx, level, fluent::errors_target_missing_alignment) + Diag::new(dcx, level, inline_fluent!("missing alignment for `{$cause}` in \"data-layout\"")) .with_arg("cause", cause) } TargetDataLayoutErrors::InvalidAlignment { cause, err } => { - Diag::new(dcx, level, fluent::errors_target_invalid_alignment) - .with_arg("cause", cause) - .with_arg("err_kind", err.diag_ident()) - .with_arg("align", err.align()) + Diag::new(dcx, level, inline_fluent!("invalid alignment for `{$cause}` in \"data-layout\": `{$align}` is {$err_kind -> + [not_power_of_two] not a power of 2 + [too_large] too large + *[other] {\"\"} + }")) + .with_arg("cause", cause) + .with_arg("err_kind", err.diag_ident()) + .with_arg("align", err.align()) } TargetDataLayoutErrors::InconsistentTargetArchitecture { dl, target } => { - Diag::new(dcx, level, fluent::errors_target_inconsistent_architecture) - .with_arg("dl", dl) - .with_arg("target", target) + Diag::new(dcx, level, inline_fluent!( + "inconsistent target specification: \"data-layout\" claims architecture is {$dl}-endian, while \"target-endian\" is `{$target}`" + )) + .with_arg("dl", dl).with_arg("target", target) } TargetDataLayoutErrors::InconsistentTargetPointerWidth { pointer_size, target } => { - Diag::new(dcx, level, fluent::errors_target_inconsistent_pointer_width) - .with_arg("pointer_size", pointer_size) - .with_arg("target", target) + Diag::new(dcx, level, inline_fluent!( + "inconsistent target specification: \"data-layout\" claims pointers are {$pointer_size}-bit, while \"target-pointer-width\" is `{$target}`" + )).with_arg("pointer_size", pointer_size).with_arg("target", target) } TargetDataLayoutErrors::InvalidBitsSize { err } => { - Diag::new(dcx, level, fluent::errors_target_invalid_bits_size).with_arg("err", err) + Diag::new(dcx, level, inline_fluent!("{$err}")).with_arg("err", err) } TargetDataLayoutErrors::UnknownPointerSpecification { err } => { - Diag::new(dcx, level, fluent::errors_target_invalid_datalayout_pointer_spec) + Diag::new(dcx, level, inline_fluent!("unknown pointer specification `{$err}` in datalayout string")) .with_arg("err", err) } } @@ -99,7 +103,12 @@ impl Subdiagnostic for SingleLabelManySpans { } #[derive(Subdiagnostic)] -#[label(errors_expected_lifetime_parameter)] +#[label( + "expected lifetime {$count -> + [1] parameter + *[other] parameters + }" +)] pub struct ExpectedLifetimeParameter { #[primary_span] pub span: Span, @@ -107,7 +116,14 @@ pub struct ExpectedLifetimeParameter { } #[derive(Subdiagnostic)] -#[suggestion(errors_indicate_anonymous_lifetime, code = "{suggestion}", style = "verbose")] +#[suggestion( + "indicate the anonymous {$count -> + [1] lifetime + *[other] lifetimes + }", + code = "{suggestion}", + style = "verbose" +)] pub struct IndicateAnonymousLifetime { #[primary_span] pub span: Span, diff --git a/compiler/rustc_errors/src/json/tests.rs b/compiler/rustc_errors/src/json/tests.rs index c1c9ecf7198f6..6f99930c433be 100644 --- a/compiler/rustc_errors/src/json/tests.rs +++ b/compiler/rustc_errors/src/json/tests.rs @@ -45,8 +45,7 @@ fn test_positions(code: &str, span: (u32, u32), expected_output: SpanTestData) { rustc_span::create_default_session_globals_then(|| { let sm = Arc::new(SourceMap::new(FilePathMapping::empty())); sm.new_source_file(filename(&sm, "test.rs"), code.to_owned()); - let translator = - Translator::with_fallback_bundle(vec![crate::DEFAULT_LOCALE_RESOURCE], false); + let translator = Translator::with_fallback_bundle(vec![], false); let output = Arc::new(Mutex::new(Vec::new())); let je = JsonEmitter::new( diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 68d825a4514a9..f89a2af71022c 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -92,8 +92,6 @@ pub mod translation; pub type PResult<'a, T> = Result>; -rustc_fluent_macro::fluent_messages! { "../messages.ftl" } - // `PResult` is used a lot. Make sure it doesn't unintentionally get bigger. #[cfg(target_pointer_width = "64")] rustc_data_structures::static_assert_size!(PResult<'_, ()>, 24); @@ -1531,7 +1529,9 @@ impl DiagCtxtInner { // the usual `Diag`/`DiagCtxt` level, so we must augment `bug` // in a lower-level fashion. bug.arg("level", bug.level); - let msg = crate::fluent_generated::errors_invalid_flushed_delayed_diagnostic_level; + let msg = inline_fluent!( + "`flushed_delayed` got diagnostic with level {$level}, instead of the expected `DelayedBug`" + ); let msg = self.eagerly_translate_for_subdiag(&bug, msg); // after the `arg` call bug.sub(Note, msg, bug.span.primary_span().unwrap().into()); } @@ -1573,10 +1573,13 @@ impl DelayedDiagInner { // lower-level fashion. let mut diag = self.inner; let msg = match self.note.status() { - BacktraceStatus::Captured => crate::fluent_generated::errors_delayed_at_with_newline, + BacktraceStatus::Captured => inline_fluent!( + "delayed at {$emitted_at} +{$note}" + ), // Avoid the needless newline when no backtrace has been captured, // the display impl should just be a single line. - _ => crate::fluent_generated::errors_delayed_at_without_newline, + _ => inline_fluent!("delayed at {$emitted_at} - {$note}"), }; diag.arg("emitted_at", diag.emitted_at.clone()); diag.arg("note", self.note); diff --git a/compiler/rustc_macros/src/query.rs b/compiler/rustc_macros/src/query.rs index 5d7204f7a30cb..adcf4e00241e9 100644 --- a/compiler/rustc_macros/src/query.rs +++ b/compiler/rustc_macros/src/query.rs @@ -429,7 +429,14 @@ pub(super) fn rustc_queries(input: TokenStream) -> TokenStream { $macro!(#feedable_queries); } } - pub mod descs { + + /// Functions that format a human-readable description of each query + /// and its key, as specified by the `desc` query modifier. + /// + /// (The leading `_` avoids collisions with actual query names when + /// expanded in `rustc_middle::queries`, and makes this macro-generated + /// module easier to search for.) + pub mod _description_fns { use super::*; #query_description_stream } diff --git a/compiler/rustc_middle/Cargo.toml b/compiler/rustc_middle/Cargo.toml index fbcce16cedca8..f9d5e7c027894 100644 --- a/compiler/rustc_middle/Cargo.toml +++ b/compiler/rustc_middle/Cargo.toml @@ -18,7 +18,6 @@ rustc_data_structures = { path = "../rustc_data_structures" } rustc_error_messages = { path = "../rustc_error_messages" } # Used for intra-doc links rustc_errors = { path = "../rustc_errors" } rustc_feature = { path = "../rustc_feature" } -rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_graphviz = { path = "../rustc_graphviz" } rustc_hashes = { path = "../rustc_hashes" } rustc_hir = { path = "../rustc_hir" } diff --git a/compiler/rustc_middle/messages.ftl b/compiler/rustc_middle/messages.ftl deleted file mode 100644 index b46f43841c8e8..0000000000000 --- a/compiler/rustc_middle/messages.ftl +++ /dev/null @@ -1,133 +0,0 @@ -middle_assert_async_resume_after_drop = `async fn` resumed after async drop - -middle_assert_async_resume_after_panic = `async fn` resumed after panicking - -middle_assert_async_resume_after_return = `async fn` resumed after completion - -middle_assert_coroutine_resume_after_drop = coroutine resumed after async drop - -middle_assert_coroutine_resume_after_panic = coroutine resumed after panicking - -middle_assert_coroutine_resume_after_return = coroutine resumed after completion - -middle_assert_divide_by_zero = - attempt to divide `{$val}` by zero - -middle_assert_gen_resume_after_drop = `gen` fn or block cannot be further iterated on after it async dropped - -middle_assert_gen_resume_after_panic = `gen` fn or block cannot be further iterated on after it panicked - -middle_assert_invalid_enum_construction = - trying to construct an enum from an invalid value `{$source}` - -middle_assert_misaligned_ptr_deref = - misaligned pointer dereference: address must be a multiple of {$required} but is {$found} - -middle_assert_null_ptr_deref = - null pointer dereference occurred - -middle_assert_op_overflow = - attempt to compute `{$left} {$op} {$right}`, which would overflow - -middle_assert_overflow_neg = - attempt to negate `{$val}`, which would overflow - -middle_assert_remainder_by_zero = - attempt to calculate the remainder of `{$val}` with a divisor of zero - -middle_assert_shl_overflow = - attempt to shift left by `{$val}`, which would overflow - -middle_assert_shr_overflow = - attempt to shift right by `{$val}`, which would overflow - -middle_autodiff_unsafe_inner_const_ref = reading from a `Duplicated` const {$ty} is unsafe - -middle_bounds_check = - index out of bounds: the length is {$len} but the index is {$index} - -middle_conflict_types = - this expression supplies two conflicting concrete types for the same opaque type - -middle_consider_type_length_limit = - consider adding a `#![type_length_limit="{$type_length}"]` attribute to your crate - -middle_const_eval_non_int = - constant evaluation of enum discriminant resulted in non-integer - -middle_const_not_used_in_type_alias = - const parameter `{$ct}` is part of concrete type but not used in parameter list for the `impl Trait` type alias - -middle_deprecated = use of deprecated {$kind} `{$path}`{$has_note -> - [true] : {$note} - *[other] {""} - } -middle_deprecated_in_future = use of {$kind} `{$path}` that will be deprecated in a future Rust version{$has_note -> - [true] : {$note} - *[other] {""} - } -middle_deprecated_in_version = use of {$kind} `{$path}` that will be deprecated in future version {$version}{$has_note -> - [true] : {$note} - *[other] {""} - } -middle_deprecated_suggestion = replace the use of the deprecated {$kind} - -middle_drop_check_overflow = - overflow while adding drop-check rules for `{$ty}` - .note = overflowed on `{$overflow_ty}` - -middle_erroneous_constant = erroneous constant encountered - -middle_failed_writing_file = - failed to write file {$path}: {$error}" - -# Note: We only mention patterns here since the error can only occur with references, and those -# are forbidden in const generics. -middle_invalid_const_in_valtree = constant {$global_const_id} cannot be used as pattern - .note = constants that reference mutable or external memory cannot be used as patterns - -middle_layout_cycle = - a cycle occurred during layout computation - -middle_layout_normalization_failure = - unable to determine layout for `{$ty}` because `{$failure_ty}` cannot be normalized - -middle_layout_references_error = - the type has an unknown layout - -middle_layout_simd_too_many = - the SIMD type `{$ty}` has more elements than the limit {$max_lanes} - -middle_layout_simd_zero_length = - the SIMD type `{$ty}` has zero elements - -middle_layout_size_overflow = - values of the type `{$ty}` are too big for the target architecture - -middle_layout_too_generic = the type `{$ty}` does not have a fixed layout - -middle_layout_unknown = - the type `{$ty}` has an unknown layout - -middle_max_num_nodes_in_valtree = maximum number of nodes exceeded in constant {$global_const_id} - -middle_opaque_hidden_type_mismatch = - concrete type differs from previous defining opaque type use - .label = expected `{$self_ty}`, got `{$other_ty}` - -middle_previous_use_here = - previous use here - -middle_recursion_limit_reached = - reached the recursion limit finding the struct tail for `{$ty}` - .help = consider increasing the recursion limit by adding a `#![recursion_limit = "{$suggested_limit}"]` - -middle_requires_lang_item = requires `{$name}` lang_item - -middle_strict_coherence_needs_negative_coherence = - to use `strict_coherence` on this trait, the `with_negative_coherence` feature must be enabled - .label = due to this attribute - -middle_type_length_limit = reached the type-length limit while instantiating `{$instance}` - -middle_unsupported_union = we don't support unions yet: '{$ty_name}' diff --git a/compiler/rustc_middle/src/error.rs b/compiler/rustc_middle/src/error.rs index 3ff9eea8cc4bf..a5d5978916eb9 100644 --- a/compiler/rustc_middle/src/error.rs +++ b/compiler/rustc_middle/src/error.rs @@ -9,8 +9,8 @@ use rustc_span::{Span, Symbol}; use crate::ty::{Instance, Ty}; #[derive(Diagnostic)] -#[diag(middle_drop_check_overflow, code = E0320)] -#[note] +#[diag("overflow while adding drop-check rules for `{$ty}`", code = E0320)] +#[note("overflowed on `{$overflow_ty}`")] pub(crate) struct DropCheckOverflow<'tcx> { #[primary_span] pub span: Span, @@ -19,33 +19,33 @@ pub(crate) struct DropCheckOverflow<'tcx> { } #[derive(Diagnostic)] -#[diag(middle_failed_writing_file)] +#[diag("failed to write file {$path}: {$error}\"")] pub(crate) struct FailedWritingFile<'a> { pub path: &'a Path, pub error: io::Error, } #[derive(Diagnostic)] -#[diag(middle_opaque_hidden_type_mismatch)] +#[diag("concrete type differs from previous defining opaque type use")] pub(crate) struct OpaqueHiddenTypeMismatch<'tcx> { pub self_ty: Ty<'tcx>, pub other_ty: Ty<'tcx>, #[primary_span] - #[label] + #[label("expected `{$self_ty}`, got `{$other_ty}`")] pub other_span: Span, #[subdiagnostic] pub sub: TypeMismatchReason, } #[derive(Diagnostic)] -#[diag(middle_unsupported_union)] +#[diag("we don't support unions yet: '{$ty_name}'")] pub struct UnsupportedUnion { pub ty_name: String, } // FIXME(autodiff): I should get used somewhere #[derive(Diagnostic)] -#[diag(middle_autodiff_unsafe_inner_const_ref)] +#[diag("reading from a `Duplicated` const {$ty} is unsafe")] pub struct AutodiffUnsafeInnerConstRef<'tcx> { #[primary_span] pub span: Span, @@ -54,12 +54,12 @@ pub struct AutodiffUnsafeInnerConstRef<'tcx> { #[derive(Subdiagnostic)] pub enum TypeMismatchReason { - #[label(middle_conflict_types)] + #[label("this expression supplies two conflicting concrete types for the same opaque type")] ConflictType { #[primary_span] span: Span, }, - #[note(middle_previous_use_here)] + #[note("previous use here")] PreviousUse { #[primary_span] span: Span, @@ -67,8 +67,10 @@ pub enum TypeMismatchReason { } #[derive(Diagnostic)] -#[diag(middle_recursion_limit_reached)] -#[help] +#[diag("reached the recursion limit finding the struct tail for `{$ty}`")] +#[help( + "consider increasing the recursion limit by adding a `#![recursion_limit = \"{$suggested_limit}\"]`" +)] pub(crate) struct RecursionLimitReached<'tcx> { #[primary_span] pub span: Span, @@ -77,23 +79,25 @@ pub(crate) struct RecursionLimitReached<'tcx> { } #[derive(Diagnostic)] -#[diag(middle_const_eval_non_int)] +#[diag("constant evaluation of enum discriminant resulted in non-integer")] pub(crate) struct ConstEvalNonIntError { #[primary_span] pub span: Span, } #[derive(Diagnostic)] -#[diag(middle_strict_coherence_needs_negative_coherence)] +#[diag( + "to use `strict_coherence` on this trait, the `with_negative_coherence` feature must be enabled" +)] pub(crate) struct StrictCoherenceNeedsNegativeCoherence { #[primary_span] pub span: Span, - #[label] + #[label("due to this attribute")] pub attr_span: Option, } #[derive(Diagnostic)] -#[diag(middle_requires_lang_item)] +#[diag("requires `{$name}` lang_item")] pub(crate) struct RequiresLangItem { #[primary_span] pub span: Span, @@ -101,7 +105,9 @@ pub(crate) struct RequiresLangItem { } #[derive(Diagnostic)] -#[diag(middle_const_not_used_in_type_alias)] +#[diag( + "const parameter `{$ct}` is part of concrete type but not used in parameter list for the `impl Trait` type alias" +)] pub(super) struct ConstNotUsedTraitAlias { pub ct: String, #[primary_span] @@ -133,41 +139,41 @@ impl fmt::Debug for CustomSubdiagnostic<'_> { #[derive(Diagnostic)] pub enum LayoutError<'tcx> { - #[diag(middle_layout_unknown)] + #[diag("the type `{$ty}` has an unknown layout")] Unknown { ty: Ty<'tcx> }, - #[diag(middle_layout_too_generic)] + #[diag("the type `{$ty}` does not have a fixed layout")] TooGeneric { ty: Ty<'tcx> }, - #[diag(middle_layout_size_overflow)] + #[diag("values of the type `{$ty}` are too big for the target architecture")] Overflow { ty: Ty<'tcx> }, - #[diag(middle_layout_simd_too_many)] + #[diag("the SIMD type `{$ty}` has more elements than the limit {$max_lanes}")] SimdTooManyLanes { ty: Ty<'tcx>, max_lanes: u64 }, - #[diag(middle_layout_simd_zero_length)] + #[diag("the SIMD type `{$ty}` has zero elements")] SimdZeroLength { ty: Ty<'tcx> }, - #[diag(middle_layout_normalization_failure)] + #[diag("unable to determine layout for `{$ty}` because `{$failure_ty}` cannot be normalized")] NormalizationFailure { ty: Ty<'tcx>, failure_ty: String }, - #[diag(middle_layout_cycle)] + #[diag("a cycle occurred during layout computation")] Cycle, - #[diag(middle_layout_references_error)] + #[diag("the type has an unknown layout")] ReferencesError, } #[derive(Diagnostic)] -#[diag(middle_erroneous_constant)] +#[diag("erroneous constant encountered")] pub(crate) struct ErroneousConstant { #[primary_span] pub span: Span, } #[derive(Diagnostic)] -#[diag(middle_type_length_limit)] -#[help(middle_consider_type_length_limit)] +#[diag("reached the type-length limit while instantiating `{$instance}`")] +#[help("consider adding a `#![type_length_limit=\"{$type_length}\"]` attribute to your crate")] pub(crate) struct TypeLengthLimit<'tcx> { #[primary_span] pub span: Span, @@ -176,7 +182,7 @@ pub(crate) struct TypeLengthLimit<'tcx> { } #[derive(Diagnostic)] -#[diag(middle_max_num_nodes_in_valtree)] +#[diag("maximum number of nodes exceeded in constant {$global_const_id}")] pub(crate) struct MaxNumNodesInValtree { #[primary_span] pub span: Span, @@ -184,8 +190,8 @@ pub(crate) struct MaxNumNodesInValtree { } #[derive(Diagnostic)] -#[diag(middle_invalid_const_in_valtree)] -#[note] +#[diag("constant {$global_const_id} cannot be used as pattern")] +#[note("constants that reference mutable or external memory cannot be used as patterns")] pub(crate) struct InvalidConstInValtree { #[primary_span] pub span: Span, diff --git a/compiler/rustc_middle/src/lib.rs b/compiler/rustc_middle/src/lib.rs index 7d1b775cc4bcd..5b32d4551a16f 100644 --- a/compiler/rustc_middle/src/lib.rs +++ b/compiler/rustc_middle/src/lib.rs @@ -91,5 +91,3 @@ pub mod dep_graph; // Allows macros to refer to this crate as `::rustc_middle` extern crate self as rustc_middle; - -rustc_fluent_macro::fluent_messages! { "../messages.ftl" } diff --git a/compiler/rustc_middle/src/middle/stability.rs b/compiler/rustc_middle/src/middle/stability.rs index fe2d4b9130ed5..fce0158aa5111 100644 --- a/compiler/rustc_middle/src/middle/stability.rs +++ b/compiler/rustc_middle/src/middle/stability.rs @@ -4,7 +4,7 @@ use std::num::NonZero; use rustc_ast::NodeId; -use rustc_errors::{Applicability, Diag, EmissionGuarantee, LintBuffer}; +use rustc_errors::{Applicability, Diag, EmissionGuarantee, LintBuffer, inline_fluent}; use rustc_feature::GateIssue; use rustc_hir::attrs::{DeprecatedSince, Deprecation}; use rustc_hir::def_id::{DefId, LocalDefId}; @@ -103,7 +103,7 @@ fn deprecation_lint(is_in_effect: bool) -> &'static Lint { #[derive(Subdiagnostic)] #[suggestion( - middle_deprecated_suggestion, + "replace the use of the deprecated {$kind}", code = "{suggestion}", style = "verbose", applicability = "machine-applicable" @@ -128,10 +128,19 @@ pub struct Deprecated { impl<'a, G: EmissionGuarantee> rustc_errors::LintDiagnostic<'a, G> for Deprecated { fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, G>) { diag.primary_message(match &self.since_kind { - DeprecatedSinceKind::InEffect => crate::fluent_generated::middle_deprecated, - DeprecatedSinceKind::InFuture => crate::fluent_generated::middle_deprecated_in_future, + DeprecatedSinceKind::InEffect => inline_fluent!("use of deprecated {$kind} `{$path}`{$has_note -> + [true] : {$note} + *[other] {\"\"} + }"), + DeprecatedSinceKind::InFuture => inline_fluent!("use of {$kind} `{$path}` that will be deprecated in a future Rust version{$has_note -> + [true] : {$note} + *[other] {\"\"} + }"), DeprecatedSinceKind::InVersion(_) => { - crate::fluent_generated::middle_deprecated_in_version + inline_fluent!("use of {$kind} `{$path}` that will be deprecated in future version {$version}{$has_note -> + [true] : {$note} + *[other] {\"\"} + }") } }); diag.arg("kind", self.kind); diff --git a/compiler/rustc_middle/src/mir/terminator.rs b/compiler/rustc_middle/src/mir/terminator.rs index cd447d4ed992b..e212dd43fa7d9 100644 --- a/compiler/rustc_middle/src/mir/terminator.rs +++ b/compiler/rustc_middle/src/mir/terminator.rs @@ -336,18 +336,26 @@ impl AssertKind { pub fn diagnostic_message(&self) -> DiagMessage { use AssertKind::*; - use crate::fluent_generated::*; - match self { - BoundsCheck { .. } => middle_bounds_check, - Overflow(BinOp::Shl, _, _) => middle_assert_shl_overflow, - Overflow(BinOp::Shr, _, _) => middle_assert_shr_overflow, - Overflow(_, _, _) => middle_assert_op_overflow, - OverflowNeg(_) => middle_assert_overflow_neg, - DivisionByZero(_) => middle_assert_divide_by_zero, - RemainderByZero(_) => middle_assert_remainder_by_zero, + BoundsCheck { .. } => inline_fluent!( + "index out of bounds: the length is {$len} but the index is {$index}" + ), + Overflow(BinOp::Shl, _, _) => { + inline_fluent!("attempt to shift left by `{$val}`, which would overflow") + } + Overflow(BinOp::Shr, _, _) => { + inline_fluent!("attempt to shift right by `{$val}`, which would overflow") + } + Overflow(_, _, _) => { + inline_fluent!("attempt to compute `{$left} {$op} {$right}`, which would overflow") + } + OverflowNeg(_) => inline_fluent!("attempt to negate `{$val}`, which would overflow"), + DivisionByZero(_) => inline_fluent!("attempt to divide `{$val}` by zero"), + RemainderByZero(_) => inline_fluent!( + "attempt to calculate the remainder of `{$val}` with a divisor of zero" + ), ResumedAfterReturn(CoroutineKind::Desugared(CoroutineDesugaring::Async, _)) => { - middle_assert_async_resume_after_return + inline_fluent!("`async fn` resumed after completion") } ResumedAfterReturn(CoroutineKind::Desugared(CoroutineDesugaring::AsyncGen, _)) => { todo!() @@ -356,36 +364,42 @@ impl AssertKind { bug!("gen blocks can be resumed after they return and will keep returning `None`") } ResumedAfterReturn(CoroutineKind::Coroutine(_)) => { - middle_assert_coroutine_resume_after_return + inline_fluent!("coroutine resumed after completion") } ResumedAfterPanic(CoroutineKind::Desugared(CoroutineDesugaring::Async, _)) => { - middle_assert_async_resume_after_panic + inline_fluent!("`async fn` resumed after panicking") } ResumedAfterPanic(CoroutineKind::Desugared(CoroutineDesugaring::AsyncGen, _)) => { todo!() } ResumedAfterPanic(CoroutineKind::Desugared(CoroutineDesugaring::Gen, _)) => { - middle_assert_gen_resume_after_panic + inline_fluent!("`gen` fn or block cannot be further iterated on after it panicked") } ResumedAfterPanic(CoroutineKind::Coroutine(_)) => { - middle_assert_coroutine_resume_after_panic + inline_fluent!("coroutine resumed after panicking") + } + NullPointerDereference => inline_fluent!("null pointer dereference occurred"), + InvalidEnumConstruction(_) => { + inline_fluent!("trying to construct an enum from an invalid value `{$source}`") } - NullPointerDereference => middle_assert_null_ptr_deref, - InvalidEnumConstruction(_) => middle_assert_invalid_enum_construction, ResumedAfterDrop(CoroutineKind::Desugared(CoroutineDesugaring::Async, _)) => { - middle_assert_async_resume_after_drop + inline_fluent!("`async fn` resumed after async drop") } ResumedAfterDrop(CoroutineKind::Desugared(CoroutineDesugaring::AsyncGen, _)) => { todo!() } ResumedAfterDrop(CoroutineKind::Desugared(CoroutineDesugaring::Gen, _)) => { - middle_assert_gen_resume_after_drop + inline_fluent!( + "`gen` fn or block cannot be further iterated on after it async dropped" + ) } ResumedAfterDrop(CoroutineKind::Coroutine(_)) => { - middle_assert_coroutine_resume_after_drop + inline_fluent!("coroutine resumed after async drop") } - MisalignedPointerDereference { .. } => middle_assert_misaligned_ptr_deref, + MisalignedPointerDereference { .. } => inline_fluent!( + "misaligned pointer dereference: address must be a multiple of {$required} but is {$found}" + ), } } @@ -498,6 +512,7 @@ impl<'tcx> TerminatorKind<'tcx> { } pub use helper::*; +use rustc_errors::inline_fluent; mod helper { use super::*; diff --git a/compiler/rustc_middle/src/query/plumbing.rs b/compiler/rustc_middle/src/query/plumbing.rs index b8f1fe9ec20b0..abb02caef25d8 100644 --- a/compiler/rustc_middle/src/query/plumbing.rs +++ b/compiler/rustc_middle/src/query/plumbing.rs @@ -32,7 +32,8 @@ pub type IsLoadableFromDiskFn<'tcx, Key> = /// Stores function pointers and other metadata for a particular query. /// -/// Used indirectly by query plumbing in `rustc_query_system`, via a trait. +/// Used indirectly by query plumbing in `rustc_query_system` via a trait, +/// and also used directly by query plumbing in `rustc_query_impl`. pub struct QueryVTable<'tcx, C: QueryCache> { pub name: &'static str, pub eval_always: bool, @@ -52,6 +53,12 @@ pub struct QueryVTable<'tcx, C: QueryCache> { pub value_from_cycle_error: fn(tcx: TyCtxt<'tcx>, cycle_error: &CycleError, guar: ErrorGuaranteed) -> C::Value, pub format_value: fn(&C::Value) -> String, + + /// Formats a human-readable description of this query and its key, as + /// specified by the `desc` query modifier. + /// + /// Used when reporting query cycle errors and similar problems. + pub description_fn: fn(TyCtxt<'tcx>, C::Key) -> String, } pub struct QuerySystemFns { diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 14ebcc968f7af..d3b4654a8d799 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -9,6 +9,7 @@ use rustc_abi::{ use rustc_error_messages::DiagMessage; use rustc_errors::{ Diag, DiagArgValue, DiagCtxtHandle, Diagnostic, EmissionGuarantee, IntoDiagArg, Level, + inline_fluent, }; use rustc_hir::LangItem; use rustc_hir::def_id::DefId; @@ -268,18 +269,25 @@ impl<'tcx> LayoutError<'tcx> { pub fn diagnostic_message(&self) -> DiagMessage { use LayoutError::*; - use crate::fluent_generated::*; match self { - Unknown(_) => middle_layout_unknown, - SizeOverflow(_) => middle_layout_size_overflow, + Unknown(_) => inline_fluent!("the type `{$ty}` has an unknown layout"), + SizeOverflow(_) => { + inline_fluent!("values of the type `{$ty}` are too big for the target architecture") + } InvalidSimd { kind: SimdLayoutError::TooManyLanes(_), .. } => { - middle_layout_simd_too_many + inline_fluent!( + "the SIMD type `{$ty}` has more elements than the limit {$max_lanes}" + ) } - InvalidSimd { kind: SimdLayoutError::ZeroLength, .. } => middle_layout_simd_zero_length, - TooGeneric(_) => middle_layout_too_generic, - NormalizationFailure(_, _) => middle_layout_normalization_failure, - Cycle(_) => middle_layout_cycle, - ReferencesError(_) => middle_layout_references_error, + InvalidSimd { kind: SimdLayoutError::ZeroLength, .. } => { + inline_fluent!("the SIMD type `{$ty}` has zero elements") + } + TooGeneric(_) => inline_fluent!("the type `{$ty}` does not have a fixed layout"), + NormalizationFailure(_, _) => inline_fluent!( + "unable to determine layout for `{$ty}` because `{$failure_ty}` cannot be normalized" + ), + Cycle(_) => inline_fluent!("a cycle occurred during layout computation"), + ReferencesError(_) => inline_fluent!("the type has an unknown layout"), } } diff --git a/compiler/rustc_pattern_analysis/Cargo.toml b/compiler/rustc_pattern_analysis/Cargo.toml index a59f7bbeb9e5e..a644c6a7c01a2 100644 --- a/compiler/rustc_pattern_analysis/Cargo.toml +++ b/compiler/rustc_pattern_analysis/Cargo.toml @@ -11,7 +11,6 @@ rustc_apfloat = "0.2.0" rustc_arena = { path = "../rustc_arena", optional = true } rustc_data_structures = { path = "../rustc_data_structures", optional = true } rustc_errors = { path = "../rustc_errors", optional = true } -rustc_fluent_macro = { path = "../rustc_fluent_macro", optional = true } rustc_hir = { path = "../rustc_hir", optional = true } rustc_index = { path = "../rustc_index", default-features = false } rustc_macros = { path = "../rustc_macros", optional = true } @@ -36,7 +35,6 @@ rustc = [ "dep:rustc_arena", "dep:rustc_data_structures", "dep:rustc_errors", - "dep:rustc_fluent_macro", "dep:rustc_hir", "dep:rustc_macros", "dep:rustc_middle", diff --git a/compiler/rustc_pattern_analysis/messages.ftl b/compiler/rustc_pattern_analysis/messages.ftl deleted file mode 100644 index d3a3107f8e898..0000000000000 --- a/compiler/rustc_pattern_analysis/messages.ftl +++ /dev/null @@ -1,31 +0,0 @@ -pattern_analysis_excluside_range_missing_gap = multiple ranges are one apart - .label = this range doesn't match `{$gap}` because `..` is an exclusive range - .suggestion = use an inclusive range instead - -pattern_analysis_excluside_range_missing_max = exclusive range missing `{$max}` - .label = this range doesn't match `{$max}` because `..` is an exclusive range - .suggestion = use an inclusive range instead - -pattern_analysis_mixed_deref_pattern_constructors = mix of deref patterns and normal constructors - .deref_pattern_label = matches on the result of dereferencing `{$smart_pointer_ty}` - .normal_constructor_label = matches directly on `{$smart_pointer_ty}` - -pattern_analysis_non_exhaustive_omitted_pattern = some variants are not matched explicitly - .help = ensure that all variants are matched explicitly by adding the suggested match arms - .note = the matched value is of type `{$scrut_ty}` and the `non_exhaustive_omitted_patterns` attribute was found - -pattern_analysis_non_exhaustive_omitted_pattern_lint_on_arm = the lint level must be set on the whole match - .help = it no longer has any effect to set the lint level on an individual match arm - .label = remove this attribute - .suggestion = set the lint level on the whole match - -pattern_analysis_overlapping_range_endpoints = multiple patterns overlap on their endpoints - .label = ... with this range - .note = you likely meant to write mutually exclusive ranges - -pattern_analysis_uncovered = {$count -> - [1] pattern `{$witness_1}` - [2] patterns `{$witness_1}` and `{$witness_2}` - [3] patterns `{$witness_1}`, `{$witness_2}` and `{$witness_3}` - *[other] patterns `{$witness_1}`, `{$witness_2}`, `{$witness_3}` and {$remainder} more - } not covered diff --git a/compiler/rustc_pattern_analysis/src/errors.rs b/compiler/rustc_pattern_analysis/src/errors.rs index 156ba9737673e..64d4ff4220430 100644 --- a/compiler/rustc_pattern_analysis/src/errors.rs +++ b/compiler/rustc_pattern_analysis/src/errors.rs @@ -6,7 +6,14 @@ use rustc_span::Span; use crate::rustc::{RustcPatCtxt, WitnessPat}; #[derive(Subdiagnostic)] -#[label(pattern_analysis_uncovered)] +#[label( + "{$count -> + [1] pattern `{$witness_1}` + [2] patterns `{$witness_1}` and `{$witness_2}` + [3] patterns `{$witness_1}`, `{$witness_2}` and `{$witness_3}` + *[other] patterns `{$witness_1}`, `{$witness_2}`, `{$witness_3}` and {$remainder} more + } not covered" +)] pub struct Uncovered { #[primary_span] span: Span, @@ -40,10 +47,10 @@ impl Uncovered { } #[derive(LintDiagnostic)] -#[diag(pattern_analysis_overlapping_range_endpoints)] -#[note] +#[diag("multiple patterns overlap on their endpoints")] +#[note("you likely meant to write mutually exclusive ranges")] pub struct OverlappingRangeEndpoints { - #[label] + #[label("... with this range")] pub range: Span, #[subdiagnostic] pub overlap: Vec, @@ -66,10 +73,14 @@ impl Subdiagnostic for Overlap { } #[derive(LintDiagnostic)] -#[diag(pattern_analysis_excluside_range_missing_max)] +#[diag("exclusive range missing `{$max}`")] pub struct ExclusiveRangeMissingMax { - #[label] - #[suggestion(code = "{suggestion}", applicability = "maybe-incorrect")] + #[label("this range doesn't match `{$max}` because `..` is an exclusive range")] + #[suggestion( + "use an inclusive range instead", + code = "{suggestion}", + applicability = "maybe-incorrect" + )] /// This is an exclusive range that looks like `lo..max` (i.e. doesn't match `max`). pub first_range: Span, /// Suggest `lo..=max` instead. @@ -78,10 +89,14 @@ pub struct ExclusiveRangeMissingMax { } #[derive(LintDiagnostic)] -#[diag(pattern_analysis_excluside_range_missing_gap)] +#[diag("multiple ranges are one apart")] pub struct ExclusiveRangeMissingGap { - #[label] - #[suggestion(code = "{suggestion}", applicability = "maybe-incorrect")] + #[label("this range doesn't match `{$gap}` because `..` is an exclusive range")] + #[suggestion( + "use an inclusive range instead", + code = "{suggestion}", + applicability = "maybe-incorrect" + )] /// This is an exclusive range that looks like `lo..gap` (i.e. doesn't match `gap`). pub first_range: Span, pub gap: String, // a printed pattern @@ -113,9 +128,11 @@ impl Subdiagnostic for GappedRange { } #[derive(LintDiagnostic)] -#[diag(pattern_analysis_non_exhaustive_omitted_pattern)] -#[help] -#[note] +#[diag("some variants are not matched explicitly")] +#[help("ensure that all variants are matched explicitly by adding the suggested match arms")] +#[note( + "the matched value is of type `{$scrut_ty}` and the `non_exhaustive_omitted_patterns` attribute was found" +)] pub(crate) struct NonExhaustiveOmittedPattern<'tcx> { pub scrut_ty: Ty<'tcx>, #[subdiagnostic] @@ -123,25 +140,29 @@ pub(crate) struct NonExhaustiveOmittedPattern<'tcx> { } #[derive(LintDiagnostic)] -#[diag(pattern_analysis_non_exhaustive_omitted_pattern_lint_on_arm)] -#[help] +#[diag("the lint level must be set on the whole match")] +#[help("it no longer has any effect to set the lint level on an individual match arm")] pub(crate) struct NonExhaustiveOmittedPatternLintOnArm { - #[label] + #[label("remove this attribute")] pub lint_span: Span, - #[suggestion(code = "#[{lint_level}({lint_name})]\n", applicability = "maybe-incorrect")] + #[suggestion( + "set the lint level on the whole match", + code = "#[{lint_level}({lint_name})]\n", + applicability = "maybe-incorrect" + )] pub suggest_lint_on_match: Option, pub lint_level: &'static str, pub lint_name: &'static str, } #[derive(Diagnostic)] -#[diag(pattern_analysis_mixed_deref_pattern_constructors)] +#[diag("mix of deref patterns and normal constructors")] pub(crate) struct MixedDerefPatternConstructors<'tcx> { #[primary_span] pub spans: Vec, pub smart_pointer_ty: Ty<'tcx>, - #[label(pattern_analysis_deref_pattern_label)] + #[label("matches on the result of dereferencing `{$smart_pointer_ty}`")] pub deref_pattern_label: Span, - #[label(pattern_analysis_normal_constructor_label)] + #[label("matches directly on `{$smart_pointer_ty}`")] pub normal_constructor_label: Span, } diff --git a/compiler/rustc_pattern_analysis/src/lib.rs b/compiler/rustc_pattern_analysis/src/lib.rs index 2652840863776..9ffc237c63290 100644 --- a/compiler/rustc_pattern_analysis/src/lib.rs +++ b/compiler/rustc_pattern_analysis/src/lib.rs @@ -19,9 +19,6 @@ pub mod pat_column; pub mod rustc; pub mod usefulness; -#[cfg(feature = "rustc")] -rustc_fluent_macro::fluent_messages! { "../messages.ftl" } - use std::fmt; pub use rustc_index::{Idx, IndexVec}; // re-exported to avoid rustc_index version issues diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index 296b2ae5404b9..a71acae3096e5 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -9,17 +9,18 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::sync::{DynSend, DynSync}; use rustc_data_structures::unord::UnordMap; use rustc_hashes::Hash64; +use rustc_hir::def_id::DefId; use rustc_hir::limit::Limit; use rustc_index::Idx; use rustc_middle::bug; use rustc_middle::dep_graph::{ - self, DepContext, DepKind, DepKindVTable, DepNode, DepNodeIndex, SerializedDepNodeIndex, - dep_kinds, + self, DepContext, DepKindVTable, DepNode, DepNodeIndex, SerializedDepNodeIndex, dep_kinds, }; use rustc_middle::query::Key; use rustc_middle::query::on_disk_cache::{ AbsoluteBytePos, CacheDecoder, CacheEncoder, EncodedDepNodeIndex, }; +use rustc_middle::query::plumbing::QueryVTable; use rustc_middle::ty::codec::TyEncoder; use rustc_middle::ty::print::with_reduced_queries; use rustc_middle::ty::tls::{self, ImplicitCtxt}; @@ -312,15 +313,14 @@ macro_rules! should_ever_cache_on_disk { }; } -fn mk_query_stack_frame_extra<'tcx, K: Key + Copy + 'tcx>( - (tcx, key, kind, name, do_describe): ( - TyCtxt<'tcx>, - K, - DepKind, - &'static str, - fn(TyCtxt<'tcx>, K) -> String, - ), -) -> QueryStackFrameExtra { +/// The deferred part of a deferred query stack frame. +fn mk_query_stack_frame_extra<'tcx, Cache>( + (tcx, vtable, key): (TyCtxt<'tcx>, &'tcx QueryVTable<'tcx, Cache>, Cache::Key), +) -> QueryStackFrameExtra +where + Cache: QueryCache, + Cache::Key: Key, +{ let def_id = key.key_as_def_id(); // If reduced queries are requested, we may be printing a query stack due @@ -328,13 +328,13 @@ fn mk_query_stack_frame_extra<'tcx, K: Key + Copy + 'tcx>( let reduce_queries = with_reduced_queries(); // Avoid calling queries while formatting the description - let description = ty::print::with_no_queries!(do_describe(tcx, key)); + let description = ty::print::with_no_queries!((vtable.description_fn)(tcx, key)); let description = if tcx.sess.verbose_internals() { - format!("{description} [{name:?}]") + format!("{description} [{name:?}]", name = vtable.name) } else { description }; - let span = if kind == dep_graph::dep_kinds::def_span || reduce_queries { + let span = if vtable.dep_kind == dep_graph::dep_kinds::def_span || reduce_queries { // The `def_span` query is used to calculate `default_span`, // so exit to avoid infinite recursion. None @@ -342,7 +342,7 @@ fn mk_query_stack_frame_extra<'tcx, K: Key + Copy + 'tcx>( Some(key.default_span(tcx)) }; - let def_kind = if kind == dep_graph::dep_kinds::def_kind || reduce_queries { + let def_kind = if vtable.dep_kind == dep_graph::dep_kinds::def_kind || reduce_queries { // Try to avoid infinite recursion. None } else { @@ -351,17 +351,16 @@ fn mk_query_stack_frame_extra<'tcx, K: Key + Copy + 'tcx>( QueryStackFrameExtra::new(description, span, def_kind) } -pub(crate) fn create_query_frame< - 'tcx, - K: Copy + DynSend + DynSync + Key + for<'a> HashStable> + 'tcx, ->( +pub(crate) fn create_deferred_query_stack_frame<'tcx, Cache>( tcx: TyCtxt<'tcx>, - do_describe: fn(TyCtxt<'tcx>, K) -> String, - key: K, - kind: DepKind, - name: &'static str, -) -> QueryStackFrame> { - let def_id = key.key_as_def_id(); + vtable: &'tcx QueryVTable<'tcx, Cache>, + key: Cache::Key, +) -> QueryStackFrame> +where + Cache: QueryCache, + Cache::Key: Key + DynSend + DynSync + for<'a> HashStable> + 'tcx, +{ + let kind = vtable.dep_kind; let hash = tcx.with_stable_hashing_context(|mut hcx| { let mut hasher = StableHasher::new(); @@ -369,11 +368,11 @@ pub(crate) fn create_query_frame< key.hash_stable(&mut hcx, &mut hasher); hasher.finish::() }); - let def_id_for_ty_in_cycle = key.def_id_for_ty_in_cycle(); - let info = - QueryStackDeferred::new((tcx, key, kind, name, do_describe), mk_query_stack_frame_extra); + let def_id: Option = key.key_as_def_id(); + let def_id_for_ty_in_cycle: Option = key.def_id_for_ty_in_cycle(); + let info = QueryStackDeferred::new((tcx, vtable, key), mk_query_stack_frame_extra); QueryStackFrame::new(info, kind, hash, def_id, def_id_for_ty_in_cycle) } @@ -697,6 +696,7 @@ macro_rules! define_queries { }, hash_result: hash_result!([$($modifiers)*][queries::$name::Value<'tcx>]), format_value: |value| format!("{:?}", erase::restore_val::>(*value)), + description_fn: $crate::queries::_description_fns::$name, } } @@ -742,10 +742,9 @@ macro_rules! define_queries { qmap: &mut QueryMap<'tcx>, require_complete: bool, ) -> Option<()> { - let make_frame = |tcx, key| { - let kind = rustc_middle::dep_graph::dep_kinds::$name; - let name = stringify!($name); - $crate::plumbing::create_query_frame(tcx, queries::descs::$name, key, kind, name) + let make_frame = |tcx: TyCtxt<'tcx>, key| { + let vtable = &tcx.query_system.query_vtables.$name; + $crate::plumbing::create_deferred_query_stack_frame(tcx, vtable, key) }; // Call `gather_active_jobs_inner` to do the actual work. diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 26efa03c898c7..298b250881515 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -1432,8 +1432,7 @@ impl EarlyDiagCtxt { fn mk_emitter(output: ErrorOutputType) -> Box { // FIXME(#100717): early errors aren't translated at the moment, so this is fine, but it will // need to reference every crate that might emit an early error for translation to work. - let translator = - Translator::with_fallback_bundle(vec![rustc_errors::DEFAULT_LOCALE_RESOURCE], false); + let translator = Translator::with_fallback_bundle(vec![], false); let emitter: Box = match output { config::ErrorOutputType::HumanReadable { kind, color_config } => match kind { HumanReadableErrorType { short, unicode } => Box::new( diff --git a/library/std/src/sys/pal/unix/mod.rs b/library/std/src/sys/pal/unix/mod.rs index 6127bb98f80ef..0fbf37fda7fbf 100644 --- a/library/std/src/sys/pal/unix/mod.rs +++ b/library/std/src/sys/pal/unix/mod.rs @@ -169,15 +169,15 @@ pub unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) { pub const SIG_DFL: u8 = 3; } - let (sigpipe_attr_specified, handler) = match sigpipe { + let (on_broken_pipe_used, handler) = match sigpipe { sigpipe::DEFAULT => (false, Some(libc::SIG_IGN)), sigpipe::INHERIT => (true, None), sigpipe::SIG_IGN => (true, Some(libc::SIG_IGN)), sigpipe::SIG_DFL => (true, Some(libc::SIG_DFL)), _ => unreachable!(), }; - if sigpipe_attr_specified { - ON_BROKEN_PIPE_FLAG_USED.store(true, crate::sync::atomic::Ordering::Relaxed); + if on_broken_pipe_used { + ON_BROKEN_PIPE_USED.store(true, crate::sync::atomic::Ordering::Relaxed); } if let Some(handler) = handler { rtassert!(signal(libc::SIGPIPE, handler) != libc::SIG_ERR); @@ -199,7 +199,7 @@ pub unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) { target_os = "vxworks", target_os = "vita", )))] -static ON_BROKEN_PIPE_FLAG_USED: crate::sync::atomic::Atomic = +static ON_BROKEN_PIPE_USED: crate::sync::atomic::Atomic = crate::sync::atomic::AtomicBool::new(false); #[cfg(not(any( @@ -211,8 +211,8 @@ static ON_BROKEN_PIPE_FLAG_USED: crate::sync::atomic::Atomic = target_os = "vita", target_os = "nuttx", )))] -pub(crate) fn on_broken_pipe_flag_used() -> bool { - ON_BROKEN_PIPE_FLAG_USED.load(crate::sync::atomic::Ordering::Relaxed) +pub(crate) fn on_broken_pipe_used() -> bool { + ON_BROKEN_PIPE_USED.load(crate::sync::atomic::Ordering::Relaxed) } // SAFETY: must be called only once during runtime cleanup. diff --git a/library/std/src/sys/process/unix/unix.rs b/library/std/src/sys/process/unix/unix.rs index 62d6e0581e6c8..82ff94fb1e030 100644 --- a/library/std/src/sys/process/unix/unix.rs +++ b/library/std/src/sys/process/unix/unix.rs @@ -356,7 +356,7 @@ impl Command { // If -Zon-broken-pipe is not used, reset SIGPIPE to SIG_DFL for backward compatibility. // // -Zon-broken-pipe is an opportunity to change the default here. - if !crate::sys::pal::on_broken_pipe_flag_used() { + if !crate::sys::pal::on_broken_pipe_used() { #[cfg(target_os = "android")] // see issue #88585 { let mut action: libc::sigaction = mem::zeroed(); @@ -455,7 +455,7 @@ impl Command { use core::sync::atomic::{Atomic, AtomicU8, Ordering}; use crate::mem::MaybeUninit; - use crate::sys::{self, cvt_nz, on_broken_pipe_flag_used}; + use crate::sys::{self, cvt_nz, on_broken_pipe_used}; if self.get_gid().is_some() || self.get_uid().is_some() @@ -731,7 +731,7 @@ impl Command { // If -Zon-broken-pipe is not used, reset SIGPIPE to SIG_DFL for backward compatibility. // // -Zon-broken-pipe is an opportunity to change the default here. - if !on_broken_pipe_flag_used() { + if !on_broken_pipe_used() { let mut default_set = MaybeUninit::::uninit(); cvt(sigemptyset(default_set.as_mut_ptr()))?; cvt(sigaddset(default_set.as_mut_ptr(), libc::SIGPIPE))?; diff --git a/src/ci/docker/run.sh b/src/ci/docker/run.sh index 691b8b8deb81a..6c35105225c01 100755 --- a/src/ci/docker/run.sh +++ b/src/ci/docker/run.sh @@ -359,11 +359,11 @@ docker \ rust-ci \ "${command[@]}" -if isCI; then - cat $objdir/${SUMMARY_FILE} >> "${GITHUB_STEP_SUMMARY}" -fi - if [ -f /.dockerenv ]; then rm -rf $objdir docker cp checkout:/checkout/obj $objdir fi + +if isCI; then + cat $objdir/${SUMMARY_FILE} >> "${GITHUB_STEP_SUMMARY}" +fi