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
This commit is contained in:
commit
027187094e
@ -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);
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
// run-pass
|
||||
// pretty-expanded FIXME #23616
|
||||
#![allow(dead_code)]
|
||||
|
||||
pub fn main() {
|
||||
struct A {
|
||||
|
@ -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)]
|
||||
|
@ -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 });
|
||||
}
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user