Auto merge of #17546 - Veykril:unresolved-self, r=Veykril

internal: Diagnose unresolved self value in path expression
This commit is contained in:
bors 2024-07-06 13:46:01 +00:00
commit 39d7962c69
2 changed files with 18 additions and 1 deletions

View file

@ -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,
});

View file

@ -53,6 +53,22 @@ fn main() {
let x = 5;
let _ = x;
}
"#,
);
}
#[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
}
"#,
);
}