-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Rust: Make path resolution robust against invalid code with conflicting declarations #21311
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
base: main
Are you sure you want to change the base?
Rust: Make path resolution robust against invalid code with conflicting declarations #21311
Conversation
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.
Pull request overview
Improves Rust path resolution to remain performant and deterministic in the presence of invalid Rust code that introduces conflicting declarations (e.g., duplicate names), and adds a regression test covering that scenario.
Changes:
- Add an invalid-Rust test case with conflicting
struct Adeclarations and disablecargo checkfor that fixture. - Update path resolution to avoid combinatorial blow-ups in invalid code by selecting a single (last) matching child item.
- Update expected test output to reflect the new resolution behavior for the invalid fixture.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| rust/ql/lib/codeql/rust/internal/PathResolution.qll | Adjusts child-successor selection to be robust in invalid/conflicting-declaration scenarios. |
| rust/ql/test/library-tests/path-resolution/invalid/main.rs | Adds an invalid Rust fixture with conflicting declarations. |
| rust/ql/test/library-tests/path-resolution/invalid/options.yml | Disables cargo checking for the invalid fixture. |
| rust/ql/test/library-tests/path-resolution/path-resolution.expected | Updates expected results for the new invalid-code path resolution behavior. |
Comments suppressed due to low confidence (1)
rust/ql/test/library-tests/path-resolution/invalid/main.rs:6
- Typo in comment: “precendence” should be “precedence”.
fn f(x: A) {} // $ item=A2 (the later occurence takes precendence)
| struct A; // A1 | ||
| struct A; // A2 | ||
|
|
||
| fn f(x: A) {} // $ item=A2 (the later occurence takes precendence) |
Copilot
AI
Feb 12, 2026
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.
Typo in comment: “occurence” should be “occurrence”.
This issue also appears on line 6 of the same file.
| fn f(x: A) {} // $ item=A2 (the later occurence takes precendence) | |
| fn f(x: A) {} // $ item=A2 (the later occurrence takes precendence) |
| struct A; // A1 | ||
| struct A; // A2 | ||
|
|
||
| fn f(x: A) {} // $ item=A2 (the later occurence takes precendence) |
Copilot
AI
Feb 12, 2026
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.
Wording in comment: “the later” is ambiguous here; “the latter” better matches the intent (A2 vs A1).
| fn f(x: A) {} // $ item=A2 (the later occurence takes precendence) | |
| fn f(x: A) {} // $ item=A2 (the latter occurrence takes precedence) |
| not result instanceof NamedItemNode | ||
| or | ||
| // In valid Rust code, there cannot be multiple children with the same name and namespace, | ||
| // but to safe-guard against combinatorial explosions in invalid code, we always pick the |
Copilot
AI
Feb 12, 2026
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.
Grammar in comment: “to safe-guard” should be “to safeguard”.
| // but to safe-guard against combinatorial explosions in invalid code, we always pick the | |
| // but to safeguard against combinatorial explosions in invalid code, we always pick the |
Fixes performance on
edl-lang/edl, which contains e.g. https://github.com/edl-lang/edl/blob/main/tests/ui/impl-trait/impl-trait-plus-priority.rs.