diff --git a/rust/ql/integration-tests/hello-workspace/exe/src/main.rs b/rust/ql/integration-tests/hello-workspace/exe/src/main.rs index 5bb9375719ea..63670ff63a37 100644 --- a/rust/ql/integration-tests/hello-workspace/exe/src/main.rs +++ b/rust/ql/integration-tests/hello-workspace/exe/src/main.rs @@ -7,4 +7,5 @@ mod a_module; fn main() { my_macro2!(); // $ item=my_macro2 hello(); // $ item=HELLO + lib::extern_crate_alias::a_module::hello(); // $ item=HELLO } diff --git a/rust/ql/integration-tests/hello-workspace/functions.expected b/rust/ql/integration-tests/hello-workspace/functions.expected index 6d8aa73cd833..b6d54fa07d3e 100644 --- a/rust/ql/integration-tests/hello-workspace/functions.expected +++ b/rust/ql/integration-tests/hello-workspace/functions.expected @@ -1,2 +1,2 @@ -| exe/src/main.rs:7:1:10:1 | fn main | +| exe/src/main.rs:7:1:11:1 | fn main | | lib/src/a_module/mod.rs:1:1:4:1 | fn hello | diff --git a/rust/ql/integration-tests/hello-workspace/lib/src/lib.rs b/rust/ql/integration-tests/hello-workspace/lib/src/lib.rs index f313f76edadd..7999517c72d4 100644 --- a/rust/ql/integration-tests/hello-workspace/lib/src/lib.rs +++ b/rust/ql/integration-tests/hello-workspace/lib/src/lib.rs @@ -15,3 +15,5 @@ mod macros { } pub mod a_module; + +pub extern crate self as extern_crate_alias; diff --git a/rust/ql/integration-tests/hello-workspace/summary.cargo.expected b/rust/ql/integration-tests/hello-workspace/summary.cargo.expected index cb07b66d437d..11fba34f9019 100644 --- a/rust/ql/integration-tests/hello-workspace/summary.cargo.expected +++ b/rust/ql/integration-tests/hello-workspace/summary.cargo.expected @@ -9,8 +9,8 @@ | Inconsistencies - Path resolution | 0 | | Inconsistencies - SSA | 0 | | Inconsistencies - data flow | 0 | -| Lines of code extracted | 21 | -| Lines of user code extracted | 21 | +| Lines of code extracted | 23 | +| Lines of user code extracted | 23 | | Macro calls - resolved | 10 | | Macro calls - total | 10 | | Macro calls - unresolved | 0 | diff --git a/rust/ql/integration-tests/hello-workspace/summary.rust-project.expected b/rust/ql/integration-tests/hello-workspace/summary.rust-project.expected index cb07b66d437d..11fba34f9019 100644 --- a/rust/ql/integration-tests/hello-workspace/summary.rust-project.expected +++ b/rust/ql/integration-tests/hello-workspace/summary.rust-project.expected @@ -9,8 +9,8 @@ | Inconsistencies - Path resolution | 0 | | Inconsistencies - SSA | 0 | | Inconsistencies - data flow | 0 | -| Lines of code extracted | 21 | -| Lines of user code extracted | 21 | +| Lines of code extracted | 23 | +| Lines of user code extracted | 23 | | Macro calls - resolved | 10 | | Macro calls - total | 10 | | Macro calls - unresolved | 0 | diff --git a/rust/ql/lib/codeql/rust/internal/PathResolution.qll b/rust/ql/lib/codeql/rust/internal/PathResolution.qll index 54df4a3ca0c4..f4346062f371 100644 --- a/rust/ql/lib/codeql/rust/internal/PathResolution.qll +++ b/rust/ql/lib/codeql/rust/internal/PathResolution.qll @@ -259,8 +259,7 @@ abstract class ItemNode extends Locatable { kind.isInternal() and useOpt.isNone() or - externCrateEdge(this, name, result) and - kind.isInternal() and + externCrateEdge(this, name, kind, result) and useOpt.isNone() or macroExportEdge(this, name, result) and @@ -276,7 +275,7 @@ abstract class ItemNode extends Locatable { result = use_.getASuccessor(name, kind, _) ) or - exists(ExternCrateItemNode ec | result = ec.(ItemNode).getASuccessor(name, kind, useOpt) | + exists(ExternCrateItemNode ec | result = ec.getASuccessor(name, kind, useOpt) | ec = this.getASuccessor(_, _, _) or // if the extern crate appears in the crate root, then the crate name is also added @@ -527,7 +526,7 @@ class ExternCrateItemNode extends ItemNode instanceof ExternCrate { override Namespace getNamespace() { none() } - override Visibility getVisibility() { none() } + override Visibility getVisibility() { result = ExternCrate.super.getVisibility() } override Attr getAnAttr() { result = ExternCrate.super.getAnAttr() } @@ -2107,8 +2106,11 @@ private predicate useImportEdge(Use use, string name, ItemNode item, SuccessorKi /** Holds if `ec` imports `crate` as `name`. */ pragma[nomagic] -private predicate externCrateEdge(ExternCrateItemNode ec, string name, CrateItemNode crate) { +private predicate externCrateEdge( + ExternCrateItemNode ec, string name, SuccessorKind kind, CrateItemNode crate +) { name = ec.getName() and + (if ec.isPublic() then kind.isBoth() else kind.isInternal()) and exists(SourceFile f, string s | ec.getFile() = f.getFile() and s = ec.(ExternCrate).getIdentifier().getText()