From 71e57ad0d9f89aade32ff32e605a2461f7212a69 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Mon, 15 Mar 2021 16:39:41 -0400 Subject: [PATCH] Revert PR 81473 to resolve (on beta) issues 81626 and 81658. Revert "Add missing brace" This reverts commit 85ad773049536d7fed9a94ae0ac74f97135c8655. Revert "Simplify base_expr" This reverts commit 899aae465eb4ef295dc1eeb2603f744568e0768c. Revert "Warn write-only fields" This reverts commit d3c69a4c0dd98af2611b7553d1a65afef6a6ccb0. --- compiler/rustc_passes/src/dead.rs | 15 ----------- .../borrowck/borrowck-assign-to-subfield.rs | 1 - .../ui/lint/dead-code/write-only-field.rs | 20 -------------- .../ui/lint/dead-code/write-only-field.stderr | 26 ------------------- 4 files changed, 62 deletions(-) delete mode 100644 src/test/ui/lint/dead-code/write-only-field.rs delete mode 100644 src/test/ui/lint/dead-code/write-only-field.stderr diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index 0d096a0556ba1..3b1b53553d5e4 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -37,15 +37,6 @@ fn should_explore(tcx: TyCtxt<'_>, hir_id: hir::HirId) -> bool { ) } -fn base_expr<'a>(mut expr: &'a hir::Expr<'a>) -> &'a hir::Expr<'a> { - loop { - match expr.kind { - hir::ExprKind::Field(base, ..) => expr = base, - _ => return expr, - } - } -} - struct MarkSymbolVisitor<'tcx> { worklist: Vec, tcx: TyCtxt<'tcx>, @@ -272,12 +263,6 @@ 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); } diff --git a/src/test/ui/borrowck/borrowck-assign-to-subfield.rs b/src/test/ui/borrowck/borrowck-assign-to-subfield.rs index dfa3a561ec7ee..050d702b625ab 100644 --- a/src/test/ui/borrowck/borrowck-assign-to-subfield.rs +++ b/src/test/ui/borrowck/borrowck-assign-to-subfield.rs @@ -1,6 +1,5 @@ // run-pass // pretty-expanded FIXME #23616 -#![allow(dead_code)] pub fn main() { struct A { diff --git a/src/test/ui/lint/dead-code/write-only-field.rs b/src/test/ui/lint/dead-code/write-only-field.rs deleted file mode 100644 index 78cfcfda8f971..0000000000000 --- a/src/test/ui/lint/dead-code/write-only-field.rs +++ /dev/null @@ -1,20 +0,0 @@ -#![deny(dead_code)] - -struct S { - f: i32, //~ ERROR: field is never read - sub: Sub, //~ ERROR: field is never read -} - -struct Sub { - f: i32, //~ ERROR: field is never read -} - -fn field_write(s: &mut S) { - s.f = 1; - s.sub.f = 2; -} - -fn main() { - let mut s = S { f: 0, sub: Sub { f: 0 } }; - field_write(&mut s); -} diff --git a/src/test/ui/lint/dead-code/write-only-field.stderr b/src/test/ui/lint/dead-code/write-only-field.stderr deleted file mode 100644 index 70d2149665b20..0000000000000 --- a/src/test/ui/lint/dead-code/write-only-field.stderr +++ /dev/null @@ -1,26 +0,0 @@ -error: field is never read: `f` - --> $DIR/write-only-field.rs:4:5 - | -LL | f: i32, - | ^^^^^^ - | -note: the lint level is defined here - --> $DIR/write-only-field.rs:1:9 - | -LL | #![deny(dead_code)] - | ^^^^^^^^^ - -error: field is never read: `sub` - --> $DIR/write-only-field.rs:5:5 - | -LL | sub: Sub, - | ^^^^^^^^ - -error: field is never read: `f` - --> $DIR/write-only-field.rs:9:5 - | -LL | f: i32, - | ^^^^^^ - -error: aborting due to 3 previous errors -