Merge pull request #20842 from hvitved/rust/path-resolution-extern-crate-visibility

Rust: Handle `pub extern crate` in path resolution
This commit is contained in:
Tom Hvitved
2025-11-20 11:59:05 +01:00
committed by GitHub
6 changed files with 15 additions and 10 deletions

View File

@@ -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
}

View File

@@ -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 |

View File

@@ -15,3 +15,5 @@ mod macros {
}
pub mod a_module;
pub extern crate self as extern_crate_alias;

View File

@@ -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 |

View File

@@ -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 |

View File

@@ -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()