Skip to content

Commit

Permalink
Merge pull request #17442 from geoffw0/files
Browse files Browse the repository at this point in the history
Rust: Extracted Files diagnostic query
  • Loading branch information
geoffw0 committed Sep 13, 2024
2 parents 40c5f10 + 587ebbf commit e129914
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 0 deletions.
13 changes: 13 additions & 0 deletions rust/ql/src/queries/diagnostics/ExtractedFiles.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* @name Extracted files
* @description Lists all files in the source code directory that were extracted.
* @kind diagnostic
* @id rust/diagnostics/successfully-extracted-files
* @tags successfully-extracted-files
*/

import rust

from File f
where exists(f.getRelativePath())
select f, "File successfully extracted."
6 changes: 6 additions & 0 deletions rust/ql/test/query-tests/diagnostics/ExtractedFiles.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
| 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. |
| main.rs:0:0:0:0 | main.rs | File successfully extracted. |
| my_macro.rs:0:0:0:0 | my_macro.rs | File successfully extracted. |
| my_struct.rs:0:0:0:0 | my_struct.rs | File successfully extracted. |
1 change: 1 addition & 0 deletions rust/ql/test/query-tests/diagnostics/ExtractedFiles.qlref
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
queries/diagnostics/ExtractedFiles.ql
3 changes: 3 additions & 0 deletions rust/ql/test/query-tests/diagnostics/does_not_compile.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub fn my_func() {
This is not correct Rust code.
}
3 changes: 3 additions & 0 deletions rust/ql/test/query-tests/diagnostics/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub fn my_func() {
compile_error!("An error!");
}
18 changes: 18 additions & 0 deletions rust/ql/test/query-tests/diagnostics/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* total lines in this file: 18
* of which code: 7
* of which only comments: 7
* of which blank: 4
*/

mod my_struct;
mod my_macro;

// another comment

fn main() {
println!("Hello, world!"); // another comment

my_struct::my_func();
my_macro::my_func();
}
18 changes: 18 additions & 0 deletions rust/ql/test/query-tests/diagnostics/my_macro.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* total lines in this file: 18
* of which code: 10
* of which only comments: 6
* of which blank: 2
*/

macro_rules! myMacro {
() => {
println!("Hello, world!");
};
}

pub fn my_func() {
if true {
myMacro!();
}
}
30 changes: 30 additions & 0 deletions rust/ql/test/query-tests/diagnostics/my_struct.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#![allow(dead_code)]
/**
* total lines in this file: 30
* of which code: 20
* of which only comments: 6
* of which blank: 4
*/

#[derive(Debug)]
struct MyStruct {
name: String,
value: i32,
}

impl MyStruct {
fn my_method(&self) {
println!("Hello, world!");
}
}

pub fn my_func() {
let _a = 1;
let b =
MyStruct {
name: String::from("abc"),
value: 123,
};

b.my_method();
}

0 comments on commit e129914

Please sign in to comment.