Skip to content

Commit a4c06b2

Browse files
committed
Rust: Define SuccessfullyExtractedFile and use it to simplify queries.
1 parent 12fbd18 commit a4c06b2

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

rust/ql/lib/codeql/files/FileSystem.qll

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ private import codeql.util.FileSystem
55
private import codeql.rust.elements.SourceFile
66
private import codeql.rust.elements.AstNode
77
private import codeql.rust.elements.Comment
8+
private import codeql.rust.Diagnostics
89

910
private module Input implements InputSig {
1011
abstract class ContainerBase extends @container {
@@ -56,3 +57,20 @@ class File extends Container, Impl::File {
5657
)
5758
}
5859
}
60+
61+
/**
62+
* A successfully extracted file, that is, a file that was extracted and
63+
* contains no extraction errors or warnings.
64+
*/
65+
class SuccessfullyExtractedFile extends File {
66+
SuccessfullyExtractedFile() {
67+
not exists(Diagnostic d |
68+
d.getLocation().getFile() = this and
69+
(
70+
d instanceof ExtractionError
71+
or
72+
d instanceof ExtractionWarning
73+
)
74+
)
75+
}
76+
}

rust/ql/src/queries/summary/NumberOfFilesExtractedWithErrors.ql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
* @id rust/summary/number-of-files-extracted-with-errors
33
* @name Total number of Rust files that were extracted with errors
44
* @description The total number of Rust files in the source code directory that
5-
* were extracted, but where at least one extraction error occurred in the process.
5+
* were extracted, but where at least one extraction error (or warning) occurred
6+
* in the process.
67
* @kind metric
78
* @tags summary
89
*/
910

1011
import codeql.files.FileSystem
11-
import codeql.rust.Diagnostics
1212

1313
select count(File f |
14-
exists(ExtractionError e | e.getLocation().getFile() = f) and exists(f.getRelativePath())
14+
exists(f.getRelativePath()) and
15+
not f instanceof SuccessfullyExtractedFile
1516
)

rust/ql/src/queries/summary/NumberOfSuccessfullyExtractedFiles.ql

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22
* @id rust/summary/number-of-successfully-extracted-files
33
* @name Total number of Rust files that were extracted without error
44
* @description The total number of Rust files in the source code directory that
5-
* were extracted without encountering any extraction errors.
5+
* were extracted without encountering any extraction errors (or warnings).
66
* @kind metric
77
* @tags summary
88
*/
99

10-
import codeql.rust.Diagnostics
1110
import codeql.files.FileSystem
1211

13-
select count(File f |
14-
not exists(ExtractionError e | e.getLocation().getFile() = f) and exists(f.getRelativePath())
15-
)
12+
select count(SuccessfullyExtractedFile f | exists(f.getRelativePath()))

0 commit comments

Comments
 (0)