summaryrefslogtreecommitdiffstats
path: root/tests/ui/liveness/liveness-consts.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:58 +0000
commita4b7ed7a42c716ab9f05e351f003d589124fd55d (patch)
treeb620cd3f223850b28716e474e80c58059dca5dd4 /tests/ui/liveness/liveness-consts.rs
parentAdding upstream version 1.67.1+dfsg1. (diff)
downloadrustc-a4b7ed7a42c716ab9f05e351f003d589124fd55d.tar.xz
rustc-a4b7ed7a42c716ab9f05e351f003d589124fd55d.zip
Adding upstream version 1.68.2+dfsg1.upstream/1.68.2+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/liveness/liveness-consts.rs')
-rw-r--r--tests/ui/liveness/liveness-consts.rs63
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/ui/liveness/liveness-consts.rs b/tests/ui/liveness/liveness-consts.rs
new file mode 100644
index 000000000..8fe2453ca
--- /dev/null
+++ b/tests/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
+ }];
+}