Skip to content

Rust: More path resolution improvements#19133

Merged
hvitved merged 2 commits intogithub:mainfrom
hvitved:rust/more-path-resolution
Apr 1, 2025
Merged

Rust: More path resolution improvements#19133
hvitved merged 2 commits intogithub:mainfrom
hvitved:rust/more-path-resolution

Conversation

@hvitved
Copy link
Copy Markdown
Contributor

@hvitved hvitved commented Mar 27, 2025

Implements a couple of improvements to path resolution:

  • Correct handling of mod foo; imports inside nested modules.
  • Restrict sibling mod foo; imports to crate entry files and mod.rs files.

@github-actions github-actions Bot added the Rust Pull requests that update Rust code label Mar 27, 2025
@hvitved hvitved force-pushed the rust/more-path-resolution branch from b6b6f7c to 73193d6 Compare March 27, 2025 14:55
@hvitved hvitved force-pushed the rust/more-path-resolution branch from 73193d6 to 605cf35 Compare March 28, 2025 14:32
@hvitved hvitved marked this pull request as ready for review March 31, 2025 08:26
Copilot AI review requested due to automatic review settings March 31, 2025 08:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements improvements to how Rust resolves module paths, focusing on better handling of nested module imports and restricting sibling module imports. Key changes include:

  • Adding a new module file at rust/ql/test/library-tests/path-resolution/my/my4/my5/mod.rs.
  • Updating rust/ql/test/library-tests/path-resolution/my.rs to re-export a nested module function.
  • Enhancing rust/ql/test/library-tests/path-resolution/main.rs with a new module (m18) and its nested structure to test complex resolution scenarios.

Reviewed Changes

Copilot reviewed 3 out of 5 changed files in this pull request and generated no comments.

File Description
rust/ql/test/library-tests/path-resolution/my/my4/my5/mod.rs Introduces a new module function f with a test annotation.
rust/ql/test/library-tests/path-resolution/my.rs Adds a nested module my4 containing my5 and re-exports its function as nested_f.
rust/ql/test/library-tests/path-resolution/main.rs Adds module m18 with nested modules to test resolution calls using relative paths.
Files not reviewed (2)
  • rust/ql/lib/codeql/rust/internal/PathResolution.qll: Language not supported
  • rust/ql/test/library-tests/path-resolution/path-resolution.expected: Language not supported
Comments suppressed due to low confidence (3)

rust/ql/test/library-tests/path-resolution/main.rs:489

  • [nitpick] The function name 'f' appears in both m18 and m19, which may lead to ambiguity when using relative paths. Consider renaming one of them to clarify which function is being referenced.
                super::f(); // $ item=I102

rust/ql/test/library-tests/path-resolution/main.rs:490

  • [nitpick] Using 'super::super::f()' in the context of similarly named functions might be unclear. A more distinct naming scheme could improve readability of the module resolution.
                super::super::f(); // $ item=I101

rust/ql/test/library-tests/path-resolution/my/my4/my5/mod.rs:3

  • [nitpick] The annotation 'I201' in the comment may be unclear to future maintainers. Consider providing additional context or a more descriptive comment to indicate its purpose.
} // I201

Tip: Copilot code review supports C#, Go, Java, JavaScript, Markdown, Python, Ruby and TypeScript, with more languages coming soon. Learn more

Copy link
Copy Markdown
Contributor

@paldepind paldepind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@hvitved hvitved merged commit f54d832 into github:main Apr 1, 2025
17 checks passed
@hvitved hvitved deleted the rust/more-path-resolution branch April 1, 2025 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants