Skip to content

Commit 1cee226

Browse files
committed
Rust: add file for root modules of crates
1 parent 0cfed92 commit 1cee226

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

rust/extractor/src/crate_graph.rs

+17
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use chalk_ir::IntTy;
66
use chalk_ir::Scalar;
77
use chalk_ir::UintTy;
88
use chalk_ir::{FloatTy, Safety};
9+
use codeql_extractor::trap::Location;
910
use itertools::Itertools;
1011
use ra_ap_base_db::CrateGraph;
1112
use ra_ap_base_db::CrateId;
@@ -85,6 +86,22 @@ pub fn extract_crate_graph(trap_provider: &trap::TrapFileProvider, db: &RootData
8586
DefMap::ROOT,
8687
&mut trap,
8788
);
89+
let file_label = trap.emit_file(root_module_file).as_untyped();
90+
let location_label = codeql_extractor::extractor::location_label(
91+
&mut trap.writer,
92+
Location {
93+
file_label,
94+
start_line: 0,
95+
start_column: 0,
96+
end_line: 0,
97+
end_column: 0,
98+
},
99+
);
100+
trap.writer.add_tuple(
101+
"locatable_locations",
102+
vec![module.into(), location_label.into()],
103+
);
104+
88105
let element = generated::Crate {
89106
id: trap::TrapId::Key(format!("{}:{hash}", root_module_file.display())),
90107
name: krate

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ class File extends Container, Impl::File {
5555
|
5656
node.getFile() = this and
5757
line = [/*loc.getStartLine(), */ loc.getEndLine()] and // ignore start locations for now as we're getting them wrong for things with a comment attached
58-
not loc instanceof EmptyLocation
58+
not loc instanceof EmptyLocation and
59+
line > 0
5960
)
6061
)
6162
}

rust/ql/test/extractor-tests/crate_graph/modules.expected

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
#-----| impl AsString for ...::X { ... }
1919
#-----| -> fn as_string
2020

21-
#-----| mod crate
21+
lib.rs:
22+
# 1| mod crate
2223
#-----| -> mod module
2324

2425
#-----| mod module

0 commit comments

Comments
 (0)