ide_diagnostics/handlers/
bad_rtn.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
{
}
        "#,
        );
    }
}