Unnamed repository; edit this file 'description' to name the repository.
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
53
54
55
56
57
58
59
use crate::{Diagnostic, DiagnosticCode, DiagnosticsContext};

// Diagnostic: unresolved-ident
//
// This diagnostic is triggered if an expr-position ident is invalid.
pub(crate) fn unresolved_ident(
    ctx: &DiagnosticsContext<'_>,
    d: &hir::UnresolvedIdent,
) -> Diagnostic {
    Diagnostic::new_with_syntax_node_ptr(
        ctx,
        DiagnosticCode::RustcHardError("E0425"),
        "no such value in this scope",
        d.expr.map(Into::into),
    )
    .experimental()
}

#[cfg(test)]
mod tests {
    use crate::tests::check_diagnostics;

    // FIXME: This should show a diagnostic
    #[test]
    fn feature() {
        check_diagnostics(
            r#"
//- minicore: fmt
fn main() {
    format_args!("{unresolved}");
}
"#,
        )
    }

    #[test]
    fn missing() {
        check_diagnostics(
            r#"
fn main() {
    let _ = x;
          //^ error: no such value in this scope
}
"#,
        );
    }

    #[test]
    fn present() {
        check_diagnostics(
            r#"
fn main() {
    let x = 5;
    let _ = x;
}
"#,
        );
    }
}