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