about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-07-06 13:46:01 +0000
committerbors <bors@rust-lang.org>2024-07-06 13:46:01 +0000
commitc412ea9ac4c43149a8b442223ff924aa896e8947 (patch)
treec727c3fa057272b3fb45295570d7682cc1e821b4 /src
parentfc92ee8f24edd1b6c6116b93b8118dfb1bc400ff (diff)
parente8be2a0ac5c4756fed82ea6c38532a12cd9d68d2 (diff)
downloadrust-c412ea9ac4c43149a8b442223ff924aa896e8947.tar.gz
rust-c412ea9ac4c43149a8b442223ff924aa896e8947.zip
Auto merge of #17546 - Veykril:unresolved-self, r=Veykril
internal: Diagnose unresolved self value in path expression
Diffstat (limited to 'src')
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/infer/expr.rs3
-rw-r--r--src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/unresolved_ident.rs16
2 files changed, 18 insertions, 1 deletions
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/infer/expr.rs b/src/tools/rust-analyzer/crates/hir-ty/src/infer/expr.rs
index 36472435370..7a0f7872a64 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/infer/expr.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/infer/expr.rs
@@ -440,7 +440,8 @@ impl InferenceContext<'_> {
                 let ty = match self.infer_path(p, tgt_expr.into()) {
                     Some(ty) => ty,
                     None => {
-                        if matches!(p, Path::Normal { mod_path, .. } if mod_path.is_ident()) {
+                        if matches!(p, Path::Normal { mod_path, .. } if mod_path.is_ident() || mod_path.is_self())
+                        {
                             self.push_diagnostic(InferenceDiagnostic::UnresolvedIdent {
                                 expr: tgt_expr,
                             });
diff --git a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/unresolved_ident.rs b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/unresolved_ident.rs
index 7aa3e16536c..9a81682aaeb 100644
--- a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/unresolved_ident.rs
+++ b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/unresolved_ident.rs
@@ -56,4 +56,20 @@ fn main() {
 "#,
         );
     }
+
+    #[test]
+    fn unresolved_self_val() {
+        check_diagnostics(
+            r#"
+fn main() {
+    self.a;
+  //^^^^ error: no such value in this scope
+    let self:
+         self =
+            self;
+          //^^^^ error: no such value in this scope
+}
+"#,
+        );
+    }
 }