Warn write-only fields
This commit is contained in:
@@ -37,6 +37,19 @@ fn should_explore(tcx: TyCtxt<'_>, hir_id: hir::HirId) -> bool {
|
||||
)
|
||||
}
|
||||
|
||||
fn base_expr<'a>(expr: &'a hir::Expr<'a>) -> &'a hir::Expr<'a> {
|
||||
let mut current = expr;
|
||||
loop {
|
||||
match current.kind {
|
||||
hir::ExprKind::Field(base, ..) => {
|
||||
current = base;
|
||||
}
|
||||
_ => break,
|
||||
}
|
||||
}
|
||||
current
|
||||
}
|
||||
|
||||
struct MarkSymbolVisitor<'tcx> {
|
||||
worklist: Vec<hir::HirId>,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
@@ -263,6 +276,12 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
|
||||
hir::ExprKind::MethodCall(..) => {
|
||||
self.lookup_and_handle_method(expr.hir_id);
|
||||
}
|
||||
hir::ExprKind::Assign(ref left, ref right, ..) => {
|
||||
// Ignore write to field
|
||||
self.visit_expr(base_expr(left));
|
||||
self.visit_expr(right);
|
||||
return;
|
||||
}
|
||||
hir::ExprKind::Field(ref lhs, ..) => {
|
||||
self.handle_field_access(&lhs, expr.hir_id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user