ide_diagnostics/handlers/
bad_rtn.rs

1use ide_db::Severity;
2
3use crate::{Diagnostic, DiagnosticCode, DiagnosticsContext};
4
5// Diagnostic: bad-rtn
6//
7// This diagnostic is shown when a RTN (Return Type Notation, `Type::method(..): Send`) is written in an improper place.
8pub(crate) fn bad_rtn(ctx: &DiagnosticsContext<'_>, d: &hir::BadRtn) -> Diagnostic {
9    Diagnostic::new_with_syntax_node_ptr(
10        ctx,
11        DiagnosticCode::Ra("bad-rtn", Severity::Error),
12        "return type notation not allowed in this position yet",
13        d.rtn.map(Into::into),
14    )
15    .stable()
16}
17
18#[cfg(test)]
19mod tests {
20    use crate::tests::check_diagnostics;
21
22    #[test]
23    fn fn_traits_also_emit() {
24        check_diagnostics(
25            r#"
26//- minicore: fn
27fn foo<
28    A: Fn(..),
29      // ^^^^ error: return type notation not allowed in this position yet
30>() {}
31        "#,
32        );
33    }
34
35    #[test]
36    fn bad_rtn() {
37        check_diagnostics(
38            r#"
39mod module {
40    pub struct Type;
41}
42trait Trait {}
43
44fn foo()
45where
46    module(..)::Type: Trait
47       // ^^^^ error: return type notation not allowed in this position yet
48{
49}
50        "#,
51        );
52    }
53}