rustc_attr_parsing/attributes/diagnostic/
on_unmatched_args.rs1use rustc_feature::AttributeStability;
2use rustc_hir::attrs::diagnostic::Directive;
3
4use crate::attributes::diagnostic::*;
5use crate::attributes::prelude::*;
6
7#[derive(#[automatically_derived]
impl ::core::default::Default for OnUnmatchedArgsParser {
#[inline]
fn default() -> OnUnmatchedArgsParser {
OnUnmatchedArgsParser {
span: ::core::default::Default::default(),
directive: ::core::default::Default::default(),
}
}
}Default)]
8pub(crate) struct OnUnmatchedArgsParser {
9 span: Option<Span>,
10 directive: Option<(Span, Directive)>,
11}
12
13impl AttributeParser for OnUnmatchedArgsParser {
14 const ATTRIBUTES: AcceptMapping<Self> = &[(
15 &[sym::diagnostic, sym::on_unmatched_args],
16 crate::AttributeTemplate {
word: false,
list: Some(&[r#"/*opt*/ message = "...", /*opt*/ label = "...", /*opt*/ note = "...""#]),
one_of: &[],
name_value_str: None,
docs: None,
}template!(List: &[r#"/*opt*/ message = "...", /*opt*/ label = "...", /*opt*/ note = "...""#]),
17 AttributeStability::Stable, |this, cx, args| {
19 if !cx.features().diagnostic_on_unmatched_args() {
20 return;
21 }
22
23 let span = cx.attr_span;
24 this.span = Some(span);
25
26 let mode = Mode::DiagnosticOnUnmatchedArgs;
27 let Some(items) = parse_list(cx, args, mode) else { return };
28
29 let Some(directive) = parse_directive_items(cx, mode, items.mixed(), true) else {
30 return;
31 };
32 merge_directives(cx, &mut this.directive, (span, directive));
33 },
34 )];
35
36 const ALLOWED_TARGETS: AllowedTargets =
37 AllowedTargets::AllowListWarnRest(&[Allow(Target::MacroDef)]);
38
39 fn finalize(self, _cx: &FinalizeContext<'_, '_>) -> Option<AttributeKind> {
40 if let Some(_span) = self.span {
41 Some(AttributeKind::OnUnmatchedArgs {
42 directive: self.directive.map(|d| Box::new(d.1)),
43 })
44 } else {
45 None
46 }
47 }
48}