-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Rust: Path resolution associated type fix #20096
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
71a5e41
ac6715f
8ebebf0
2885046
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -112,13 +112,18 @@ abstract class ItemNode extends Locatable { | |||||||||||||||||||||||||||||||||||||||||||||||||
| result = this.(SourceFileItemNode).getSuper() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| pragma[nomagic] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| private ItemNode getAChildSuccessor(string name) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| this = result.getImmediateParent() and | ||||||||||||||||||||||||||||||||||||||||||||||||||
| name = result.getName() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| cached | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ItemNode getASuccessorRec(string name) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Stages::PathResolutionStage::ref() and | ||||||||||||||||||||||||||||||||||||||||||||||||||
| sourceFileEdge(this, name, result) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| or | ||||||||||||||||||||||||||||||||||||||||||||||||||
| this = result.getImmediateParent() and | ||||||||||||||||||||||||||||||||||||||||||||||||||
| name = result.getName() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| result = this.getAChildSuccessor(name) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| or | ||||||||||||||||||||||||||||||||||||||||||||||||||
| fileImportEdge(this, name, result) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| or | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -224,6 +229,38 @@ abstract class ItemNode extends Locatable { | |||||||||||||||||||||||||||||||||||||||||||||||||
| result.(CrateItemNode).isPotentialDollarCrateTarget() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * Holds if the successor `item` with the name `name` is not available locally | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * for unqualified paths. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * This has the effect that a path of the form `name` inside `this` will not | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * resolve to `item`. | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| * resolve to `item`. | |
| * resolve to `item`. | |
| * | |
| * ## Specific Scenarios | |
| * In Rust, associated items (such as methods, associated types, or constants) | |
| * defined within an `impl` or `trait` block are not directly accessible | |
| * without qualification. To access these items, a `Self::` prefix is required. | |
| * | |
| * For example: | |
| * ``` | |
| * impl MyTrait for MyType { | |
| * fn my_method() {} | |
| * } | |
| * | |
| * // Inside the `impl` block, `my_method` must be accessed as `Self::my_method`. | |
| * ``` | |
| * | |
| * This predicate identifies such cases where unqualified access is not allowed. | |
| * | |
| * ## References | |
| * For more details, see the Rust reference on [associated items](https://doc.rust-lang.org/reference/items/associated-items.html). |
Copilot
AI
Jul 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The excludedExternally predicate should include documentation with examples showing when type parameters are not accessible outside their declaring scope.
| * `Qualifier` resolves to this item, will not resolve to `item`. | |
| * `Qualifier` resolves to this item, will not resolve to `item`. | |
| * | |
| * ## Examples | |
| * | |
| * Consider the following Rust code: | |
| * | |
| * ``` | |
| * impl<T> MyStruct<T> { | |
| * fn new() -> Self { | |
| * // ... | |
| * } | |
| * } | |
| * ``` | |
| * | |
| * Here, the type parameter `T` is not accessible outside the `impl` block. | |
| * For example, the following code would result in a compilation error: | |
| * | |
| * ``` | |
| * let x: MyStruct::T; // Error: `T` is not accessible here | |
| * ``` | |
| * | |
| * The `excludedExternally` predicate ensures that such type parameters are | |
| * excluded from external path resolution. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new
getAChildSuccessorpredicate lacks documentation explaining its purpose and relationship to the existing successor methods.