ide_diagnostics/handlers/
invalid_derive_target.rsuse crate::{Diagnostic, DiagnosticCode, DiagnosticsContext};
pub(crate) fn invalid_derive_target(
ctx: &DiagnosticsContext<'_>,
d: &hir::InvalidDeriveTarget,
) -> Diagnostic {
let display_range = ctx.sema.diagnostics_display_range(d.node);
Diagnostic::new(
DiagnosticCode::RustcHardError("E0774"),
"`derive` may only be applied to `struct`s, `enum`s and `union`s",
display_range,
)
}
#[cfg(test)]
mod tests {
use crate::tests::check_diagnostics;
#[test]
fn fails_on_function() {
check_diagnostics(
r#"
//- minicore:derive
mod __ {
#[derive()]
//^^^^^^^^^^^ error: `derive` may only be applied to `struct`s, `enum`s and `union`s
fn main() {}
}
"#,
);
}
}