From 3657326ebc9e31af45dd6cb5d0e656536b3bf26c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Sun, 14 Jun 2026 14:36:22 +0200 Subject: [PATCH 1/2] Rename attribute `diagnostic::on_unmatch_args` to `diagnostic::on_unmatched_args` --- .../src/attributes/diagnostic/mod.rs | 22 ++++++++-------- ...n_unmatch_args.rs => on_unmatched_args.rs} | 16 +++++++----- compiler/rustc_attr_parsing/src/context.rs | 4 +-- .../rustc_attr_parsing/src/diagnostics.rs | 4 +-- compiler/rustc_expand/src/mbe/diagnostics.rs | 4 +-- compiler/rustc_expand/src/mbe/macro_rules.rs | 26 +++++++++---------- .../rustc_hir/src/attrs/data_structures.rs | 4 +-- .../rustc_hir/src/attrs/encode_cross_crate.rs | 2 +- compiler/rustc_passes/src/check_attr.rs | 2 +- compiler/rustc_resolve/src/macros.rs | 2 +- compiler/rustc_span/src/symbol.rs | 2 +- library/core/src/field.rs | 2 +- library/core/src/mem/mod.rs | 2 +- .../diagnostic-on-unmatch-args.md | 4 +-- .../report_warning_on_non_macro.rs | 10 ------- .../report_warning_on_unknown_options.rs | 12 --------- .../report_warning_on_unknown_options.stderr | 11 -------- .../auxiliary/other.rs | 2 +- .../error_is_shown_in_downstream_crates.rs | 0 ...error_is_shown_in_downstream_crates.stderr | 0 .../message_and_label.rs | 2 +- .../message_and_label.stderr | 0 .../notes_on_extra_args.rs | 2 +- .../notes_on_extra_args.stderr | 0 .../on_unmatched_args.rs} | 2 +- .../on_unmatched_args.stderr} | 4 +-- .../other_match_macro_error.rs | 2 +- .../other_match_macro_error.stderr | 0 .../report_warning_on_invalid_formats.rs | 4 +-- .../report_warning_on_invalid_formats.stderr | 2 +- ...ort_warning_on_invalid_meta_item_syntax.rs | 4 +-- ...warning_on_invalid_meta_item_syntax.stderr | 6 ++--- .../report_warning_on_missing_options.rs | 4 +-- .../report_warning_on_missing_options.stderr | 6 ++--- .../report_warning_on_non_macro.rs | 10 +++++++ .../report_warning_on_non_macro.stderr | 6 ++--- .../report_warning_on_unknown_options.rs | 12 +++++++++ .../report_warning_on_unknown_options.stderr | 11 ++++++++ ...feature-gate-diagnostic-on-unmatch-args.rs | 2 +- 39 files changed, 106 insertions(+), 104 deletions(-) rename compiler/rustc_attr_parsing/src/attributes/diagnostic/{on_unmatch_args.rs => on_unmatched_args.rs} (77%) delete mode 100644 tests/ui/diagnostic_namespace/on_unmatch_args/report_warning_on_non_macro.rs delete mode 100644 tests/ui/diagnostic_namespace/on_unmatch_args/report_warning_on_unknown_options.rs delete mode 100644 tests/ui/diagnostic_namespace/on_unmatch_args/report_warning_on_unknown_options.stderr rename tests/ui/diagnostic_namespace/{on_unmatch_args => on_unmatched_args}/auxiliary/other.rs (91%) rename tests/ui/diagnostic_namespace/{on_unmatch_args => on_unmatched_args}/error_is_shown_in_downstream_crates.rs (100%) rename tests/ui/diagnostic_namespace/{on_unmatch_args => on_unmatched_args}/error_is_shown_in_downstream_crates.stderr (100%) rename tests/ui/diagnostic_namespace/{on_unmatch_args => on_unmatched_args}/message_and_label.rs (95%) rename tests/ui/diagnostic_namespace/{on_unmatch_args => on_unmatched_args}/message_and_label.stderr (100%) rename tests/ui/diagnostic_namespace/{on_unmatch_args => on_unmatched_args}/notes_on_extra_args.rs (95%) rename tests/ui/diagnostic_namespace/{on_unmatch_args => on_unmatched_args}/notes_on_extra_args.stderr (100%) rename tests/ui/diagnostic_namespace/{on_unmatch_args/on_unmatch_args.rs => on_unmatched_args/on_unmatched_args.rs} (94%) rename tests/ui/diagnostic_namespace/{on_unmatch_args/on_unmatch_args.stderr => on_unmatched_args/on_unmatched_args.stderr} (85%) rename tests/ui/diagnostic_namespace/{on_unmatch_args => on_unmatched_args}/other_match_macro_error.rs (89%) rename tests/ui/diagnostic_namespace/{on_unmatch_args => on_unmatched_args}/other_match_macro_error.stderr (100%) rename tests/ui/diagnostic_namespace/{on_unmatch_args => on_unmatched_args}/report_warning_on_invalid_formats.rs (89%) rename tests/ui/diagnostic_namespace/{on_unmatch_args => on_unmatched_args}/report_warning_on_invalid_formats.stderr (96%) rename tests/ui/diagnostic_namespace/{on_unmatch_args => on_unmatched_args}/report_warning_on_invalid_meta_item_syntax.rs (51%) rename tests/ui/diagnostic_namespace/{on_unmatch_args => on_unmatched_args}/report_warning_on_invalid_meta_item_syntax.stderr (62%) rename tests/ui/diagnostic_namespace/{on_unmatch_args => on_unmatched_args}/report_warning_on_missing_options.rs (50%) rename tests/ui/diagnostic_namespace/{on_unmatch_args => on_unmatched_args}/report_warning_on_missing_options.stderr (67%) create mode 100644 tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_non_macro.rs rename tests/ui/diagnostic_namespace/{on_unmatch_args => on_unmatched_args}/report_warning_on_non_macro.stderr (64%) create mode 100644 tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_unknown_options.rs create mode 100644 tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_unknown_options.stderr diff --git a/compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs b/compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs index ddf1b7942ca11..0bed40ca639fb 100644 --- a/compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs +++ b/compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs @@ -27,7 +27,7 @@ pub(crate) mod on_move; pub(crate) mod on_type_error; pub(crate) mod on_unimplemented; pub(crate) mod on_unknown; -pub(crate) mod on_unmatch_args; +pub(crate) mod on_unmatched_args; #[derive(Copy, Clone)] pub(crate) enum Mode { @@ -41,8 +41,8 @@ pub(crate) enum Mode { DiagnosticOnMove, /// `#[diagnostic::on_unknown]` DiagnosticOnUnknown, - /// `#[diagnostic::on_unmatch_args]` - DiagnosticOnUnmatchArgs, + /// `#[diagnostic::on_unmatched_args]` + DiagnosticOnUnmatchedArgs, /// `#[diagnostic::on_type_error]` DiagnosticOnTypeError, } @@ -55,7 +55,7 @@ impl Mode { Self::DiagnosticOnConst => "diagnostic::on_const", Self::DiagnosticOnMove => "diagnostic::on_move", Self::DiagnosticOnUnknown => "diagnostic::on_unknown", - Self::DiagnosticOnUnmatchArgs => "diagnostic::on_unmatch_args", + Self::DiagnosticOnUnmatchedArgs => "diagnostic::on_unmatched_args", Self::DiagnosticOnTypeError => "diagnostic::on_type_error", } } @@ -73,7 +73,7 @@ impl Mode { Self::DiagnosticOnConst => DEFAULT, Self::DiagnosticOnMove => DEFAULT, Self::DiagnosticOnUnknown => DEFAULT, - Self::DiagnosticOnUnmatchArgs => DEFAULT, + Self::DiagnosticOnUnmatchedArgs => DEFAULT, Self::DiagnosticOnTypeError => DIAGNOSTIC_ON_TYPE_ERROR_EXPECTED_OPTIONS, } } @@ -90,7 +90,7 @@ impl Mode { Self::DiagnosticOnConst => DEFAULT, Self::DiagnosticOnMove => DEFAULT, Self::DiagnosticOnUnknown => DEFAULT, - Self::DiagnosticOnUnmatchArgs => DEFAULT, + Self::DiagnosticOnUnmatchedArgs => DEFAULT, Self::DiagnosticOnTypeError => DIAGNOSTIC_ON_TYPE_ERROR_ALLOWED_OPTIONS, } } @@ -112,7 +112,7 @@ impl Mode { Self::DiagnosticOnUnknown => { "only `This` is allowed as a format argument, referring to the failed import" } - Self::DiagnosticOnUnmatchArgs => { + Self::DiagnosticOnUnmatchedArgs => { "only `This` is allowed as a format argument, referring to the macro's name" } Self::DiagnosticOnTypeError => { @@ -313,7 +313,7 @@ fn parse_directive_items<'p>( | Mode::DiagnosticOnConst | Mode::DiagnosticOnMove | Mode::DiagnosticOnUnknown - | Mode::DiagnosticOnUnmatchArgs, + | Mode::DiagnosticOnUnmatchedArgs, sym::message, ) => { let value = or_malformed!(value?); @@ -329,7 +329,7 @@ fn parse_directive_items<'p>( | Mode::DiagnosticOnConst | Mode::DiagnosticOnMove | Mode::DiagnosticOnUnknown - | Mode::DiagnosticOnUnmatchArgs, + | Mode::DiagnosticOnUnmatchedArgs, sym::label, ) => { let value = or_malformed!(value?); @@ -469,7 +469,7 @@ fn parse_arg( ( Mode::DiagnosticOnUnknown | Mode::DiagnosticOnMove - | Mode::DiagnosticOnUnmatchArgs + | Mode::DiagnosticOnUnmatchedArgs | Mode::DiagnosticOnTypeError, sym::This, ) => FormatArg::This, @@ -502,7 +502,7 @@ fn parse_arg( ) => FormatArg::GenericParam { generic_param, span }, // Generics are explicitly not allowed, we print those back as is. - (Mode::DiagnosticOnUnknown | Mode::DiagnosticOnUnmatchArgs, as_is) => { + (Mode::DiagnosticOnUnknown | Mode::DiagnosticOnUnmatchedArgs, as_is) => { warnings.push(FormatWarning::DisallowedPlaceholder { span, attr: mode.as_str(), diff --git a/compiler/rustc_attr_parsing/src/attributes/diagnostic/on_unmatch_args.rs b/compiler/rustc_attr_parsing/src/attributes/diagnostic/on_unmatched_args.rs similarity index 77% rename from compiler/rustc_attr_parsing/src/attributes/diagnostic/on_unmatch_args.rs rename to compiler/rustc_attr_parsing/src/attributes/diagnostic/on_unmatched_args.rs index 4d6f833a79751..3a66052dd08d7 100644 --- a/compiler/rustc_attr_parsing/src/attributes/diagnostic/on_unmatch_args.rs +++ b/compiler/rustc_attr_parsing/src/attributes/diagnostic/on_unmatched_args.rs @@ -4,17 +4,17 @@ use rustc_session::lint::builtin::MISPLACED_DIAGNOSTIC_ATTRIBUTES; use crate::attributes::diagnostic::*; use crate::attributes::prelude::*; -use crate::diagnostics::DiagnosticOnUnmatchArgsOnlyForMacros; +use crate::diagnostics::DiagnosticOnUnmatchedArgsOnlyForMacros; #[derive(Default)] -pub(crate) struct OnUnmatchArgsParser { +pub(crate) struct OnUnmatchedArgsParser { span: Option, directive: Option<(Span, Directive)>, } -impl AttributeParser for OnUnmatchArgsParser { +impl AttributeParser for OnUnmatchedArgsParser { const ATTRIBUTES: AcceptMapping = &[( - &[sym::diagnostic, sym::on_unmatch_args], + &[sym::diagnostic, sym::on_unmatched_args], template!(List: &[r#"/*opt*/ message = "...", /*opt*/ label = "...", /*opt*/ note = "...""#]), AttributeStability::Stable, // Unstable, stability checked manually in the parser |this, cx, args| { @@ -28,13 +28,13 @@ impl AttributeParser for OnUnmatchArgsParser { if !matches!(cx.target, Target::MacroDef) { cx.emit_lint( MISPLACED_DIAGNOSTIC_ATTRIBUTES, - DiagnosticOnUnmatchArgsOnlyForMacros, + DiagnosticOnUnmatchedArgsOnlyForMacros, span, ); return; } - let mode = Mode::DiagnosticOnUnmatchArgs; + let mode = Mode::DiagnosticOnUnmatchedArgs; let Some(items) = parse_list(cx, args, mode) else { return }; let Some(directive) = parse_directive_items(cx, mode, items.mixed(), true) else { @@ -48,7 +48,9 @@ impl AttributeParser for OnUnmatchArgsParser { fn finalize(self, _cx: &FinalizeContext<'_, '_>) -> Option { if let Some(_span) = self.span { - Some(AttributeKind::OnUnmatchArgs { directive: self.directive.map(|d| Box::new(d.1)) }) + Some(AttributeKind::OnUnmatchedArgs { + directive: self.directive.map(|d| Box::new(d.1)), + }) } else { None } diff --git a/compiler/rustc_attr_parsing/src/context.rs b/compiler/rustc_attr_parsing/src/context.rs index b03d28c0cdfa5..bda71e6d566c7 100644 --- a/compiler/rustc_attr_parsing/src/context.rs +++ b/compiler/rustc_attr_parsing/src/context.rs @@ -35,7 +35,7 @@ use crate::attributes::diagnostic::on_move::*; use crate::attributes::diagnostic::on_type_error::*; use crate::attributes::diagnostic::on_unimplemented::*; use crate::attributes::diagnostic::on_unknown::*; -use crate::attributes::diagnostic::on_unmatch_args::*; +use crate::attributes::diagnostic::on_unmatched_args::*; use crate::attributes::doc::*; use crate::attributes::dummy::*; use crate::attributes::inline::*; @@ -149,7 +149,7 @@ attribute_parsers!( OnTypeErrorParser, OnUnimplementedParser, OnUnknownParser, - OnUnmatchArgsParser, + OnUnmatchedArgsParser, RustcAlignParser, RustcAlignStaticParser, RustcCguTestAttributeParser, diff --git a/compiler/rustc_attr_parsing/src/diagnostics.rs b/compiler/rustc_attr_parsing/src/diagnostics.rs index 7cca75462ab8c..98b72f2fa97f6 100644 --- a/compiler/rustc_attr_parsing/src/diagnostics.rs +++ b/compiler/rustc_attr_parsing/src/diagnostics.rs @@ -302,8 +302,8 @@ pub(crate) struct DiagnosticOnUnknownOnlyForImports { } #[derive(Diagnostic)] -#[diag("`#[diagnostic::on_unmatch_args]` can only be applied to macro definitions")] -pub(crate) struct DiagnosticOnUnmatchArgsOnlyForMacros; +#[diag("`#[diagnostic::on_unmatched_args]` can only be applied to macro definitions")] +pub(crate) struct DiagnosticOnUnmatchedArgsOnlyForMacros; #[derive(Diagnostic)] #[diag("`#[diagnostic::on_type_error]` can only be applied to enums, structs or unions")] diff --git a/compiler/rustc_expand/src/mbe/diagnostics.rs b/compiler/rustc_expand/src/mbe/diagnostics.rs index 7abf3ac308805..a80842c8def18 100644 --- a/compiler/rustc_expand/src/mbe/diagnostics.rs +++ b/compiler/rustc_expand/src/mbe/diagnostics.rs @@ -33,7 +33,7 @@ pub(super) fn failed_to_match_macro( args: FailedMacro<'_>, body: &TokenStream, rules: &[MacroRule], - on_unmatch_args: Option<&Directive>, + on_unmatched_args: Option<&Directive>, ) -> (Span, ErrorGuaranteed) { debug!("failed to match macro"); let def_head_span = if !def_span.is_dummy() && !psess.source_map().is_imported(def_span) { @@ -77,7 +77,7 @@ pub(super) fn failed_to_match_macro( let CustomDiagnostic { message: custom_message, label: custom_label, notes: custom_notes, .. } = { - on_unmatch_args + on_unmatched_args .map(|directive| directive.eval(None, &FormatArgs { this: name.to_string(), .. })) .unwrap_or_default() }; diff --git a/compiler/rustc_expand/src/mbe/macro_rules.rs b/compiler/rustc_expand/src/mbe/macro_rules.rs index 1a1ef0f06963e..e50ffb556b3ba 100644 --- a/compiler/rustc_expand/src/mbe/macro_rules.rs +++ b/compiler/rustc_expand/src/mbe/macro_rules.rs @@ -166,7 +166,7 @@ pub struct MacroRulesMacroExpander { node_id: NodeId, name: Ident, span: Span, - on_unmatch_args: Option, + on_unmatched_args: Option, transparency: Transparency, kinds: MacroKinds, rules: Vec, @@ -249,7 +249,7 @@ impl MacroRulesMacroExpander { FailedMacro::Derive, body, rules, - self.on_unmatch_args.as_ref(), + self.on_unmatched_args.as_ref(), ); cx.macro_error_and_trace_macros_diag(); Err(guar) @@ -274,7 +274,7 @@ impl TTMacroExpander for MacroRulesMacroExpander { self.transparency, input, &self.rules, - self.on_unmatch_args.as_ref(), + self.on_unmatched_args.as_ref(), )) } } @@ -309,7 +309,7 @@ impl AttrProcMacro for MacroRulesMacroExpander { args, body, &self.rules, - self.on_unmatch_args.as_ref(), + self.on_unmatched_args.as_ref(), ) } } @@ -371,7 +371,7 @@ impl<'matcher> Tracker<'matcher> for NoopTracker { } /// Expands the rules based macro defined by `rules` for a given input `arg`. -#[instrument(skip(cx, transparency, arg, rules, on_unmatch_args))] +#[instrument(skip(cx, transparency, arg, rules, on_unmatched_args))] fn expand_macro<'cx, 'a: 'cx>( cx: &'cx mut ExtCtxt<'_>, sp: Span, @@ -381,7 +381,7 @@ fn expand_macro<'cx, 'a: 'cx>( transparency: Transparency, arg: TokenStream, rules: &'a [MacroRule], - on_unmatch_args: Option<&Directive>, + on_unmatched_args: Option<&Directive>, ) -> Box { let psess = &cx.sess.psess; @@ -440,7 +440,7 @@ fn expand_macro<'cx, 'a: 'cx>( FailedMacro::Func, &arg, rules, - on_unmatch_args, + on_unmatched_args, ); cx.macro_error_and_trace_macros_diag(); DummyResult::any(span, guar) @@ -449,7 +449,7 @@ fn expand_macro<'cx, 'a: 'cx>( } /// Expands the rules based macro defined by `rules` for a given attribute `args` and `body`. -#[instrument(skip(cx, transparency, args, body, rules, on_unmatch_args))] +#[instrument(skip(cx, transparency, args, body, rules, on_unmatched_args))] fn expand_macro_attr( cx: &mut ExtCtxt<'_>, sp: Span, @@ -461,7 +461,7 @@ fn expand_macro_attr( args: TokenStream, body: TokenStream, rules: &[MacroRule], - on_unmatch_args: Option<&Directive>, + on_unmatched_args: Option<&Directive>, ) -> Result { let psess = &cx.sess.psess; // Macros defined in the current crate have a real node id, @@ -526,7 +526,7 @@ fn expand_macro_attr( FailedMacro::Attr(&args), &body, rules, - on_unmatch_args, + on_unmatched_args, ); cx.trace_macros_diag(); Err(guar) @@ -865,9 +865,9 @@ pub fn compile_declarative_macro( return dummy_syn_ext(guar); } - let on_unmatch_args = find_attr!( + let on_unmatched_args = find_attr!( attrs, - OnUnmatchArgs { directive, .. } => directive.clone() + OnUnmatchedArgs { directive, .. } => directive.clone() ) .flatten() .map(|directive| *directive); @@ -877,7 +877,7 @@ pub fn compile_declarative_macro( kinds, span, node_id, - on_unmatch_args, + on_unmatched_args, transparency, rules, macro_rules, diff --git a/compiler/rustc_hir/src/attrs/data_structures.rs b/compiler/rustc_hir/src/attrs/data_structures.rs index dc850e22ef5ea..bf9f0709bbdc4 100644 --- a/compiler/rustc_hir/src/attrs/data_structures.rs +++ b/compiler/rustc_hir/src/attrs/data_structures.rs @@ -1191,8 +1191,8 @@ pub enum AttributeKind { directive: Option>, }, - /// Represents `#[diagnostic::on_unmatch_args]`. - OnUnmatchArgs { + /// Represents `#[diagnostic::on_unmatched_args]`. + OnUnmatchedArgs { /// None if the directive was malformed in some way. directive: Option>, }, diff --git a/compiler/rustc_hir/src/attrs/encode_cross_crate.rs b/compiler/rustc_hir/src/attrs/encode_cross_crate.rs index 40ec566b43d11..11dcd37816bd6 100644 --- a/compiler/rustc_hir/src/attrs/encode_cross_crate.rs +++ b/compiler/rustc_hir/src/attrs/encode_cross_crate.rs @@ -81,7 +81,7 @@ impl AttributeKind { OnTypeError { .. } => Yes, OnUnimplemented { .. } => Yes, OnUnknown { .. } => Yes, - OnUnmatchArgs { .. } => Yes, + OnUnmatchedArgs { .. } => Yes, Optimize(..) => No, PanicRuntime => No, PatchableFunctionEntry { .. } => Yes, diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index e639b9e3b0709..ec94e33e92c69 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -301,7 +301,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { AttributeKind::NoMangle(..) => (), AttributeKind::NoStd { .. } => (), AttributeKind::OnUnknown { .. } => (), - AttributeKind::OnUnmatchArgs { .. } => (), + AttributeKind::OnUnmatchedArgs { .. } => (), AttributeKind::Optimize(..) => (), AttributeKind::PanicRuntime => (), AttributeKind::PatchableFunctionEntry { .. } => (), diff --git a/compiler/rustc_resolve/src/macros.rs b/compiler/rustc_resolve/src/macros.rs index 9c92ce85f44e8..25eb2c5d8413d 100644 --- a/compiler/rustc_resolve/src/macros.rs +++ b/compiler/rustc_resolve/src/macros.rs @@ -719,7 +719,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { (sym::on_move, Some(sym::diagnostic_on_move)), (sym::on_const, Some(sym::diagnostic_on_const)), (sym::on_unknown, Some(sym::diagnostic_on_unknown)), - (sym::on_unmatch_args, Some(sym::diagnostic_on_unmatch_args)), + (sym::on_unmatched_args, Some(sym::diagnostic_on_unmatch_args)), (sym::on_type_error, Some(sym::diagnostic_on_type_error)), ]; diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index c5410563f65e0..c87cb1e74d7ea 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1458,7 +1458,7 @@ symbols! { on_type_error, on_unimplemented, on_unknown, - on_unmatch_args, + on_unmatched_args, opaque, opaque_module_name_placeholder: "", ops, diff --git a/library/core/src/field.rs b/library/core/src/field.rs index 90d16e5f2af5f..33b978c786b53 100644 --- a/library/core/src/field.rs +++ b/library/core/src/field.rs @@ -125,7 +125,7 @@ impl Ord /// variant must also be specified. Only a single field is supported. #[unstable(feature = "field_projections", issue = "145383")] #[allow_internal_unstable(field_representing_type_raw, builtin_syntax)] -#[diagnostic::on_unmatch_args( +#[diagnostic::on_unmatched_args( note = "this macro expects a container type and a field path, like `field_of!(Type, field)` or `field_of!(Enum, Variant.field)`" )] // NOTE: when stabilizing this macro, we can never add new trait impls for `FieldRepresentingType`, diff --git a/library/core/src/mem/mod.rs b/library/core/src/mem/mod.rs index 565c23e1ca48b..828572df6968b 100644 --- a/library/core/src/mem/mod.rs +++ b/library/core/src/mem/mod.rs @@ -1604,7 +1604,7 @@ impl SizedTypeProperties for T {} /// [`offset_of_enum`]: https://doc.rust-lang.org/nightly/unstable-book/language-features/offset-of-enum.html /// [`offset_of_slice`]: https://doc.rust-lang.org/nightly/unstable-book/language-features/offset-of-slice.html #[stable(feature = "offset_of", since = "1.77.0")] -#[diagnostic::on_unmatch_args( +#[diagnostic::on_unmatched_args( note = "this macro expects a container type and a (nested) field path, like `offset_of!(Type, field)`" )] #[doc(alias = "memoffset")] diff --git a/src/doc/unstable-book/src/language-features/diagnostic-on-unmatch-args.md b/src/doc/unstable-book/src/language-features/diagnostic-on-unmatch-args.md index 514ad1969bb0f..5ef88eeefea1c 100644 --- a/src/doc/unstable-book/src/language-features/diagnostic-on-unmatch-args.md +++ b/src/doc/unstable-book/src/language-features/diagnostic-on-unmatch-args.md @@ -7,7 +7,7 @@ The tracking issue for this feature is: [#155642] ------------------------ The `diagnostic_on_unmatch_args` feature adds the -`#[diagnostic::on_unmatch_args(...)]` attribute for declarative macros. +`#[diagnostic::on_unmatched_args(...)]` attribute for declarative macros. It lets a macro definition customize diagnostics for matcher failures after all arms have been tried, such as incomplete invocations or trailing extra arguments. @@ -18,7 +18,7 @@ errors still use their existing diagnostics. ```rust,compile_fail #![feature(diagnostic_on_unmatch_args)] -#[diagnostic::on_unmatch_args( +#[diagnostic::on_unmatched_args( message = "invalid arguments to {This} macro invocation", label = "expected a type and value here", note = "this macro expects a type and a value, like `pair!(u8, 0)`", diff --git a/tests/ui/diagnostic_namespace/on_unmatch_args/report_warning_on_non_macro.rs b/tests/ui/diagnostic_namespace/on_unmatch_args/report_warning_on_non_macro.rs deleted file mode 100644 index 6f8629d679a0c..0000000000000 --- a/tests/ui/diagnostic_namespace/on_unmatch_args/report_warning_on_non_macro.rs +++ /dev/null @@ -1,10 +0,0 @@ -//@ check-pass -#![feature(diagnostic_on_unmatch_args)] - -#[diagnostic::on_unmatch_args(message = "not allowed here")] -//~^ WARN `#[diagnostic::on_unmatch_args]` can only be applied to macro definitions -struct Foo; - -fn main() { - let _ = Foo; -} diff --git a/tests/ui/diagnostic_namespace/on_unmatch_args/report_warning_on_unknown_options.rs b/tests/ui/diagnostic_namespace/on_unmatch_args/report_warning_on_unknown_options.rs deleted file mode 100644 index b1e50256dc886..0000000000000 --- a/tests/ui/diagnostic_namespace/on_unmatch_args/report_warning_on_unknown_options.rs +++ /dev/null @@ -1,12 +0,0 @@ -//@ check-pass -#![feature(diagnostic_on_unmatch_args)] - -#[diagnostic::on_unmatch_args(unsupported = "foo")] -//~^ WARN malformed `diagnostic::on_unmatch_args` attribute [malformed_diagnostic_attributes] -macro_rules! pair { - ($ty:ty, $value:expr) => {}; -} - -fn main() { - pair!(u8, 0); -} diff --git a/tests/ui/diagnostic_namespace/on_unmatch_args/report_warning_on_unknown_options.stderr b/tests/ui/diagnostic_namespace/on_unmatch_args/report_warning_on_unknown_options.stderr deleted file mode 100644 index 2e897a6b180da..0000000000000 --- a/tests/ui/diagnostic_namespace/on_unmatch_args/report_warning_on_unknown_options.stderr +++ /dev/null @@ -1,11 +0,0 @@ -warning: malformed `diagnostic::on_unmatch_args` attribute - --> $DIR/report_warning_on_unknown_options.rs:4:31 - | -LL | #[diagnostic::on_unmatch_args(unsupported = "foo")] - | ^^^^^^^^^^^^^^^^^^^ invalid option found here - | - = help: only `message`, `note` and `label` are allowed as options - = note: `#[warn(malformed_diagnostic_attributes)]` (part of `#[warn(unknown_or_malformed_diagnostic_attributes)]`) on by default - -warning: 1 warning emitted - diff --git a/tests/ui/diagnostic_namespace/on_unmatch_args/auxiliary/other.rs b/tests/ui/diagnostic_namespace/on_unmatched_args/auxiliary/other.rs similarity index 91% rename from tests/ui/diagnostic_namespace/on_unmatch_args/auxiliary/other.rs rename to tests/ui/diagnostic_namespace/on_unmatched_args/auxiliary/other.rs index 2dd032ecf41cb..9703e61182390 100644 --- a/tests/ui/diagnostic_namespace/on_unmatch_args/auxiliary/other.rs +++ b/tests/ui/diagnostic_namespace/on_unmatched_args/auxiliary/other.rs @@ -1,7 +1,7 @@ #![feature(diagnostic_on_unmatch_args)] #[macro_export] -#[diagnostic::on_unmatch_args( +#[diagnostic::on_unmatched_args( message = "invalid arguments to {This} macro invocation", label = "expected a type and value here", note = "this macro expects a type and a value, like `pair!(u8, 0)`", diff --git a/tests/ui/diagnostic_namespace/on_unmatch_args/error_is_shown_in_downstream_crates.rs b/tests/ui/diagnostic_namespace/on_unmatched_args/error_is_shown_in_downstream_crates.rs similarity index 100% rename from tests/ui/diagnostic_namespace/on_unmatch_args/error_is_shown_in_downstream_crates.rs rename to tests/ui/diagnostic_namespace/on_unmatched_args/error_is_shown_in_downstream_crates.rs diff --git a/tests/ui/diagnostic_namespace/on_unmatch_args/error_is_shown_in_downstream_crates.stderr b/tests/ui/diagnostic_namespace/on_unmatched_args/error_is_shown_in_downstream_crates.stderr similarity index 100% rename from tests/ui/diagnostic_namespace/on_unmatch_args/error_is_shown_in_downstream_crates.stderr rename to tests/ui/diagnostic_namespace/on_unmatched_args/error_is_shown_in_downstream_crates.stderr diff --git a/tests/ui/diagnostic_namespace/on_unmatch_args/message_and_label.rs b/tests/ui/diagnostic_namespace/on_unmatched_args/message_and_label.rs similarity index 95% rename from tests/ui/diagnostic_namespace/on_unmatch_args/message_and_label.rs rename to tests/ui/diagnostic_namespace/on_unmatched_args/message_and_label.rs index 26a8b07bd6e48..38fd3368391fd 100644 --- a/tests/ui/diagnostic_namespace/on_unmatch_args/message_and_label.rs +++ b/tests/ui/diagnostic_namespace/on_unmatched_args/message_and_label.rs @@ -1,6 +1,6 @@ #![feature(diagnostic_on_unmatch_args)] -#[diagnostic::on_unmatch_args( +#[diagnostic::on_unmatched_args( message = "invalid arguments to {This} macro invocation", label = "expected a type and value here", note = "this macro expects a type and a value, like `pair!(u8, 0)`", diff --git a/tests/ui/diagnostic_namespace/on_unmatch_args/message_and_label.stderr b/tests/ui/diagnostic_namespace/on_unmatched_args/message_and_label.stderr similarity index 100% rename from tests/ui/diagnostic_namespace/on_unmatch_args/message_and_label.stderr rename to tests/ui/diagnostic_namespace/on_unmatched_args/message_and_label.stderr diff --git a/tests/ui/diagnostic_namespace/on_unmatch_args/notes_on_extra_args.rs b/tests/ui/diagnostic_namespace/on_unmatched_args/notes_on_extra_args.rs similarity index 95% rename from tests/ui/diagnostic_namespace/on_unmatch_args/notes_on_extra_args.rs rename to tests/ui/diagnostic_namespace/on_unmatched_args/notes_on_extra_args.rs index 083445c7f9691..d76c84be24def 100644 --- a/tests/ui/diagnostic_namespace/on_unmatch_args/notes_on_extra_args.rs +++ b/tests/ui/diagnostic_namespace/on_unmatched_args/notes_on_extra_args.rs @@ -1,6 +1,6 @@ #![feature(diagnostic_on_unmatch_args)] -#[diagnostic::on_unmatch_args( +#[diagnostic::on_unmatched_args( message = "{This}! expects exactly two arguments", label = "unexpected extra input starts here", note = "this macro expects a type and a value, like `pair!(u8, 0)`", diff --git a/tests/ui/diagnostic_namespace/on_unmatch_args/notes_on_extra_args.stderr b/tests/ui/diagnostic_namespace/on_unmatched_args/notes_on_extra_args.stderr similarity index 100% rename from tests/ui/diagnostic_namespace/on_unmatch_args/notes_on_extra_args.stderr rename to tests/ui/diagnostic_namespace/on_unmatched_args/notes_on_extra_args.stderr diff --git a/tests/ui/diagnostic_namespace/on_unmatch_args/on_unmatch_args.rs b/tests/ui/diagnostic_namespace/on_unmatched_args/on_unmatched_args.rs similarity index 94% rename from tests/ui/diagnostic_namespace/on_unmatch_args/on_unmatch_args.rs rename to tests/ui/diagnostic_namespace/on_unmatched_args/on_unmatched_args.rs index a4fc1460b60ed..77f6d8dadf6f4 100644 --- a/tests/ui/diagnostic_namespace/on_unmatch_args/on_unmatch_args.rs +++ b/tests/ui/diagnostic_namespace/on_unmatched_args/on_unmatched_args.rs @@ -1,6 +1,6 @@ #![feature(diagnostic_on_unmatch_args)] -#[diagnostic::on_unmatch_args( +#[diagnostic::on_unmatched_args( note = "this macro expects a type and a value, like `pair!(u8, 0)`", note = "make sure to pass both arguments", )] diff --git a/tests/ui/diagnostic_namespace/on_unmatch_args/on_unmatch_args.stderr b/tests/ui/diagnostic_namespace/on_unmatched_args/on_unmatched_args.stderr similarity index 85% rename from tests/ui/diagnostic_namespace/on_unmatch_args/on_unmatch_args.stderr rename to tests/ui/diagnostic_namespace/on_unmatched_args/on_unmatched_args.stderr index 9d3c4a5392cde..3e9a7a969fd9e 100644 --- a/tests/ui/diagnostic_namespace/on_unmatch_args/on_unmatch_args.stderr +++ b/tests/ui/diagnostic_namespace/on_unmatched_args/on_unmatched_args.stderr @@ -1,5 +1,5 @@ error: unexpected end of macro invocation - --> $DIR/on_unmatch_args.rs:14:13 + --> $DIR/on_unmatched_args.rs:14:13 | LL | macro_rules! pair { | ----------------- when calling this macro @@ -8,7 +8,7 @@ LL | pair!(u8); | ^ missing tokens in macro arguments | note: while trying to match `,` - --> $DIR/on_unmatch_args.rs:9:12 + --> $DIR/on_unmatched_args.rs:9:12 | LL | ($ty:ty, $value:expr) => {}; | ^ diff --git a/tests/ui/diagnostic_namespace/on_unmatch_args/other_match_macro_error.rs b/tests/ui/diagnostic_namespace/on_unmatched_args/other_match_macro_error.rs similarity index 89% rename from tests/ui/diagnostic_namespace/on_unmatch_args/other_match_macro_error.rs rename to tests/ui/diagnostic_namespace/on_unmatched_args/other_match_macro_error.rs index 36197997b3e60..acf91c6cc0489 100644 --- a/tests/ui/diagnostic_namespace/on_unmatch_args/other_match_macro_error.rs +++ b/tests/ui/diagnostic_namespace/on_unmatched_args/other_match_macro_error.rs @@ -1,6 +1,6 @@ #![feature(diagnostic_on_unmatch_args)] -#[diagnostic::on_unmatch_args( +#[diagnostic::on_unmatched_args( message = "invalid route method", note = "this macro expects a action, like `{This}!(get \"/hello\")`" )] diff --git a/tests/ui/diagnostic_namespace/on_unmatch_args/other_match_macro_error.stderr b/tests/ui/diagnostic_namespace/on_unmatched_args/other_match_macro_error.stderr similarity index 100% rename from tests/ui/diagnostic_namespace/on_unmatch_args/other_match_macro_error.stderr rename to tests/ui/diagnostic_namespace/on_unmatched_args/other_match_macro_error.stderr diff --git a/tests/ui/diagnostic_namespace/on_unmatch_args/report_warning_on_invalid_formats.rs b/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_invalid_formats.rs similarity index 89% rename from tests/ui/diagnostic_namespace/on_unmatch_args/report_warning_on_invalid_formats.rs rename to tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_invalid_formats.rs index 1fcaca8300f85..98dd11664c91e 100644 --- a/tests/ui/diagnostic_namespace/on_unmatch_args/report_warning_on_invalid_formats.rs +++ b/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_invalid_formats.rs @@ -1,9 +1,9 @@ //@ check-pass #![feature(diagnostic_on_unmatch_args)] -#[diagnostic::on_unmatch_args( +#[diagnostic::on_unmatched_args( message = "{T}! is missing arguments", - //~^ WARN this format argument is not allowed in `#[diagnostic::on_unmatch_args]` + //~^ WARN this format argument is not allowed in `#[diagnostic::on_unmatched_args]` //~| NOTE only `This` is allowed as a format argument //~| NOTE remove this format argument //~| NOTE `#[warn(malformed_diagnostic_format_literals)]` (part of `#[warn(unknown_or_malformed_diagnostic_attributes)]`) on by default diff --git a/tests/ui/diagnostic_namespace/on_unmatch_args/report_warning_on_invalid_formats.stderr b/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_invalid_formats.stderr similarity index 96% rename from tests/ui/diagnostic_namespace/on_unmatch_args/report_warning_on_invalid_formats.stderr rename to tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_invalid_formats.stderr index fd68ad5570f31..e814ecacc006c 100644 --- a/tests/ui/diagnostic_namespace/on_unmatch_args/report_warning_on_invalid_formats.stderr +++ b/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_invalid_formats.stderr @@ -1,4 +1,4 @@ -warning: this format argument is not allowed in `#[diagnostic::on_unmatch_args]` +warning: this format argument is not allowed in `#[diagnostic::on_unmatched_args]` --> $DIR/report_warning_on_invalid_formats.rs:5:17 | LL | message = "{T}! is missing arguments", diff --git a/tests/ui/diagnostic_namespace/on_unmatch_args/report_warning_on_invalid_meta_item_syntax.rs b/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_invalid_meta_item_syntax.rs similarity index 51% rename from tests/ui/diagnostic_namespace/on_unmatch_args/report_warning_on_invalid_meta_item_syntax.rs rename to tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_invalid_meta_item_syntax.rs index aa5371de07c09..3da1d3e73a63e 100644 --- a/tests/ui/diagnostic_namespace/on_unmatch_args/report_warning_on_invalid_meta_item_syntax.rs +++ b/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_invalid_meta_item_syntax.rs @@ -1,8 +1,8 @@ //@ check-pass #![feature(diagnostic_on_unmatch_args)] -#[diagnostic::on_unmatch_args = "foo"] -//~^ WARN malformed `diagnostic::on_unmatch_args` attribute [malformed_diagnostic_attributes] +#[diagnostic::on_unmatched_args = "foo"] +//~^ WARN malformed `diagnostic::on_unmatched_args` attribute [malformed_diagnostic_attributes] macro_rules! pair { ($ty:ty, $value:expr) => {}; } diff --git a/tests/ui/diagnostic_namespace/on_unmatch_args/report_warning_on_invalid_meta_item_syntax.stderr b/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_invalid_meta_item_syntax.stderr similarity index 62% rename from tests/ui/diagnostic_namespace/on_unmatch_args/report_warning_on_invalid_meta_item_syntax.stderr rename to tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_invalid_meta_item_syntax.stderr index 51f25f1165d60..488abeb097d6e 100644 --- a/tests/ui/diagnostic_namespace/on_unmatch_args/report_warning_on_invalid_meta_item_syntax.stderr +++ b/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_invalid_meta_item_syntax.stderr @@ -1,8 +1,8 @@ -warning: malformed `diagnostic::on_unmatch_args` attribute +warning: malformed `diagnostic::on_unmatched_args` attribute --> $DIR/report_warning_on_invalid_meta_item_syntax.rs:4:1 | -LL | #[diagnostic::on_unmatch_args = "foo"] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid option found here +LL | #[diagnostic::on_unmatched_args = "foo"] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid option found here | = help: only `message`, `note` and `label` are allowed as options = note: `#[warn(malformed_diagnostic_attributes)]` (part of `#[warn(unknown_or_malformed_diagnostic_attributes)]`) on by default diff --git a/tests/ui/diagnostic_namespace/on_unmatch_args/report_warning_on_missing_options.rs b/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_missing_options.rs similarity index 50% rename from tests/ui/diagnostic_namespace/on_unmatch_args/report_warning_on_missing_options.rs rename to tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_missing_options.rs index 13eec1834d7cd..06d4133b027de 100644 --- a/tests/ui/diagnostic_namespace/on_unmatch_args/report_warning_on_missing_options.rs +++ b/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_missing_options.rs @@ -1,8 +1,8 @@ //@ check-pass #![feature(diagnostic_on_unmatch_args)] -#[diagnostic::on_unmatch_args] -//~^ WARN missing options for `diagnostic::on_unmatch_args` attribute [malformed_diagnostic_attributes] +#[diagnostic::on_unmatched_args] +//~^ WARN missing options for `diagnostic::on_unmatched_args` attribute [malformed_diagnostic_attributes] macro_rules! pair { ($ty:ty, $value:expr) => {}; } diff --git a/tests/ui/diagnostic_namespace/on_unmatch_args/report_warning_on_missing_options.stderr b/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_missing_options.stderr similarity index 67% rename from tests/ui/diagnostic_namespace/on_unmatch_args/report_warning_on_missing_options.stderr rename to tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_missing_options.stderr index bbd8dba4e6206..f0af014cfc6c7 100644 --- a/tests/ui/diagnostic_namespace/on_unmatch_args/report_warning_on_missing_options.stderr +++ b/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_missing_options.stderr @@ -1,8 +1,8 @@ -warning: missing options for `diagnostic::on_unmatch_args` attribute +warning: missing options for `diagnostic::on_unmatched_args` attribute --> $DIR/report_warning_on_missing_options.rs:4:1 | -LL | #[diagnostic::on_unmatch_args] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[diagnostic::on_unmatched_args] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: at least one of the `message`, `note` and `label` options are expected = note: `#[warn(malformed_diagnostic_attributes)]` (part of `#[warn(unknown_or_malformed_diagnostic_attributes)]`) on by default diff --git a/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_non_macro.rs b/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_non_macro.rs new file mode 100644 index 0000000000000..6a0f117f61f3f --- /dev/null +++ b/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_non_macro.rs @@ -0,0 +1,10 @@ +//@ check-pass +#![feature(diagnostic_on_unmatch_args)] + +#[diagnostic::on_unmatched_args(message = "not allowed here")] +//~^ WARN `#[diagnostic::on_unmatched_args]` can only be applied to macro definitions +struct Foo; + +fn main() { + let _ = Foo; +} diff --git a/tests/ui/diagnostic_namespace/on_unmatch_args/report_warning_on_non_macro.stderr b/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_non_macro.stderr similarity index 64% rename from tests/ui/diagnostic_namespace/on_unmatch_args/report_warning_on_non_macro.stderr rename to tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_non_macro.stderr index c6d1b620c44be..10c6fd9ce8bea 100644 --- a/tests/ui/diagnostic_namespace/on_unmatch_args/report_warning_on_non_macro.stderr +++ b/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_non_macro.stderr @@ -1,8 +1,8 @@ -warning: `#[diagnostic::on_unmatch_args]` can only be applied to macro definitions +warning: `#[diagnostic::on_unmatched_args]` can only be applied to macro definitions --> $DIR/report_warning_on_non_macro.rs:4:1 | -LL | #[diagnostic::on_unmatch_args(message = "not allowed here")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[diagnostic::on_unmatched_args(message = "not allowed here")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(misplaced_diagnostic_attributes)]` (part of `#[warn(unknown_or_malformed_diagnostic_attributes)]`) on by default diff --git a/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_unknown_options.rs b/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_unknown_options.rs new file mode 100644 index 0000000000000..61aa9e5af1989 --- /dev/null +++ b/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_unknown_options.rs @@ -0,0 +1,12 @@ +//@ check-pass +#![feature(diagnostic_on_unmatch_args)] + +#[diagnostic::on_unmatched_args(unsupported = "foo")] +//~^ WARN malformed `diagnostic::on_unmatched_args` attribute [malformed_diagnostic_attributes] +macro_rules! pair { + ($ty:ty, $value:expr) => {}; +} + +fn main() { + pair!(u8, 0); +} diff --git a/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_unknown_options.stderr b/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_unknown_options.stderr new file mode 100644 index 0000000000000..194aeed3f5d88 --- /dev/null +++ b/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_unknown_options.stderr @@ -0,0 +1,11 @@ +warning: malformed `diagnostic::on_unmatched_args` attribute + --> $DIR/report_warning_on_unknown_options.rs:4:33 + | +LL | #[diagnostic::on_unmatched_args(unsupported = "foo")] + | ^^^^^^^^^^^^^^^^^^^ invalid option found here + | + = help: only `message`, `note` and `label` are allowed as options + = note: `#[warn(malformed_diagnostic_attributes)]` (part of `#[warn(unknown_or_malformed_diagnostic_attributes)]`) on by default + +warning: 1 warning emitted + diff --git a/tests/ui/feature-gates/feature-gate-diagnostic-on-unmatch-args.rs b/tests/ui/feature-gates/feature-gate-diagnostic-on-unmatch-args.rs index 72686d1003279..97f7211465a67 100644 --- a/tests/ui/feature-gates/feature-gate-diagnostic-on-unmatch-args.rs +++ b/tests/ui/feature-gates/feature-gate-diagnostic-on-unmatch-args.rs @@ -1,7 +1,7 @@ //! This is an unusual feature gate test, as it doesn't test the feature //! gate, but the fact that not adding the feature gate will cause the //! diagnostic to not emit the custom diagnostic message. -#[diagnostic::on_unmatch_args(note = "custom note")] +#[diagnostic::on_unmatched_args(note = "custom note")] macro_rules! pair { //~^ NOTE when calling this macro ($ty:ty, $value:expr) => {}; From 69a17b186f401e388677671124a871905ccaeab2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Sun, 14 Jun 2026 14:53:12 +0200 Subject: [PATCH 2/2] Rename feature `diagnostic_on_unmatch_args` to `diagnostic_on_unmatched_args` --- .../src/attributes/diagnostic/on_unmatched_args.rs | 2 +- compiler/rustc_feature/src/removed.rs | 2 ++ compiler/rustc_feature/src/unstable.rs | 2 +- compiler/rustc_resolve/src/macros.rs | 2 +- compiler/rustc_span/src/symbol.rs | 1 + library/core/src/lib.rs | 2 +- ...c-on-unmatch-args.md => diagnostic-on-unmatched-args.md} | 6 +++--- .../on_unmatched_args/auxiliary/other.rs | 2 +- .../on_unmatched_args/message_and_label.rs | 2 +- .../on_unmatched_args/notes_on_extra_args.rs | 2 +- .../on_unmatched_args/on_unmatched_args.rs | 2 +- .../on_unmatched_args/other_match_macro_error.rs | 2 +- .../on_unmatched_args/report_warning_on_invalid_formats.rs | 2 +- .../report_warning_on_invalid_meta_item_syntax.rs | 2 +- .../on_unmatched_args/report_warning_on_missing_options.rs | 2 +- .../on_unmatched_args/report_warning_on_non_macro.rs | 2 +- .../on_unmatched_args/report_warning_on_unknown_options.rs | 2 +- ...args.rs => feature-gate-diagnostic-on-unmatched-args.rs} | 0 ...err => feature-gate-diagnostic-on-unmatched-args.stderr} | 4 ++-- 19 files changed, 22 insertions(+), 19 deletions(-) rename src/doc/unstable-book/src/language-features/{diagnostic-on-unmatch-args.md => diagnostic-on-unmatched-args.md} (91%) rename tests/ui/feature-gates/{feature-gate-diagnostic-on-unmatch-args.rs => feature-gate-diagnostic-on-unmatched-args.rs} (100%) rename tests/ui/feature-gates/{feature-gate-diagnostic-on-unmatch-args.stderr => feature-gate-diagnostic-on-unmatched-args.stderr} (73%) diff --git a/compiler/rustc_attr_parsing/src/attributes/diagnostic/on_unmatched_args.rs b/compiler/rustc_attr_parsing/src/attributes/diagnostic/on_unmatched_args.rs index 3a66052dd08d7..17b9fcd52d225 100644 --- a/compiler/rustc_attr_parsing/src/attributes/diagnostic/on_unmatched_args.rs +++ b/compiler/rustc_attr_parsing/src/attributes/diagnostic/on_unmatched_args.rs @@ -18,7 +18,7 @@ impl AttributeParser for OnUnmatchedArgsParser { template!(List: &[r#"/*opt*/ message = "...", /*opt*/ label = "...", /*opt*/ note = "...""#]), AttributeStability::Stable, // Unstable, stability checked manually in the parser |this, cx, args| { - if !cx.features().diagnostic_on_unmatch_args() { + if !cx.features().diagnostic_on_unmatched_args() { return; } diff --git a/compiler/rustc_feature/src/removed.rs b/compiler/rustc_feature/src/removed.rs index 431461e1ddf15..ab24b0ed37d22 100644 --- a/compiler/rustc_feature/src/removed.rs +++ b/compiler/rustc_feature/src/removed.rs @@ -106,6 +106,8 @@ declare_features! ( (removed, deprecated_safe, "1.95.0", Some(94978), Some("never properly implemented, in the way of attribute refactor"), 152554), /// Allows deriving traits as per `SmartPointer` specification (removed, derive_smart_pointer, "1.84.0", Some(123430), Some("replaced by `CoercePointee`"), 131284), + /// Allows macros to customize macro argument matcher diagnostics. + (removed, diagnostic_on_unmatch_args, "CURRENT_RUSTC_VERSION", Some(155642), Some("renamed to `diagnostic_on_unmatched_args`"), 157887), /// Tells rustdoc to automatically generate `#[doc(cfg(...))]`. (removed, doc_auto_cfg, "1.92.0", Some(43781), Some("merged into `doc_cfg`"), 138907), /// Allows `#[doc(cfg_hide(...))]`. diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index 9220b31a1cce0..675ad38d7a0e2 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -515,7 +515,7 @@ declare_features! ( /// Allows giving unresolved imports a custom diagnostic message (unstable, diagnostic_on_unknown, "1.96.0", Some(152900)), /// Allows macros to customize macro argument matcher diagnostics. - (unstable, diagnostic_on_unmatch_args, "1.97.0", Some(155642)), + (unstable, diagnostic_on_unmatched_args, "1.97.0", Some(155642)), /// Allows `#[doc(cfg(...))]`. (unstable, doc_cfg, "1.21.0", Some(43781)), /// Allows `#[doc(masked)]`. diff --git a/compiler/rustc_resolve/src/macros.rs b/compiler/rustc_resolve/src/macros.rs index 25eb2c5d8413d..2a5c2e6c2df83 100644 --- a/compiler/rustc_resolve/src/macros.rs +++ b/compiler/rustc_resolve/src/macros.rs @@ -719,7 +719,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { (sym::on_move, Some(sym::diagnostic_on_move)), (sym::on_const, Some(sym::diagnostic_on_const)), (sym::on_unknown, Some(sym::diagnostic_on_unknown)), - (sym::on_unmatched_args, Some(sym::diagnostic_on_unmatch_args)), + (sym::on_unmatched_args, Some(sym::diagnostic_on_unmatched_args)), (sym::on_type_error, Some(sym::diagnostic_on_type_error)), ]; diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index c87cb1e74d7ea..f544521d4cbfe 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -816,6 +816,7 @@ symbols! { diagnostic_on_type_error, diagnostic_on_unknown, diagnostic_on_unmatch_args, + diagnostic_on_unmatched_args, dialect, direct, discriminant_kind, diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 192c5eff29e10..a26304c46ecea 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -131,7 +131,7 @@ #![feature(deprecated_suggestion)] #![feature(derive_const)] #![feature(diagnostic_on_const)] -#![feature(diagnostic_on_unmatch_args)] +#![feature(diagnostic_on_unmatched_args)] #![feature(doc_cfg)] #![feature(doc_notable_trait)] #![feature(extern_types)] diff --git a/src/doc/unstable-book/src/language-features/diagnostic-on-unmatch-args.md b/src/doc/unstable-book/src/language-features/diagnostic-on-unmatched-args.md similarity index 91% rename from src/doc/unstable-book/src/language-features/diagnostic-on-unmatch-args.md rename to src/doc/unstable-book/src/language-features/diagnostic-on-unmatched-args.md index 5ef88eeefea1c..830adcf34acdb 100644 --- a/src/doc/unstable-book/src/language-features/diagnostic-on-unmatch-args.md +++ b/src/doc/unstable-book/src/language-features/diagnostic-on-unmatched-args.md @@ -1,4 +1,4 @@ -# `diagnostic_on_unmatch_args` +# `diagnostic_on_unmatched_args` The tracking issue for this feature is: [#155642] @@ -6,7 +6,7 @@ The tracking issue for this feature is: [#155642] ------------------------ -The `diagnostic_on_unmatch_args` feature adds the +The `diagnostic_on_unmatched_args` feature adds the `#[diagnostic::on_unmatched_args(...)]` attribute for declarative macros. It lets a macro definition customize diagnostics for matcher failures after all arms have been tried, such as incomplete invocations or trailing extra arguments. @@ -16,7 +16,7 @@ It is currently used for errors emitted by declarative macro matching itself; fr errors still use their existing diagnostics. ```rust,compile_fail -#![feature(diagnostic_on_unmatch_args)] +#![feature(diagnostic_on_unmatched_args)] #[diagnostic::on_unmatched_args( message = "invalid arguments to {This} macro invocation", diff --git a/tests/ui/diagnostic_namespace/on_unmatched_args/auxiliary/other.rs b/tests/ui/diagnostic_namespace/on_unmatched_args/auxiliary/other.rs index 9703e61182390..32cbf69a695ba 100644 --- a/tests/ui/diagnostic_namespace/on_unmatched_args/auxiliary/other.rs +++ b/tests/ui/diagnostic_namespace/on_unmatched_args/auxiliary/other.rs @@ -1,4 +1,4 @@ -#![feature(diagnostic_on_unmatch_args)] +#![feature(diagnostic_on_unmatched_args)] #[macro_export] #[diagnostic::on_unmatched_args( diff --git a/tests/ui/diagnostic_namespace/on_unmatched_args/message_and_label.rs b/tests/ui/diagnostic_namespace/on_unmatched_args/message_and_label.rs index 38fd3368391fd..4209c939ed52f 100644 --- a/tests/ui/diagnostic_namespace/on_unmatched_args/message_and_label.rs +++ b/tests/ui/diagnostic_namespace/on_unmatched_args/message_and_label.rs @@ -1,4 +1,4 @@ -#![feature(diagnostic_on_unmatch_args)] +#![feature(diagnostic_on_unmatched_args)] #[diagnostic::on_unmatched_args( message = "invalid arguments to {This} macro invocation", diff --git a/tests/ui/diagnostic_namespace/on_unmatched_args/notes_on_extra_args.rs b/tests/ui/diagnostic_namespace/on_unmatched_args/notes_on_extra_args.rs index d76c84be24def..66e951297a1b6 100644 --- a/tests/ui/diagnostic_namespace/on_unmatched_args/notes_on_extra_args.rs +++ b/tests/ui/diagnostic_namespace/on_unmatched_args/notes_on_extra_args.rs @@ -1,4 +1,4 @@ -#![feature(diagnostic_on_unmatch_args)] +#![feature(diagnostic_on_unmatched_args)] #[diagnostic::on_unmatched_args( message = "{This}! expects exactly two arguments", diff --git a/tests/ui/diagnostic_namespace/on_unmatched_args/on_unmatched_args.rs b/tests/ui/diagnostic_namespace/on_unmatched_args/on_unmatched_args.rs index 77f6d8dadf6f4..12ed333cd6621 100644 --- a/tests/ui/diagnostic_namespace/on_unmatched_args/on_unmatched_args.rs +++ b/tests/ui/diagnostic_namespace/on_unmatched_args/on_unmatched_args.rs @@ -1,4 +1,4 @@ -#![feature(diagnostic_on_unmatch_args)] +#![feature(diagnostic_on_unmatched_args)] #[diagnostic::on_unmatched_args( note = "this macro expects a type and a value, like `pair!(u8, 0)`", diff --git a/tests/ui/diagnostic_namespace/on_unmatched_args/other_match_macro_error.rs b/tests/ui/diagnostic_namespace/on_unmatched_args/other_match_macro_error.rs index acf91c6cc0489..ec7ea5888b6c9 100644 --- a/tests/ui/diagnostic_namespace/on_unmatched_args/other_match_macro_error.rs +++ b/tests/ui/diagnostic_namespace/on_unmatched_args/other_match_macro_error.rs @@ -1,4 +1,4 @@ -#![feature(diagnostic_on_unmatch_args)] +#![feature(diagnostic_on_unmatched_args)] #[diagnostic::on_unmatched_args( message = "invalid route method", diff --git a/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_invalid_formats.rs b/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_invalid_formats.rs index 98dd11664c91e..b98d7f777aee8 100644 --- a/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_invalid_formats.rs +++ b/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_invalid_formats.rs @@ -1,5 +1,5 @@ //@ check-pass -#![feature(diagnostic_on_unmatch_args)] +#![feature(diagnostic_on_unmatched_args)] #[diagnostic::on_unmatched_args( message = "{T}! is missing arguments", diff --git a/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_invalid_meta_item_syntax.rs b/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_invalid_meta_item_syntax.rs index 3da1d3e73a63e..407b6b013ef7d 100644 --- a/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_invalid_meta_item_syntax.rs +++ b/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_invalid_meta_item_syntax.rs @@ -1,5 +1,5 @@ //@ check-pass -#![feature(diagnostic_on_unmatch_args)] +#![feature(diagnostic_on_unmatched_args)] #[diagnostic::on_unmatched_args = "foo"] //~^ WARN malformed `diagnostic::on_unmatched_args` attribute [malformed_diagnostic_attributes] diff --git a/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_missing_options.rs b/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_missing_options.rs index 06d4133b027de..622fac89e1539 100644 --- a/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_missing_options.rs +++ b/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_missing_options.rs @@ -1,5 +1,5 @@ //@ check-pass -#![feature(diagnostic_on_unmatch_args)] +#![feature(diagnostic_on_unmatched_args)] #[diagnostic::on_unmatched_args] //~^ WARN missing options for `diagnostic::on_unmatched_args` attribute [malformed_diagnostic_attributes] diff --git a/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_non_macro.rs b/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_non_macro.rs index 6a0f117f61f3f..28b6e0cbe3be7 100644 --- a/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_non_macro.rs +++ b/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_non_macro.rs @@ -1,5 +1,5 @@ //@ check-pass -#![feature(diagnostic_on_unmatch_args)] +#![feature(diagnostic_on_unmatched_args)] #[diagnostic::on_unmatched_args(message = "not allowed here")] //~^ WARN `#[diagnostic::on_unmatched_args]` can only be applied to macro definitions diff --git a/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_unknown_options.rs b/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_unknown_options.rs index 61aa9e5af1989..b18003ca0f0d5 100644 --- a/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_unknown_options.rs +++ b/tests/ui/diagnostic_namespace/on_unmatched_args/report_warning_on_unknown_options.rs @@ -1,5 +1,5 @@ //@ check-pass -#![feature(diagnostic_on_unmatch_args)] +#![feature(diagnostic_on_unmatched_args)] #[diagnostic::on_unmatched_args(unsupported = "foo")] //~^ WARN malformed `diagnostic::on_unmatched_args` attribute [malformed_diagnostic_attributes] diff --git a/tests/ui/feature-gates/feature-gate-diagnostic-on-unmatch-args.rs b/tests/ui/feature-gates/feature-gate-diagnostic-on-unmatched-args.rs similarity index 100% rename from tests/ui/feature-gates/feature-gate-diagnostic-on-unmatch-args.rs rename to tests/ui/feature-gates/feature-gate-diagnostic-on-unmatched-args.rs diff --git a/tests/ui/feature-gates/feature-gate-diagnostic-on-unmatch-args.stderr b/tests/ui/feature-gates/feature-gate-diagnostic-on-unmatched-args.stderr similarity index 73% rename from tests/ui/feature-gates/feature-gate-diagnostic-on-unmatch-args.stderr rename to tests/ui/feature-gates/feature-gate-diagnostic-on-unmatched-args.stderr index 39eecc8322b22..26de03f51d2ee 100644 --- a/tests/ui/feature-gates/feature-gate-diagnostic-on-unmatch-args.stderr +++ b/tests/ui/feature-gates/feature-gate-diagnostic-on-unmatched-args.stderr @@ -1,5 +1,5 @@ error: unexpected end of macro invocation - --> $DIR/feature-gate-diagnostic-on-unmatch-args.rs:12:13 + --> $DIR/feature-gate-diagnostic-on-unmatched-args.rs:12:13 | LL | macro_rules! pair { | ----------------- when calling this macro @@ -8,7 +8,7 @@ LL | pair!(u8); | ^ missing tokens in macro arguments | note: while trying to match `,` - --> $DIR/feature-gate-diagnostic-on-unmatch-args.rs:7:12 + --> $DIR/feature-gate-diagnostic-on-unmatched-args.rs:7:12 | LL | ($ty:ty, $value:expr) => {}; | ^