Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-diagnostics/src/handlers/bad_rtn.rs')
-rw-r--r--crates/ide-diagnostics/src/handlers/bad_rtn.rs52
1 files changed, 52 insertions, 0 deletions
diff --git a/crates/ide-diagnostics/src/handlers/bad_rtn.rs b/crates/ide-diagnostics/src/handlers/bad_rtn.rs
new file mode 100644
index 0000000000..9ed85f9f20
--- /dev/null
+++ b/crates/ide-diagnostics/src/handlers/bad_rtn.rs
@@ -0,0 +1,52 @@
+use ide_db::Severity;
+
+use crate::{Diagnostic, DiagnosticCode, DiagnosticsContext};
+
+// Diagnostic: bad-rtn
+//
+// This diagnostic is shown when a RTN (Return Type Notation, `Type::method(..): Send`) is written in an improper place.
+pub(crate) fn bad_rtn(ctx: &DiagnosticsContext<'_>, d: &hir::BadRtn) -> Diagnostic {
+ Diagnostic::new_with_syntax_node_ptr(
+ ctx,
+ DiagnosticCode::Ra("bad-rtn", Severity::Error),
+ "return type notation not allowed in this position yet",
+ d.rtn.map(Into::into),
+ )
+}
+
+#[cfg(test)]
+mod tests {
+ use crate::tests::check_diagnostics;
+
+ #[test]
+ fn fn_traits_also_emit() {
+ check_diagnostics(
+ r#"
+//- minicore: fn
+fn foo<
+ A: Fn(..),
+ // ^^^^ error: return type notation not allowed in this position yet
+>() {}
+ "#,
+ );
+ }
+
+ #[test]
+ fn bad_rtn() {
+ check_diagnostics(
+ r#"
+mod module {
+ pub struct Type;
+}
+trait Trait {}
+
+fn foo()
+where
+ module(..)::Type: Trait
+ // ^^^^ error: return type notation not allowed in this position yet
+{
+}
+ "#,
+ );
+ }
+}