ide_diagnostics/handlers/
unresolved_ident.rs1use crate::{Diagnostic, DiagnosticCode, DiagnosticsContext};
2
3pub(crate) fn unresolved_ident(
7 ctx: &DiagnosticsContext<'_>,
8 d: &hir::UnresolvedIdent,
9) -> Diagnostic {
10 let mut range =
11 ctx.sema.diagnostics_display_range(d.node.map(|(node, _)| node.syntax_node_ptr()));
12 if let Some(in_node_range) = d.node.value.1 {
13 range.range = in_node_range + range.range.start();
14 }
15 Diagnostic::new(DiagnosticCode::RustcHardError("E0425"), "no such value in this scope", range)
16}
17
18#[cfg(test)]
19mod tests {
20 use crate::tests::check_diagnostics;
21
22 #[test]
23 fn feature() {
24 check_diagnostics(
25 r#"
26//- minicore: fmt
27fn main() {
28 format_args!("{unresolved}");
29 // ^^^^^^^^^^ error: no such value in this scope
30}
31"#,
32 )
33 }
34
35 #[test]
36 fn missing() {
37 check_diagnostics(
38 r#"
39fn main() {
40 let _ = x;
41 //^ error: no such value in this scope
42}
43"#,
44 );
45 }
46
47 #[test]
48 fn present() {
49 check_diagnostics(
50 r#"
51fn main() {
52 let x = 5;
53 let _ = x;
54}
55"#,
56 );
57 }
58
59 #[test]
60 fn unresolved_self_val() {
61 check_diagnostics(
62 r#"
63fn main() {
64 self.a;
65 //^^^^ error: no such value in this scope
66 let self:
67 self =
68 self;
69 //^^^^ error: no such value in this scope
70}
71"#,
72 );
73 }
74}