Rust: improve modules test case

This commit is contained in:
Arthur Baars
2025-02-27 16:41:54 +01:00
parent e5b039702a
commit ff321194b7
3 changed files with 80 additions and 55 deletions

View File

@@ -1,23 +1,23 @@
#-----| Crate(allocator_api2@0.2.21)
#-----| Crate(allocator_api2@0.2.18)
#-----| Crate(core@0.0.0)
#-----| -> Crate(rand@0.8.5)
#-----| -> Crate(rand_xorshift@0.3.0)
#-----| Crate(compiler_builtins@0.1.140)
#-----| Crate(compiler_builtins@0.1.138)
#-----| -> Crate(core@0.0.0)
#-----| Crate(cfg_if@1.0.0)
#-----| -> Crate(core@0.0.0)
#-----| -> Crate(compiler_builtins@0.1.140)
#-----| -> Crate(compiler_builtins@0.1.138)
#-----| Crate(std@0.0.0)
#-----| -> Crate(core@0.0.0)
#-----| -> Crate(compiler_builtins@0.1.140)
#-----| -> Crate(compiler_builtins@0.1.138)
#-----| -> Crate(cfg_if@1.0.0)
#-----| -> Crate(alloc@0.0.0)
#-----| -> Crate(hashbrown@0.15.2)
#-----| -> Crate(libc@0.2.169)
#-----| -> Crate(hashbrown@0.15.0)
#-----| -> Crate(libc@0.2.162)
#-----| -> Crate(rand@0.8.5)
#-----| -> Crate(rand_xorshift@0.3.0)
#-----| -> Crate(rustc_demangle@0.1.24)
@@ -28,7 +28,7 @@
#-----| Crate(unicode_width@0.1.14)
#-----| -> Crate(core@0.0.0)
#-----| -> Crate(compiler_builtins@0.1.140)
#-----| -> Crate(compiler_builtins@0.1.138)
#-----| -> Crate(std@0.0.0)
#-----| Crate(getopts@0.2.21)
@@ -38,17 +38,17 @@
#-----| Crate(alloc@0.0.0)
#-----| -> Crate(core@0.0.0)
#-----| -> Crate(compiler_builtins@0.1.140)
#-----| -> Crate(compiler_builtins@0.1.138)
#-----| -> Crate(rand@0.8.5)
#-----| -> Crate(rand_xorshift@0.3.0)
#-----| Crate(hashbrown@0.15.2)
#-----| -> Crate(allocator_api2@0.2.21)
#-----| Crate(hashbrown@0.15.0)
#-----| -> Crate(allocator_api2@0.2.18)
#-----| -> Crate(core@0.0.0)
#-----| -> Crate(compiler_builtins@0.1.140)
#-----| -> Crate(compiler_builtins@0.1.138)
#-----| -> Crate(alloc@0.0.0)
#-----| Crate(libc@0.2.169)
#-----| Crate(libc@0.2.162)
#-----| -> Crate(core@0.0.0)
#-----| Crate(rand_core@0.6.4)
@@ -61,27 +61,27 @@
#-----| Crate(rustc_demangle@0.1.24)
#-----| -> Crate(core@0.0.0)
#-----| -> Crate(compiler_builtins@0.1.140)
#-----| -> Crate(compiler_builtins@0.1.138)
#-----| Crate(panic_abort@0.0.0)
#-----| -> Crate(core@0.0.0)
#-----| -> Crate(compiler_builtins@0.1.140)
#-----| -> Crate(compiler_builtins@0.1.138)
#-----| -> Crate(cfg_if@1.0.0)
#-----| -> Crate(alloc@0.0.0)
#-----| -> Crate(libc@0.2.169)
#-----| -> Crate(libc@0.2.162)
#-----| Crate(unwind@0.0.0)
#-----| -> Crate(core@0.0.0)
#-----| -> Crate(compiler_builtins@0.1.140)
#-----| -> Crate(compiler_builtins@0.1.138)
#-----| -> Crate(cfg_if@1.0.0)
#-----| -> Crate(libc@0.2.169)
#-----| -> Crate(libc@0.2.162)
#-----| Crate(panic_unwind@0.0.0)
#-----| -> Crate(core@0.0.0)
#-----| -> Crate(compiler_builtins@0.1.140)
#-----| -> Crate(compiler_builtins@0.1.138)
#-----| -> Crate(cfg_if@1.0.0)
#-----| -> Crate(alloc@0.0.0)
#-----| -> Crate(libc@0.2.169)
#-----| -> Crate(libc@0.2.162)
#-----| -> Crate(unwind@0.0.0)
#-----| Crate(proc_macro@0.0.0)
@@ -90,16 +90,16 @@
#-----| Crate(std_detect@0.1.5)
#-----| -> Crate(core@0.0.0)
#-----| -> Crate(compiler_builtins@0.1.140)
#-----| -> Crate(compiler_builtins@0.1.138)
#-----| -> Crate(cfg_if@1.0.0)
#-----| -> Crate(alloc@0.0.0)
#-----| -> Crate(libc@0.2.169)
#-----| -> Crate(libc@0.2.162)
#-----| Crate(test@0.0.0)
#-----| -> Crate(core@0.0.0)
#-----| -> Crate(std@0.0.0)
#-----| -> Crate(getopts@0.2.21)
#-----| -> Crate(libc@0.2.169)
#-----| -> Crate(libc@0.2.162)
#-----| Crate(test@0.0.1)
#-----| -> Crate(core@0.0.0)

View File

@@ -1,40 +1,37 @@
#-----| Const
#-----| Static
#-----| enum X
#-----| fn as_string
#-----| fn length
#-----| fn write
#-----| fn as_string
#-----| fn fmt
#-----| struct X_List
#-----| Static
#-----| mod module
#-----| -> fn length
#-----| -> fn write
#-----| -> struct X_List
#-----| -> Static
#-----| -> trait AsString
#-----| -> Const
#-----| -> impl AsString for ...::X { ... }
#-----| -> impl ...::Display for ...::X { ... }
#-----| -> enum X
#-----| mod crate
#-----| -> mod module
#-----| trait AsString
#-----| -> fn as_string
#-----| Const
#-----| impl AsString for ...::X { ... }
#-----| -> fn as_string
#-----| fn length
#-----| impl ...::Display for ...::X { ... }
#-----| -> fn fmt
#-----| enum X
#-----| impl AsString for ...::X { ... }
#-----| -> fn as_string
#-----| mod crate
#-----| -> mod module
#-----| mod module
#-----| -> Const
#-----| -> Static
#-----| -> enum X
#-----| -> fn length
#-----| -> impl ...::Display for ...::X { ... }
#-----| -> impl AsString for ...::X { ... }
#-----| -> struct X_List
#-----| -> trait AsString
#-----| struct X_List
#-----| trait AsString
#-----| -> fn as_string

View File

@@ -6,12 +6,40 @@
import rust
query predicate nodes(Item i) {
i.getParentNode*() = any(Crate m | m.getName() = "test" and m.getVersion() = "0.0.1").getModule()
predicate nodes(Item i) { i instanceof RelevantNode }
class RelevantNode extends Item {
RelevantNode() {
this.getParentNode*() =
any(Crate m | m.getName() = "test" and m.getVersion() = "0.0.1").getModule()
}
}
query predicate edges(Item container, Item element) {
predicate edges(RelevantNode container, RelevantNode element) {
element = container.(Module).getItemList().getAnItem() or
element = container.(Impl).getAssocItemList().getAnAssocItem() or
element = container.(Trait).getAssocItemList().getAnAssocItem()
}
query predicate nodes(RelevantNode node, string attr, string val) {
nodes(node) and
(
attr = "semmle.label" and
val = node.toString()
or
attr = "semmle.order" and
val =
any(int i | node = rank[i](RelevantNode n | nodes(n) | n order by n.toString())).toString()
)
}
query predicate edges(RelevantNode pred, RelevantNode succ, string attr, string val) {
edges(pred, succ) and
(
attr = "semmle.label" and
val = ""
or
attr = "semmle.order" and
val = any(int i | succ = rank[i](Item s | edges(pred, s) | s order by s.toString())).toString()
)
}