From 30910837051f1cdb7e4009bb3387959b16302000 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Tue, 5 Nov 2024 10:54:54 +0000 Subject: [PATCH 1/9] Rust: Call all the test cases. --- .../unusedentities/UnusedValue.expected | 32 +++++++------- .../unusedentities/UnusedVariable.expected | 42 +++++++++---------- .../test/query-tests/unusedentities/main.rs | 8 +++- .../test/query-tests/unusedentities/more.rs | 4 +- 4 files changed, 45 insertions(+), 41 deletions(-) diff --git a/rust/ql/test/query-tests/unusedentities/UnusedValue.expected b/rust/ql/test/query-tests/unusedentities/UnusedValue.expected index 420ffcee1448..ed5f261dac3e 100644 --- a/rust/ql/test/query-tests/unusedentities/UnusedValue.expected +++ b/rust/ql/test/query-tests/unusedentities/UnusedValue.expected @@ -1,19 +1,19 @@ -| main.rs:8:9:8:9 | a | Variable $@ is assigned a value that is never used. | main.rs:8:9:8:9 | a | a | -| main.rs:11:9:11:9 | d | Variable $@ is assigned a value that is never used. | main.rs:11:9:11:9 | d | d | -| main.rs:37:5:37:5 | b | Variable $@ is assigned a value that is never used. | main.rs:28:9:28:9 | b | b | -| main.rs:39:5:39:5 | c | Variable $@ is assigned a value that is never used. | main.rs:29:13:29:13 | c | c | -| main.rs:42:5:42:5 | c | Variable $@ is assigned a value that is never used. | main.rs:29:13:29:13 | c | c | -| main.rs:46:9:46:9 | d | Variable $@ is assigned a value that is never used. | main.rs:30:13:30:13 | d | d | -| main.rs:52:5:52:5 | e | Variable $@ is assigned a value that is never used. | main.rs:31:13:31:13 | e | e | -| main.rs:63:5:63:5 | f | Variable $@ is assigned a value that is never used. | main.rs:32:13:32:13 | f | f | -| main.rs:65:5:65:5 | f | Variable $@ is assigned a value that is never used. | main.rs:32:13:32:13 | f | f | -| main.rs:67:5:67:5 | g | Variable $@ is assigned a value that is never used. | main.rs:33:9:33:9 | g | g | -| main.rs:89:9:89:9 | a | Variable $@ is assigned a value that is never used. | main.rs:89:9:89:9 | a | a | -| main.rs:110:9:110:10 | is | Variable $@ is assigned a value that is never used. | main.rs:110:9:110:10 | is | is | -| main.rs:133:13:133:17 | total | Variable $@ is assigned a value that is never used. | main.rs:133:13:133:17 | total | total | -| main.rs:270:13:270:17 | total | Variable $@ is assigned a value that is never used. | main.rs:238:13:238:17 | total | total | -| main.rs:363:9:363:9 | x | Variable $@ is assigned a value that is never used. | main.rs:363:9:363:9 | x | x | -| main.rs:371:17:371:17 | x | Variable $@ is assigned a value that is never used. | main.rs:371:17:371:17 | x | x | +| main.rs:10:9:10:9 | a | Variable $@ is assigned a value that is never used. | main.rs:10:9:10:9 | a | a | +| main.rs:13:9:13:9 | d | Variable $@ is assigned a value that is never used. | main.rs:13:9:13:9 | d | d | +| main.rs:39:5:39:5 | b | Variable $@ is assigned a value that is never used. | main.rs:30:9:30:9 | b | b | +| main.rs:41:5:41:5 | c | Variable $@ is assigned a value that is never used. | main.rs:31:13:31:13 | c | c | +| main.rs:44:5:44:5 | c | Variable $@ is assigned a value that is never used. | main.rs:31:13:31:13 | c | c | +| main.rs:48:9:48:9 | d | Variable $@ is assigned a value that is never used. | main.rs:32:13:32:13 | d | d | +| main.rs:54:5:54:5 | e | Variable $@ is assigned a value that is never used. | main.rs:33:13:33:13 | e | e | +| main.rs:65:5:65:5 | f | Variable $@ is assigned a value that is never used. | main.rs:34:13:34:13 | f | f | +| main.rs:67:5:67:5 | f | Variable $@ is assigned a value that is never used. | main.rs:34:13:34:13 | f | f | +| main.rs:69:5:69:5 | g | Variable $@ is assigned a value that is never used. | main.rs:35:9:35:9 | g | g | +| main.rs:91:9:91:9 | a | Variable $@ is assigned a value that is never used. | main.rs:91:9:91:9 | a | a | +| main.rs:112:9:112:10 | is | Variable $@ is assigned a value that is never used. | main.rs:112:9:112:10 | is | is | +| main.rs:135:13:135:17 | total | Variable $@ is assigned a value that is never used. | main.rs:135:13:135:17 | total | total | +| main.rs:272:13:272:17 | total | Variable $@ is assigned a value that is never used. | main.rs:240:13:240:17 | total | total | +| main.rs:365:9:365:9 | x | Variable $@ is assigned a value that is never used. | main.rs:365:9:365:9 | x | x | +| main.rs:373:17:373:17 | x | Variable $@ is assigned a value that is never used. | main.rs:373:17:373:17 | x | x | | more.rs:44:9:44:14 | a_ptr4 | Variable $@ is assigned a value that is never used. | more.rs:44:9:44:14 | a_ptr4 | a_ptr4 | | more.rs:59:9:59:13 | d_ptr | Variable $@ is assigned a value that is never used. | more.rs:59:9:59:13 | d_ptr | d_ptr | | more.rs:65:9:65:17 | f_ptr | Variable $@ is assigned a value that is never used. | more.rs:65:13:65:17 | f_ptr | f_ptr | diff --git a/rust/ql/test/query-tests/unusedentities/UnusedVariable.expected b/rust/ql/test/query-tests/unusedentities/UnusedVariable.expected index 7f459575f02e..134bef8692b8 100644 --- a/rust/ql/test/query-tests/unusedentities/UnusedVariable.expected +++ b/rust/ql/test/query-tests/unusedentities/UnusedVariable.expected @@ -1,22 +1,22 @@ -| main.rs:27:9:27:9 | a | Variable 'a' is not used. | -| main.rs:92:13:92:13 | d | Variable 'd' is not used. | -| main.rs:141:5:141:5 | y | Variable 'y' is not used. | -| main.rs:168:9:168:9 | x | Variable 'x' is not used. | -| main.rs:240:17:240:17 | a | Variable 'a' is not used. | -| main.rs:248:20:248:22 | val | Variable 'val' is not used. | -| main.rs:262:14:262:16 | val | Variable 'val' is not used. | -| main.rs:277:22:277:24 | val | Variable 'val' is not used. | -| main.rs:284:24:284:26 | val | Variable 'val' is not used. | -| main.rs:292:13:292:15 | num | Variable 'num' is not used. | -| main.rs:307:12:307:12 | j | Variable 'j' is not used. | -| main.rs:327:25:327:25 | y | Variable 'y' is not used. | -| main.rs:330:28:330:28 | a | Variable 'a' is not used. | -| main.rs:333:9:333:9 | p | Variable 'p' is not used. | -| main.rs:351:9:351:13 | right | Variable 'right' is not used. | -| main.rs:357:9:357:14 | right2 | Variable 'right2' is not used. | -| main.rs:364:13:364:13 | y | Variable 'y' is not used. | -| main.rs:372:21:372:21 | y | Variable 'y' is not used. | -| main.rs:417:26:417:28 | val | Variable 'val' is not used. | -| main.rs:420:21:420:23 | acc | Variable 'acc' is not used. | -| main.rs:441:9:441:14 | unused | Variable 'unused' is not used. | +| main.rs:29:9:29:9 | a | Variable 'a' is not used. | +| main.rs:94:13:94:13 | d | Variable 'd' is not used. | +| main.rs:143:5:143:5 | y | Variable 'y' is not used. | +| main.rs:170:9:170:9 | x | Variable 'x' is not used. | +| main.rs:242:17:242:17 | a | Variable 'a' is not used. | +| main.rs:250:20:250:22 | val | Variable 'val' is not used. | +| main.rs:264:14:264:16 | val | Variable 'val' is not used. | +| main.rs:279:22:279:24 | val | Variable 'val' is not used. | +| main.rs:286:24:286:26 | val | Variable 'val' is not used. | +| main.rs:294:13:294:15 | num | Variable 'num' is not used. | +| main.rs:309:12:309:12 | j | Variable 'j' is not used. | +| main.rs:329:25:329:25 | y | Variable 'y' is not used. | +| main.rs:332:28:332:28 | a | Variable 'a' is not used. | +| main.rs:335:9:335:9 | p | Variable 'p' is not used. | +| main.rs:353:9:353:13 | right | Variable 'right' is not used. | +| main.rs:359:9:359:14 | right2 | Variable 'right2' is not used. | +| main.rs:366:13:366:13 | y | Variable 'y' is not used. | +| main.rs:374:21:374:21 | y | Variable 'y' is not used. | +| main.rs:419:26:419:28 | val | Variable 'val' is not used. | +| main.rs:422:21:422:23 | acc | Variable 'acc' is not used. | +| main.rs:443:9:443:14 | unused | Variable 'unused' is not used. | | more.rs:24:9:24:11 | val | Variable 'val' is not used. | diff --git a/rust/ql/test/query-tests/unusedentities/main.rs b/rust/ql/test/query-tests/unusedentities/main.rs index ee315f63d002..a1f865e5cce0 100644 --- a/rust/ql/test/query-tests/unusedentities/main.rs +++ b/rust/ql/test/query-tests/unusedentities/main.rs @@ -1,5 +1,7 @@ +mod more; mod unreachable; +use more::*; use unreachable::*; // --- locals --- @@ -479,6 +481,10 @@ fn main() { shadowing(); func_ptrs(); folds_and_closures(); + macros(); + + generics(); + pointers(); unreachable_if_1(); // unreachable_panic(); @@ -489,6 +495,4 @@ fn main() { unreachable_let_2(); unreachable_if_2(); unreachable_if_3(); - - macros(); } diff --git a/rust/ql/test/query-tests/unusedentities/more.rs b/rust/ql/test/query-tests/unusedentities/more.rs index 4788575b9de1..27acf729ef65 100644 --- a/rust/ql/test/query-tests/unusedentities/more.rs +++ b/rust/ql/test/query-tests/unusedentities/more.rs @@ -27,7 +27,7 @@ impl MyGettable for MyContainer { } } -fn generics() { +pub fn generics() { let mut a = MyContainer { val: 1 }; // $ MISSING: Alert[rust/unused-value] let b = MyContainer { val: 2 }; @@ -36,7 +36,7 @@ fn generics() { // --- pointers --- -fn pointers() { +pub fn pointers() { let a = 1; let a_ptr1 = &a; let a_ptr2 = &a; From 35ffd0cc9c8d34fb1a4701f478594a143af3a26b Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Tue, 5 Nov 2024 11:03:10 +0000 Subject: [PATCH 2/9] Rust: Add more test cases for unused variables (inspired by real world FPs). --- .../unusedentities/UnusedValue.expected | 7 ++-- .../unusedentities/UnusedVariable.expected | 38 ++++++++++--------- .../test/query-tests/unusedentities/main.rs | 36 ++++++++++++++++++ 3 files changed, 61 insertions(+), 20 deletions(-) diff --git a/rust/ql/test/query-tests/unusedentities/UnusedValue.expected b/rust/ql/test/query-tests/unusedentities/UnusedValue.expected index ed5f261dac3e..f8538e5b8bc8 100644 --- a/rust/ql/test/query-tests/unusedentities/UnusedValue.expected +++ b/rust/ql/test/query-tests/unusedentities/UnusedValue.expected @@ -11,9 +11,10 @@ | main.rs:91:9:91:9 | a | Variable $@ is assigned a value that is never used. | main.rs:91:9:91:9 | a | a | | main.rs:112:9:112:10 | is | Variable $@ is assigned a value that is never used. | main.rs:112:9:112:10 | is | is | | main.rs:135:13:135:17 | total | Variable $@ is assigned a value that is never used. | main.rs:135:13:135:17 | total | total | -| main.rs:272:13:272:17 | total | Variable $@ is assigned a value that is never used. | main.rs:240:13:240:17 | total | total | -| main.rs:365:9:365:9 | x | Variable $@ is assigned a value that is never used. | main.rs:365:9:365:9 | x | x | -| main.rs:373:17:373:17 | x | Variable $@ is assigned a value that is never used. | main.rs:373:17:373:17 | x | x | +| main.rs:280:13:280:17 | total | Variable $@ is assigned a value that is never used. | main.rs:248:13:248:17 | total | total | +| main.rs:373:9:373:9 | x | Variable $@ is assigned a value that is never used. | main.rs:373:9:373:9 | x | x | +| main.rs:381:17:381:17 | x | Variable $@ is assigned a value that is never used. | main.rs:381:17:381:17 | x | x | +| main.rs:482:9:482:9 | c | Variable $@ is assigned a value that is never used. | main.rs:482:9:482:9 | c | c | | more.rs:44:9:44:14 | a_ptr4 | Variable $@ is assigned a value that is never used. | more.rs:44:9:44:14 | a_ptr4 | a_ptr4 | | more.rs:59:9:59:13 | d_ptr | Variable $@ is assigned a value that is never used. | more.rs:59:9:59:13 | d_ptr | d_ptr | | more.rs:65:9:65:17 | f_ptr | Variable $@ is assigned a value that is never used. | more.rs:65:13:65:17 | f_ptr | f_ptr | diff --git a/rust/ql/test/query-tests/unusedentities/UnusedVariable.expected b/rust/ql/test/query-tests/unusedentities/UnusedVariable.expected index 134bef8692b8..a7af5a4fb033 100644 --- a/rust/ql/test/query-tests/unusedentities/UnusedVariable.expected +++ b/rust/ql/test/query-tests/unusedentities/UnusedVariable.expected @@ -2,21 +2,25 @@ | main.rs:94:13:94:13 | d | Variable 'd' is not used. | | main.rs:143:5:143:5 | y | Variable 'y' is not used. | | main.rs:170:9:170:9 | x | Variable 'x' is not used. | -| main.rs:242:17:242:17 | a | Variable 'a' is not used. | -| main.rs:250:20:250:22 | val | Variable 'val' is not used. | -| main.rs:264:14:264:16 | val | Variable 'val' is not used. | -| main.rs:279:22:279:24 | val | Variable 'val' is not used. | -| main.rs:286:24:286:26 | val | Variable 'val' is not used. | -| main.rs:294:13:294:15 | num | Variable 'num' is not used. | -| main.rs:309:12:309:12 | j | Variable 'j' is not used. | -| main.rs:329:25:329:25 | y | Variable 'y' is not used. | -| main.rs:332:28:332:28 | a | Variable 'a' is not used. | -| main.rs:335:9:335:9 | p | Variable 'p' is not used. | -| main.rs:353:9:353:13 | right | Variable 'right' is not used. | -| main.rs:359:9:359:14 | right2 | Variable 'right2' is not used. | -| main.rs:366:13:366:13 | y | Variable 'y' is not used. | -| main.rs:374:21:374:21 | y | Variable 'y' is not used. | -| main.rs:419:26:419:28 | val | Variable 'val' is not used. | -| main.rs:422:21:422:23 | acc | Variable 'acc' is not used. | -| main.rs:443:9:443:14 | unused | Variable 'unused' is not used. | +| main.rs:250:17:250:17 | a | Variable 'a' is not used. | +| main.rs:258:20:258:22 | val | Variable 'val' is not used. | +| main.rs:272:14:272:16 | val | Variable 'val' is not used. | +| main.rs:287:22:287:24 | val | Variable 'val' is not used. | +| main.rs:294:24:294:26 | val | Variable 'val' is not used. | +| main.rs:302:13:302:15 | num | Variable 'num' is not used. | +| main.rs:317:12:317:12 | j | Variable 'j' is not used. | +| main.rs:337:25:337:25 | y | Variable 'y' is not used. | +| main.rs:340:28:340:28 | a | Variable 'a' is not used. | +| main.rs:343:9:343:9 | p | Variable 'p' is not used. | +| main.rs:361:9:361:13 | right | Variable 'right' is not used. | +| main.rs:367:9:367:14 | right2 | Variable 'right2' is not used. | +| main.rs:374:13:374:13 | y | Variable 'y' is not used. | +| main.rs:382:21:382:21 | y | Variable 'y' is not used. | +| main.rs:427:26:427:28 | val | Variable 'val' is not used. | +| main.rs:430:21:430:23 | acc | Variable 'acc' is not used. | +| main.rs:451:9:451:14 | unused | Variable 'unused' is not used. | +| main.rs:494:16:494:16 | x | Variable 'x' is not used. | +| main.rs:495:16:495:16 | y | Variable 'y' is not used. | +| main.rs:496:12:496:12 | z | Variable 'z' is not used. | +| main.rs:499:18:499:18 | x | Variable 'x' is not used. | | more.rs:24:9:24:11 | val | Variable 'val' is not used. | diff --git a/rust/ql/test/query-tests/unusedentities/main.rs b/rust/ql/test/query-tests/unusedentities/main.rs index a1f865e5cce0..e57878c235fa 100644 --- a/rust/ql/test/query-tests/unusedentities/main.rs +++ b/rust/ql/test/query-tests/unusedentities/main.rs @@ -198,6 +198,14 @@ fn loops() { _ = format!("x is {x}"); } + for x in 1..10 { + _ = format!("x is {x:?}"); + } + + [1, 2, 3].iter().for_each(|x| { + _ = format!("x is {x}"); + }); + for x in 1..10 { println!("x is {val}", val = x); } @@ -466,6 +474,33 @@ fn macros() { }) ) } +// --- references --- + +fn references() { + let a = 1; + let b = &a; + let c = *b; // $ Alert[rust/unused-value] + let d = 2; + let e = 3; + let f = &&e; + + assert!(&d != *f); +} + +// --- declarations in types --- + +pub struct my_declaration { + field1: fn(i32) -> i32, + field2: fn(x: i32) -> i32, // $ SPURIOUS: Alert[rust/unused-variable] + field3: fn(y: // $ SPURIOUS: Alert[rust/unused-variable] + fn(z: i32) -> i32) -> i32, // $ SPURIOUS: Alert[rust/unused-variable] +} + +type MyType = fn(x: i32) -> i32; // $ SPURIOUS: Alert[rust/unused-variable] + +trait MyTrait { + fn my_func2(&self, x: i32) -> i32; +} // --- main --- @@ -482,6 +517,7 @@ fn main() { func_ptrs(); folds_and_closures(); macros(); + references(); generics(); pointers(); From 278760c73525fbdbb44057eb341ec7a053d361bd Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Tue, 5 Nov 2024 14:42:18 +0000 Subject: [PATCH 3/9] Rust: Add another exception to rust/unused-variable. --- rust/ql/src/queries/unusedentities/UnusedVariable.qll | 6 +++++- .../test/query-tests/unusedentities/UnusedValue.expected | 4 ++++ .../query-tests/unusedentities/UnusedVariable.expected | 4 ---- rust/ql/test/query-tests/unusedentities/main.rs | 8 ++++---- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/rust/ql/src/queries/unusedentities/UnusedVariable.qll b/rust/ql/src/queries/unusedentities/UnusedVariable.qll index 020b559c2765..2d3409f22aa7 100644 --- a/rust/ql/src/queries/unusedentities/UnusedVariable.qll +++ b/rust/ql/src/queries/unusedentities/UnusedVariable.qll @@ -7,8 +7,12 @@ class DiscardVariable extends Variable { /** Holds if variable `v` is unused. */ predicate isUnused(Variable v) { + // variable is accessed or initialized not exists(v.getAnAccess()) and not exists(v.getInitializer()) and + // variable is intentionally unused not v instanceof DiscardVariable and - not v.getPat().isInMacroExpansion() + // variable is in a context where is may not have a use + not v.getPat().isInMacroExpansion() and + not exists(FnPtrType fp | fp.getParamList().getParam(_).getPat() = v.getPat()) } diff --git a/rust/ql/test/query-tests/unusedentities/UnusedValue.expected b/rust/ql/test/query-tests/unusedentities/UnusedValue.expected index f8538e5b8bc8..c435b4f78a88 100644 --- a/rust/ql/test/query-tests/unusedentities/UnusedValue.expected +++ b/rust/ql/test/query-tests/unusedentities/UnusedValue.expected @@ -15,6 +15,10 @@ | main.rs:373:9:373:9 | x | Variable $@ is assigned a value that is never used. | main.rs:373:9:373:9 | x | x | | main.rs:381:17:381:17 | x | Variable $@ is assigned a value that is never used. | main.rs:381:17:381:17 | x | x | | main.rs:482:9:482:9 | c | Variable $@ is assigned a value that is never used. | main.rs:482:9:482:9 | c | c | +| main.rs:494:16:494:16 | x | Variable $@ is assigned a value that is never used. | main.rs:494:16:494:16 | x | x | +| main.rs:495:16:495:16 | y | Variable $@ is assigned a value that is never used. | main.rs:495:16:495:16 | y | y | +| main.rs:496:12:496:12 | z | Variable $@ is assigned a value that is never used. | main.rs:496:12:496:12 | z | z | +| main.rs:499:18:499:18 | x | Variable $@ is assigned a value that is never used. | main.rs:499:18:499:18 | x | x | | more.rs:44:9:44:14 | a_ptr4 | Variable $@ is assigned a value that is never used. | more.rs:44:9:44:14 | a_ptr4 | a_ptr4 | | more.rs:59:9:59:13 | d_ptr | Variable $@ is assigned a value that is never used. | more.rs:59:9:59:13 | d_ptr | d_ptr | | more.rs:65:9:65:17 | f_ptr | Variable $@ is assigned a value that is never used. | more.rs:65:13:65:17 | f_ptr | f_ptr | diff --git a/rust/ql/test/query-tests/unusedentities/UnusedVariable.expected b/rust/ql/test/query-tests/unusedentities/UnusedVariable.expected index a7af5a4fb033..dcfde3c46f54 100644 --- a/rust/ql/test/query-tests/unusedentities/UnusedVariable.expected +++ b/rust/ql/test/query-tests/unusedentities/UnusedVariable.expected @@ -19,8 +19,4 @@ | main.rs:427:26:427:28 | val | Variable 'val' is not used. | | main.rs:430:21:430:23 | acc | Variable 'acc' is not used. | | main.rs:451:9:451:14 | unused | Variable 'unused' is not used. | -| main.rs:494:16:494:16 | x | Variable 'x' is not used. | -| main.rs:495:16:495:16 | y | Variable 'y' is not used. | -| main.rs:496:12:496:12 | z | Variable 'z' is not used. | -| main.rs:499:18:499:18 | x | Variable 'x' is not used. | | more.rs:24:9:24:11 | val | Variable 'val' is not used. | diff --git a/rust/ql/test/query-tests/unusedentities/main.rs b/rust/ql/test/query-tests/unusedentities/main.rs index e57878c235fa..f29f1afd6599 100644 --- a/rust/ql/test/query-tests/unusedentities/main.rs +++ b/rust/ql/test/query-tests/unusedentities/main.rs @@ -491,12 +491,12 @@ fn references() { pub struct my_declaration { field1: fn(i32) -> i32, - field2: fn(x: i32) -> i32, // $ SPURIOUS: Alert[rust/unused-variable] - field3: fn(y: // $ SPURIOUS: Alert[rust/unused-variable] - fn(z: i32) -> i32) -> i32, // $ SPURIOUS: Alert[rust/unused-variable] + field2: fn(x: i32) -> i32, // $ SPURIOUS: Alert[rust/unused-value] + field3: fn(y: // $ SPURIOUS: Alert[rust/unused-value] + fn(z: i32) -> i32) -> i32, // $ SPURIOUS: Alert[rust/unused-value] } -type MyType = fn(x: i32) -> i32; // $ SPURIOUS: Alert[rust/unused-variable] +type MyType = fn(x: i32) -> i32; // $ SPURIOUS: Alert[rust/unused-value] trait MyTrait { fn my_func2(&self, x: i32) -> i32; From 93836a55e2b6396ac583bf4f5a7497d416d8642d Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Tue, 5 Nov 2024 15:03:11 +0000 Subject: [PATCH 4/9] Rust: Clean up code / clarify responsibilities and fix the issue in rust/unused-value as well. --- .../queries/unusedentities/UnusedVariable.ql | 5 +++- .../queries/unusedentities/UnusedVariable.qll | 26 +++++++++++++------ .../unusedentities/UnusedValue.expected | 4 --- .../test/query-tests/unusedentities/main.rs | 8 +++--- 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/rust/ql/src/queries/unusedentities/UnusedVariable.ql b/rust/ql/src/queries/unusedentities/UnusedVariable.ql index 339bb0967fbf..388c98d07b6a 100644 --- a/rust/ql/src/queries/unusedentities/UnusedVariable.ql +++ b/rust/ql/src/queries/unusedentities/UnusedVariable.ql @@ -12,5 +12,8 @@ import rust import UnusedVariable from Variable v -where isUnused(v) +where + isUnused(v) and + not isAllowableUnused(v) and + not v instanceof DiscardVariable select v, "Variable '" + v + "' is not used." diff --git a/rust/ql/src/queries/unusedentities/UnusedVariable.qll b/rust/ql/src/queries/unusedentities/UnusedVariable.qll index 2d3409f22aa7..26edc7e0a9c2 100644 --- a/rust/ql/src/queries/unusedentities/UnusedVariable.qll +++ b/rust/ql/src/queries/unusedentities/UnusedVariable.qll @@ -1,18 +1,28 @@ import rust -/** A deliberately unused variable. */ +/** + * A deliberately unused variable, for example `_` or `_x`. + */ class DiscardVariable extends Variable { DiscardVariable() { this.getName().charAt(0) = "_" } } -/** Holds if variable `v` is unused. */ +/** + * Holds if variable `v` is unused. + */ predicate isUnused(Variable v) { // variable is accessed or initialized not exists(v.getAnAccess()) and - not exists(v.getInitializer()) and - // variable is intentionally unused - not v instanceof DiscardVariable and - // variable is in a context where is may not have a use - not v.getPat().isInMacroExpansion() and - not exists(FnPtrType fp | fp.getParamList().getParam(_).getPat() = v.getPat()) + not exists(v.getInitializer()) +} + +/** + * Holds if variable `v` is in a context where we may not find a use for it, + * but that's expected and should not be considered a problem. + */ +predicate isAllowableUnused(Variable v) { + // in a macro expansion + v.getPat().isInMacroExpansion() or + // function pointer parameters + exists(FnPtrType fp | fp.getParamList().getParam(_).getPat() = v.getPat()) } diff --git a/rust/ql/test/query-tests/unusedentities/UnusedValue.expected b/rust/ql/test/query-tests/unusedentities/UnusedValue.expected index c435b4f78a88..f8538e5b8bc8 100644 --- a/rust/ql/test/query-tests/unusedentities/UnusedValue.expected +++ b/rust/ql/test/query-tests/unusedentities/UnusedValue.expected @@ -15,10 +15,6 @@ | main.rs:373:9:373:9 | x | Variable $@ is assigned a value that is never used. | main.rs:373:9:373:9 | x | x | | main.rs:381:17:381:17 | x | Variable $@ is assigned a value that is never used. | main.rs:381:17:381:17 | x | x | | main.rs:482:9:482:9 | c | Variable $@ is assigned a value that is never used. | main.rs:482:9:482:9 | c | c | -| main.rs:494:16:494:16 | x | Variable $@ is assigned a value that is never used. | main.rs:494:16:494:16 | x | x | -| main.rs:495:16:495:16 | y | Variable $@ is assigned a value that is never used. | main.rs:495:16:495:16 | y | y | -| main.rs:496:12:496:12 | z | Variable $@ is assigned a value that is never used. | main.rs:496:12:496:12 | z | z | -| main.rs:499:18:499:18 | x | Variable $@ is assigned a value that is never used. | main.rs:499:18:499:18 | x | x | | more.rs:44:9:44:14 | a_ptr4 | Variable $@ is assigned a value that is never used. | more.rs:44:9:44:14 | a_ptr4 | a_ptr4 | | more.rs:59:9:59:13 | d_ptr | Variable $@ is assigned a value that is never used. | more.rs:59:9:59:13 | d_ptr | d_ptr | | more.rs:65:9:65:17 | f_ptr | Variable $@ is assigned a value that is never used. | more.rs:65:13:65:17 | f_ptr | f_ptr | diff --git a/rust/ql/test/query-tests/unusedentities/main.rs b/rust/ql/test/query-tests/unusedentities/main.rs index f29f1afd6599..814a2ffee5b2 100644 --- a/rust/ql/test/query-tests/unusedentities/main.rs +++ b/rust/ql/test/query-tests/unusedentities/main.rs @@ -491,12 +491,12 @@ fn references() { pub struct my_declaration { field1: fn(i32) -> i32, - field2: fn(x: i32) -> i32, // $ SPURIOUS: Alert[rust/unused-value] - field3: fn(y: // $ SPURIOUS: Alert[rust/unused-value] - fn(z: i32) -> i32) -> i32, // $ SPURIOUS: Alert[rust/unused-value] + field2: fn(x: i32) -> i32, + field3: fn(y: + fn(z: i32) -> i32) -> i32, } -type MyType = fn(x: i32) -> i32; // $ SPURIOUS: Alert[rust/unused-value] +type MyType = fn(x: i32) -> i32; trait MyTrait { fn my_func2(&self, x: i32) -> i32; From 1a5d2e1f5de86b8898fce9a9d74c4bb916ebf10a Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Tue, 5 Nov 2024 15:22:46 +0000 Subject: [PATCH 5/9] Rust: Correct a comment and autoformat. --- rust/ql/src/queries/unusedentities/UnusedVariable.qll | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rust/ql/src/queries/unusedentities/UnusedVariable.qll b/rust/ql/src/queries/unusedentities/UnusedVariable.qll index 26edc7e0a9c2..650d63f318ed 100644 --- a/rust/ql/src/queries/unusedentities/UnusedVariable.qll +++ b/rust/ql/src/queries/unusedentities/UnusedVariable.qll @@ -11,7 +11,7 @@ class DiscardVariable extends Variable { * Holds if variable `v` is unused. */ predicate isUnused(Variable v) { - // variable is accessed or initialized + // variable is not accessed or initialized not exists(v.getAnAccess()) and not exists(v.getInitializer()) } @@ -22,7 +22,8 @@ predicate isUnused(Variable v) { */ predicate isAllowableUnused(Variable v) { // in a macro expansion - v.getPat().isInMacroExpansion() or + v.getPat().isInMacroExpansion() + or // function pointer parameters exists(FnPtrType fp | fp.getParamList().getParam(_).getPat() = v.getPat()) } From 8a35e151d11241ef95b9ef983d0fdaf2be60627a Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Wed, 6 Nov 2024 10:51:41 +0000 Subject: [PATCH 6/9] Rust: Move the function pointer parameter exclusion into VariableImpl.qll. --- rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll | 4 +++- rust/ql/src/queries/unusedentities/UnusedVariable.qll | 3 --- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll b/rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll index f862ec2cef1c..d6fa101f40b3 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll @@ -87,7 +87,9 @@ module Impl { not name.charAt(0).isUppercase() and // exclude parameters from functions without a body as these are trait method declarations // without implementations - not exists(Function f | not f.hasBody() and f.getParamList().getAParam().getPat() = p) + not exists(Function f | not f.hasBody() and f.getParamList().getAParam().getPat() = p) and + // exclude parameters from function pointers as well, which also lack a body + not exists(FnPtrType fp | fp.getParamList().getParam(_).getPat() = p) } /** A variable. */ diff --git a/rust/ql/src/queries/unusedentities/UnusedVariable.qll b/rust/ql/src/queries/unusedentities/UnusedVariable.qll index 650d63f318ed..d92f8787af12 100644 --- a/rust/ql/src/queries/unusedentities/UnusedVariable.qll +++ b/rust/ql/src/queries/unusedentities/UnusedVariable.qll @@ -23,7 +23,4 @@ predicate isUnused(Variable v) { predicate isAllowableUnused(Variable v) { // in a macro expansion v.getPat().isInMacroExpansion() - or - // function pointer parameters - exists(FnPtrType fp | fp.getParamList().getParam(_).getPat() = v.getPat()) } From 18ce8be3024bfb79cea8571a1446d4401a20f20f Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Wed, 6 Nov 2024 19:00:10 +0000 Subject: [PATCH 7/9] Update rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll Co-authored-by: Simon Friis Vindum --- rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll b/rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll index d6fa101f40b3..10f079a4c5d6 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll @@ -88,7 +88,7 @@ module Impl { // exclude parameters from functions without a body as these are trait method declarations // without implementations not exists(Function f | not f.hasBody() and f.getParamList().getAParam().getPat() = p) and - // exclude parameters from function pointers as well, which also lack a body + // exclude parameters from function pointer types (e.g. `x` in `fn(x: i32) -> i32`) not exists(FnPtrType fp | fp.getParamList().getParam(_).getPat() = p) } From df7bcfd11673eb4c31c37770c3af9f271a5c6799 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Thu, 7 Nov 2024 09:53:26 +0000 Subject: [PATCH 8/9] Rust: Accept dataflow consistency check changes. --- .../CONSISTENCY/DataFlowConsistency.expected | 241 ++++++++++-------- 1 file changed, 132 insertions(+), 109 deletions(-) diff --git a/rust/ql/test/query-tests/unusedentities/CONSISTENCY/DataFlowConsistency.expected b/rust/ql/test/query-tests/unusedentities/CONSISTENCY/DataFlowConsistency.expected index 300f3fc863aa..27c29a9ae962 100644 --- a/rust/ql/test/query-tests/unusedentities/CONSISTENCY/DataFlowConsistency.expected +++ b/rust/ql/test/query-tests/unusedentities/CONSISTENCY/DataFlowConsistency.expected @@ -1,105 +1,121 @@ uniqueEnclosingCallable -| main.rs:140:5:140:10 | Param | Node should have one enclosing callable but has 0. | -| main.rs:141:5:141:10 | Param | Node should have one enclosing callable but has 0. | -| main.rs:142:5:142:11 | Param | Node should have one enclosing callable but has 0. | -| main.rs:149:7:149:12 | Param | Node should have one enclosing callable but has 0. | -| main.rs:382:19:382:21 | Param | Node should have one enclosing callable but has 0. | -| main.rs:384:14:384:19 | Param | Node should have one enclosing callable but has 0. | -| main.rs:411:21:411:28 | Param | Node should have one enclosing callable but has 0. | -| main.rs:411:31:411:38 | Param | Node should have one enclosing callable but has 0. | -| main.rs:414:21:414:23 | Param | Node should have one enclosing callable but has 0. | -| main.rs:414:26:414:28 | Param | Node should have one enclosing callable but has 0. | -| main.rs:417:21:417:23 | Param | Node should have one enclosing callable but has 0. | -| main.rs:417:26:417:28 | Param | Node should have one enclosing callable but has 0. | -| main.rs:420:21:420:23 | Param | Node should have one enclosing callable but has 0. | -| main.rs:420:26:420:28 | Param | Node should have one enclosing callable but has 0. | +| main.rs:142:5:142:10 | Param | Node should have one enclosing callable but has 0. | +| main.rs:143:5:143:10 | Param | Node should have one enclosing callable but has 0. | +| main.rs:144:5:144:11 | Param | Node should have one enclosing callable but has 0. | +| main.rs:151:7:151:12 | Param | Node should have one enclosing callable but has 0. | +| main.rs:205:32:205:32 | Param | Node should have one enclosing callable but has 0. | +| main.rs:392:19:392:21 | Param | Node should have one enclosing callable but has 0. | +| main.rs:394:14:394:19 | Param | Node should have one enclosing callable but has 0. | +| main.rs:421:21:421:28 | Param | Node should have one enclosing callable but has 0. | +| main.rs:421:31:421:38 | Param | Node should have one enclosing callable but has 0. | | main.rs:424:21:424:23 | Param | Node should have one enclosing callable but has 0. | | main.rs:424:26:424:28 | Param | Node should have one enclosing callable but has 0. | -| main.rs:430:29:430:38 | Param | Node should have one enclosing callable but has 0. | -| main.rs:430:41:430:56 | Param | Node should have one enclosing callable but has 0. | -| main.rs:440:9:440:18 | Param | Node should have one enclosing callable but has 0. | -| main.rs:441:9:441:24 | Param | Node should have one enclosing callable but has 0. | +| main.rs:427:21:427:23 | Param | Node should have one enclosing callable but has 0. | +| main.rs:427:26:427:28 | Param | Node should have one enclosing callable but has 0. | +| main.rs:430:21:430:23 | Param | Node should have one enclosing callable but has 0. | +| main.rs:430:26:430:28 | Param | Node should have one enclosing callable but has 0. | +| main.rs:434:21:434:23 | Param | Node should have one enclosing callable but has 0. | +| main.rs:434:26:434:28 | Param | Node should have one enclosing callable but has 0. | +| main.rs:440:29:440:38 | Param | Node should have one enclosing callable but has 0. | +| main.rs:440:41:440:56 | Param | Node should have one enclosing callable but has 0. | +| main.rs:450:9:450:18 | Param | Node should have one enclosing callable but has 0. | +| main.rs:451:9:451:24 | Param | Node should have one enclosing callable but has 0. | +| main.rs:493:16:493:18 | Param | Node should have one enclosing callable but has 0. | +| main.rs:494:16:494:21 | Param | Node should have one enclosing callable but has 0. | +| main.rs:495:16:496:25 | Param | Node should have one enclosing callable but has 0. | +| main.rs:496:12:496:17 | Param | Node should have one enclosing callable but has 0. | +| main.rs:499:18:499:23 | Param | Node should have one enclosing callable but has 0. | +| main.rs:502:24:502:29 | Param | Node should have one enclosing callable but has 0. | | more.rs:4:23:4:28 | Param | Node should have one enclosing callable but has 0. | | more.rs:8:19:8:24 | Param | Node should have one enclosing callable but has 0. | | more.rs:16:23:16:28 | Param | Node should have one enclosing callable but has 0. | | more.rs:24:9:24:14 | Param | Node should have one enclosing callable but has 0. | | unreachable.rs:10:34:10:34 | Param | Node should have one enclosing callable but has 0. | uniqueCallEnclosingCallable -| main.rs:11:13:11:29 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:12:13:12:29 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:16:14:16:24 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:18:8:18:13 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:19:18:19:28 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:22:14:22:24 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:23:5:23:19 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:23:5:23:19 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:41:14:41:24 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:45:8:45:13 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:50:14:50:24 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:53:8:53:13 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:58:14:58:24 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:62:14:62:24 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:67:12:67:17 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:68:12:68:17 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:13:13:13:29 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:14:13:14:29 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:18:14:18:24 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:20:8:20:13 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:21:18:21:28 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:24:14:24:24 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:25:5:25:19 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:25:5:25:19 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:43:14:43:24 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:47:8:47:13 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:52:14:52:24 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:55:8:55:13 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:60:14:60:24 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:64:14:64:24 | CallExpr | Call should have one enclosing callable but has 0. | | main.rs:69:12:69:17 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:70:14:70:24 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:96:14:96:45 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:99:14:99:38 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:70:12:70:17 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:71:12:71:17 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:72:14:72:24 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:98:14:98:45 | CallExpr | Call should have one enclosing callable but has 0. | | main.rs:101:14:101:38 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:114:14:114:32 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:117:18:117:33 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:174:18:174:29 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:178:18:178:31 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:182:18:182:37 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:187:22:187:33 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:192:18:192:27 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:196:21:196:30 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:196:21:196:30 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:200:18:200:38 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:204:9:204:24 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:204:9:204:24 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:208:9:208:24 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:213:9:213:32 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:213:20:213:24 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:213:27:213:31 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:240:22:240:29 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:243:22:243:29 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:247:20:247:27 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:254:21:254:28 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:260:13:260:20 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:267:13:267:20 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:275:13:275:28 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:282:13:282:30 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:289:31:289:37 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:337:21:337:51 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:338:5:338:39 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:340:58:340:92 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:340:61:340:91 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:343:22:343:59 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:346:22:346:29 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:396:13:396:24 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:400:13:400:22 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:460:9:464:10 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:471:5:471:14 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:472:5:472:14 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:473:5:473:13 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:474:5:474:12 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:475:5:475:13 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:476:14:476:54 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:476:36:476:54 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:477:5:477:11 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:478:5:478:21 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:479:5:479:15 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:480:5:480:15 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:481:5:481:24 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:483:5:483:22 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:485:5:485:23 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:487:5:487:23 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:488:5:488:23 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:489:5:489:23 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:490:5:490:22 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:491:5:491:22 | CallExpr | Call should have one enclosing callable but has 0. | -| main.rs:493:5:493:12 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:103:14:103:38 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:116:14:116:32 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:119:18:119:33 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:176:18:176:29 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:180:18:180:31 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:184:18:184:37 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:189:22:189:33 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:194:18:194:27 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:198:21:198:30 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:198:21:198:30 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:202:21:202:32 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:202:21:202:32 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:206:21:206:30 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:206:21:206:30 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:210:18:210:38 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:214:9:214:24 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:214:9:214:24 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:218:9:218:24 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:223:9:223:32 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:223:20:223:24 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:223:27:223:31 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:250:22:250:29 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:253:22:253:29 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:257:20:257:27 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:264:21:264:28 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:270:13:270:20 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:277:13:277:20 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:285:13:285:28 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:292:13:292:30 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:299:31:299:37 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:347:21:347:51 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:348:5:348:39 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:350:58:350:92 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:350:61:350:91 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:353:22:353:59 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:356:22:356:29 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:406:13:406:24 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:410:13:410:22 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:470:9:474:10 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:487:5:487:21 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:487:5:487:21 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:508:5:508:14 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:509:5:509:14 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:510:5:510:13 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:511:5:511:12 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:512:5:512:13 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:513:14:513:54 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:513:36:513:54 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:514:5:514:11 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:515:5:515:21 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:516:5:516:15 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:517:5:517:15 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:518:5:518:24 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:519:5:519:12 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:520:5:520:16 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:522:5:522:14 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:523:5:523:14 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:525:5:525:22 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:527:5:527:23 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:529:5:529:23 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:530:5:530:23 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:531:5:531:23 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:532:5:532:22 | CallExpr | Call should have one enclosing callable but has 0. | +| main.rs:533:5:533:22 | CallExpr | Call should have one enclosing callable but has 0. | | more.rs:45:14:45:26 | CallExpr | Call should have one enclosing callable but has 0. | | more.rs:46:14:46:25 | CallExpr | Call should have one enclosing callable but has 0. | | more.rs:47:14:47:26 | CallExpr | Call should have one enclosing callable but has 0. | @@ -213,26 +229,33 @@ uniqueCallEnclosingCallable | unreachable.rs:248:9:248:22 | CallExpr | Call should have one enclosing callable but has 0. | | unreachable.rs:252:5:252:18 | CallExpr | Call should have one enclosing callable but has 0. | uniqueType -| main.rs:140:5:140:10 | Param | Node should have one type but has 0. | -| main.rs:141:5:141:10 | Param | Node should have one type but has 0. | -| main.rs:142:5:142:11 | Param | Node should have one type but has 0. | -| main.rs:149:7:149:12 | Param | Node should have one type but has 0. | -| main.rs:382:19:382:21 | Param | Node should have one type but has 0. | -| main.rs:384:14:384:19 | Param | Node should have one type but has 0. | -| main.rs:411:21:411:28 | Param | Node should have one type but has 0. | -| main.rs:411:31:411:38 | Param | Node should have one type but has 0. | -| main.rs:414:21:414:23 | Param | Node should have one type but has 0. | -| main.rs:414:26:414:28 | Param | Node should have one type but has 0. | -| main.rs:417:21:417:23 | Param | Node should have one type but has 0. | -| main.rs:417:26:417:28 | Param | Node should have one type but has 0. | -| main.rs:420:21:420:23 | Param | Node should have one type but has 0. | -| main.rs:420:26:420:28 | Param | Node should have one type but has 0. | +| main.rs:142:5:142:10 | Param | Node should have one type but has 0. | +| main.rs:143:5:143:10 | Param | Node should have one type but has 0. | +| main.rs:144:5:144:11 | Param | Node should have one type but has 0. | +| main.rs:151:7:151:12 | Param | Node should have one type but has 0. | +| main.rs:205:32:205:32 | Param | Node should have one type but has 0. | +| main.rs:392:19:392:21 | Param | Node should have one type but has 0. | +| main.rs:394:14:394:19 | Param | Node should have one type but has 0. | +| main.rs:421:21:421:28 | Param | Node should have one type but has 0. | +| main.rs:421:31:421:38 | Param | Node should have one type but has 0. | | main.rs:424:21:424:23 | Param | Node should have one type but has 0. | | main.rs:424:26:424:28 | Param | Node should have one type but has 0. | -| main.rs:430:29:430:38 | Param | Node should have one type but has 0. | -| main.rs:430:41:430:56 | Param | Node should have one type but has 0. | -| main.rs:440:9:440:18 | Param | Node should have one type but has 0. | -| main.rs:441:9:441:24 | Param | Node should have one type but has 0. | +| main.rs:427:21:427:23 | Param | Node should have one type but has 0. | +| main.rs:427:26:427:28 | Param | Node should have one type but has 0. | +| main.rs:430:21:430:23 | Param | Node should have one type but has 0. | +| main.rs:430:26:430:28 | Param | Node should have one type but has 0. | +| main.rs:434:21:434:23 | Param | Node should have one type but has 0. | +| main.rs:434:26:434:28 | Param | Node should have one type but has 0. | +| main.rs:440:29:440:38 | Param | Node should have one type but has 0. | +| main.rs:440:41:440:56 | Param | Node should have one type but has 0. | +| main.rs:450:9:450:18 | Param | Node should have one type but has 0. | +| main.rs:451:9:451:24 | Param | Node should have one type but has 0. | +| main.rs:493:16:493:18 | Param | Node should have one type but has 0. | +| main.rs:494:16:494:21 | Param | Node should have one type but has 0. | +| main.rs:495:16:496:25 | Param | Node should have one type but has 0. | +| main.rs:496:12:496:17 | Param | Node should have one type but has 0. | +| main.rs:499:18:499:23 | Param | Node should have one type but has 0. | +| main.rs:502:24:502:29 | Param | Node should have one type but has 0. | | more.rs:4:23:4:28 | Param | Node should have one type but has 0. | | more.rs:8:19:8:24 | Param | Node should have one type but has 0. | | more.rs:16:23:16:28 | Param | Node should have one type but has 0. | From 7c2c5ee1fa4b133708f2974e84e6fb65f82a0b0a Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Fri, 8 Nov 2024 11:22:35 +0000 Subject: [PATCH 9/9] Rust: Fix expected consistency results. --- .../CONSISTENCY/DataFlowConsistency.expected | 57 ------------------- 1 file changed, 57 deletions(-) diff --git a/rust/ql/test/query-tests/unusedentities/CONSISTENCY/DataFlowConsistency.expected b/rust/ql/test/query-tests/unusedentities/CONSISTENCY/DataFlowConsistency.expected index de9edf571912..6345a132ee60 100644 --- a/rust/ql/test/query-tests/unusedentities/CONSISTENCY/DataFlowConsistency.expected +++ b/rust/ql/test/query-tests/unusedentities/CONSISTENCY/DataFlowConsistency.expected @@ -1,34 +1,13 @@ uniqueEnclosingCallable -| main.rs:142:5:142:10 | Param | Node should have one enclosing callable but has 0. | -| main.rs:143:5:143:10 | Param | Node should have one enclosing callable but has 0. | -| main.rs:144:5:144:11 | Param | Node should have one enclosing callable but has 0. | -| main.rs:151:7:151:12 | Param | Node should have one enclosing callable but has 0. | -| main.rs:205:32:205:32 | Param | Node should have one enclosing callable but has 0. | | main.rs:392:19:392:21 | Param | Node should have one enclosing callable but has 0. | -| main.rs:394:14:394:19 | Param | Node should have one enclosing callable but has 0. | -| main.rs:421:21:421:28 | Param | Node should have one enclosing callable but has 0. | -| main.rs:421:31:421:38 | Param | Node should have one enclosing callable but has 0. | -| main.rs:424:21:424:23 | Param | Node should have one enclosing callable but has 0. | -| main.rs:424:26:424:28 | Param | Node should have one enclosing callable but has 0. | -| main.rs:427:21:427:23 | Param | Node should have one enclosing callable but has 0. | -| main.rs:427:26:427:28 | Param | Node should have one enclosing callable but has 0. | -| main.rs:430:21:430:23 | Param | Node should have one enclosing callable but has 0. | -| main.rs:430:26:430:28 | Param | Node should have one enclosing callable but has 0. | -| main.rs:434:21:434:23 | Param | Node should have one enclosing callable but has 0. | -| main.rs:434:26:434:28 | Param | Node should have one enclosing callable but has 0. | | main.rs:440:29:440:38 | Param | Node should have one enclosing callable but has 0. | | main.rs:440:41:440:56 | Param | Node should have one enclosing callable but has 0. | -| main.rs:450:9:450:18 | Param | Node should have one enclosing callable but has 0. | -| main.rs:451:9:451:24 | Param | Node should have one enclosing callable but has 0. | | main.rs:493:16:493:18 | Param | Node should have one enclosing callable but has 0. | | main.rs:494:16:494:21 | Param | Node should have one enclosing callable but has 0. | | main.rs:495:16:496:25 | Param | Node should have one enclosing callable but has 0. | | main.rs:496:12:496:17 | Param | Node should have one enclosing callable but has 0. | | main.rs:499:18:499:23 | Param | Node should have one enclosing callable but has 0. | | main.rs:502:24:502:29 | Param | Node should have one enclosing callable but has 0. | -| main.rs:382:19:382:21 | Param | Node should have one enclosing callable but has 0. | -| main.rs:430:29:430:38 | Param | Node should have one enclosing callable but has 0. | -| main.rs:430:41:430:56 | Param | Node should have one enclosing callable but has 0. | | more.rs:4:23:4:28 | Param | Node should have one enclosing callable but has 0. | | more.rs:8:19:8:24 | Param | Node should have one enclosing callable but has 0. | uniqueCallEnclosingCallable @@ -209,39 +188,3 @@ uniqueCallEnclosingCallable | unreachable.rs:247:9:247:14 | CallExpr | Call should have one enclosing callable but has 0. | | unreachable.rs:248:9:248:22 | CallExpr | Call should have one enclosing callable but has 0. | | unreachable.rs:252:5:252:18 | CallExpr | Call should have one enclosing callable but has 0. | -<<<<<<< HEAD -uniqueType -| main.rs:142:5:142:10 | Param | Node should have one type but has 0. | -| main.rs:143:5:143:10 | Param | Node should have one type but has 0. | -| main.rs:144:5:144:11 | Param | Node should have one type but has 0. | -| main.rs:151:7:151:12 | Param | Node should have one type but has 0. | -| main.rs:205:32:205:32 | Param | Node should have one type but has 0. | -| main.rs:392:19:392:21 | Param | Node should have one type but has 0. | -| main.rs:394:14:394:19 | Param | Node should have one type but has 0. | -| main.rs:421:21:421:28 | Param | Node should have one type but has 0. | -| main.rs:421:31:421:38 | Param | Node should have one type but has 0. | -| main.rs:424:21:424:23 | Param | Node should have one type but has 0. | -| main.rs:424:26:424:28 | Param | Node should have one type but has 0. | -| main.rs:427:21:427:23 | Param | Node should have one type but has 0. | -| main.rs:427:26:427:28 | Param | Node should have one type but has 0. | -| main.rs:430:21:430:23 | Param | Node should have one type but has 0. | -| main.rs:430:26:430:28 | Param | Node should have one type but has 0. | -| main.rs:434:21:434:23 | Param | Node should have one type but has 0. | -| main.rs:434:26:434:28 | Param | Node should have one type but has 0. | -| main.rs:440:29:440:38 | Param | Node should have one type but has 0. | -| main.rs:440:41:440:56 | Param | Node should have one type but has 0. | -| main.rs:450:9:450:18 | Param | Node should have one type but has 0. | -| main.rs:451:9:451:24 | Param | Node should have one type but has 0. | -| main.rs:493:16:493:18 | Param | Node should have one type but has 0. | -| main.rs:494:16:494:21 | Param | Node should have one type but has 0. | -| main.rs:495:16:496:25 | Param | Node should have one type but has 0. | -| main.rs:496:12:496:17 | Param | Node should have one type but has 0. | -| main.rs:499:18:499:23 | Param | Node should have one type but has 0. | -| main.rs:502:24:502:29 | Param | Node should have one type but has 0. | -| more.rs:4:23:4:28 | Param | Node should have one type but has 0. | -| more.rs:8:19:8:24 | Param | Node should have one type but has 0. | -| more.rs:16:23:16:28 | Param | Node should have one type but has 0. | -| more.rs:24:9:24:14 | Param | Node should have one type but has 0. | -| unreachable.rs:10:34:10:34 | Param | Node should have one type but has 0. | -======= ->>>>>>> main