diff options
| author | Seo Sanghyeon <sanxiyn@gmail.com> | 2021-01-28 23:56:13 +0900 |
|---|---|---|
| committer | Seo Sanghyeon <sanxiyn@gmail.com> | 2021-01-28 23:56:13 +0900 |
| commit | d3c69a4c0dd98af2611b7553d1a65afef6a6ccb0 (patch) | |
| tree | 7d3144433422bcf97f6812296b5646ed0166771a /compiler/rustc_passes | |
| parent | 0e190206e2ff0c13d64701d9b4145bf89a2d0cab (diff) | |
| download | rust-d3c69a4c0dd98af2611b7553d1a65afef6a6ccb0.tar.gz rust-d3c69a4c0dd98af2611b7553d1a65afef6a6ccb0.zip | |
Warn write-only fields
Diffstat (limited to 'compiler/rustc_passes')
| -rw-r--r-- | compiler/rustc_passes/src/dead.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index 3b1b53553d5..a4798b9ae1f 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -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); } |
