Rust: Make path resolution robust against invalid code with conflicting declarations#21311
Rust: Make path resolution robust against invalid code with conflicting declarations#21311hvitved wants to merge 1 commit intogithub:mainfrom
Conversation
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.