Skip to main content

rustc_attr_parsing/attributes/diagnostic/
on_move.rs

1use rustc_attr_ir::AttributeKind;
2use rustc_feature::AttributeStability;
3use rustc_span::sym;
4
5use crate::attributes::diagnostic::*;
6use crate::attributes::prelude::*;
7use crate::target_checking::AllowedTargets;
8use crate::template;
9
10#[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)]
11pub(crate) struct OnMoveParser {
12    span: Option<Span>,
13    directive: Option<(Span, Directive)>,
14}
15
16impl AttributeParser for OnMoveParser {
17    const ATTRIBUTES: AcceptMapping<Self> = &[(
18        &[sym::diagnostic, sym::on_move],
19        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 = "...""#]),
20        AttributeStability::Stable, // Unstable, stability checked manually below
21        |this, cx, args| {
22            {
    if let Some(features) = cx.features_option() &&
            !features.diagnostic_on_move() {
        args.ignore_args();
        let nightly_build = cx.sess.is_nightly_build();
        let span = cx.attr_span;
        cx.emit_lint(rustc_lint_defs::builtin::UNKNOWN_DIAGNOSTIC_ATTRIBUTES,
            crate::diagnostics::UnstableDiagnosticAttribute {
                feature: sym::diagnostic_on_move,
                nightly_build,
            }, span);
        return;
    }
};gate_diagnostic_attr!(diagnostic_on_move);
23
24            let span = cx.attr_span;
25            this.span = Some(span);
26            let mode = Mode::DiagnosticOnMove;
27
28            let Some(items) = parse_list(cx, args, mode) else { return };
29
30            if let Some(directive) = parse_directive_items(cx, mode, items.mixed(), true) {
31                merge_directives(cx, &mut this.directive, (span, directive));
32            }
33        },
34    )];
35
36    const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowListWarnRest(&[
37        Allow(Target::Enum),
38        Allow(Target::Struct),
39        Allow(Target::Union),
40    ]);
41
42    fn finalize(self, _cx: &FinalizeContext<'_, '_>) -> Option<AttributeKind> {
43        if let Some(_span) = self.span {
44            Some(AttributeKind::OnMove { directive: self.directive.map(|d| Box::new(d.1)) })
45        } else {
46            None
47        }
48    }
49}