mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 14:13:58 +00:00
Diagnose unresolved self value in path expression
This commit is contained in:
parent
f2afcb874e
commit
4420e7148f
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()) {
|
||||
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,
|
||||
});
|
||||
|
|
|
@ -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
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue