about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-07-22 18:41:27 +0000
committerbors <bors@rust-lang.org>2021-07-22 18:41:27 +0000
commit027187094ee05011d6602f5742f550851ccc7fd6 (patch)
treea20cfb3ccd190058614782e470581383ccc68f13
parente742158ef5483b9cd756b193402329af3d4ba177 (diff)
parentee2bb1f33868414f7cca441c6be3aec8d6a1d81a (diff)
downloadrust-027187094ee05011d6602f5742f550851ccc7fd6.tar.gz
rust-027187094ee05011d6602f5742f550851ccc7fd6.zip
Auto merge of #86212 - pnkfelix:mainline-targetted-revert-81473-warn-write-only-fields, r=simulacrum
Revert PR 81473 to resolve (on mainline) issues 81626 and 81658.

This is a nightly-targetted variant of PR #83171

The intent is to just address issue #81658 on all release channels, rather that keep repeatedly reverting PR #83171 on beta.

However, our intent is *also* to reland PR #83171 after we have addressed issue #81658 , most likely by coupling the re-landing of PR #83171 with an enhancement like PR #83004
-rw-r--r--compiler/rustc_passes/src/dead.rs8
-rw-r--r--src/test/ui/borrowck/borrowck-assign-to-subfield.rs1
-rw-r--r--src/test/ui/lint/dead-code/self-assign.rs2
-rw-r--r--src/test/ui/lint/dead-code/write-only-field.rs69
-rw-r--r--src/test/ui/lint/dead-code/write-only-field.stderr44
5 files changed, 4 insertions, 120 deletions
diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs
index 713d572b93a..b71ec700f81 100644
--- a/compiler/rustc_passes/src/dead.rs
+++ b/compiler/rustc_passes/src/dead.rs
@@ -134,6 +134,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
         }
     }
 
+    #[allow(dead_code)] // FIXME(81658): should be used + lint reinstated after #83171 relands.
     fn handle_assign(&mut self, expr: &'tcx hir::Expr<'tcx>) {
         if self
             .typeck_results()
@@ -150,6 +151,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
         }
     }
 
+    #[allow(dead_code)] // FIXME(81658): should be used + lint reinstated after #83171 relands.
     fn check_for_self_assign(&mut self, assign: &'tcx hir::Expr<'tcx>) {
         fn check_for_self_assign_helper(
             tcx: TyCtxt<'tcx>,
@@ -338,12 +340,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, ..) => {
-                self.handle_assign(left);
-                self.check_for_self_assign(expr);
-                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 dfa3a561ec7..050d702b625 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/self-assign.rs b/src/test/ui/lint/dead-code/self-assign.rs
index b8bf7d860c4..ea7ce98d884 100644
--- a/src/test/ui/lint/dead-code/self-assign.rs
+++ b/src/test/ui/lint/dead-code/self-assign.rs
@@ -1,6 +1,8 @@
 // Test that dead code warnings are issued for superfluous assignments of
 // fields or variables to themselves (issue #75356).
 
+// ignore-test FIXME(81658, 83171)
+
 // check-pass
 #![allow(unused_assignments)]
 #![warn(dead_code)]
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 7b3f1e9f5b6..00000000000
--- a/src/test/ui/lint/dead-code/write-only-field.rs
+++ /dev/null
@@ -1,69 +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);
-
-    auto_deref();
-    nested_boxes();
-}
-
-fn auto_deref() {
-    struct E {
-        x: bool,
-        y: bool, //~ ERROR: field is never read
-    }
-
-    struct P<'a> {
-        e: &'a mut E
-    }
-
-    impl P<'_> {
-        fn f(&mut self) {
-            self.e.x = true;
-            self.e.y = true;
-        }
-    }
-
-    let mut e = E { x: false, y: false };
-    let mut p = P { e: &mut e };
-    p.f();
-    assert!(e.x);
-}
-
-fn nested_boxes() {
-    struct A {
-        b: Box<B>,
-    }
-
-    struct B {
-        c: Box<C>,
-    }
-
-    struct C {
-        u: u32, //~ ERROR: field is never read
-        v: u32, //~ ERROR: field is never read
-    }
-
-    let mut a = A {
-        b: Box::new(B {
-            c: Box::new(C { u: 0, v: 0 }),
-        }),
-    };
-    a.b.c.v = 10;
-    a.b.c = Box::new(C { u: 1, v: 2 });
-}
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 a191d22c8b9..00000000000
--- a/src/test/ui/lint/dead-code/write-only-field.stderr
+++ /dev/null
@@ -1,44 +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: field is never read: `y`
-  --> $DIR/write-only-field.rs:28:9
-   |
-LL |         y: bool,
-   |         ^^^^^^^
-
-error: field is never read: `u`
-  --> $DIR/write-only-field.rs:58:9
-   |
-LL |         u: u32,
-   |         ^^^^^^
-
-error: field is never read: `v`
-  --> $DIR/write-only-field.rs:59:9
-   |
-LL |         v: u32,
-   |         ^^^^^^
-
-error: aborting due to 6 previous errors
-