Rust: Add test annotations.

This commit is contained in:
Geoffrey White
2024-09-18 13:05:06 +01:00
parent d79aa073ea
commit 3632a76eaf

View File

@@ -4,10 +4,10 @@
// --- locals ---
fn locals_1() {
let a = 1; // BAD: unused value
let a = 1; // BAD: unused value [NOT DETECTED]
let b = 1;
let c = 1;
let d = String::from("a"); // BAD: unused value
let d = String::from("a"); // BAD: unused value [NOT DETECTED]
let e = String::from("b");
let _ = 1; // (deliberately unused)
@@ -22,7 +22,7 @@ fn locals_1() {
fn locals_2() {
let a: i32;
let b: i32; // BAD: unused variable
let b: i32; // BAD: unused variable [NOT DETECTED]
let mut c: i32;
let mut d: i32;
let mut e: i32;
@@ -31,22 +31,22 @@ fn locals_2() {
let h: i32;
let i: i32;
b = 1; // BAD: unused value
b = 1; // BAD: unused value [NOT DETECTED]
c = 1; // BAD: unused value
c = 1; // BAD: unused value [NOT DETECTED]
c = 2;
println!("use {}", c);
c = 3; // BAD: unused value
c = 3; // BAD: unused value [NOT DETECTED]
d = 1;
if cond() {
d = 2; // BAD: unused value
d = 2; // BAD: unused value [NOT DETECTED]
d = 3;
} else {
}
println!("use {}", d);
e = 1; // BAD: unused value
e = 1; // BAD: unused value [NOT DETECTED]
if cond() {
e = 2;
} else {
@@ -57,16 +57,16 @@ fn locals_2() {
f = 1;
f += 1;
println!("use {}", f);
f += 1; // BAD: unused value
f += 1; // BAD: unused value [NOT DETECTED]
f = 1;
f += 1; // BAD: unused value
f += 1; // BAD: unused value [NOT DETECTED]
g = if cond() { 1 } else { 2 }; // BAD: unused value (x2)
g = if cond() { 1 } else { 2 }; // BAD: unused value (x2) [NOT DETECTED]
h = if cond() { 3 } else { 4 };
i = if cond() { h } else { 5 };
println!("use {}", i);
_ = 1; // (deliberately unused)
_ = 1; // (deliberately unused) [NOT DETECTED]
}
// --- structs ---
@@ -83,10 +83,10 @@ impl MyStruct {
}
fn structs() {
let a = MyStruct {val : 1 }; // BAD: unused value
let a = MyStruct {val : 1 }; // BAD: unused value [NOT DETECTED]
let b = MyStruct {val : 2 };
let c = MyStruct {val : 3 };
let mut d : MyStruct; // BAD: unused variable
let mut d : MyStruct; // BAD: unused variable [NOT DETECTED]
let mut e : MyStruct;
let mut f : MyStruct;
@@ -97,14 +97,14 @@ fn structs() {
e.val = 5;
println!("lets use {}", e.my_get());
f = MyStruct {val : 6 }; // BAD: unused value
f.val = 7; // BAD: unused value
f = MyStruct {val : 6 }; // BAD: unused value [NOT DETECTED]
f.val = 7; // BAD: unused value [NOT DETECTED]
}
// --- arrays ---
fn arrays() {
let is = [1, 2, 3]; // BAD: unused values (x3)
let is = [1, 2, 3]; // BAD: unused values (x3) [NOT DETECTED]
let js = [1, 2, 3];
let ks = [1, 2, 3];
@@ -118,13 +118,13 @@ fn arrays() {
// --- constants and statics ---
const CON1: i32 = 1;
const CON2: i32 = 2; // BAD: unused value
const CON2: i32 = 2; // BAD: unused value [NOT DETECTED]
static mut STAT1: i32 = 1;
static mut STAT2: i32 = 2; // BAD: unused value
static mut STAT2: i32 = 2; // BAD: unused value [NOT DETECTED]
fn statics() {
static mut STAT3: i32 = 0;
static mut STAT4: i32 = 0; // BAD: unused value
static mut STAT4: i32 = 0; // BAD: unused value [NOT DETECTED]
unsafe
{
@@ -136,7 +136,7 @@ fn statics() {
fn parameters(
x: i32,
y: i32, // BAD: unused variable
y: i32, // BAD: unused variable [NOT DETECTED]
_z: i32 // (`_` is asking the compiler, and by extension us, to not warn that this is unused)
) -> i32 {
return x;