Skip to content

Commit e631902

Browse files
committed
Use query ID
1 parent 94f8d1f commit e631902

File tree

8 files changed

+111
-137
lines changed

8 files changed

+111
-137
lines changed

rust/ql/test/query-tests/unusedentities/UnreachableCode.ext.yml

Lines changed: 0 additions & 6 deletions
This file was deleted.

rust/ql/test/query-tests/unusedentities/UnusedValue.ext.yml

Lines changed: 0 additions & 6 deletions
This file was deleted.

rust/ql/test/query-tests/unusedentities/UnusedVariable.ext.yml

Lines changed: 0 additions & 6 deletions
This file was deleted.

rust/ql/test/query-tests/unusedentities/main.rs

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
// --- locals ---
44

55
fn locals_1() {
6-
let a = 1; // $ Alert[value that is never used]
6+
let a = 1; // $ Alert[rust/unused-value]
77
let b = 1;
88
let c = 1;
9-
let d = String::from("a"); // $ Alert[value that is never used]
9+
let d = String::from("a"); // $ Alert[rust/unused-value]
1010
let e = String::from("b");
1111
let f = 1;
1212
let _ = 1; // (deliberately unused)
@@ -22,7 +22,7 @@ fn locals_1() {
2222
}
2323

2424
fn locals_2() {
25-
let a: i32; // $ Alert[Variable is not used]
25+
let a: i32; // $ Alert[rust/unused-variable]
2626
let b: i32;
2727
let mut c: i32;
2828
let mut d: i32;
@@ -32,22 +32,22 @@ fn locals_2() {
3232
let h: i32;
3333
let i: i32;
3434

35-
b = 1; // $ Alert[value that is never used]
35+
b = 1; // $ Alert[rust/unused-value]
3636

37-
c = 1; // $ Alert[value that is never used]
37+
c = 1; // $ Alert[rust/unused-value]
3838
c = 2;
3939
println!("use {}", c);
40-
c = 3; // $ Alert[value that is never used]
40+
c = 3; // $ Alert[rust/unused-value]
4141

4242
d = 1;
4343
if cond() {
44-
d = 2; // $ Alert[value that is never used]
44+
d = 2; // $ Alert[rust/unused-value]
4545
d = 3;
4646
} else {
4747
}
4848
println!("use {}", d);
4949

50-
e = 1; // $ Alert[value that is never used]
50+
e = 1; // $ Alert[rust/unused-value]
5151
if cond() {
5252
e = 2;
5353
} else {
@@ -58,11 +58,11 @@ fn locals_2() {
5858
f = 1;
5959
f += 1;
6060
println!("use {}", f);
61-
f += 1; // $ Alert[value that is never used]
61+
f += 1; // $ Alert[rust/unused-value]
6262
f = 1;
63-
f += 1; // $ Alert[value that is never used]
63+
f += 1; // $ Alert[rust/unused-value]
6464

65-
g = if cond() { 1 } else { 2 }; // $ Alert[value that is never used]
65+
g = if cond() { 1 } else { 2 }; // $ Alert[rust/unused-value]
6666
h = if cond() { 3 } else { 4 };
6767
i = if cond() { h } else { 5 };
6868
println!("use {}", i);
@@ -84,10 +84,10 @@ impl MyStruct {
8484
}
8585

8686
fn structs() {
87-
let a = MyStruct { val: 1 }; // $ Alert[value that is never used]
87+
let a = MyStruct { val: 1 }; // $ Alert[rust/unused-value]
8888
let b = MyStruct { val: 2 };
8989
let c = MyStruct { val: 3 };
90-
let mut d: MyStruct; // $ Alert[Variable is not used]
90+
let mut d: MyStruct; // $ Alert[rust/unused-variable]
9191
let mut e: MyStruct;
9292
let mut f: MyStruct;
9393

@@ -98,14 +98,14 @@ fn structs() {
9898
e.val = 5;
9999
println!("lets use {}", e.my_get());
100100

101-
f = MyStruct { val: 6 }; // $ MISSING: Alert[value that is never used]
102-
f.val = 7; // $ MISSING: Alert[value that is never used]
101+
f = MyStruct { val: 6 }; // $ MISSING: Alert[rust/unused-value]
102+
f.val = 7; // $ MISSING: Alert[rust/unused-value]
103103
}
104104

105105
// --- arrays ---
106106

107107
fn arrays() {
108-
let is = [1, 2, 3]; // $ Alert[value that is never used]
108+
let is = [1, 2, 3]; // $ Alert[rust/unused-value]
109109
let js = [1, 2, 3];
110110
let ks = [1, 2, 3];
111111

@@ -119,24 +119,24 @@ fn arrays() {
119119
// --- constants and statics ---
120120

121121
const CON1: i32 = 1;
122-
const CON2: i32 = 2; // $ MISSING: Alert[value that is never used]
122+
const CON2: i32 = 2; // $ MISSING: Alert[rust/unused-value]
123123
static mut STAT1: i32 = 1;
124-
static mut STAT2: i32 = 2; // $ MISSING: Alert[value that is never used]
124+
static mut STAT2: i32 = 2; // $ MISSING: Alert[rust/unused-value]
125125

126126
fn statics() {
127127
static mut STAT3: i32 = 0;
128-
static mut STAT4: i32 = 0; // $ MISSING: Alert[value that is never used]
128+
static mut STAT4: i32 = 0; // $ MISSING: Alert[rust/unused-value]
129129

130130
unsafe {
131-
let total = CON1 + STAT1 + STAT3; // $ Alert[value that is never used]
131+
let total = CON1 + STAT1 + STAT3; // $ Alert[rust/unused-value]
132132
}
133133
}
134134

135135
// --- parameters ---
136136

137137
fn parameters(
138138
x: i32,
139-
y: i32, // $ Alert[Variable is not used]
139+
y: i32, // $ Alert[rust/unused-variable]
140140
_z: i32, // (`_` is asking the compiler, and by extension us, to not warn that this is unused)
141141
) -> i32 {
142142
return x;
@@ -163,7 +163,7 @@ fn loops() {
163163
e += x;
164164
}
165165

166-
for x in 1..10 { // $ Alert[Variable is not used]
166+
for x in 1..10 { // $ Alert[rust/unused-variable]
167167
}
168168

169169
for _ in 1..10 {}
@@ -191,7 +191,7 @@ fn loops() {
191191
}
192192

193193
for x in 1..10 {
194-
_ = format!("x is {x}"); // $ SPURIOUS: Alert[value that is never used]
194+
_ = format!("x is {x}"); // $ SPURIOUS: Alert[rust/unused-value]
195195
}
196196

197197
for x in 1..10 {
@@ -203,11 +203,11 @@ fn loops() {
203203
}
204204

205205
for x in 1..10 {
206-
assert_eq!(x, 1); // $ SPURIOUS: Alert[value that is never used]
206+
assert_eq!(x, 1); // $ SPURIOUS: Alert[rust/unused-value]
207207
}
208208

209209
for x in 1..10 {
210-
assert_eq!(id(x), id(1)); // $ SPURIOUS: Alert[value that is never used]
210+
assert_eq!(id(x), id(1)); // $ SPURIOUS: Alert[rust/unused-value]
211211
}
212212
}
213213

@@ -233,15 +233,15 @@ struct MyPoint {
233233
fn if_lets_matches() {
234234
let mut total: i64 = 0;
235235

236-
if let Some(a) = Some(10) { // $ Alert[Variable is not used]
236+
if let Some(a) = Some(10) { // $ Alert[rust/unused-variable]
237237
}
238238

239239
if let Some(b) = Some(20) {
240240
total += b;
241241
}
242242

243243
let mut next = Some(30);
244-
while let Some(val) = // $ Alert[Variable is not used]
244+
while let Some(val) = // $ Alert[rust/unused-variable]
245245
next
246246
{
247247
next = None;
@@ -255,37 +255,37 @@ fn if_lets_matches() {
255255

256256
let c = Some(60);
257257
match c {
258-
Some(val) => { // $ Alert[Variable is not used]
258+
Some(val) => { // $ Alert[rust/unused-variable]
259259
}
260260
None => {}
261261
}
262262

263263
let d = Some(70);
264264
match d {
265265
Some(val) => {
266-
total += val; // $ Alert[value that is never used]
266+
total += val; // $ Alert[rust/unused-value]
267267
}
268268
None => {}
269269
}
270270

271271
let e = Option::Some(80);
272272
match e {
273-
Option::Some(val) => { // $ Alert[Variable is not used]
273+
Option::Some(val) => { // $ Alert[rust/unused-variable]
274274
}
275275
Option::None => {}
276276
}
277277

278278
let f = MyOption::Some(90);
279279
match f {
280-
MyOption::Some(val) => { // $ Alert[Variable is not used]
280+
MyOption::Some(val) => { // $ Alert[rust/unused-variable]
281281
}
282282
MyOption::None => {}
283283
}
284284

285285
let g: Result<i64, i64> = Ok(100);
286286
match g {
287287
Ok(_) => {}
288-
Err(num) => {} // $ Alert[Variable is not used]
288+
Err(num) => {} // $ Alert[rust/unused-variable]
289289
}
290290

291291
let h = YesOrNo::Yes;
@@ -300,7 +300,7 @@ fn if_lets_matches() {
300300
No => {}
301301
}
302302

303-
if let j = Yes { // $ Alert[Variable is not used]
303+
if let j = Yes { // $ Alert[rust/unused-variable]
304304
}
305305

306306
if let k = Yes {
@@ -320,18 +320,18 @@ fn if_lets_matches() {
320320
let p1 = MyPoint { x: 1, y: 2 };
321321
match p1 {
322322
MyPoint { x: 0, y: 0 } => {}
323-
MyPoint { x: 1, y } => { // $ Alert[Variable is not used]
323+
MyPoint { x: 1, y } => { // $ Alert[rust/unused-variable]
324324
}
325325
MyPoint { x: 2, y: _ } => {}
326-
MyPoint { x: 3, y: a } => { // $ Alert[Variable is not used]
326+
MyPoint { x: 3, y: a } => { // $ Alert[rust/unused-variable]
327327
}
328328
MyPoint { x: 4, .. } => {}
329-
p => { // $ Alert[Variable is not used]
329+
p => { // $ Alert[rust/unused-variable]
330330
}
331331
}
332332

333333
let duration1 = std::time::Duration::new(10, 0); // ten seconds
334-
assert_eq!(duration1.as_secs(), 10); // $ SPURIOUS: Alert[value that is never used]
334+
assert_eq!(duration1.as_secs(), 10); // $ SPURIOUS: Alert[rust/unused-value]
335335

336336
let duration2: Result<std::time::Duration, String> = Ok(std::time::Duration::new(10, 0));
337337
match duration2 {
@@ -344,28 +344,28 @@ fn if_lets_matches() {
344344
}
345345

346346
let (left,
347-
right) = // $ MISSING: Alert[value that is never used] $ SPURIOUS: Alert[Variable is not used]
347+
right) = // $ MISSING: Alert[rust/unused-value] $ SPURIOUS: Alert[rust/unused-variable]
348348
(1, 2);
349349
_ = left;
350350

351351
let pair = (1, 2);
352352
let (left2,
353-
right2) = // $ MISSING: Alert[value that is never used] $ SPURIOUS: Alert[Variable is not used]
353+
right2) = // $ MISSING: Alert[rust/unused-value] $ SPURIOUS: Alert[rust/unused-variable]
354354
pair;
355355
_ = left2;
356356
}
357357

358358
fn shadowing() -> i32 {
359-
let x = 1; // $ Alert[value that is never used]
360-
let mut y: i32; // $ Alert[Variable is not used]
359+
let x = 1; // $ Alert[rust/unused-value]
360+
let mut y: i32; // $ Alert[rust/unused-variable]
361361

362362
{
363363
let x = 2;
364364
let mut y: i32;
365365

366366
{
367-
let x = 3; // $ Alert[value that is never used]
368-
let mut y: i32; // $ Alert[Variable is not used]
367+
let x = 3; // $ Alert[rust/unused-value]
368+
let mut y: i32; // $ Alert[rust/unused-variable]
369369
}
370370

371371
y = x;
@@ -410,12 +410,12 @@ fn folds_and_closures() {
410410
_ = a3.fold(0, |acc, val| acc + val);
411411

412412
let a4 = 1..10;
413-
_ = a4.fold(0, |acc, val| acc); // $ Alert[Variable is not used]
413+
_ = a4.fold(0, |acc, val| acc); // $ Alert[rust/unused-variable]
414414

415415
let a5 = 1..10;
416-
_ = a5.fold(0, |acc, val| val); // $ Alert[Variable is not used]
416+
_ = a5.fold(0, |acc, val| val); // $ Alert[rust/unused-variable]
417417

418-
let i6 = 1; // $ SPURIOUS: Alert[value that is never used]
418+
let i6 = 1; // $ SPURIOUS: Alert[rust/unused-value]
419419
let a6 = 1..10;
420420
_ = a6.fold(0, |acc, val| acc + val + i6);
421421
}
@@ -434,7 +434,7 @@ impl Incrementable for MyValue {
434434
fn increment(
435435
&mut self,
436436
times: i32,
437-
unused: i32, // $ Alert[Variable is not used]
437+
unused: i32, // $ Alert[rust/unused-variable]
438438
) {
439439
self.value += times;
440440
}

rust/ql/test/query-tests/unusedentities/more.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ impl<T> MySettable<T> for MyContainer<T> {
2121
impl<T> MyGettable<T> for MyContainer<T> {
2222
fn get(
2323
&self,
24-
val: T, // $ SPURIOUS: Alert[value that is never used] $ MISSING: Alert[Variable is not used]
24+
val: T, // $ SPURIOUS: Alert[rust/unused-value] $ MISSING: Alert[rust/unused-variable]
2525
) -> &T {
2626
return &(self.val);
2727
}
2828
}
2929

3030
fn generics() {
31-
let mut a = MyContainer { val: 1 }; // $ MISSING: Alert[value that is never used]
31+
let mut a = MyContainer { val: 1 }; // $ MISSING: Alert[rust/unused-value]
3232
let b = MyContainer { val: 2 };
3333

3434
a.set(*b.get(3));
@@ -40,13 +40,13 @@ fn pointers() {
4040
let a = 1;
4141
let a_ptr1 = &a;
4242
let a_ptr2 = &a;
43-
let a_ptr3 = &a; // $ MISSING: Alert[value that is never used]
44-
let a_ptr4 = &a; // $ Alert[value that is never used]
43+
let a_ptr3 = &a; // $ MISSING: Alert[rust/unused-value]
44+
let a_ptr4 = &a; // $ Alert[rust/unused-value]
4545
println!("{}", *a_ptr1);
4646
println!("{}", a_ptr2);
4747
println!("{}", &a_ptr3);
4848

49-
let b = 2; // $ MISSING: Alert[value that is never used]
49+
let b = 2; // $ MISSING: Alert[rust/unused-value]
5050
let b_ptr = &b;
5151
println!("{}", b_ptr);
5252

@@ -56,26 +56,26 @@ fn pointers() {
5656
println!("{}", **c_ptr_ptr);
5757

5858
let d = 4;
59-
let d_ptr = &d; // $ Alert[value that is never used]
59+
let d_ptr = &d; // $ Alert[rust/unused-value]
6060
let d_ptr_ptr = &&d;
6161
println!("{}", **d_ptr_ptr);
6262

63-
let e = 5; // $ MISSING: Alert[value that is never used]
63+
let e = 5; // $ MISSING: Alert[rust/unused-value]
6464
let f = 6;
65-
let mut f_ptr = &e; // $ Alert[value that is never used]
65+
let mut f_ptr = &e; // $ Alert[rust/unused-value]
6666
f_ptr = &f;
6767
println!("{}", *f_ptr);
6868

69-
let mut g = 7; // $ MISSING: Alert[value that is never used]
69+
let mut g = 7; // $ MISSING: Alert[rust/unused-value]
7070
let g_ptr = &mut g;
71-
*g_ptr = 77; // $ MISSING: Alert[value that is never used]
71+
*g_ptr = 77; // $ MISSING: Alert[rust/unused-value]
7272

73-
let mut h = 8; // $ MISSING: Alert[value that is never used]
73+
let mut h = 8; // $ MISSING: Alert[rust/unused-value]
7474
let h_ptr = &mut h;
7575
*h_ptr = 88;
7676
println!("{}", h);
7777

78-
let mut i = 9; // $ MISSING: Alert[value that is never used]
78+
let mut i = 9; // $ MISSING: Alert[rust/unused-value]
7979
let i_ptr = &mut i;
8080
*i_ptr = 99;
8181
let i_ptr2 = &mut i;

0 commit comments

Comments
 (0)