about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorFabian Wolff <fabian.wolff@alumni.ethz.ch>2021-05-21 19:35:49 +0200
committerFabian Wolff <fabian.wolff@alumni.ethz.ch>2021-09-09 19:49:07 +0200
commit79adda930f9b607ecb4819ed7abcf1cd285e938a (patch)
tree96a1db43372408e95bcd5c6c5f250a43382a17cb /src/test
parent497ee321af3b8496eaccd7af7b437f18bab81abf (diff)
Ignore automatically derived impls of `Clone` and `Debug` in dead code analysis
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/array-slice-vec/slice_binary_search.rs1
-rw-r--r--src/test/ui/borrowck/borrowck-unused-mut-locals.rs1
-rw-r--r--src/test/ui/closures/2229_closure_analysis/diagnostics/liveness.rs1
-rw-r--r--src/test/ui/closures/2229_closure_analysis/diagnostics/liveness.stderr14
-rw-r--r--src/test/ui/closures/2229_closure_analysis/diagnostics/liveness_unintentional_copy.rs1
-rw-r--r--src/test/ui/closures/2229_closure_analysis/diagnostics/liveness_unintentional_copy.stderr6
-rw-r--r--src/test/ui/closures/2229_closure_analysis/run_pass/struct-pattern-matching-with-methods.rs1
-rw-r--r--src/test/ui/closures/2229_closure_analysis/run_pass/unsafe_ptr.rs2
-rw-r--r--src/test/ui/const-generics/broken-mir-2.rs3
-rw-r--r--src/test/ui/derives/clone-debug-dead-code.rs45
-rw-r--r--src/test/ui/derives/clone-debug-dead-code.stderr38
-rw-r--r--src/test/ui/deriving/deriving-clone-generic-struct.rs2
-rw-r--r--src/test/ui/deriving/deriving-clone-struct.rs2
-rw-r--r--src/test/ui/deriving/deriving-clone-tuple-struct.rs2
-rw-r--r--src/test/ui/deriving/deriving-in-fn.rs3
-rw-r--r--src/test/ui/issues/issue-19358.rs3
-rw-r--r--src/test/ui/issues/issue-3794.rs1
-rw-r--r--src/test/ui/monomorphize-abi-alignment.rs1
-rw-r--r--src/test/ui/moves/move-1-unique.rs1
-rw-r--r--src/test/ui/moves/move-3-unique.rs1
-rw-r--r--src/test/ui/overloaded/overloaded-autoderef-order.rs2
-rw-r--r--src/test/ui/self/ufcs-explicit-self.rs1
-rw-r--r--src/test/ui/structs-enums/class-cast-to-trait-multiple-types.rs1
-rw-r--r--src/test/ui/structs-enums/class-implement-traits.rs1
-rw-r--r--src/test/ui/structs-enums/functional-struct-upd.rs3
-rw-r--r--src/test/ui/structs-enums/tag-align-shape.rs1
26 files changed, 128 insertions, 10 deletions
diff --git a/src/test/ui/array-slice-vec/slice_binary_search.rs b/src/test/ui/array-slice-vec/slice_binary_search.rs
index 12236960179..4d8022ecba7 100644
--- a/src/test/ui/array-slice-vec/slice_binary_search.rs
+++ b/src/test/ui/array-slice-vec/slice_binary_search.rs
@@ -2,6 +2,7 @@
 
 // Test binary_search_by_key lifetime. Issue #34683
 
+#[allow(dead_code)]
 #[derive(Debug)]
 struct Assignment {
     topic: String,
diff --git a/src/test/ui/borrowck/borrowck-unused-mut-locals.rs b/src/test/ui/borrowck/borrowck-unused-mut-locals.rs
index fd0e346e2b4..23ef975cbbc 100644
--- a/src/test/ui/borrowck/borrowck-unused-mut-locals.rs
+++ b/src/test/ui/borrowck/borrowck-unused-mut-locals.rs
@@ -1,4 +1,5 @@
 // run-pass
+#![allow(dead_code)]
 #![deny(unused_mut)]
 
 #[derive(Debug)]
diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness.rs b/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness.rs
index 1cc22fac352..3399bc0018e 100644
--- a/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness.rs
+++ b/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness.rs
@@ -3,6 +3,7 @@
 // check-pass
 #![allow(unreachable_code)]
 #![warn(unused)]
+#![allow(dead_code)]
 
 #[derive(Debug)]
 struct Point {
diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness.stderr b/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness.stderr
index 4eac5a2d282..74109772724 100644
--- a/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness.stderr
+++ b/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness.stderr
@@ -1,5 +1,5 @@
 warning: value captured by `a` is never read
-  --> $DIR/liveness.rs:23:9
+  --> $DIR/liveness.rs:24:9
    |
 LL |         a = 1;
    |         ^
@@ -13,7 +13,7 @@ LL | #![warn(unused)]
    = help: did you mean to capture by reference instead?
 
 warning: unused variable: `a`
-  --> $DIR/liveness.rs:32:9
+  --> $DIR/liveness.rs:33:9
    |
 LL |         a += 1;
    |         ^
@@ -27,7 +27,7 @@ LL | #![warn(unused)]
    = help: did you mean to capture by reference instead?
 
 warning: value assigned to `a` is never read
-  --> $DIR/liveness.rs:52:9
+  --> $DIR/liveness.rs:53:9
    |
 LL |         a += 1;
    |         ^
@@ -35,7 +35,7 @@ LL |         a += 1;
    = help: maybe it is overwritten before being read?
 
 warning: value assigned to `a` is never read
-  --> $DIR/liveness.rs:76:13
+  --> $DIR/liveness.rs:77:13
    |
 LL |             a = Some("d1");
    |             ^
@@ -43,7 +43,7 @@ LL |             a = Some("d1");
    = help: maybe it is overwritten before being read?
 
 warning: value assigned to `b` is never read
-  --> $DIR/liveness.rs:84:13
+  --> $DIR/liveness.rs:85:13
    |
 LL |             b = Some("e1");
    |             ^
@@ -51,7 +51,7 @@ LL |             b = Some("e1");
    = help: maybe it is overwritten before being read?
 
 warning: value assigned to `b` is never read
-  --> $DIR/liveness.rs:86:13
+  --> $DIR/liveness.rs:87:13
    |
 LL |             b = Some("e2");
    |             ^
@@ -59,7 +59,7 @@ LL |             b = Some("e2");
    = help: maybe it is overwritten before being read?
 
 warning: unused variable: `b`
-  --> $DIR/liveness.rs:84:13
+  --> $DIR/liveness.rs:85:13
    |
 LL |             b = Some("e1");
    |             ^
diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness_unintentional_copy.rs b/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness_unintentional_copy.rs
index 10a7d07a1df..465c9476ba6 100644
--- a/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness_unintentional_copy.rs
+++ b/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness_unintentional_copy.rs
@@ -2,6 +2,7 @@
 
 // check-pass
 #![warn(unused)]
+#![allow(dead_code)]
 
 #[derive(Debug)]
 struct MyStruct {
diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness_unintentional_copy.stderr b/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness_unintentional_copy.stderr
index f74303e3dd6..11a440554f7 100644
--- a/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness_unintentional_copy.stderr
+++ b/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness_unintentional_copy.stderr
@@ -1,5 +1,5 @@
 warning: value assigned to `a` is never read
-  --> $DIR/liveness_unintentional_copy.rs:19:9
+  --> $DIR/liveness_unintentional_copy.rs:20:9
    |
 LL |         a = s;
    |         ^
@@ -13,7 +13,7 @@ LL | #![warn(unused)]
    = help: maybe it is overwritten before being read?
 
 warning: unused variable: `a`
-  --> $DIR/liveness_unintentional_copy.rs:19:9
+  --> $DIR/liveness_unintentional_copy.rs:20:9
    |
 LL |         a = s;
    |         ^
@@ -27,7 +27,7 @@ LL | #![warn(unused)]
    = help: did you mean to capture by reference instead?
 
 warning: unused variable: `a`
-  --> $DIR/liveness_unintentional_copy.rs:35:9
+  --> $DIR/liveness_unintentional_copy.rs:36:9
    |
 LL |         a += x;
    |         ^
diff --git a/src/test/ui/closures/2229_closure_analysis/run_pass/struct-pattern-matching-with-methods.rs b/src/test/ui/closures/2229_closure_analysis/run_pass/struct-pattern-matching-with-methods.rs
index 045fe78040a..ed222b3148f 100644
--- a/src/test/ui/closures/2229_closure_analysis/run_pass/struct-pattern-matching-with-methods.rs
+++ b/src/test/ui/closures/2229_closure_analysis/run_pass/struct-pattern-matching-with-methods.rs
@@ -1,6 +1,7 @@
 // edition:2021
 //check-pass
 #![warn(unused)]
+#![allow(dead_code)]
 #![feature(rustc_attrs)]
 
 #[derive(Debug, Clone, Copy)]
diff --git a/src/test/ui/closures/2229_closure_analysis/run_pass/unsafe_ptr.rs b/src/test/ui/closures/2229_closure_analysis/run_pass/unsafe_ptr.rs
index 8e4f91c27e2..3f7ddf93f06 100644
--- a/src/test/ui/closures/2229_closure_analysis/run_pass/unsafe_ptr.rs
+++ b/src/test/ui/closures/2229_closure_analysis/run_pass/unsafe_ptr.rs
@@ -3,6 +3,8 @@
 
 // Test that we can use raw ptrs when using `capture_disjoint_fields`.
 
+#![allow(dead_code)]
+
 #[derive(Debug)]
 struct S {
     s: String,
diff --git a/src/test/ui/const-generics/broken-mir-2.rs b/src/test/ui/const-generics/broken-mir-2.rs
index f9e03151374..9d62281178c 100644
--- a/src/test/ui/const-generics/broken-mir-2.rs
+++ b/src/test/ui/const-generics/broken-mir-2.rs
@@ -1,4 +1,7 @@
 // run-pass
+
+#![allow(dead_code)]
+
 use std::fmt::Debug;
 
 #[derive(Debug)]
diff --git a/src/test/ui/derives/clone-debug-dead-code.rs b/src/test/ui/derives/clone-debug-dead-code.rs
new file mode 100644
index 00000000000..80e91320939
--- /dev/null
+++ b/src/test/ui/derives/clone-debug-dead-code.rs
@@ -0,0 +1,45 @@
+// Checks that derived implementations of Clone and Debug do not
+// contribute to dead code analysis (issue #84647).
+
+#![forbid(dead_code)]
+
+struct A { f: () }
+//~^ ERROR: field is never read: `f`
+
+#[derive(Clone)]
+struct B { f: () }
+//~^ ERROR: field is never read: `f`
+
+#[derive(Debug)]
+struct C { f: () }
+//~^ ERROR: field is never read: `f`
+
+#[derive(Debug,Clone)]
+struct D { f: () }
+//~^ ERROR: field is never read: `f`
+
+struct E { f: () }
+//~^ ERROR: field is never read: `f`
+// Custom impl, still doesn't read f
+impl Clone for E {
+    fn clone(&self) -> Self {
+        Self { f: () }
+    }
+}
+
+struct F { f: () }
+// Custom impl that actually reads f
+impl Clone for F {
+    fn clone(&self) -> Self {
+        Self { f: self.f }
+    }
+}
+
+fn main() {
+    let _ = A { f: () };
+    let _ = B { f: () };
+    let _ = C { f: () };
+    let _ = D { f: () };
+    let _ = E { f: () };
+    let _ = F { f: () };
+}
diff --git a/src/test/ui/derives/clone-debug-dead-code.stderr b/src/test/ui/derives/clone-debug-dead-code.stderr
new file mode 100644
index 00000000000..226007f3647
--- /dev/null
+++ b/src/test/ui/derives/clone-debug-dead-code.stderr
@@ -0,0 +1,38 @@
+error: field is never read: `f`
+  --> $DIR/clone-debug-dead-code.rs:6:12
+   |
+LL | struct A { f: () }
+   |            ^^^^^
+   |
+note: the lint level is defined here
+  --> $DIR/clone-debug-dead-code.rs:4:11
+   |
+LL | #![forbid(dead_code)]
+   |           ^^^^^^^^^
+
+error: field is never read: `f`
+  --> $DIR/clone-debug-dead-code.rs:10:12
+   |
+LL | struct B { f: () }
+   |            ^^^^^
+
+error: field is never read: `f`
+  --> $DIR/clone-debug-dead-code.rs:14:12
+   |
+LL | struct C { f: () }
+   |            ^^^^^
+
+error: field is never read: `f`
+  --> $DIR/clone-debug-dead-code.rs:18:12
+   |
+LL | struct D { f: () }
+   |            ^^^^^
+
+error: field is never read: `f`
+  --> $DIR/clone-debug-dead-code.rs:21:12
+   |
+LL | struct E { f: () }
+   |            ^^^^^
+
+error: aborting due to 5 previous errors
+
diff --git a/src/test/ui/deriving/deriving-clone-generic-struct.rs b/src/test/ui/deriving/deriving-clone-generic-struct.rs
index f6e105555fd..4374d1594e4 100644
--- a/src/test/ui/deriving/deriving-clone-generic-struct.rs
+++ b/src/test/ui/deriving/deriving-clone-generic-struct.rs
@@ -1,6 +1,8 @@
 // run-pass
 // pretty-expanded FIXME #23616
 
+#![allow(dead_code)]
+
 #[derive(Clone)]
 struct S<T> {
     foo: (),
diff --git a/src/test/ui/deriving/deriving-clone-struct.rs b/src/test/ui/deriving/deriving-clone-struct.rs
index 7b0a1d20260..b93cbe5f8b6 100644
--- a/src/test/ui/deriving/deriving-clone-struct.rs
+++ b/src/test/ui/deriving/deriving-clone-struct.rs
@@ -1,6 +1,8 @@
 // run-pass
 // pretty-expanded FIXME #23616
 
+#![allow(dead_code)]
+
 #[derive(Clone)]
 struct S {
     _int: isize,
diff --git a/src/test/ui/deriving/deriving-clone-tuple-struct.rs b/src/test/ui/deriving/deriving-clone-tuple-struct.rs
index 166f1be55e0..7ad3f034713 100644
--- a/src/test/ui/deriving/deriving-clone-tuple-struct.rs
+++ b/src/test/ui/deriving/deriving-clone-tuple-struct.rs
@@ -1,6 +1,8 @@
 // run-pass
 // pretty-expanded FIXME #23616
 
+#![allow(dead_code)]
+
 #[derive(Clone)]
 struct S((), ());
 
diff --git a/src/test/ui/deriving/deriving-in-fn.rs b/src/test/ui/deriving/deriving-in-fn.rs
index 8931e94a4f8..07f91d05973 100644
--- a/src/test/ui/deriving/deriving-in-fn.rs
+++ b/src/test/ui/deriving/deriving-in-fn.rs
@@ -1,4 +1,7 @@
 // run-pass
+
+#![allow(dead_code)]
+
 pub fn main() {
     #[derive(Debug)]
     struct Foo {
diff --git a/src/test/ui/issues/issue-19358.rs b/src/test/ui/issues/issue-19358.rs
index f66e0a1c078..3970a4155e9 100644
--- a/src/test/ui/issues/issue-19358.rs
+++ b/src/test/ui/issues/issue-19358.rs
@@ -1,4 +1,7 @@
 // run-pass
+
+#![allow(dead_code)]
+
 trait Trait { fn dummy(&self) { } }
 
 #[derive(Debug)]
diff --git a/src/test/ui/issues/issue-3794.rs b/src/test/ui/issues/issue-3794.rs
index 408d8d866d8..1809e822c54 100644
--- a/src/test/ui/issues/issue-3794.rs
+++ b/src/test/ui/issues/issue-3794.rs
@@ -1,5 +1,6 @@
 // run-pass
 #![feature(box_syntax)]
+#![allow(dead_code)]
 
 trait T {
     fn print(&self);
diff --git a/src/test/ui/monomorphize-abi-alignment.rs b/src/test/ui/monomorphize-abi-alignment.rs
index 637b09fc04e..a8d8bd1d5fd 100644
--- a/src/test/ui/monomorphize-abi-alignment.rs
+++ b/src/test/ui/monomorphize-abi-alignment.rs
@@ -1,6 +1,7 @@
 // run-pass
 
 #![allow(non_upper_case_globals)]
+#![allow(dead_code)]
 /*!
  * On x86_64-linux-gnu and possibly other platforms, structs get 8-byte "preferred" alignment,
  * but their "ABI" alignment (i.e., what actually matters for data layout) is the largest alignment
diff --git a/src/test/ui/moves/move-1-unique.rs b/src/test/ui/moves/move-1-unique.rs
index 48baead074a..7d3987f6560 100644
--- a/src/test/ui/moves/move-1-unique.rs
+++ b/src/test/ui/moves/move-1-unique.rs
@@ -1,5 +1,6 @@
 // run-pass
 #![allow(unused_mut)]
+#![allow(dead_code)]
 #![feature(box_syntax)]
 
 #[derive(Clone)]
diff --git a/src/test/ui/moves/move-3-unique.rs b/src/test/ui/moves/move-3-unique.rs
index 55b10e057d8..d23a852433f 100644
--- a/src/test/ui/moves/move-3-unique.rs
+++ b/src/test/ui/moves/move-3-unique.rs
@@ -1,5 +1,6 @@
 // run-pass
 #![allow(unused_mut)]
+#![allow(dead_code)]
 #![feature(box_syntax)]
 
 #[derive(Clone)]
diff --git a/src/test/ui/overloaded/overloaded-autoderef-order.rs b/src/test/ui/overloaded/overloaded-autoderef-order.rs
index 1ae16d2a7fc..f48bae55f5f 100644
--- a/src/test/ui/overloaded/overloaded-autoderef-order.rs
+++ b/src/test/ui/overloaded/overloaded-autoderef-order.rs
@@ -1,5 +1,7 @@
 // run-pass
 
+#![allow(dead_code)]
+
 use std::rc::Rc;
 use std::ops::Deref;
 
diff --git a/src/test/ui/self/ufcs-explicit-self.rs b/src/test/ui/self/ufcs-explicit-self.rs
index 4e2405504f0..0aaaa7d47c3 100644
--- a/src/test/ui/self/ufcs-explicit-self.rs
+++ b/src/test/ui/self/ufcs-explicit-self.rs
@@ -1,5 +1,6 @@
 // run-pass
 #![feature(box_syntax)]
+#![allow(dead_code)]
 
 #[derive(Copy, Clone)]
 struct Foo {
diff --git a/src/test/ui/structs-enums/class-cast-to-trait-multiple-types.rs b/src/test/ui/structs-enums/class-cast-to-trait-multiple-types.rs
index 55975cbdb53..ca35a615d21 100644
--- a/src/test/ui/structs-enums/class-cast-to-trait-multiple-types.rs
+++ b/src/test/ui/structs-enums/class-cast-to-trait-multiple-types.rs
@@ -1,5 +1,6 @@
 // run-pass
 #![allow(non_camel_case_types)]
+#![allow(dead_code)]
 
 trait noisy {
   fn speak(&mut self) -> isize;
diff --git a/src/test/ui/structs-enums/class-implement-traits.rs b/src/test/ui/structs-enums/class-implement-traits.rs
index c9e98e21b9e..732aa146ce4 100644
--- a/src/test/ui/structs-enums/class-implement-traits.rs
+++ b/src/test/ui/structs-enums/class-implement-traits.rs
@@ -1,5 +1,6 @@
 // run-pass
 #![allow(non_camel_case_types)]
+#![allow(dead_code)]
 
 trait noisy {
     fn speak(&mut self);
diff --git a/src/test/ui/structs-enums/functional-struct-upd.rs b/src/test/ui/structs-enums/functional-struct-upd.rs
index 51c6b6d7e4f..68ff73a0805 100644
--- a/src/test/ui/structs-enums/functional-struct-upd.rs
+++ b/src/test/ui/structs-enums/functional-struct-upd.rs
@@ -1,4 +1,7 @@
 // run-pass
+
+#![allow(dead_code)]
+
 #[derive(Debug)]
 struct Foo {
     x: isize,
diff --git a/src/test/ui/structs-enums/tag-align-shape.rs b/src/test/ui/structs-enums/tag-align-shape.rs
index 87282ddbcca..ce599582378 100644
--- a/src/test/ui/structs-enums/tag-align-shape.rs
+++ b/src/test/ui/structs-enums/tag-align-shape.rs
@@ -1,5 +1,6 @@
 // run-pass
 #![allow(non_camel_case_types)]
+#![allow(dead_code)]
 
 #[derive(Debug)]
 enum a_tag {