ide_diagnostics/handlers/
malformed_derive.rs

1use crate::{Diagnostic, DiagnosticCode, DiagnosticsContext};
2
3// Diagnostic: malformed-derive
4//
5// This diagnostic is shown when the derive attribute has invalid input.
6pub(crate) fn malformed_derive(
7    ctx: &DiagnosticsContext<'_>,
8    d: &hir::MalformedDerive,
9) -> Diagnostic {
10    let display_range = ctx.sema.diagnostics_display_range_for_range(d.range);
11
12    Diagnostic::new(
13        DiagnosticCode::RustcHardError("E0777"),
14        "malformed derive input, derive attributes are of the form `#[derive(Derive1, Derive2, ...)]`",
15        display_range,
16    )
17    .stable()
18}
19
20#[cfg(test)]
21mod tests {
22    use crate::tests::check_diagnostics;
23
24    #[test]
25    fn invalid_input() {
26        check_diagnostics(
27            r#"
28//- minicore:derive
29mod __ {
30    #[derive = "aaaa"]
31   // ^^^^^^^^^^^^^^^ error: malformed derive input, derive attributes are of the form `#[derive(Derive1, Derive2, ...)]`
32    struct Foo;
33}
34            "#,
35        );
36    }
37}