diff --git a/Cargo.lock b/Cargo.lock index 9c98946c9d390..07afb4a277794 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3600,7 +3600,6 @@ dependencies = [ "rustc_errors", "rustc_expand", "rustc_feature", - "rustc_fluent_macro", "rustc_hir", "rustc_index", "rustc_lexer", @@ -3775,7 +3774,6 @@ dependencies = [ "rustc_ast_passes", "rustc_ast_pretty", "rustc_borrowck", - "rustc_builtin_macros", "rustc_codegen_ssa", "rustc_const_eval", "rustc_data_structures", 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_driver_impl/Cargo.toml b/compiler/rustc_driver_impl/Cargo.toml index c24a4ca532194..e7b266552f4f8 100644 --- a/compiler/rustc_driver_impl/Cargo.toml +++ b/compiler/rustc_driver_impl/Cargo.toml @@ -12,7 +12,6 @@ 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" } diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs index 02298dbf82670..9dbdfb141fc1c 100644 --- a/compiler/rustc_driver_impl/src/lib.rs +++ b/compiler/rustc_driver_impl/src/lib.rs @@ -116,7 +116,6 @@ 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,