Skip to content

Commit 39d7962

Browse files
committed
Auto merge of #17546 - Veykril:unresolved-self, r=Veykril
internal: Diagnose unresolved self value in path expression
2 parents f2afcb8 + 4420e71 commit 39d7962

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

crates/hir-ty/src/infer/expr.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,8 @@ impl InferenceContext<'_> {
440440
let ty = match self.infer_path(p, tgt_expr.into()) {
441441
Some(ty) => ty,
442442
None => {
443-
if matches!(p, Path::Normal { mod_path, .. } if mod_path.is_ident()) {
443+
if matches!(p, Path::Normal { mod_path, .. } if mod_path.is_ident() || mod_path.is_self())
444+
{
444445
self.push_diagnostic(InferenceDiagnostic::UnresolvedIdent {
445446
expr: tgt_expr,
446447
});

crates/ide-diagnostics/src/handlers/unresolved_ident.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,22 @@ fn main() {
5353
let x = 5;
5454
let _ = x;
5555
}
56+
"#,
57+
);
58+
}
59+
60+
#[test]
61+
fn unresolved_self_val() {
62+
check_diagnostics(
63+
r#"
64+
fn main() {
65+
self.a;
66+
//^^^^ error: no such value in this scope
67+
let self:
68+
self =
69+
self;
70+
//^^^^ error: no such value in this scope
71+
}
5672
"#,
5773
);
5874
}

0 commit comments

Comments
 (0)