Skip to content

Commit 9c95a17

Browse files
author
Paolo Tranquilli
committed
Rust: add block ids to canonical paths, making them "extended"
1 parent 652e471 commit 9c95a17

File tree

67 files changed

+262
-169
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+262
-169
lines changed

rust/extractor/src/generated/.generated.list

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/extractor/src/generated/top.rs

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/extractor/src/translate/base.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::trap::{DiagnosticSeverity, TrapFile, TrapId};
55
use crate::trap::{Label, TrapClass};
66
use codeql_extractor::trap::{self};
77
use log::Level;
8+
use ra_ap_base_db::salsa::InternKey;
89
use ra_ap_base_db::CrateOrigin;
910
use ra_ap_hir::db::ExpandDatabase;
1011
use ra_ap_hir::{Adt, ItemContainer, Module, Semantics, Type};
@@ -347,9 +348,9 @@ impl<'a> Translator<'a> {
347348
}
348349

349350
fn canonical_path_from_hir_module(&self, item: Module) -> Option<String> {
350-
if ModuleId::from(item).is_block_module() {
351+
if let Some(block_id) = ModuleId::from(item).containing_block() {
351352
// this means this is a block module, i.e. a virtual module for a block scope
352-
return None;
353+
return Some(format!("{{{}}}", block_id.as_intern_id()));
353354
}
354355
if item.is_crate_root() {
355356
return Some("crate".into());
@@ -407,7 +408,7 @@ impl<'a> Translator<'a> {
407408
let path = self.canonical_path_from_hir(def)?;
408409
let origin = self.origin_from_hir(def);
409410
generated::Item::emit_crate_origin(label, origin, &mut self.trap.writer);
410-
generated::Item::emit_canonical_path(label, path, &mut self.trap.writer);
411+
generated::Item::emit_extended_canonical_path(label, path, &mut self.trap.writer);
411412
Some(())
412413
})();
413414
}

rust/ql/.generated.list

Lines changed: 36 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/ql/.gitattributes

Lines changed: 17 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/ql/lib/codeql/rust/elements/internal/generated/Item.qll

Lines changed: 10 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/ql/lib/codeql/rust/elements/internal/generated/Raw.qll

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/ql/lib/rust.dbscheme

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1844,9 +1844,9 @@ infer_types(
18441844
;
18451845

18461846
#keyset[id]
1847-
item_canonical_paths(
1847+
item_extended_canonical_paths(
18481848
int id: @item ref,
1849-
string canonical_path: string ref
1849+
string extended_canonical_path: string ref
18501850
);
18511851

18521852
#keyset[id]

rust/ql/test/extractor-tests/canonical_name/canonical_name.expected renamed to rust/ql/test/extractor-tests/canonical_path/canonical_path.expected

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,19 @@
1010
| canonical_paths.rs:17:9:17:20 | h | crate::canonical_paths::a::TraitWithBlanketImpl::h |
1111
| canonical_paths.rs:20:5:22:5 | Impl | None |
1212
| canonical_paths.rs:21:9:21:22 | h | <_ as crate::canonical_paths::a::TraitWithBlanketImpl>::h |
13-
| canonical_paths.rs:25:1:45:1 | Module | crate::canonical_paths::without |
14-
| canonical_paths.rs:26:5:44:5 | canonicals | crate::canonical_paths::without::canonicals |
15-
| canonical_paths.rs:27:9:27:27 | Struct | None |
16-
| canonical_paths.rs:29:9:31:9 | Trait | None |
17-
| canonical_paths.rs:30:13:30:24 | g | None |
13+
| canonical_paths.rs:25:1:53:1 | Module | crate::canonical_paths::without |
14+
| canonical_paths.rs:26:5:48:5 | canonicals | crate::canonical_paths::without::canonicals |
15+
| canonical_paths.rs:27:9:27:27 | Struct | {0}::OtherStruct |
16+
| canonical_paths.rs:29:9:31:9 | Trait | {0}::OtherTrait |
17+
| canonical_paths.rs:30:13:30:24 | g | {0}::OtherTrait::g |
1818
| canonical_paths.rs:33:9:35:9 | Impl | None |
19-
| canonical_paths.rs:34:13:34:26 | g | None |
19+
| canonical_paths.rs:34:13:34:26 | g | <{0}::OtherStruct as {0}::OtherTrait>::g |
2020
| canonical_paths.rs:37:9:39:9 | Impl | None |
21-
| canonical_paths.rs:38:13:38:26 | g | None |
21+
| canonical_paths.rs:38:13:38:26 | g | <crate::canonical_paths::a::Struct as {0}::OtherTrait>::g |
2222
| canonical_paths.rs:41:9:43:9 | Impl | None |
23-
| canonical_paths.rs:42:13:42:26 | f | None |
23+
| canonical_paths.rs:42:13:42:26 | f | <{0}::OtherStruct as crate::canonical_paths::a::Trait>::f |
24+
| canonical_paths.rs:45:9:47:9 | nested | {0}::nested |
25+
| canonical_paths.rs:46:13:46:31 | Struct | {1}::OtherStruct |
26+
| canonical_paths.rs:50:5:52:5 | other | crate::canonical_paths::without::other |
27+
| canonical_paths.rs:51:9:51:27 | Struct | {2}::OtherStruct |
2428
| lib.rs:1:1:1:20 | Module | crate::canonical_paths |

rust/ql/test/extractor-tests/canonical_name/canonical_name.ql renamed to rust/ql/test/extractor-tests/canonical_path/canonical_path.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ from Item i, string path
55
where
66
toBeTested(i) and
77
(
8-
path = i.getCanonicalPath()
8+
path = i.getExtendedCanonicalPath()
99
or
10-
not i.hasCanonicalPath() and path = "None"
10+
not i.hasExtendedCanonicalPath() and path = "None"
1111
)
1212
select i, path

0 commit comments

Comments
 (0)