about summary refs log tree commit diff
path: root/src/test/ui
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-09-30 12:44:31 +0000
committerbors <bors@rust-lang.org>2020-09-30 12:44:31 +0000
commit939cc3e445db1eaf8b3834984e274f8c2267d9c5 (patch)
treeee1792368a944eb82f5794f6ea5b7a54a4b3a9f7 /src/test/ui
parent511ed9f2356af365ad8affe046b3dd33f7ac3c98 (diff)
parent924e8aaaf21653ffb1775a0ed9be219ee377370b (diff)
downloadrust-939cc3e445db1eaf8b3834984e274f8c2267d9c5.tar.gz
rust-939cc3e445db1eaf8b3834984e274f8c2267d9c5.zip
Auto merge of #77281 - tmiasko:liveness-everybody, r=oli-obk
Liveness analysis for everybody

Perform liveness analysis for every body instead of limiting it to fns.

Fixes #77169.
Diffstat (limited to 'src/test/ui')
-rw-r--r--src/test/ui/consts/const-block-non-item-statement-3.rs2
-rw-r--r--src/test/ui/consts/const-block-non-item-statement-rpass.rs2
-rw-r--r--src/test/ui/consts/control-flow/drop-pass.rs1
-rw-r--r--src/test/ui/liveness/liveness-consts.rs63
-rw-r--r--src/test/ui/liveness/liveness-consts.stderr68
-rw-r--r--src/test/ui/liveness/liveness-derive.rs2
-rw-r--r--src/test/ui/liveness/liveness-derive.stderr16
7 files changed, 146 insertions, 8 deletions
diff --git a/src/test/ui/consts/const-block-non-item-statement-3.rs b/src/test/ui/consts/const-block-non-item-statement-3.rs
index 10a4c31f24e..c513946d189 100644
--- a/src/test/ui/consts/const-block-non-item-statement-3.rs
+++ b/src/test/ui/consts/const-block-non-item-statement-3.rs
@@ -1,5 +1,5 @@
 // run-pass
-#![allow(dead_code)]
+#![allow(dead_code, unused)]
 
 type Array = [u32; {  let x = 2; 5 }];
 
diff --git a/src/test/ui/consts/const-block-non-item-statement-rpass.rs b/src/test/ui/consts/const-block-non-item-statement-rpass.rs
index a1b9b586ad0..3e52eb50e75 100644
--- a/src/test/ui/consts/const-block-non-item-statement-rpass.rs
+++ b/src/test/ui/consts/const-block-non-item-statement-rpass.rs
@@ -1,5 +1,5 @@
 // run-pass
-#![allow(dead_code)]
+#![allow(dead_code, unused)]
 
 #[repr(u8)]
 enum Foo {
diff --git a/src/test/ui/consts/control-flow/drop-pass.rs b/src/test/ui/consts/control-flow/drop-pass.rs
index 95f954a59a8..2a6d12768c3 100644
--- a/src/test/ui/consts/control-flow/drop-pass.rs
+++ b/src/test/ui/consts/control-flow/drop-pass.rs
@@ -1,6 +1,7 @@
 // run-pass
 // revisions: stock precise
 
+#![allow(unused)]
 #![cfg_attr(precise, feature(const_precise_live_drops))]
 
 // `x` is always moved into the final value and is not dropped inside the initializer.
diff --git a/src/test/ui/liveness/liveness-consts.rs b/src/test/ui/liveness/liveness-consts.rs
new file mode 100644
index 00000000000..8fe2453ca22
--- /dev/null
+++ b/src/test/ui/liveness/liveness-consts.rs
@@ -0,0 +1,63 @@
+// check-pass
+#![warn(unused)]
+#![allow(unreachable_code)]
+
+pub static A: i32 = {
+    let mut i = 0;
+    let mut a = 0; //~ WARN variable `a` is assigned to, but never used
+    while i < 10 {
+        i += 1;
+        a += 1;
+    }
+    i
+};
+
+pub const B: u32 = {
+    let mut b = 1;
+    b += 1; //~ WARN value assigned to `b` is never read
+    b = 42;
+    b
+};
+
+pub enum E {
+    V1 = {
+        let e = 1; //~ WARN unused variable: `e`
+        1
+    },
+    V2 = {
+        let _f = 10;
+        2
+    }
+}
+
+pub fn f(x: [u8; { let s = 17; 100 }]) -> [u8;  { let z = 18; 100 }] {
+    //~^ WARN unused variable: `s`
+    //~| WARN unused variable: `z`
+    x
+}
+
+pub trait T {
+    const T: usize = {
+        let mut t = 10;
+        t = t + t; //~ WARN value assigned to `t` is never read
+        20
+    };
+}
+
+impl T for String {
+    const T: usize = {
+        let w = 10; //~ WARN unused variable: `w`
+        loop {
+            break;
+            let _ = w;
+        }
+        44
+    };
+}
+
+fn main() {
+    let _ = [(); {
+        let z = 42; //~ WARN unused variable: `z`
+        35
+    }];
+}
diff --git a/src/test/ui/liveness/liveness-consts.stderr b/src/test/ui/liveness/liveness-consts.stderr
new file mode 100644
index 00000000000..fa8a590a819
--- /dev/null
+++ b/src/test/ui/liveness/liveness-consts.stderr
@@ -0,0 +1,68 @@
+warning: variable `a` is assigned to, but never used
+  --> $DIR/liveness-consts.rs:7:9
+   |
+LL |     let mut a = 0;
+   |         ^^^^^
+   |
+note: the lint level is defined here
+  --> $DIR/liveness-consts.rs:2:9
+   |
+LL | #![warn(unused)]
+   |         ^^^^^^
+   = note: `#[warn(unused_variables)]` implied by `#[warn(unused)]`
+   = note: consider using `_a` instead
+
+warning: value assigned to `b` is never read
+  --> $DIR/liveness-consts.rs:17:5
+   |
+LL |     b += 1;
+   |     ^
+   |
+note: the lint level is defined here
+  --> $DIR/liveness-consts.rs:2:9
+   |
+LL | #![warn(unused)]
+   |         ^^^^^^
+   = note: `#[warn(unused_assignments)]` implied by `#[warn(unused)]`
+   = help: maybe it is overwritten before being read?
+
+warning: unused variable: `e`
+  --> $DIR/liveness-consts.rs:24:13
+   |
+LL |         let e = 1;
+   |             ^ help: if this is intentional, prefix it with an underscore: `_e`
+
+warning: unused variable: `s`
+  --> $DIR/liveness-consts.rs:33:24
+   |
+LL | pub fn f(x: [u8; { let s = 17; 100 }]) -> [u8;  { let z = 18; 100 }] {
+   |                        ^ help: if this is intentional, prefix it with an underscore: `_s`
+
+warning: unused variable: `z`
+  --> $DIR/liveness-consts.rs:33:55
+   |
+LL | pub fn f(x: [u8; { let s = 17; 100 }]) -> [u8;  { let z = 18; 100 }] {
+   |                                                       ^ help: if this is intentional, prefix it with an underscore: `_z`
+
+warning: unused variable: `z`
+  --> $DIR/liveness-consts.rs:60:13
+   |
+LL |         let z = 42;
+   |             ^ help: if this is intentional, prefix it with an underscore: `_z`
+
+warning: value assigned to `t` is never read
+  --> $DIR/liveness-consts.rs:42:9
+   |
+LL |         t = t + t;
+   |         ^
+   |
+   = help: maybe it is overwritten before being read?
+
+warning: unused variable: `w`
+  --> $DIR/liveness-consts.rs:49:13
+   |
+LL |         let w = 10;
+   |             ^ help: if this is intentional, prefix it with an underscore: `_w`
+
+warning: 8 warnings emitted
+
diff --git a/src/test/ui/liveness/liveness-derive.rs b/src/test/ui/liveness/liveness-derive.rs
index 66d0b7090ff..1921d0d72bc 100644
--- a/src/test/ui/liveness/liveness-derive.rs
+++ b/src/test/ui/liveness/liveness-derive.rs
@@ -12,7 +12,7 @@ pub trait T: Sized {
 
 impl T for u32 {
     const N: usize = {
-        let a = 0; // FIXME should warn about unused variable
+        let a = 0; //~ WARN unused variable: `a`
         4
     };
 
diff --git a/src/test/ui/liveness/liveness-derive.stderr b/src/test/ui/liveness/liveness-derive.stderr
index d4f45a0a313..c03d9099183 100644
--- a/src/test/ui/liveness/liveness-derive.stderr
+++ b/src/test/ui/liveness/liveness-derive.stderr
@@ -1,8 +1,8 @@
-warning: unused variable: `b`
-  --> $DIR/liveness-derive.rs:20:13
+warning: unused variable: `a`
+  --> $DIR/liveness-derive.rs:15:13
    |
-LL |         let b = 16;
-   |             ^ help: if this is intentional, prefix it with an underscore: `_b`
+LL |         let a = 0;
+   |             ^ help: if this is intentional, prefix it with an underscore: `_a`
    |
 note: the lint level is defined here
   --> $DIR/liveness-derive.rs:6:9
@@ -11,5 +11,11 @@ LL | #![warn(unused)]
    |         ^^^^^^
    = note: `#[warn(unused_variables)]` implied by `#[warn(unused)]`
 
-warning: 1 warning emitted
+warning: unused variable: `b`
+  --> $DIR/liveness-derive.rs:20:13
+   |
+LL |         let b = 16;
+   |             ^ help: if this is intentional, prefix it with an underscore: `_b`
+
+warning: 2 warnings emitted