Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-diagnostics/src/handlers/not_implemented.rs')
| -rw-r--r-- | crates/ide-diagnostics/src/handlers/not_implemented.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/crates/ide-diagnostics/src/handlers/not_implemented.rs b/crates/ide-diagnostics/src/handlers/not_implemented.rs new file mode 100644 index 0000000000..3bf6a42322 --- /dev/null +++ b/crates/ide-diagnostics/src/handlers/not_implemented.rs @@ -0,0 +1,35 @@ +use hir::{db::DefDatabase, HirDisplay}; + +use crate::{Diagnostic, DiagnosticsContext}; + +// Diagnostic: not-implemented +// +// This diagnostic is triggered if a type doesn't implement a necessary trait. +pub(crate) fn not_implemented(ctx: &DiagnosticsContext<'_>, d: &hir::NotImplemented) -> Diagnostic { + Diagnostic::new( + "not-implemented", + format!( + "the trait `{}` is not implemented for `{}`", + ctx.sema.db.trait_data(d.trait_).name, + d.ty.display(ctx.sema.db) + ), + ctx.sema.diagnostics_display_range(d.expr.clone().map(|it| it.into())).range, + ) +} + +#[cfg(test)] +mod tests { + use crate::tests::check_diagnostics; + + #[test] + fn missing_try_impl() { + check_diagnostics( + r#" +//- minicore: try +fn main() { + ()?; +} //^^ error: the trait `Try` is not implemented for `()` +"#, + ) + } +} |