Skip to content

Commit 0a4ee11

Browse files
Rollup merge of #157887 - fmease:rn-to-on-unmatched-args, r=mejrs
Rename `diagnostic::on_unmatch_args` to `diagnostic::on_unmatched_args` This renders the name of the attribute and the feature grammatical. #154794 (comment). r? mejrs
2 parents ace8b9a + 69a17b1 commit 0a4ee11

45 files changed

Lines changed: 143 additions & 138 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub(crate) mod on_move;
2727
pub(crate) mod on_type_error;
2828
pub(crate) mod on_unimplemented;
2929
pub(crate) mod on_unknown;
30-
pub(crate) mod on_unmatch_args;
30+
pub(crate) mod on_unmatched_args;
3131

3232
#[derive(Copy, Clone)]
3333
pub(crate) enum Mode {
@@ -41,8 +41,8 @@ pub(crate) enum Mode {
4141
DiagnosticOnMove,
4242
/// `#[diagnostic::on_unknown]`
4343
DiagnosticOnUnknown,
44-
/// `#[diagnostic::on_unmatch_args]`
45-
DiagnosticOnUnmatchArgs,
44+
/// `#[diagnostic::on_unmatched_args]`
45+
DiagnosticOnUnmatchedArgs,
4646
/// `#[diagnostic::on_type_error]`
4747
DiagnosticOnTypeError,
4848
}
@@ -55,7 +55,7 @@ impl Mode {
5555
Self::DiagnosticOnConst => "diagnostic::on_const",
5656
Self::DiagnosticOnMove => "diagnostic::on_move",
5757
Self::DiagnosticOnUnknown => "diagnostic::on_unknown",
58-
Self::DiagnosticOnUnmatchArgs => "diagnostic::on_unmatch_args",
58+
Self::DiagnosticOnUnmatchedArgs => "diagnostic::on_unmatched_args",
5959
Self::DiagnosticOnTypeError => "diagnostic::on_type_error",
6060
}
6161
}
@@ -73,7 +73,7 @@ impl Mode {
7373
Self::DiagnosticOnConst => DEFAULT,
7474
Self::DiagnosticOnMove => DEFAULT,
7575
Self::DiagnosticOnUnknown => DEFAULT,
76-
Self::DiagnosticOnUnmatchArgs => DEFAULT,
76+
Self::DiagnosticOnUnmatchedArgs => DEFAULT,
7777
Self::DiagnosticOnTypeError => DIAGNOSTIC_ON_TYPE_ERROR_EXPECTED_OPTIONS,
7878
}
7979
}
@@ -90,7 +90,7 @@ impl Mode {
9090
Self::DiagnosticOnConst => DEFAULT,
9191
Self::DiagnosticOnMove => DEFAULT,
9292
Self::DiagnosticOnUnknown => DEFAULT,
93-
Self::DiagnosticOnUnmatchArgs => DEFAULT,
93+
Self::DiagnosticOnUnmatchedArgs => DEFAULT,
9494
Self::DiagnosticOnTypeError => DIAGNOSTIC_ON_TYPE_ERROR_ALLOWED_OPTIONS,
9595
}
9696
}
@@ -112,7 +112,7 @@ impl Mode {
112112
Self::DiagnosticOnUnknown => {
113113
"only `This` is allowed as a format argument, referring to the failed import"
114114
}
115-
Self::DiagnosticOnUnmatchArgs => {
115+
Self::DiagnosticOnUnmatchedArgs => {
116116
"only `This` is allowed as a format argument, referring to the macro's name"
117117
}
118118
Self::DiagnosticOnTypeError => {
@@ -313,7 +313,7 @@ fn parse_directive_items<'p>(
313313
| Mode::DiagnosticOnConst
314314
| Mode::DiagnosticOnMove
315315
| Mode::DiagnosticOnUnknown
316-
| Mode::DiagnosticOnUnmatchArgs,
316+
| Mode::DiagnosticOnUnmatchedArgs,
317317
sym::message,
318318
) => {
319319
let value = or_malformed!(value?);
@@ -329,7 +329,7 @@ fn parse_directive_items<'p>(
329329
| Mode::DiagnosticOnConst
330330
| Mode::DiagnosticOnMove
331331
| Mode::DiagnosticOnUnknown
332-
| Mode::DiagnosticOnUnmatchArgs,
332+
| Mode::DiagnosticOnUnmatchedArgs,
333333
sym::label,
334334
) => {
335335
let value = or_malformed!(value?);
@@ -469,7 +469,7 @@ fn parse_arg(
469469
(
470470
Mode::DiagnosticOnUnknown
471471
| Mode::DiagnosticOnMove
472-
| Mode::DiagnosticOnUnmatchArgs
472+
| Mode::DiagnosticOnUnmatchedArgs
473473
| Mode::DiagnosticOnTypeError,
474474
sym::This,
475475
) => FormatArg::This,
@@ -502,7 +502,7 @@ fn parse_arg(
502502
) => FormatArg::GenericParam { generic_param, span },
503503

504504
// Generics are explicitly not allowed, we print those back as is.
505-
(Mode::DiagnosticOnUnknown | Mode::DiagnosticOnUnmatchArgs, as_is) => {
505+
(Mode::DiagnosticOnUnknown | Mode::DiagnosticOnUnmatchedArgs, as_is) => {
506506
warnings.push(FormatWarning::DisallowedPlaceholder {
507507
span,
508508
attr: mode.as_str(),

compiler/rustc_attr_parsing/src/attributes/diagnostic/on_unmatch_args.rs renamed to compiler/rustc_attr_parsing/src/attributes/diagnostic/on_unmatched_args.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ use rustc_session::lint::builtin::MISPLACED_DIAGNOSTIC_ATTRIBUTES;
44

55
use crate::attributes::diagnostic::*;
66
use crate::attributes::prelude::*;
7-
use crate::diagnostics::DiagnosticOnUnmatchArgsOnlyForMacros;
7+
use crate::diagnostics::DiagnosticOnUnmatchedArgsOnlyForMacros;
88

99
#[derive(Default)]
10-
pub(crate) struct OnUnmatchArgsParser {
10+
pub(crate) struct OnUnmatchedArgsParser {
1111
span: Option<Span>,
1212
directive: Option<(Span, Directive)>,
1313
}
1414

15-
impl AttributeParser for OnUnmatchArgsParser {
15+
impl AttributeParser for OnUnmatchedArgsParser {
1616
const ATTRIBUTES: AcceptMapping<Self> = &[(
17-
&[sym::diagnostic, sym::on_unmatch_args],
17+
&[sym::diagnostic, sym::on_unmatched_args],
1818
template!(List: &[r#"/*opt*/ message = "...", /*opt*/ label = "...", /*opt*/ note = "...""#]),
1919
AttributeStability::Stable, // Unstable, stability checked manually in the parser
2020
|this, cx, args| {
21-
if !cx.features().diagnostic_on_unmatch_args() {
21+
if !cx.features().diagnostic_on_unmatched_args() {
2222
return;
2323
}
2424

@@ -28,13 +28,13 @@ impl AttributeParser for OnUnmatchArgsParser {
2828
if !matches!(cx.target, Target::MacroDef) {
2929
cx.emit_lint(
3030
MISPLACED_DIAGNOSTIC_ATTRIBUTES,
31-
DiagnosticOnUnmatchArgsOnlyForMacros,
31+
DiagnosticOnUnmatchedArgsOnlyForMacros,
3232
span,
3333
);
3434
return;
3535
}
3636

37-
let mode = Mode::DiagnosticOnUnmatchArgs;
37+
let mode = Mode::DiagnosticOnUnmatchedArgs;
3838
let Some(items) = parse_list(cx, args, mode) else { return };
3939

4040
let Some(directive) = parse_directive_items(cx, mode, items.mixed(), true) else {
@@ -48,7 +48,9 @@ impl AttributeParser for OnUnmatchArgsParser {
4848

4949
fn finalize(self, _cx: &FinalizeContext<'_, '_>) -> Option<AttributeKind> {
5050
if let Some(_span) = self.span {
51-
Some(AttributeKind::OnUnmatchArgs { directive: self.directive.map(|d| Box::new(d.1)) })
51+
Some(AttributeKind::OnUnmatchedArgs {
52+
directive: self.directive.map(|d| Box::new(d.1)),
53+
})
5254
} else {
5355
None
5456
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use crate::attributes::diagnostic::on_move::*;
3535
use crate::attributes::diagnostic::on_type_error::*;
3636
use crate::attributes::diagnostic::on_unimplemented::*;
3737
use crate::attributes::diagnostic::on_unknown::*;
38-
use crate::attributes::diagnostic::on_unmatch_args::*;
38+
use crate::attributes::diagnostic::on_unmatched_args::*;
3939
use crate::attributes::doc::*;
4040
use crate::attributes::dummy::*;
4141
use crate::attributes::inline::*;
@@ -149,7 +149,7 @@ attribute_parsers!(
149149
OnTypeErrorParser,
150150
OnUnimplementedParser,
151151
OnUnknownParser,
152-
OnUnmatchArgsParser,
152+
OnUnmatchedArgsParser,
153153
RustcAlignParser,
154154
RustcAlignStaticParser,
155155
RustcCguTestAttributeParser,

compiler/rustc_attr_parsing/src/diagnostics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,8 @@ pub(crate) struct DiagnosticOnUnknownOnlyForImports {
302302
}
303303

304304
#[derive(Diagnostic)]
305-
#[diag("`#[diagnostic::on_unmatch_args]` can only be applied to macro definitions")]
306-
pub(crate) struct DiagnosticOnUnmatchArgsOnlyForMacros;
305+
#[diag("`#[diagnostic::on_unmatched_args]` can only be applied to macro definitions")]
306+
pub(crate) struct DiagnosticOnUnmatchedArgsOnlyForMacros;
307307

308308
#[derive(Diagnostic)]
309309
#[diag("`#[diagnostic::on_type_error]` can only be applied to enums, structs or unions")]

compiler/rustc_expand/src/mbe/diagnostics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub(super) fn failed_to_match_macro(
3333
args: FailedMacro<'_>,
3434
body: &TokenStream,
3535
rules: &[MacroRule],
36-
on_unmatch_args: Option<&Directive>,
36+
on_unmatched_args: Option<&Directive>,
3737
) -> (Span, ErrorGuaranteed) {
3838
debug!("failed to match macro");
3939
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(
7777
let CustomDiagnostic {
7878
message: custom_message, label: custom_label, notes: custom_notes, ..
7979
} = {
80-
on_unmatch_args
80+
on_unmatched_args
8181
.map(|directive| directive.eval(None, &FormatArgs { this: name.to_string(), .. }))
8282
.unwrap_or_default()
8383
};

compiler/rustc_expand/src/mbe/macro_rules.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ pub struct MacroRulesMacroExpander {
166166
node_id: NodeId,
167167
name: Ident,
168168
span: Span,
169-
on_unmatch_args: Option<Directive>,
169+
on_unmatched_args: Option<Directive>,
170170
transparency: Transparency,
171171
kinds: MacroKinds,
172172
rules: Vec<MacroRule>,
@@ -249,7 +249,7 @@ impl MacroRulesMacroExpander {
249249
FailedMacro::Derive,
250250
body,
251251
rules,
252-
self.on_unmatch_args.as_ref(),
252+
self.on_unmatched_args.as_ref(),
253253
);
254254
cx.macro_error_and_trace_macros_diag();
255255
Err(guar)
@@ -274,7 +274,7 @@ impl TTMacroExpander for MacroRulesMacroExpander {
274274
self.transparency,
275275
input,
276276
&self.rules,
277-
self.on_unmatch_args.as_ref(),
277+
self.on_unmatched_args.as_ref(),
278278
))
279279
}
280280
}
@@ -309,7 +309,7 @@ impl AttrProcMacro for MacroRulesMacroExpander {
309309
args,
310310
body,
311311
&self.rules,
312-
self.on_unmatch_args.as_ref(),
312+
self.on_unmatched_args.as_ref(),
313313
)
314314
}
315315
}
@@ -371,7 +371,7 @@ impl<'matcher> Tracker<'matcher> for NoopTracker {
371371
}
372372

373373
/// Expands the rules based macro defined by `rules` for a given input `arg`.
374-
#[instrument(skip(cx, transparency, arg, rules, on_unmatch_args))]
374+
#[instrument(skip(cx, transparency, arg, rules, on_unmatched_args))]
375375
fn expand_macro<'cx, 'a: 'cx>(
376376
cx: &'cx mut ExtCtxt<'_>,
377377
sp: Span,
@@ -381,7 +381,7 @@ fn expand_macro<'cx, 'a: 'cx>(
381381
transparency: Transparency,
382382
arg: TokenStream,
383383
rules: &'a [MacroRule],
384-
on_unmatch_args: Option<&Directive>,
384+
on_unmatched_args: Option<&Directive>,
385385
) -> Box<dyn MacResult + 'cx> {
386386
let psess = &cx.sess.psess;
387387

@@ -440,7 +440,7 @@ fn expand_macro<'cx, 'a: 'cx>(
440440
FailedMacro::Func,
441441
&arg,
442442
rules,
443-
on_unmatch_args,
443+
on_unmatched_args,
444444
);
445445
cx.macro_error_and_trace_macros_diag();
446446
DummyResult::any(span, guar)
@@ -449,7 +449,7 @@ fn expand_macro<'cx, 'a: 'cx>(
449449
}
450450

451451
/// Expands the rules based macro defined by `rules` for a given attribute `args` and `body`.
452-
#[instrument(skip(cx, transparency, args, body, rules, on_unmatch_args))]
452+
#[instrument(skip(cx, transparency, args, body, rules, on_unmatched_args))]
453453
fn expand_macro_attr(
454454
cx: &mut ExtCtxt<'_>,
455455
sp: Span,
@@ -461,7 +461,7 @@ fn expand_macro_attr(
461461
args: TokenStream,
462462
body: TokenStream,
463463
rules: &[MacroRule],
464-
on_unmatch_args: Option<&Directive>,
464+
on_unmatched_args: Option<&Directive>,
465465
) -> Result<TokenStream, ErrorGuaranteed> {
466466
let psess = &cx.sess.psess;
467467
// Macros defined in the current crate have a real node id,
@@ -526,7 +526,7 @@ fn expand_macro_attr(
526526
FailedMacro::Attr(&args),
527527
&body,
528528
rules,
529-
on_unmatch_args,
529+
on_unmatched_args,
530530
);
531531
cx.trace_macros_diag();
532532
Err(guar)
@@ -865,9 +865,9 @@ pub fn compile_declarative_macro(
865865
return dummy_syn_ext(guar);
866866
}
867867

868-
let on_unmatch_args = find_attr!(
868+
let on_unmatched_args = find_attr!(
869869
attrs,
870-
OnUnmatchArgs { directive, .. } => directive.clone()
870+
OnUnmatchedArgs { directive, .. } => directive.clone()
871871
)
872872
.flatten()
873873
.map(|directive| *directive);
@@ -877,7 +877,7 @@ pub fn compile_declarative_macro(
877877
kinds,
878878
span,
879879
node_id,
880-
on_unmatch_args,
880+
on_unmatched_args,
881881
transparency,
882882
rules,
883883
macro_rules,

compiler/rustc_feature/src/removed.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ declare_features! (
106106
(removed, deprecated_safe, "1.95.0", Some(94978), Some("never properly implemented, in the way of attribute refactor"), 152554),
107107
/// Allows deriving traits as per `SmartPointer` specification
108108
(removed, derive_smart_pointer, "1.84.0", Some(123430), Some("replaced by `CoercePointee`"), 131284),
109+
/// Allows macros to customize macro argument matcher diagnostics.
110+
(removed, diagnostic_on_unmatch_args, "CURRENT_RUSTC_VERSION", Some(155642), Some("renamed to `diagnostic_on_unmatched_args`"), 157887),
109111
/// Tells rustdoc to automatically generate `#[doc(cfg(...))]`.
110112
(removed, doc_auto_cfg, "1.92.0", Some(43781), Some("merged into `doc_cfg`"), 138907),
111113
/// Allows `#[doc(cfg_hide(...))]`.

compiler/rustc_feature/src/unstable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ declare_features! (
515515
/// Allows giving unresolved imports a custom diagnostic message
516516
(unstable, diagnostic_on_unknown, "1.96.0", Some(152900)),
517517
/// Allows macros to customize macro argument matcher diagnostics.
518-
(unstable, diagnostic_on_unmatch_args, "1.97.0", Some(155642)),
518+
(unstable, diagnostic_on_unmatched_args, "1.97.0", Some(155642)),
519519
/// Allows `#[doc(cfg(...))]`.
520520
(unstable, doc_cfg, "1.21.0", Some(43781)),
521521
/// Allows `#[doc(masked)]`.

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,8 +1191,8 @@ pub enum AttributeKind {
11911191
directive: Option<Box<Directive>>,
11921192
},
11931193

1194-
/// Represents `#[diagnostic::on_unmatch_args]`.
1195-
OnUnmatchArgs {
1194+
/// Represents `#[diagnostic::on_unmatched_args]`.
1195+
OnUnmatchedArgs {
11961196
/// None if the directive was malformed in some way.
11971197
directive: Option<Box<Directive>>,
11981198
},

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl AttributeKind {
8181
OnTypeError { .. } => Yes,
8282
OnUnimplemented { .. } => Yes,
8383
OnUnknown { .. } => Yes,
84-
OnUnmatchArgs { .. } => Yes,
84+
OnUnmatchedArgs { .. } => Yes,
8585
Optimize(..) => No,
8686
PanicRuntime => No,
8787
PatchableFunctionEntry { .. } => Yes,

0 commit comments

Comments
 (0)