mirror of
https://github.com/github/codeql.git
synced 2026-04-29 02:35:15 +02:00
Merge pull request #17442 from geoffw0/files
Rust: Extracted Files diagnostic query
This commit is contained in:
13
rust/ql/src/queries/diagnostics/ExtractedFiles.ql
Normal file
13
rust/ql/src/queries/diagnostics/ExtractedFiles.ql
Normal file
@@ -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."
|
||||
@@ -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. |
|
||||
@@ -0,0 +1 @@
|
||||
queries/diagnostics/ExtractedFiles.ql
|
||||
3
rust/ql/test/query-tests/diagnostics/does_not_compile.rs
Normal file
3
rust/ql/test/query-tests/diagnostics/does_not_compile.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
pub fn my_func() {
|
||||
This is not correct Rust code.
|
||||
}
|
||||
3
rust/ql/test/query-tests/diagnostics/error.rs
Normal file
3
rust/ql/test/query-tests/diagnostics/error.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
pub fn my_func() {
|
||||
compile_error!("An error!");
|
||||
}
|
||||
18
rust/ql/test/query-tests/diagnostics/main.rs
Normal file
18
rust/ql/test/query-tests/diagnostics/main.rs
Normal file
@@ -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
rust/ql/test/query-tests/diagnostics/my_macro.rs
Normal file
18
rust/ql/test/query-tests/diagnostics/my_macro.rs
Normal file
@@ -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
rust/ql/test/query-tests/diagnostics/my_struct.rs
Normal file
30
rust/ql/test/query-tests/diagnostics/my_struct.rs
Normal file
@@ -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();
|
||||
}
|
||||
Reference in New Issue
Block a user