rustc_attr_parsing/attributes/diagnostic/
on_move.rs1use rustc_feature::template;
2use rustc_hir::attrs::AttributeKind;
3use rustc_hir::lints::AttributeLintKind;
4use rustc_session::lint::builtin::MALFORMED_DIAGNOSTIC_ATTRIBUTES;
5use rustc_span::sym;
6
7use crate::attributes::diagnostic::*;
8use crate::attributes::prelude::*;
9use crate::context::{AcceptContext, Stage};
10use crate::parser::ArgParser;
11use crate::target_checking::{ALL_TARGETS, AllowedTargets};
12
13#[derive(#[automatically_derived]
impl ::core::default::Default for OnMoveParser {
#[inline]
fn default() -> OnMoveParser {
OnMoveParser {
span: ::core::default::Default::default(),
directive: ::core::default::Default::default(),
}
}
}Default)]
14pub(crate) struct OnMoveParser {
15 span: Option<Span>,
16 directive: Option<(Span, Directive)>,
17}
18
19impl OnMoveParser {
20 fn parse<'sess, S: Stage>(
21 &mut self,
22 cx: &mut AcceptContext<'_, 'sess, S>,
23 args: &ArgParser,
24 mode: Mode,
25 ) {
26 if !cx.features().diagnostic_on_move() {
27 return;
28 }
29
30 let span = cx.attr_span;
31 self.span = Some(span);
32 let Some(list) = args.list() else {
33 cx.emit_lint(
34 MALFORMED_DIAGNOSTIC_ATTRIBUTES,
35 AttributeLintKind::MissingOptionsForOnMove,
36 span,
37 );
38 return;
39 };
40
41 if list.is_empty() {
42 cx.emit_lint(
43 MALFORMED_DIAGNOSTIC_ATTRIBUTES,
44 AttributeLintKind::OnMoveMalformedAttrExpectedLiteralOrDelimiter,
45 list.span,
46 );
47 return;
48 }
49
50 if let Some(directive) = parse_directive_items(cx, mode, list.mixed(), true) {
51 merge_directives(cx, &mut self.directive, (span, directive));
52 }
53 }
54}
55impl<S: Stage> AttributeParser<S> for OnMoveParser {
56 const ATTRIBUTES: AcceptMapping<Self, S> = &[(
57 &[sym::diagnostic, sym::on_move],
58 ::rustc_feature::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 = "...""#]),
59 |this, cx, args| {
60 this.parse(cx, args, Mode::DiagnosticOnMove);
61 },
62 )];
63 const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS);
64
65 fn finalize(self, _cx: &FinalizeContext<'_, '_, S>) -> Option<AttributeKind> {
66 if let Some(span) = self.span {
67 Some(AttributeKind::OnMove { span, directive: self.directive.map(|d| Box::new(d.1)) })
68 } else {
69 None
70 }
71 }
72}