mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
Diagnose private field accesses
This commit is contained in:
parent
ec125fe46a
commit
e3d144d17f
6 changed files with 86 additions and 11 deletions
|
@ -10,7 +10,7 @@ use hir_def::path::ModPath;
|
|||
use hir_expand::{name::Name, HirFileId, InFile};
|
||||
use syntax::{ast, AstPtr, SyntaxNodePtr, TextRange};
|
||||
|
||||
use crate::{MacroKind, Type};
|
||||
use crate::{Field, MacroKind, Type};
|
||||
|
||||
macro_rules! diagnostics {
|
||||
($($diag:ident,)*) => {
|
||||
|
@ -41,6 +41,7 @@ diagnostics![
|
|||
MissingMatchArms,
|
||||
MissingUnsafe,
|
||||
NoSuchField,
|
||||
PrivateField,
|
||||
ReplaceFilterMapNextWithFindMap,
|
||||
TypeMismatch,
|
||||
UnimplementedBuiltinMacro,
|
||||
|
@ -121,6 +122,12 @@ pub struct NoSuchField {
|
|||
pub field: InFile<AstPtr<ast::RecordExprField>>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct PrivateField {
|
||||
pub expr: InFile<AstPtr<ast::Expr>>,
|
||||
pub field: Field,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct BreakOutsideOfLoop {
|
||||
pub expr: InFile<AstPtr<ast::Expr>>,
|
||||
|
|
|
@ -85,7 +85,7 @@ pub use crate::{
|
|||
diagnostics::{
|
||||
AnyDiagnostic, BreakOutsideOfLoop, InactiveCode, IncorrectCase, InvalidDeriveTarget,
|
||||
MacroError, MalformedDerive, MismatchedArgCount, MissingFields, MissingMatchArms,
|
||||
MissingUnsafe, NoSuchField, ReplaceFilterMapNextWithFindMap, TypeMismatch,
|
||||
MissingUnsafe, NoSuchField, PrivateField, ReplaceFilterMapNextWithFindMap, TypeMismatch,
|
||||
UnimplementedBuiltinMacro, UnresolvedExternCrate, UnresolvedImport, UnresolvedMacroCall,
|
||||
UnresolvedModule, UnresolvedProcMacro,
|
||||
},
|
||||
|
@ -1353,6 +1353,11 @@ impl DefWithBody {
|
|||
Err(SyntheticSyntax) => (),
|
||||
}
|
||||
}
|
||||
&hir_ty::InferenceDiagnostic::PrivateField { expr, field } => {
|
||||
let expr = source_map.expr_syntax(expr).expect("unexpected synthetic");
|
||||
let field = field.into();
|
||||
acc.push(PrivateField { expr, field }.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
for (expr, mismatch) in infer.expr_type_mismatches() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue