mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Diagnose unresolved field accesses
This commit is contained in:
parent
3c7a0aa00e
commit
78b2dd813a
7 changed files with 273 additions and 94 deletions
|
@ -88,8 +88,8 @@ pub use crate::{
|
|||
InvalidDeriveTarget, MacroError, MalformedDerive, MismatchedArgCount, MissingFields,
|
||||
MissingMatchArms, MissingUnsafe, NoSuchField, PrivateAssocItem, PrivateField,
|
||||
ReplaceFilterMapNextWithFindMap, TypeMismatch, UnimplementedBuiltinMacro,
|
||||
UnresolvedExternCrate, UnresolvedImport, UnresolvedMacroCall, UnresolvedModule,
|
||||
UnresolvedProcMacro,
|
||||
UnresolvedExternCrate, UnresolvedField, UnresolvedImport, UnresolvedMacroCall,
|
||||
UnresolvedModule, UnresolvedProcMacro,
|
||||
},
|
||||
has_source::HasSource,
|
||||
semantics::{PathResolution, Semantics, SemanticsScope, TypeInfo, VisibleTraits},
|
||||
|
@ -1375,6 +1375,7 @@ impl DefWithBody {
|
|||
|
||||
let infer = db.infer(self.into());
|
||||
let source_map = Lazy::new(|| db.body_with_source_map(self.into()).1);
|
||||
let expr_syntax = |expr| source_map.expr_syntax(expr).expect("unexpected synthetic");
|
||||
for d in &infer.diagnostics {
|
||||
match d {
|
||||
&hir_ty::InferenceDiagnostic::NoSuchField { expr } => {
|
||||
|
@ -1386,30 +1387,23 @@ impl DefWithBody {
|
|||
is_break,
|
||||
bad_value_break,
|
||||
} => {
|
||||
let expr = source_map
|
||||
.expr_syntax(expr)
|
||||
.expect("break outside of loop in synthetic syntax");
|
||||
let expr = expr_syntax(expr);
|
||||
acc.push(BreakOutsideOfLoop { expr, is_break, bad_value_break }.into())
|
||||
}
|
||||
&hir_ty::InferenceDiagnostic::MismatchedArgCount { call_expr, expected, found } => {
|
||||
match source_map.expr_syntax(call_expr) {
|
||||
Ok(source_ptr) => acc.push(
|
||||
MismatchedArgCount { call_expr: source_ptr, expected, found }.into(),
|
||||
),
|
||||
Err(SyntheticSyntax) => (),
|
||||
}
|
||||
acc.push(
|
||||
MismatchedArgCount { call_expr: expr_syntax(call_expr), expected, found }
|
||||
.into(),
|
||||
)
|
||||
}
|
||||
&hir_ty::InferenceDiagnostic::PrivateField { expr, field } => {
|
||||
let expr = source_map.expr_syntax(expr).expect("unexpected synthetic");
|
||||
let expr = expr_syntax(expr);
|
||||
let field = field.into();
|
||||
acc.push(PrivateField { expr, field }.into())
|
||||
}
|
||||
&hir_ty::InferenceDiagnostic::PrivateAssocItem { id, item } => {
|
||||
let expr_or_pat = match id {
|
||||
ExprOrPatId::ExprId(expr) => source_map
|
||||
.expr_syntax(expr)
|
||||
.expect("unexpected synthetic")
|
||||
.map(Either::Left),
|
||||
ExprOrPatId::ExprId(expr) => expr_syntax(expr).map(Either::Left),
|
||||
ExprOrPatId::PatId(pat) => source_map
|
||||
.pat_syntax(pat)
|
||||
.expect("unexpected synthetic")
|
||||
|
@ -1419,8 +1413,7 @@ impl DefWithBody {
|
|||
acc.push(PrivateAssocItem { expr_or_pat, item }.into())
|
||||
}
|
||||
hir_ty::InferenceDiagnostic::ExpectedFunction { call_expr, found } => {
|
||||
let call_expr =
|
||||
source_map.expr_syntax(*call_expr).expect("unexpected synthetic");
|
||||
let call_expr = expr_syntax(*call_expr);
|
||||
|
||||
acc.push(
|
||||
ExpectedFunction {
|
||||
|
@ -1430,6 +1423,24 @@ impl DefWithBody {
|
|||
.into(),
|
||||
)
|
||||
}
|
||||
hir_ty::InferenceDiagnostic::UnresolvedField {
|
||||
expr,
|
||||
receiver,
|
||||
name,
|
||||
method_with_same_name_exists,
|
||||
} => {
|
||||
let expr = expr_syntax(*expr);
|
||||
|
||||
acc.push(
|
||||
UnresolvedField {
|
||||
expr,
|
||||
name: name.clone(),
|
||||
receiver: Type::new(db, DefWithBodyId::from(self), receiver.clone()),
|
||||
method_with_same_name_exists: *method_with_same_name_exists,
|
||||
}
|
||||
.into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
for (pat_or_expr, mismatch) in infer.type_mismatches() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue