mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-28 14:03:35 +00:00
Auto merge of #17546 - Veykril:unresolved-self, r=Veykril
internal: Diagnose unresolved self value in path expression
This commit is contained in:
commit
39d7962c69
2 changed files with 18 additions and 1 deletions
|
@ -440,7 +440,8 @@ impl InferenceContext<'_> {
|
||||||
let ty = match self.infer_path(p, tgt_expr.into()) {
|
let ty = match self.infer_path(p, tgt_expr.into()) {
|
||||||
Some(ty) => ty,
|
Some(ty) => ty,
|
||||||
None => {
|
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 {
|
self.push_diagnostic(InferenceDiagnostic::UnresolvedIdent {
|
||||||
expr: tgt_expr,
|
expr: tgt_expr,
|
||||||
});
|
});
|
||||||
|
|
|
@ -53,6 +53,22 @@ fn main() {
|
||||||
let x = 5;
|
let x = 5;
|
||||||
let _ = x;
|
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
|
||||||
|
}
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue