diff --git a/rust/ql/lib/codeql/files/FileSystem.qll b/rust/ql/lib/codeql/files/FileSystem.qll index ee7a2235476e..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 + 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/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 035a74975be8..bf709e1ddc4d 100644 --- a/rust/ql/test/query-tests/diagnostics/LinesOfCode.expected +++ b/rust/ql/test/query-tests/diagnostics/LinesOfCode.expected @@ -1 +1 @@ -| 48 | +| 61 | diff --git a/rust/ql/test/query-tests/diagnostics/LinesOfUserCode.expected b/rust/ql/test/query-tests/diagnostics/LinesOfUserCode.expected index 035a74975be8..bf709e1ddc4d 100644 --- a/rust/ql/test/query-tests/diagnostics/LinesOfUserCode.expected +++ b/rust/ql/test/query-tests/diagnostics/LinesOfUserCode.expected @@ -1 +1 @@ -| 48 | +| 61 | diff --git a/rust/ql/test/query-tests/diagnostics/LinesOfUserCodeInFiles.expected b/rust/ql/test/query-tests/diagnostics/LinesOfUserCodeInFiles.expected index 2be3f73088ca..b93473f7e04a 100644 --- a/rust/ql/test/query-tests/diagnostics/LinesOfUserCodeInFiles.expected +++ b/rust/ql/test/query-tests/diagnostics/LinesOfUserCodeInFiles.expected @@ -1,6 +1,7 @@ -| my_struct.rs:0:0:0:0 | my_struct.rs | 21 | -| 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 | +| 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 | | 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 ff07c0f589a6..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 | 210 | +| Elements extracted | 290 | | Elements unextracted | 0 | -| Files extracted | 6 | -| Lines of code extracted | 48 | -| Lines of user code extracted | 48 | +| Files extracted | 7 | +| Lines of code extracted | 61 | +| Lines of user code extracted | 61 | 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..fe99fdd4e3e3 --- /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 790547c0ff9d..07dd4234a6e7 100644 --- a/rust/ql/test/query-tests/diagnostics/main.rs +++ b/rust/ql/test/query-tests/diagnostics/main.rs @@ -1,17 +1,16 @@ /** * 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 - //println!("Hello, world!"); // currently causes consistency issues +fn main() { + 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!"); }; }