Rollup merge of #152108 - JonathanBrouwer:convert_expand, r=jdonszelmann

Convert to inline diagnostics in `rustc_expand`

For https://github.com/rust-lang/rust/issues/151366
r? @jdonszelmann
This commit is contained in:
Jonathan Brouwer 2026-02-05 08:32:52 +01:00 committed by GitHub
commit d58a87b287
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 171 additions and 328 deletions

View file

@ -3872,7 +3872,6 @@ dependencies = [
"rustc_data_structures",
"rustc_errors",
"rustc_feature",
"rustc_fluent_macro",
"rustc_hir",
"rustc_lexer",
"rustc_lint_defs",

View file

@ -120,7 +120,6 @@ pub static DEFAULT_LOCALE_RESOURCES: &[&str] = &[
rustc_codegen_ssa::DEFAULT_LOCALE_RESOURCE,
rustc_const_eval::DEFAULT_LOCALE_RESOURCE,
rustc_errors::DEFAULT_LOCALE_RESOURCE,
rustc_expand::DEFAULT_LOCALE_RESOURCE,
rustc_hir_analysis::DEFAULT_LOCALE_RESOURCE,
rustc_lint::DEFAULT_LOCALE_RESOURCE,
rustc_metadata::DEFAULT_LOCALE_RESOURCE,

View file

@ -16,7 +16,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_hir = { path = "../rustc_hir" }
rustc_lexer = { path = "../rustc_lexer" }
rustc_lint_defs = { path = "../rustc_lint_defs" }

View file

@ -1,207 +0,0 @@
expand_attributes_on_expressions_experimental =
attributes on expressions are experimental
.help_outer_doc = `///` is used for outer documentation comments; for a plain comment, use `//`
.help_inner_doc = `//!` is used for inner documentation comments; for a plain comment, use `//` by removing the `!` or inserting a space in between them: `// !`
expand_cfg_attr_no_attributes = `#[cfg_attr]` does not expand to any attributes
expand_count_repetition_misplaced =
`count` can not be placed inside the innermost repetition
expand_crate_name_in_cfg_attr =
`crate_name` within an `#![cfg_attr]` attribute is forbidden
expand_crate_type_in_cfg_attr =
`crate_type` within an `#![cfg_attr]` attribute is forbidden
expand_custom_attribute_panicked =
custom attribute panicked
.help = message: {$message}
expand_duplicate_matcher_binding = duplicate matcher binding
.label = duplicate binding
.label2 = previous binding
expand_empty_delegation_mac =
empty {$kind} delegation is not supported
expand_expected_paren_or_brace =
expected `(` or `{"{"}`, found `{$token}`
expand_explain_doc_comment_inner =
inner doc comments expand to `#![doc = "..."]`, which is what this macro attempted to match
expand_explain_doc_comment_outer =
outer doc comments expand to `#[doc = "..."]`, which is what this macro attempted to match
expand_expr_repeat_no_syntax_vars =
attempted to repeat an expression containing no syntax variables matched as repeating at this depth
expand_feature_not_allowed =
the feature `{$name}` is not in the list of allowed features
expand_feature_removed =
feature has been removed
.label = feature has been removed
.note = removed in {$removed_rustc_version}{$pull_note}
.reason = {$reason}
expand_file_modules_in_proc_macro_input_are_unstable =
file modules in proc macro input are unstable
expand_glob_delegation_outside_impls =
glob delegation is only supported in impls
expand_glob_delegation_traitless_qpath =
qualified path without a trait in glob delegation
expand_incomplete_parse =
macro expansion ignores {$descr} and any tokens following
.label = caused by the macro expansion here
.note = the usage of `{$macro_path}!` is likely invalid in {$kind_name} context
.suggestion_add_semi = you might be missing a semicolon here
expand_invalid_cfg_expected_syntax = expected syntax is
expand_invalid_cfg_multiple_predicates = multiple `cfg` predicates are specified
expand_invalid_cfg_no_parens = `cfg` is not followed by parentheses
expand_invalid_cfg_no_predicate = `cfg` predicate is not specified
expand_invalid_cfg_predicate_literal = `cfg` predicate key cannot be a literal
expand_invalid_fragment_specifier =
invalid fragment specifier `{$fragment}`
.help = {$help}
expand_macro_args_bad_delim = `{$rule_kw}` rule argument matchers require parentheses
expand_macro_args_bad_delim_sugg = the delimiters should be `(` and `)`
expand_macro_body_stability =
macros cannot have body stability attributes
.label = invalid body stability attribute
.label2 = body stability attribute affects this macro
expand_macro_call_unused_doc_comment = unused doc comment
.label = rustdoc does not generate documentation for macro invocations
.help = to document an item produced by a macro, the macro must produce the documentation as part of its expansion
expand_macro_const_stability =
macros cannot have const stability attributes
.label = invalid const stability attribute
.label2 = const stability attribute affects this macro
expand_macro_expands_to_match_arm = macros cannot expand to match arms
expand_malformed_feature_attribute =
malformed `feature` attribute input
.expected = expected just one word
expand_meta_var_dif_seq_matchers = {$msg}
expand_metavar_still_repeating = variable `{$ident}` is still repeating at this depth
.label = expected repetition
expand_metavariable_wrong_operator = meta-variable repeats with different Kleene operator
.binder_label = expected repetition
.occurrence_label = conflicting repetition
expand_missing_fragment_specifier = missing fragment specifier
.note = fragment specifiers must be provided
.suggestion_add_fragspec = try adding a specifier here
.valid = {$valid}
expand_module_circular =
circular modules: {$modules}
expand_module_file_not_found =
file not found for module `{$name}`
.help = to create the module `{$name}`, create file "{$default_path}" or "{$secondary_path}"
.note = if there is a `mod {$name}` elsewhere in the crate already, import it with `use crate::...` instead
expand_module_in_block =
cannot declare a file module inside a block unless it has a path attribute
.help = maybe `use` the module `{$name}` instead of redeclaring it
.note = file modules are usually placed outside of blocks, at the top level of the file
expand_module_multiple_candidates =
file for module `{$name}` found at both "{$default_path}" and "{$secondary_path}"
.help = delete or rename one of them to remove the ambiguity
expand_must_repeat_once =
this must repeat at least once
expand_mve_extra_tokens =
unexpected trailing tokens
.label = for this metavariable expression
.range = the `{$name}` metavariable expression takes between {$min_or_exact_args} and {$max_args} arguments
.exact = the `{$name}` metavariable expression takes {$min_or_exact_args ->
[zero] no arguments
[one] a single argument
*[other] {$min_or_exact_args} arguments
}
.suggestion = try removing {$extra_count ->
[one] this token
*[other] these tokens
}
expand_mve_missing_paren =
expected `(`
.label = for this this metavariable expression
.unexpected = unexpected token
.note = metavariable expressions use function-like parentheses syntax
.suggestion = try adding parentheses
expand_mve_unrecognized_expr =
unrecognized metavariable expression
.label = not a valid metavariable expression
.note = valid metavariable expressions are {$valid_expr_list}
expand_mve_unrecognized_var =
variable `{$key}` is not recognized in meta-variable expression
expand_or_patterns_back_compat = the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro
.suggestion = use pat_param to preserve semantics
expand_proc_macro_back_compat = using an old version of `{$crate_name}`
.note = older versions of the `{$crate_name}` crate no longer compile; please update to `{$crate_name}` v{$fixed_version}, or switch to one of the `{$crate_name}` alternatives
expand_proc_macro_derive_panicked =
proc-macro derive panicked
.help = message: {$message}
expand_proc_macro_derive_tokens =
proc-macro derive produced unparsable tokens
expand_proc_macro_panicked =
proc macro panicked
.help = message: {$message}
expand_recursion_limit_reached =
recursion limit reached while expanding `{$descr}`
.help = consider increasing the recursion limit by adding a `#![recursion_limit = "{$suggested_limit}"]` attribute to your crate (`{$crate_name}`)
expand_remove_expr_not_supported =
removing an expression is not supported in this position
expand_remove_node_not_supported =
removing {$descr} is not supported in this position
expand_resolve_relative_path =
cannot resolve relative path in non-file source `{$path}`
expand_trace_macro = trace_macro
expand_trailing_semi_macro = trailing semicolon in macro used in expression position
.note1 = macro invocations at the end of a block are treated as expressions
.note2 = to ignore the value produced by the macro, add a semicolon after the invocation of `{$name}`
expand_unknown_macro_variable = unknown macro variable `{$name}`
expand_unsupported_key_value =
key-value macro attributes are not supported
expand_unused_builtin_attribute = unused attribute `{$attr_name}`
.note = the built-in attribute `{$attr_name}` will be ignored, since it's applied to the macro invocation `{$macro_name}`
.suggestion = remove the attribute
expand_wrong_fragment_kind =
non-{$kind} macro in {$kind} position: {$name}

View file

@ -15,6 +15,7 @@ use rustc_attr_parsing::{
AttributeParser, CFG_TEMPLATE, EvalConfigResult, ShouldEmit, eval_config_entry, parse_cfg,
};
use rustc_data_structures::flat_map_in_place::FlatMapInPlace;
use rustc_errors::inline_fluent;
use rustc_feature::{
ACCEPTED_LANG_FEATURES, EnabledLangFeature, EnabledLibFeature, Features, REMOVED_LANG_FEATURES,
UNSTABLE_LANG_FEATURES,
@ -432,14 +433,14 @@ impl<'a> StripUnconfigured<'a> {
&self.sess,
sym::stmt_expr_attributes,
attr.span,
crate::fluent_generated::expand_attributes_on_expressions_experimental,
inline_fluent!("attributes on expressions are experimental"),
);
if attr.is_doc_comment() {
err.help(if attr.style == AttrStyle::Outer {
crate::fluent_generated::expand_help_outer_doc
inline_fluent!("`///` is used for outer documentation comments; for a plain comment, use `//`")
} else {
crate::fluent_generated::expand_help_inner_doc
inline_fluent!("`//!` is used for inner documentation comments; for a plain comment, use `//` by removing the `!` or inserting a space in between them: `// !`")
});
}

View file

@ -7,32 +7,34 @@ use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
use rustc_span::{Ident, MacroRulesNormalizedIdent, Span, Symbol};
#[derive(LintDiagnostic)]
#[diag(expand_cfg_attr_no_attributes)]
#[diag("`#[cfg_attr]` does not expand to any attributes")]
pub(crate) struct CfgAttrNoAttributes;
#[derive(Diagnostic)]
#[diag(expand_expr_repeat_no_syntax_vars)]
#[diag(
"attempted to repeat an expression containing no syntax variables matched as repeating at this depth"
)]
pub(crate) struct NoSyntaxVarsExprRepeat {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(expand_must_repeat_once)]
#[diag("this must repeat at least once")]
pub(crate) struct MustRepeatOnce {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(expand_count_repetition_misplaced)]
#[diag("`count` can not be placed inside the innermost repetition")]
pub(crate) struct CountRepetitionMisplaced {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(expand_metavar_still_repeating)]
#[diag("variable `{$ident}` is still repeating at this depth")]
pub(crate) struct MacroVarStillRepeating {
#[primary_span]
pub span: Span,
@ -40,24 +42,24 @@ pub(crate) struct MacroVarStillRepeating {
}
#[derive(LintDiagnostic)]
#[diag(expand_metavar_still_repeating)]
#[diag("variable `{$ident}` is still repeating at this depth")]
pub(crate) struct MetaVarStillRepeatingLint {
#[label]
#[label("expected repetition")]
pub label: Span,
pub ident: MacroRulesNormalizedIdent,
}
#[derive(LintDiagnostic)]
#[diag(expand_metavariable_wrong_operator)]
#[diag("meta-variable repeats with different Kleene operator")]
pub(crate) struct MetaVariableWrongOperator {
#[label(expand_binder_label)]
#[label("expected repetition")]
pub binder: Span,
#[label(expand_occurrence_label)]
#[label("conflicting repetition")]
pub occurrence: Span,
}
#[derive(Diagnostic)]
#[diag(expand_meta_var_dif_seq_matchers)]
#[diag("{$msg}")]
pub(crate) struct MetaVarsDifSeqMatchers {
#[primary_span]
pub span: Span,
@ -65,13 +67,13 @@ pub(crate) struct MetaVarsDifSeqMatchers {
}
#[derive(LintDiagnostic)]
#[diag(expand_unknown_macro_variable)]
#[diag("unknown macro variable `{$name}`")]
pub(crate) struct UnknownMacroVariable {
pub name: MacroRulesNormalizedIdent,
}
#[derive(Diagnostic)]
#[diag(expand_resolve_relative_path)]
#[diag("cannot resolve relative path in non-file source `{$path}`")]
pub(crate) struct ResolveRelativePath {
#[primary_span]
pub span: Span,
@ -79,31 +81,31 @@ pub(crate) struct ResolveRelativePath {
}
#[derive(Diagnostic)]
#[diag(expand_macro_const_stability)]
#[diag("macros cannot have const stability attributes")]
pub(crate) struct MacroConstStability {
#[primary_span]
#[label]
#[label("invalid const stability attribute")]
pub span: Span,
#[label(expand_label2)]
#[label("const stability attribute affects this macro")]
pub head_span: Span,
}
#[derive(Diagnostic)]
#[diag(expand_macro_body_stability)]
#[diag("macros cannot have body stability attributes")]
pub(crate) struct MacroBodyStability {
#[primary_span]
#[label]
#[label("invalid body stability attribute")]
pub span: Span,
#[label(expand_label2)]
#[label("body stability attribute affects this macro")]
pub head_span: Span,
}
#[derive(Diagnostic)]
#[diag(expand_feature_removed, code = E0557)]
#[note]
#[diag("feature has been removed", code = E0557)]
#[note("removed in {$removed_rustc_version}{$pull_note}")]
pub(crate) struct FeatureRemoved<'a> {
#[primary_span]
#[label]
#[label("feature has been removed")]
pub span: Span,
#[subdiagnostic]
pub reason: Option<FeatureRemovedReason<'a>>,
@ -112,13 +114,13 @@ pub(crate) struct FeatureRemoved<'a> {
}
#[derive(Subdiagnostic)]
#[note(expand_reason)]
#[note("{$reason}")]
pub(crate) struct FeatureRemovedReason<'a> {
pub reason: &'a str,
}
#[derive(Diagnostic)]
#[diag(expand_feature_not_allowed, code = E0725)]
#[diag("the feature `{$name}` is not in the list of allowed features", code = E0725)]
pub(crate) struct FeatureNotAllowed {
#[primary_span]
pub span: Span,
@ -126,8 +128,10 @@ pub(crate) struct FeatureNotAllowed {
}
#[derive(Diagnostic)]
#[diag(expand_recursion_limit_reached)]
#[help]
#[diag("recursion limit reached while expanding `{$descr}`")]
#[help(
"consider increasing the recursion limit by adding a `#![recursion_limit = \"{$suggested_limit}\"]` attribute to your crate (`{$crate_name}`)"
)]
pub(crate) struct RecursionLimitReached {
#[primary_span]
pub span: Span,
@ -137,7 +141,7 @@ pub(crate) struct RecursionLimitReached {
}
#[derive(Diagnostic)]
#[diag(expand_malformed_feature_attribute, code = E0556)]
#[diag("malformed `feature` attribute input", code = E0556)]
pub(crate) struct MalformedFeatureAttribute {
#[primary_span]
pub span: Span,
@ -147,12 +151,16 @@ pub(crate) struct MalformedFeatureAttribute {
#[derive(Subdiagnostic)]
pub(crate) enum MalformedFeatureAttributeHelp {
#[label(expand_expected)]
#[label("expected just one word")]
Label {
#[primary_span]
span: Span,
},
#[suggestion(expand_expected, code = "{suggestion}", applicability = "maybe-incorrect")]
#[suggestion(
"expected just one word",
code = "{suggestion}",
applicability = "maybe-incorrect"
)]
Suggestion {
#[primary_span]
span: Span,
@ -161,7 +169,7 @@ pub(crate) enum MalformedFeatureAttributeHelp {
}
#[derive(Diagnostic)]
#[diag(expand_remove_expr_not_supported)]
#[diag("removing an expression is not supported in this position")]
pub(crate) struct RemoveExprNotSupported {
#[primary_span]
pub span: Span,
@ -169,32 +177,32 @@ pub(crate) struct RemoveExprNotSupported {
#[derive(Diagnostic)]
pub(crate) enum InvalidCfg {
#[diag(expand_invalid_cfg_no_parens)]
#[diag("`cfg` is not followed by parentheses")]
NotFollowedByParens {
#[primary_span]
#[suggestion(
expand_invalid_cfg_expected_syntax,
"expected syntax is",
code = "cfg(/* predicate */)",
applicability = "has-placeholders"
)]
span: Span,
},
#[diag(expand_invalid_cfg_no_predicate)]
#[diag("`cfg` predicate is not specified")]
NoPredicate {
#[primary_span]
#[suggestion(
expand_invalid_cfg_expected_syntax,
"expected syntax is",
code = "cfg(/* predicate */)",
applicability = "has-placeholders"
)]
span: Span,
},
#[diag(expand_invalid_cfg_multiple_predicates)]
#[diag("multiple `cfg` predicates are specified")]
MultiplePredicates {
#[primary_span]
span: Span,
},
#[diag(expand_invalid_cfg_predicate_literal)]
#[diag("`cfg` predicate key cannot be a literal")]
PredicateLiteral {
#[primary_span]
span: Span,
@ -202,7 +210,7 @@ pub(crate) enum InvalidCfg {
}
#[derive(Diagnostic)]
#[diag(expand_wrong_fragment_kind)]
#[diag("non-{$kind} macro in {$kind} position: {$name}")]
pub(crate) struct WrongFragmentKind<'a> {
#[primary_span]
pub span: Span,
@ -211,28 +219,28 @@ pub(crate) struct WrongFragmentKind<'a> {
}
#[derive(Diagnostic)]
#[diag(expand_unsupported_key_value)]
#[diag("key-value macro attributes are not supported")]
pub(crate) struct UnsupportedKeyValue {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(expand_incomplete_parse)]
#[note]
#[diag("macro expansion ignores {$descr} and any tokens following")]
#[note("the usage of `{$macro_path}!` is likely invalid in {$kind_name} context")]
pub(crate) struct IncompleteParse<'a> {
#[primary_span]
pub span: Span,
pub descr: String,
#[label]
#[label("caused by the macro expansion here")]
pub label_span: Span,
pub macro_path: &'a ast::Path,
pub kind_name: &'a str,
#[note(expand_macro_expands_to_match_arm)]
#[note("macros cannot expand to match arms")]
pub expands_to_match_arm: bool,
#[suggestion(
expand_suggestion_add_semi,
"you might be missing a semicolon here",
style = "verbose",
code = ";",
applicability = "maybe-incorrect"
@ -241,7 +249,7 @@ pub(crate) struct IncompleteParse<'a> {
}
#[derive(Diagnostic)]
#[diag(expand_remove_node_not_supported)]
#[diag("removing {$descr} is not supported in this position")]
pub(crate) struct RemoveNodeNotSupported {
#[primary_span]
pub span: Span,
@ -249,7 +257,7 @@ pub(crate) struct RemoveNodeNotSupported {
}
#[derive(Diagnostic)]
#[diag(expand_module_circular)]
#[diag("circular modules: {$modules}")]
pub(crate) struct ModuleCircular {
#[primary_span]
pub span: Span,
@ -257,8 +265,8 @@ pub(crate) struct ModuleCircular {
}
#[derive(Diagnostic)]
#[diag(expand_module_in_block)]
#[note]
#[diag("cannot declare a file module inside a block unless it has a path attribute")]
#[note("file modules are usually placed outside of blocks, at the top level of the file")]
pub(crate) struct ModuleInBlock {
#[primary_span]
pub span: Span,
@ -267,7 +275,7 @@ pub(crate) struct ModuleInBlock {
}
#[derive(Subdiagnostic)]
#[help(expand_help)]
#[help("maybe `use` the module `{$name}` instead of redeclaring it")]
pub(crate) struct ModuleInBlockName {
#[primary_span]
pub span: Span,
@ -275,9 +283,11 @@ pub(crate) struct ModuleInBlockName {
}
#[derive(Diagnostic)]
#[diag(expand_module_file_not_found, code = E0583)]
#[help]
#[note]
#[diag("file not found for module `{$name}`", code = E0583)]
#[help("to create the module `{$name}`, create file \"{$default_path}\" or \"{$secondary_path}\"")]
#[note(
"if there is a `mod {$name}` elsewhere in the crate already, import it with `use crate::...` instead"
)]
pub(crate) struct ModuleFileNotFound {
#[primary_span]
pub span: Span,
@ -287,8 +297,8 @@ pub(crate) struct ModuleFileNotFound {
}
#[derive(Diagnostic)]
#[diag(expand_module_multiple_candidates, code = E0761)]
#[help]
#[diag("file for module `{$name}` found at both \"{$default_path}\" and \"{$secondary_path}\"", code = E0761)]
#[help("delete or rename one of them to remove the ambiguity")]
pub(crate) struct ModuleMultipleCandidates {
#[primary_span]
pub span: Span,
@ -298,14 +308,14 @@ pub(crate) struct ModuleMultipleCandidates {
}
#[derive(Diagnostic)]
#[diag(expand_trace_macro)]
#[diag("trace_macro")]
pub(crate) struct TraceMacro {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(expand_proc_macro_panicked)]
#[diag("proc macro panicked")]
pub(crate) struct ProcMacroPanicked {
#[primary_span]
pub span: Span,
@ -314,13 +324,13 @@ pub(crate) struct ProcMacroPanicked {
}
#[derive(Subdiagnostic)]
#[help(expand_help)]
#[help("message: {$message}")]
pub(crate) struct ProcMacroPanickedHelp {
pub message: String,
}
#[derive(Diagnostic)]
#[diag(expand_proc_macro_derive_panicked)]
#[diag("proc-macro derive panicked")]
pub(crate) struct ProcMacroDerivePanicked {
#[primary_span]
pub span: Span,
@ -329,13 +339,13 @@ pub(crate) struct ProcMacroDerivePanicked {
}
#[derive(Subdiagnostic)]
#[help(expand_help)]
#[help("message: {$message}")]
pub(crate) struct ProcMacroDerivePanickedHelp {
pub message: String,
}
#[derive(Diagnostic)]
#[diag(expand_custom_attribute_panicked)]
#[diag("custom attribute panicked")]
pub(crate) struct CustomAttributePanicked {
#[primary_span]
pub span: Span,
@ -344,46 +354,46 @@ pub(crate) struct CustomAttributePanicked {
}
#[derive(Subdiagnostic)]
#[help(expand_help)]
#[help("message: {$message}")]
pub(crate) struct CustomAttributePanickedHelp {
pub message: String,
}
#[derive(Diagnostic)]
#[diag(expand_proc_macro_derive_tokens)]
#[diag("proc-macro derive produced unparsable tokens")]
pub(crate) struct ProcMacroDeriveTokens {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(expand_duplicate_matcher_binding)]
#[diag("duplicate matcher binding")]
pub(crate) struct DuplicateMatcherBinding {
#[primary_span]
#[label]
#[label("duplicate binding")]
pub span: Span,
#[label(expand_label2)]
#[label("previous binding")]
pub prev: Span,
}
#[derive(LintDiagnostic)]
#[diag(expand_duplicate_matcher_binding)]
#[diag("duplicate matcher binding")]
pub(crate) struct DuplicateMatcherBindingLint {
#[label]
#[label("duplicate binding")]
pub span: Span,
#[label(expand_label2)]
#[label("previous binding")]
pub prev: Span,
}
#[derive(Diagnostic)]
#[diag(expand_missing_fragment_specifier)]
#[note]
#[help(expand_valid)]
#[diag("missing fragment specifier")]
#[note("fragment specifiers must be provided")]
#[help("{$valid}")]
pub(crate) struct MissingFragmentSpecifier {
#[primary_span]
pub span: Span,
#[suggestion(
expand_suggestion_add_fragspec,
"try adding a specifier here",
style = "verbose",
code = ":spec",
applicability = "maybe-incorrect"
@ -393,8 +403,8 @@ pub(crate) struct MissingFragmentSpecifier {
}
#[derive(Diagnostic)]
#[diag(expand_invalid_fragment_specifier)]
#[help]
#[diag("invalid fragment specifier `{$fragment}`")]
#[help("{$help}")]
pub(crate) struct InvalidFragmentSpecifier {
#[primary_span]
pub span: Span,
@ -403,7 +413,7 @@ pub(crate) struct InvalidFragmentSpecifier {
}
#[derive(Diagnostic)]
#[diag(expand_expected_paren_or_brace)]
#[diag("expected `(` or `{\"{\"}`, found `{$token}`")]
pub(crate) struct ExpectedParenOrBrace<'a> {
#[primary_span]
pub span: Span,
@ -411,7 +421,7 @@ pub(crate) struct ExpectedParenOrBrace<'a> {
}
#[derive(Diagnostic)]
#[diag(expand_empty_delegation_mac)]
#[diag("empty {$kind} delegation is not supported")]
pub(crate) struct EmptyDelegationMac {
#[primary_span]
pub span: Span,
@ -419,28 +429,28 @@ pub(crate) struct EmptyDelegationMac {
}
#[derive(Diagnostic)]
#[diag(expand_glob_delegation_outside_impls)]
#[diag("glob delegation is only supported in impls")]
pub(crate) struct GlobDelegationOutsideImpls {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(expand_crate_name_in_cfg_attr)]
#[diag("`crate_name` within an `#![cfg_attr]` attribute is forbidden")]
pub(crate) struct CrateNameInCfgAttr {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(expand_crate_type_in_cfg_attr)]
#[diag("`crate_type` within an `#![cfg_attr]` attribute is forbidden")]
pub(crate) struct CrateTypeInCfgAttr {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(expand_glob_delegation_traitless_qpath)]
#[diag("qualified path without a trait in glob delegation")]
pub(crate) struct GlobDelegationTraitlessQpath {
#[primary_span]
pub span: Span,
@ -449,8 +459,10 @@ pub(crate) struct GlobDelegationTraitlessQpath {
// This used to be the `proc_macro_back_compat` lint (#83125). It was later
// turned into a hard error.
#[derive(Diagnostic)]
#[diag(expand_proc_macro_back_compat)]
#[note]
#[diag("using an old version of `{$crate_name}`")]
#[note(
"older versions of the `{$crate_name}` crate no longer compile; please update to `{$crate_name}` v{$fixed_version}, or switch to one of the `{$crate_name}` alternatives"
)]
pub(crate) struct ProcMacroBackCompat {
pub crate_name: String,
pub fixed_version: String,
@ -461,20 +473,35 @@ mod metavar_exprs {
use super::*;
#[derive(Diagnostic, Default)]
#[diag(expand_mve_extra_tokens)]
#[diag("unexpected trailing tokens")]
pub(crate) struct MveExtraTokens {
#[primary_span]
#[suggestion(code = "", applicability = "machine-applicable")]
#[suggestion(
"try removing {$extra_count ->
[one] this token
*[other] these tokens
}",
code = "",
applicability = "machine-applicable"
)]
pub span: Span,
#[label]
#[label("for this metavariable expression")]
pub ident_span: Span,
pub extra_count: usize,
// The rest is only used for specific diagnostics and can be default if neither
// `note` is `Some`.
#[note(expand_exact)]
#[note(
"the `{$name}` metavariable expression takes {$min_or_exact_args ->
[zero] no arguments
[one] a single argument
*[other] {$min_or_exact_args} arguments
}"
)]
pub exact_args_note: Option<()>,
#[note(expand_range)]
#[note(
"the `{$name}` metavariable expression takes between {$min_or_exact_args} and {$max_args} arguments"
)]
pub range_args_note: Option<()>,
pub min_or_exact_args: usize,
pub max_args: usize,
@ -482,30 +509,34 @@ mod metavar_exprs {
}
#[derive(Diagnostic)]
#[note]
#[diag(expand_mve_missing_paren)]
#[note("metavariable expressions use function-like parentheses syntax")]
#[diag("expected `(`")]
pub(crate) struct MveMissingParen {
#[primary_span]
#[label]
#[label("for this this metavariable expression")]
pub ident_span: Span,
#[label(expand_unexpected)]
#[label("unexpected token")]
pub unexpected_span: Option<Span>,
#[suggestion(code = "( /* ... */ )", applicability = "has-placeholders")]
#[suggestion(
"try adding parentheses",
code = "( /* ... */ )",
applicability = "has-placeholders"
)]
pub insert_span: Option<Span>,
}
#[derive(Diagnostic)]
#[note]
#[diag(expand_mve_unrecognized_expr)]
#[note("valid metavariable expressions are {$valid_expr_list}")]
#[diag("unrecognized metavariable expression")]
pub(crate) struct MveUnrecognizedExpr {
#[primary_span]
#[label]
#[label("not a valid metavariable expression")]
pub span: Span,
pub valid_expr_list: &'static str,
}
#[derive(Diagnostic)]
#[diag(expand_mve_unrecognized_var)]
#[diag("variable `{$key}` is not recognized in meta-variable expression")]
pub(crate) struct MveUnrecognizedVar {
#[primary_span]
pub span: Span,
@ -514,7 +545,7 @@ mod metavar_exprs {
}
#[derive(Diagnostic)]
#[diag(expand_macro_args_bad_delim)]
#[diag("`{$rule_kw}` rule argument matchers require parentheses")]
pub(crate) struct MacroArgsBadDelim {
#[primary_span]
pub span: Span,
@ -524,7 +555,10 @@ pub(crate) struct MacroArgsBadDelim {
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(expand_macro_args_bad_delim_sugg, applicability = "machine-applicable")]
#[multipart_suggestion(
"the delimiters should be `(` and `)`",
applicability = "machine-applicable"
)]
pub(crate) struct MacroArgsBadDelimSugg {
#[suggestion_part(code = "(")]
pub open: Span,
@ -533,37 +567,54 @@ pub(crate) struct MacroArgsBadDelimSugg {
}
#[derive(LintDiagnostic)]
#[diag(expand_macro_call_unused_doc_comment)]
#[help]
#[diag("unused doc comment")]
#[help(
"to document an item produced by a macro, the macro must produce the documentation as part of its expansion"
)]
pub(crate) struct MacroCallUnusedDocComment {
#[label]
#[label("rustdoc does not generate documentation for macro invocations")]
pub span: Span,
}
#[derive(LintDiagnostic)]
#[diag(expand_or_patterns_back_compat)]
#[diag(
"the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro"
)]
pub(crate) struct OrPatternsBackCompat {
#[suggestion(code = "{suggestion}", applicability = "machine-applicable")]
#[suggestion(
"use pat_param to preserve semantics",
code = "{suggestion}",
applicability = "machine-applicable"
)]
pub span: Span,
pub suggestion: String,
}
#[derive(LintDiagnostic)]
#[diag(expand_trailing_semi_macro)]
#[diag("trailing semicolon in macro used in expression position")]
pub(crate) struct TrailingMacro {
#[note(expand_note1)]
#[note(expand_note2)]
#[note("macro invocations at the end of a block are treated as expressions")]
#[note(
"to ignore the value produced by the macro, add a semicolon after the invocation of `{$name}`"
)]
pub is_trailing: bool,
pub name: Ident,
}
#[derive(LintDiagnostic)]
#[diag(expand_unused_builtin_attribute)]
#[diag("unused attribute `{$attr_name}`")]
pub(crate) struct UnusedBuiltinAttribute {
#[note]
#[note(
"the built-in attribute `{$attr_name}` will be ignored, since it's applied to the macro invocation `{$macro_name}`"
)]
pub invoc_span: Span,
pub attr_name: Symbol,
pub macro_name: String,
#[suggestion(code = "", applicability = "machine-applicable", style = "tool-only")]
#[suggestion(
"remove the attribute",
code = "",
applicability = "machine-applicable",
style = "tool-only"
)]
pub attr_span: Span,
}

View file

@ -19,7 +19,7 @@ use rustc_attr_parsing::{
};
use rustc_data_structures::flat_map_in_place::FlatMapInPlace;
use rustc_data_structures::stack::ensure_sufficient_stack;
use rustc_errors::PResult;
use rustc_errors::{PResult, inline_fluent};
use rustc_feature::Features;
use rustc_hir::Target;
use rustc_hir::def::MacroKinds;
@ -42,7 +42,6 @@ use crate::errors::{
RecursionLimitReached, RemoveExprNotSupported, RemoveNodeNotSupported, UnsupportedKeyValue,
WrongFragmentKind,
};
use crate::fluent_generated;
use crate::mbe::diagnostics::annotate_err_with_kind;
use crate::module::{
DirOwnership, ParsedExternalMod, mod_dir_path, mod_file_path_from_attr, parse_external_mod,
@ -1052,7 +1051,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
self.sess,
sym::proc_macro_hygiene,
item.span,
fluent_generated::expand_file_modules_in_proc_macro_input_are_unstable,
inline_fluent!("file modules in proc macro input are unstable"),
)
.emit();
}

View file

@ -26,5 +26,3 @@ pub mod proc_macro;
pub fn provide(providers: &mut rustc_middle::query::Providers) {
providers.derive_macro_expansion = proc_macro::provide_derive_macro_expansion;
}
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }

View file

@ -302,12 +302,16 @@ pub(crate) fn annotate_err_with_kind(err: &mut Diag<'_>, kind: AstFragmentKind,
#[derive(Subdiagnostic)]
enum ExplainDocComment {
#[label(expand_explain_doc_comment_inner)]
#[label(
"inner doc comments expand to `#![doc = \"...\"]`, which is what this macro attempted to match"
)]
Inner {
#[primary_span]
span: Span,
},
#[label(expand_explain_doc_comment_outer)]
#[label(
"outer doc comments expand to `#[doc = \"...\"]`, which is what this macro attempted to match"
)]
Outer {
#[primary_span]
span: Span,