From 7da2845cad4dfbbdd90cc84d3c394b7734feb1c4 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Wed, 25 Sep 2024 16:30:45 +0100 Subject: [PATCH 1/9] Rust: Uncomment two lines from the test that should now behave deterministically. --- rust/ql/test/query-tests/diagnostics/LinesOfCode.expected | 2 +- .../test/query-tests/diagnostics/LinesOfUserCode.expected | 2 +- .../query-tests/diagnostics/LinesOfUserCodeInFiles.expected | 2 +- rust/ql/test/query-tests/diagnostics/SummaryStats.expected | 6 +++--- rust/ql/test/query-tests/diagnostics/main.rs | 2 +- rust/ql/test/query-tests/diagnostics/my_macro.rs | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/rust/ql/test/query-tests/diagnostics/LinesOfCode.expected b/rust/ql/test/query-tests/diagnostics/LinesOfCode.expected index 035a74975be8..d6a21ebb49cf 100644 --- a/rust/ql/test/query-tests/diagnostics/LinesOfCode.expected +++ b/rust/ql/test/query-tests/diagnostics/LinesOfCode.expected @@ -1 +1 @@ -| 48 | +| 49 | diff --git a/rust/ql/test/query-tests/diagnostics/LinesOfUserCode.expected b/rust/ql/test/query-tests/diagnostics/LinesOfUserCode.expected index 035a74975be8..d6a21ebb49cf 100644 --- a/rust/ql/test/query-tests/diagnostics/LinesOfUserCode.expected +++ b/rust/ql/test/query-tests/diagnostics/LinesOfUserCode.expected @@ -1 +1 @@ -| 48 | +| 49 | diff --git a/rust/ql/test/query-tests/diagnostics/LinesOfUserCodeInFiles.expected b/rust/ql/test/query-tests/diagnostics/LinesOfUserCodeInFiles.expected index 2be3f73088ca..dde3c7fe35a7 100644 --- a/rust/ql/test/query-tests/diagnostics/LinesOfUserCodeInFiles.expected +++ b/rust/ql/test/query-tests/diagnostics/LinesOfUserCodeInFiles.expected @@ -1,6 +1,6 @@ | my_struct.rs:0:0:0:0 | my_struct.rs | 21 | +| main.rs:0:0:0:0 | main.rs | 8 | | my_macro.rs:0:0:0:0 | my_macro.rs | 8 | -| main.rs:0:0:0:0 | main.rs | 7 | | lib.rs:0:0:0:0 | lib.rs | 6 | | does_not_compile.rs:0:0:0:0 | does_not_compile.rs | 3 | | error.rs:0:0:0:0 | error.rs | 3 | diff --git a/rust/ql/test/query-tests/diagnostics/SummaryStats.expected b/rust/ql/test/query-tests/diagnostics/SummaryStats.expected index 145a18cae05d..f92218d10d21 100644 --- a/rust/ql/test/query-tests/diagnostics/SummaryStats.expected +++ b/rust/ql/test/query-tests/diagnostics/SummaryStats.expected @@ -1,5 +1,5 @@ -| Elements extracted | 204 | +| Elements extracted | 211 | | Elements unextracted | 0 | | Files extracted | 6 | -| Lines of code extracted | 48 | -| Lines of user code extracted | 48 | +| Lines of code extracted | 49 | +| Lines of user code extracted | 49 | diff --git a/rust/ql/test/query-tests/diagnostics/main.rs b/rust/ql/test/query-tests/diagnostics/main.rs index 790547c0ff9d..6e0ddf695a3a 100644 --- a/rust/ql/test/query-tests/diagnostics/main.rs +++ b/rust/ql/test/query-tests/diagnostics/main.rs @@ -11,7 +11,7 @@ mod my_macro; // another comment fn main() { // another comment - //println!("Hello, world!"); // currently causes consistency issues + println!("Hello, world!"); my_struct::my_func(); my_macro::my_func(); diff --git a/rust/ql/test/query-tests/diagnostics/my_macro.rs b/rust/ql/test/query-tests/diagnostics/my_macro.rs index 0f85877c3c60..d8a0cc2812bd 100644 --- a/rust/ql/test/query-tests/diagnostics/my_macro.rs +++ b/rust/ql/test/query-tests/diagnostics/my_macro.rs @@ -7,7 +7,7 @@ macro_rules! myMacro { () => { - //println!("Hello, world!"); // currently causes consistency issues + println!("Hello, world!"); }; } From f8ce11b3a7d55ffeb656767239b81d0a19efb8f8 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Wed, 25 Sep 2024 16:42:08 +0100 Subject: [PATCH 2/9] Rust: Improve File.getNumberOfLinesOfCode(). --- rust/ql/lib/codeql/files/FileSystem.qll | 5 ++++- rust/ql/test/query-tests/diagnostics/LinesOfCode.expected | 2 +- .../ql/test/query-tests/diagnostics/LinesOfUserCode.expected | 2 +- .../query-tests/diagnostics/LinesOfUserCodeInFiles.expected | 2 +- rust/ql/test/query-tests/diagnostics/SummaryStats.expected | 4 ++-- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/rust/ql/lib/codeql/files/FileSystem.qll b/rust/ql/lib/codeql/files/FileSystem.qll index f6926609d685..e4ff5aa0f7ed 100644 --- a/rust/ql/lib/codeql/files/FileSystem.qll +++ b/rust/ql/lib/codeql/files/FileSystem.qll @@ -2,6 +2,7 @@ private import codeql.Locations private import codeql.util.FileSystem +private import codeql.rust.elements.Module private import codeql.rust.elements.SourceFile private import codeql.rust.elements.AstNode @@ -44,7 +45,9 @@ class File extends Container, Impl::File { result = count(int line | exists(AstNode node, Location loc | - not node instanceof SourceFile and loc = node.getLocation() + not node instanceof Module and + not node instanceof SourceFile and + loc = node.getLocation() | node.getFile() = this and line = [loc.getStartLine(), loc.getEndLine()] and diff --git a/rust/ql/test/query-tests/diagnostics/LinesOfCode.expected b/rust/ql/test/query-tests/diagnostics/LinesOfCode.expected index d6a21ebb49cf..035a74975be8 100644 --- a/rust/ql/test/query-tests/diagnostics/LinesOfCode.expected +++ b/rust/ql/test/query-tests/diagnostics/LinesOfCode.expected @@ -1 +1 @@ -| 49 | +| 48 | diff --git a/rust/ql/test/query-tests/diagnostics/LinesOfUserCode.expected b/rust/ql/test/query-tests/diagnostics/LinesOfUserCode.expected index d6a21ebb49cf..035a74975be8 100644 --- a/rust/ql/test/query-tests/diagnostics/LinesOfUserCode.expected +++ b/rust/ql/test/query-tests/diagnostics/LinesOfUserCode.expected @@ -1 +1 @@ -| 49 | +| 48 | diff --git a/rust/ql/test/query-tests/diagnostics/LinesOfUserCodeInFiles.expected b/rust/ql/test/query-tests/diagnostics/LinesOfUserCodeInFiles.expected index dde3c7fe35a7..2be3f73088ca 100644 --- a/rust/ql/test/query-tests/diagnostics/LinesOfUserCodeInFiles.expected +++ b/rust/ql/test/query-tests/diagnostics/LinesOfUserCodeInFiles.expected @@ -1,6 +1,6 @@ | my_struct.rs:0:0:0:0 | my_struct.rs | 21 | -| main.rs:0:0:0:0 | main.rs | 8 | | my_macro.rs:0:0:0:0 | my_macro.rs | 8 | +| main.rs:0:0:0:0 | main.rs | 7 | | lib.rs:0:0:0:0 | lib.rs | 6 | | does_not_compile.rs:0:0:0:0 | does_not_compile.rs | 3 | | error.rs:0:0:0:0 | error.rs | 3 | diff --git a/rust/ql/test/query-tests/diagnostics/SummaryStats.expected b/rust/ql/test/query-tests/diagnostics/SummaryStats.expected index f92218d10d21..766ca8332fac 100644 --- a/rust/ql/test/query-tests/diagnostics/SummaryStats.expected +++ b/rust/ql/test/query-tests/diagnostics/SummaryStats.expected @@ -1,5 +1,5 @@ | Elements extracted | 211 | | Elements unextracted | 0 | | Files extracted | 6 | -| Lines of code extracted | 49 | -| Lines of user code extracted | 49 | +| Lines of code extracted | 48 | +| Lines of user code extracted | 48 | From caca4950e64097a18085e4928da940ad454e2ab1 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Thu, 26 Sep 2024 11:10:03 +0100 Subject: [PATCH 3/9] Rust: Revert the change to FileSystem.qll. --- rust/ql/lib/codeql/files/FileSystem.qll | 2 -- rust/ql/test/query-tests/diagnostics/LinesOfCode.expected | 2 +- rust/ql/test/query-tests/diagnostics/LinesOfUserCode.expected | 2 +- .../query-tests/diagnostics/LinesOfUserCodeInFiles.expected | 2 +- rust/ql/test/query-tests/diagnostics/SummaryStats.expected | 4 ++-- 5 files changed, 5 insertions(+), 7 deletions(-) diff --git a/rust/ql/lib/codeql/files/FileSystem.qll b/rust/ql/lib/codeql/files/FileSystem.qll index e4ff5aa0f7ed..0b9351800ab6 100644 --- a/rust/ql/lib/codeql/files/FileSystem.qll +++ b/rust/ql/lib/codeql/files/FileSystem.qll @@ -2,7 +2,6 @@ private import codeql.Locations private import codeql.util.FileSystem -private import codeql.rust.elements.Module private import codeql.rust.elements.SourceFile private import codeql.rust.elements.AstNode @@ -45,7 +44,6 @@ class File extends Container, Impl::File { result = count(int line | exists(AstNode node, Location loc | - not node instanceof Module and not node instanceof SourceFile and loc = node.getLocation() | diff --git a/rust/ql/test/query-tests/diagnostics/LinesOfCode.expected b/rust/ql/test/query-tests/diagnostics/LinesOfCode.expected index 035a74975be8..d6a21ebb49cf 100644 --- a/rust/ql/test/query-tests/diagnostics/LinesOfCode.expected +++ b/rust/ql/test/query-tests/diagnostics/LinesOfCode.expected @@ -1 +1 @@ -| 48 | +| 49 | diff --git a/rust/ql/test/query-tests/diagnostics/LinesOfUserCode.expected b/rust/ql/test/query-tests/diagnostics/LinesOfUserCode.expected index 035a74975be8..d6a21ebb49cf 100644 --- a/rust/ql/test/query-tests/diagnostics/LinesOfUserCode.expected +++ b/rust/ql/test/query-tests/diagnostics/LinesOfUserCode.expected @@ -1 +1 @@ -| 48 | +| 49 | diff --git a/rust/ql/test/query-tests/diagnostics/LinesOfUserCodeInFiles.expected b/rust/ql/test/query-tests/diagnostics/LinesOfUserCodeInFiles.expected index 2be3f73088ca..dde3c7fe35a7 100644 --- a/rust/ql/test/query-tests/diagnostics/LinesOfUserCodeInFiles.expected +++ b/rust/ql/test/query-tests/diagnostics/LinesOfUserCodeInFiles.expected @@ -1,6 +1,6 @@ | my_struct.rs:0:0:0:0 | my_struct.rs | 21 | +| main.rs:0:0:0:0 | main.rs | 8 | | my_macro.rs:0:0:0:0 | my_macro.rs | 8 | -| main.rs:0:0:0:0 | main.rs | 7 | | lib.rs:0:0:0:0 | lib.rs | 6 | | does_not_compile.rs:0:0:0:0 | does_not_compile.rs | 3 | | error.rs:0:0:0:0 | error.rs | 3 | diff --git a/rust/ql/test/query-tests/diagnostics/SummaryStats.expected b/rust/ql/test/query-tests/diagnostics/SummaryStats.expected index 766ca8332fac..f92218d10d21 100644 --- a/rust/ql/test/query-tests/diagnostics/SummaryStats.expected +++ b/rust/ql/test/query-tests/diagnostics/SummaryStats.expected @@ -1,5 +1,5 @@ | Elements extracted | 211 | | Elements unextracted | 0 | | Files extracted | 6 | -| Lines of code extracted | 48 | -| Lines of user code extracted | 48 | +| Lines of code extracted | 49 | +| Lines of user code extracted | 49 | From 3a54c10f369826f3d0491267f582dd4cf33c8bd5 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Tue, 1 Oct 2024 17:35:30 +0100 Subject: [PATCH 4/9] Rust: For now exclude top-level AST elements from LOC counts. This is not ideal. --- rust/ql/lib/codeql/files/FileSystem.qll | 2 ++ rust/ql/test/query-tests/diagnostics/LinesOfCode.expected | 2 +- .../test/query-tests/diagnostics/LinesOfUserCode.expected | 2 +- .../query-tests/diagnostics/LinesOfUserCodeInFiles.expected | 6 +++--- rust/ql/test/query-tests/diagnostics/SummaryStats.expected | 4 ++-- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/rust/ql/lib/codeql/files/FileSystem.qll b/rust/ql/lib/codeql/files/FileSystem.qll index ee7a2235476e..a5410ece9712 100644 --- a/rust/ql/lib/codeql/files/FileSystem.qll +++ b/rust/ql/lib/codeql/files/FileSystem.qll @@ -5,6 +5,7 @@ private import codeql.util.FileSystem private import codeql.rust.elements.SourceFile private import codeql.rust.elements.AstNode private import codeql.rust.elements.Comment +private import codeql.rust.elements.internal.generated.ParentChild private module Input implements InputSig { abstract class ContainerBase extends @container { @@ -47,6 +48,7 @@ class File extends Container, Impl::File { exists(AstNode node, Location loc | not node instanceof Comment and not node instanceof SourceFile and + not getImmediateParent(node) instanceof SourceFile and // ignore top-level elements for now as we're getting their locations wrong when a comment is attached loc = node.getLocation() | node.getFile() = this and diff --git a/rust/ql/test/query-tests/diagnostics/LinesOfCode.expected b/rust/ql/test/query-tests/diagnostics/LinesOfCode.expected index d6a21ebb49cf..3885b955c3f3 100644 --- a/rust/ql/test/query-tests/diagnostics/LinesOfCode.expected +++ b/rust/ql/test/query-tests/diagnostics/LinesOfCode.expected @@ -1 +1 @@ -| 49 | +| 46 | diff --git a/rust/ql/test/query-tests/diagnostics/LinesOfUserCode.expected b/rust/ql/test/query-tests/diagnostics/LinesOfUserCode.expected index d6a21ebb49cf..3885b955c3f3 100644 --- a/rust/ql/test/query-tests/diagnostics/LinesOfUserCode.expected +++ b/rust/ql/test/query-tests/diagnostics/LinesOfUserCode.expected @@ -1 +1 @@ -| 49 | +| 46 | diff --git a/rust/ql/test/query-tests/diagnostics/LinesOfUserCodeInFiles.expected b/rust/ql/test/query-tests/diagnostics/LinesOfUserCodeInFiles.expected index dde3c7fe35a7..52ee2055e8fe 100644 --- a/rust/ql/test/query-tests/diagnostics/LinesOfUserCodeInFiles.expected +++ b/rust/ql/test/query-tests/diagnostics/LinesOfUserCodeInFiles.expected @@ -1,6 +1,6 @@ -| my_struct.rs:0:0:0:0 | my_struct.rs | 21 | -| main.rs:0:0:0:0 | main.rs | 8 | -| my_macro.rs:0:0:0:0 | my_macro.rs | 8 | +| my_struct.rs:0:0:0:0 | my_struct.rs | 20 | +| main.rs:0:0:0:0 | main.rs | 7 | +| my_macro.rs:0:0:0:0 | my_macro.rs | 7 | | lib.rs:0:0:0:0 | lib.rs | 6 | | does_not_compile.rs:0:0:0:0 | does_not_compile.rs | 3 | | error.rs:0:0:0:0 | error.rs | 3 | diff --git a/rust/ql/test/query-tests/diagnostics/SummaryStats.expected b/rust/ql/test/query-tests/diagnostics/SummaryStats.expected index 6c5eafcc38e3..da1e6cd7b60c 100644 --- a/rust/ql/test/query-tests/diagnostics/SummaryStats.expected +++ b/rust/ql/test/query-tests/diagnostics/SummaryStats.expected @@ -1,5 +1,5 @@ | Elements extracted | 216 | | Elements unextracted | 0 | | Files extracted | 6 | -| Lines of code extracted | 49 | -| Lines of user code extracted | 49 | +| Lines of code extracted | 46 | +| Lines of user code extracted | 46 | From 8243f871791ba47aee375d97bd3aacf5c20786b4 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Wed, 2 Oct 2024 11:38:23 +0100 Subject: [PATCH 5/9] Rust: Modify the exclusion as suggested in comments. --- rust/ql/lib/codeql/files/FileSystem.qll | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/rust/ql/lib/codeql/files/FileSystem.qll b/rust/ql/lib/codeql/files/FileSystem.qll index a5410ece9712..03b5cd0b183b 100644 --- a/rust/ql/lib/codeql/files/FileSystem.qll +++ b/rust/ql/lib/codeql/files/FileSystem.qll @@ -5,7 +5,6 @@ private import codeql.util.FileSystem private import codeql.rust.elements.SourceFile private import codeql.rust.elements.AstNode private import codeql.rust.elements.Comment -private import codeql.rust.elements.internal.generated.ParentChild private module Input implements InputSig { abstract class ContainerBase extends @container { @@ -48,7 +47,7 @@ class File extends Container, Impl::File { exists(AstNode node, Location loc | not node instanceof Comment and not node instanceof SourceFile and - not getImmediateParent(node) instanceof SourceFile and // ignore top-level elements for now as we're getting their locations wrong when a comment is attached + not node instanceof Item and // ignore Items for now as we're getting their locations wrong when a comment is attached loc = node.getLocation() | node.getFile() = this and From 8c87b66bea97e8f379062f1be06f576fd0e428a5 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Wed, 2 Oct 2024 16:50:24 +0100 Subject: [PATCH 6/9] Rust: Add more test cases for comments. --- .../diagnostics/ExtractedFiles.expected | 1 + .../diagnostics/LinesOfCode.expected | 2 +- .../diagnostics/LinesOfUserCode.expected | 2 +- .../LinesOfUserCodeInFiles.expected | 5 +- .../diagnostics/SummaryStats.expected | 8 +-- .../test/query-tests/diagnostics/comments.rs | 60 +++++++++++++++++++ rust/ql/test/query-tests/diagnostics/main.rs | 9 ++- 7 files changed, 74 insertions(+), 13 deletions(-) create mode 100644 rust/ql/test/query-tests/diagnostics/comments.rs diff --git a/rust/ql/test/query-tests/diagnostics/ExtractedFiles.expected b/rust/ql/test/query-tests/diagnostics/ExtractedFiles.expected index cc6f775e86d5..c5ebb7072304 100644 --- a/rust/ql/test/query-tests/diagnostics/ExtractedFiles.expected +++ b/rust/ql/test/query-tests/diagnostics/ExtractedFiles.expected @@ -1,3 +1,4 @@ +| comments.rs:0:0:0:0 | comments.rs | File successfully extracted. | | does_not_compile.rs:0:0:0:0 | does_not_compile.rs | File successfully extracted. | | error.rs:0:0:0:0 | error.rs | File successfully extracted. | | lib.rs:0:0:0:0 | lib.rs | File successfully extracted. | diff --git a/rust/ql/test/query-tests/diagnostics/LinesOfCode.expected b/rust/ql/test/query-tests/diagnostics/LinesOfCode.expected index 3885b955c3f3..f57679361dc0 100644 --- a/rust/ql/test/query-tests/diagnostics/LinesOfCode.expected +++ b/rust/ql/test/query-tests/diagnostics/LinesOfCode.expected @@ -1 +1 @@ -| 46 | +| 68 | diff --git a/rust/ql/test/query-tests/diagnostics/LinesOfUserCode.expected b/rust/ql/test/query-tests/diagnostics/LinesOfUserCode.expected index 3885b955c3f3..f57679361dc0 100644 --- a/rust/ql/test/query-tests/diagnostics/LinesOfUserCode.expected +++ b/rust/ql/test/query-tests/diagnostics/LinesOfUserCode.expected @@ -1 +1 @@ -| 46 | +| 68 | diff --git a/rust/ql/test/query-tests/diagnostics/LinesOfUserCodeInFiles.expected b/rust/ql/test/query-tests/diagnostics/LinesOfUserCodeInFiles.expected index 52ee2055e8fe..1b0edb495195 100644 --- a/rust/ql/test/query-tests/diagnostics/LinesOfUserCodeInFiles.expected +++ b/rust/ql/test/query-tests/diagnostics/LinesOfUserCodeInFiles.expected @@ -1,6 +1,7 @@ +| comments.rs:0:0:0:0 | comments.rs | 20 | | my_struct.rs:0:0:0:0 | my_struct.rs | 20 | -| main.rs:0:0:0:0 | main.rs | 7 | +| main.rs:0:0:0:0 | main.rs | 8 | +| lib.rs:0:0:0:0 | lib.rs | 7 | | my_macro.rs:0:0:0:0 | my_macro.rs | 7 | -| lib.rs:0:0:0:0 | lib.rs | 6 | | does_not_compile.rs:0:0:0:0 | does_not_compile.rs | 3 | | error.rs:0:0:0:0 | error.rs | 3 | diff --git a/rust/ql/test/query-tests/diagnostics/SummaryStats.expected b/rust/ql/test/query-tests/diagnostics/SummaryStats.expected index da1e6cd7b60c..a39ccb0b44c5 100644 --- a/rust/ql/test/query-tests/diagnostics/SummaryStats.expected +++ b/rust/ql/test/query-tests/diagnostics/SummaryStats.expected @@ -1,5 +1,5 @@ -| Elements extracted | 216 | +| Elements extracted | 290 | | Elements unextracted | 0 | -| Files extracted | 6 | -| Lines of code extracted | 46 | -| Lines of user code extracted | 46 | +| Files extracted | 7 | +| Lines of code extracted | 68 | +| Lines of user code extracted | 68 | diff --git a/rust/ql/test/query-tests/diagnostics/comments.rs b/rust/ql/test/query-tests/diagnostics/comments.rs new file mode 100644 index 000000000000..bec721eed25f --- /dev/null +++ b/rust/ql/test/query-tests/diagnostics/comments.rs @@ -0,0 +1,60 @@ +/** + * total lines in this file: 61 + * of which code: 16 + * of which only comments: 33 + * of which blank: 12 + */ + +// a comment + +/** + * Comment attached to a struct. + */ +struct StructWithComments +{ + /** + * Another attached comment. + */ + a: i32, + + // And another attached comment. + b: i32, + + /* + * And yet another attached comment. + */ + c: i32, + + // informal + // comment + // block. + cd: i32, + + // Just a comment. +} + +pub fn my_simple_func() +{ +} + +/** + * Comment attached to a function. + */ +pub fn my_func_with_comments() +{ + // comment + let a = 1; // comment + // comment + let b = 2; + + // comment + + /* + * Comment. + */ + my_simple_func(); +} + +/** + * Comment. + */ diff --git a/rust/ql/test/query-tests/diagnostics/main.rs b/rust/ql/test/query-tests/diagnostics/main.rs index 6e0ddf695a3a..07dd4234a6e7 100644 --- a/rust/ql/test/query-tests/diagnostics/main.rs +++ b/rust/ql/test/query-tests/diagnostics/main.rs @@ -1,16 +1,15 @@ /** * total lines in this file: 18 - * of which code: 7 - * of which only comments: 7 + * of which code: 8 + * of which only comments: 6 * of which blank: 4 */ mod my_struct; mod my_macro; +mod comments; -// another comment - -fn main() { // another comment +fn main() { println!("Hello, world!"); my_struct::my_func(); From 01abcf8537f297ab169a5848803408065a041006 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Wed, 2 Oct 2024 16:54:02 +0100 Subject: [PATCH 7/9] Rust: Use just end locations for now, to avoid all false positive lines caused by attached comments. --- rust/ql/lib/codeql/files/FileSystem.qll | 3 +-- rust/ql/test/query-tests/diagnostics/LinesOfCode.expected | 2 +- rust/ql/test/query-tests/diagnostics/LinesOfUserCode.expected | 2 +- .../query-tests/diagnostics/LinesOfUserCodeInFiles.expected | 2 +- rust/ql/test/query-tests/diagnostics/SummaryStats.expected | 4 ++-- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/rust/ql/lib/codeql/files/FileSystem.qll b/rust/ql/lib/codeql/files/FileSystem.qll index 03b5cd0b183b..b78a993cb7e7 100644 --- a/rust/ql/lib/codeql/files/FileSystem.qll +++ b/rust/ql/lib/codeql/files/FileSystem.qll @@ -47,11 +47,10 @@ class File extends Container, Impl::File { exists(AstNode node, Location loc | not node instanceof Comment and not node instanceof SourceFile and - not node instanceof Item and // ignore Items for now as we're getting their locations wrong when a comment is attached loc = node.getLocation() | node.getFile() = this and - line = [loc.getStartLine(), loc.getEndLine()] and + line = [/*loc.getStartLine(), */loc.getEndLine()] and // ignore start locations for now as we're getting them wrong for things with a comment attached not loc instanceof EmptyLocation ) ) diff --git a/rust/ql/test/query-tests/diagnostics/LinesOfCode.expected b/rust/ql/test/query-tests/diagnostics/LinesOfCode.expected index f57679361dc0..bf709e1ddc4d 100644 --- a/rust/ql/test/query-tests/diagnostics/LinesOfCode.expected +++ b/rust/ql/test/query-tests/diagnostics/LinesOfCode.expected @@ -1 +1 @@ -| 68 | +| 61 | diff --git a/rust/ql/test/query-tests/diagnostics/LinesOfUserCode.expected b/rust/ql/test/query-tests/diagnostics/LinesOfUserCode.expected index f57679361dc0..bf709e1ddc4d 100644 --- a/rust/ql/test/query-tests/diagnostics/LinesOfUserCode.expected +++ b/rust/ql/test/query-tests/diagnostics/LinesOfUserCode.expected @@ -1 +1 @@ -| 68 | +| 61 | diff --git a/rust/ql/test/query-tests/diagnostics/LinesOfUserCodeInFiles.expected b/rust/ql/test/query-tests/diagnostics/LinesOfUserCodeInFiles.expected index 1b0edb495195..b93473f7e04a 100644 --- a/rust/ql/test/query-tests/diagnostics/LinesOfUserCodeInFiles.expected +++ b/rust/ql/test/query-tests/diagnostics/LinesOfUserCodeInFiles.expected @@ -1,5 +1,5 @@ -| comments.rs:0:0:0:0 | comments.rs | 20 | | my_struct.rs:0:0:0:0 | my_struct.rs | 20 | +| comments.rs:0:0:0:0 | comments.rs | 13 | | main.rs:0:0:0:0 | main.rs | 8 | | lib.rs:0:0:0:0 | lib.rs | 7 | | my_macro.rs:0:0:0:0 | my_macro.rs | 7 | diff --git a/rust/ql/test/query-tests/diagnostics/SummaryStats.expected b/rust/ql/test/query-tests/diagnostics/SummaryStats.expected index a39ccb0b44c5..d9142bcadfed 100644 --- a/rust/ql/test/query-tests/diagnostics/SummaryStats.expected +++ b/rust/ql/test/query-tests/diagnostics/SummaryStats.expected @@ -1,5 +1,5 @@ | Elements extracted | 290 | | Elements unextracted | 0 | | Files extracted | 7 | -| Lines of code extracted | 68 | -| Lines of user code extracted | 68 | +| Lines of code extracted | 61 | +| Lines of user code extracted | 61 | From d6848f5c5d9ce2cdfb1eb149765ef82081923d70 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Wed, 2 Oct 2024 17:00:28 +0100 Subject: [PATCH 8/9] Rust: Apparently a doc comment here was illegal. --- rust/ql/test/query-tests/diagnostics/comments.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/ql/test/query-tests/diagnostics/comments.rs b/rust/ql/test/query-tests/diagnostics/comments.rs index bec721eed25f..fe99fdd4e3e3 100644 --- a/rust/ql/test/query-tests/diagnostics/comments.rs +++ b/rust/ql/test/query-tests/diagnostics/comments.rs @@ -55,6 +55,6 @@ pub fn my_func_with_comments() my_simple_func(); } -/** +/* * Comment. */ From 0b6ec4624eeaf27f0d4fd715f8beb7ec9252f924 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Wed, 2 Oct 2024 17:05:01 +0100 Subject: [PATCH 9/9] Rust: Autoformat. --- rust/ql/lib/codeql/files/FileSystem.qll | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/ql/lib/codeql/files/FileSystem.qll b/rust/ql/lib/codeql/files/FileSystem.qll index b78a993cb7e7..95ca925a8840 100644 --- a/rust/ql/lib/codeql/files/FileSystem.qll +++ b/rust/ql/lib/codeql/files/FileSystem.qll @@ -50,7 +50,7 @@ class File extends Container, Impl::File { loc = node.getLocation() | node.getFile() = this and - line = [/*loc.getStartLine(), */loc.getEndLine()] and // ignore start locations for now as we're getting them wrong for things with a comment attached + line = [/*loc.getStartLine(), */ loc.getEndLine()] and // ignore start locations for now as we're getting them wrong for things with a comment attached not loc instanceof EmptyLocation ) )