Skip to content

Rust: fix canonical paths broken on StructExpr and StructPath #19072

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

Merged
merged 1 commit into from
Mar 20, 2025

Conversation

redsun82
Copy link
Contributor

After the rename done in #19059, canonical path extraction was lost on StructExpr and StructPath as the identifiers used for the type in the emit_detached! macro were not updated. This fixes that.

After the rename done in #19059,
canonical path extraction was lost on `StructExpr` and `StructPath` as
the identifiers used for the type in the `emit_detached!` macro were not
updated. This fixes that.
@Copilot Copilot AI review requested due to automatic review settings March 20, 2025 11:19
Copy link
Contributor

@Copilot 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 addresses the issue where canonical path extraction for StructExpr and StructPath was broken by a previous rename.

  • Updated the emit_detached! macro branch from RecordExpr to StructExpr.
  • Updated the emit_detached! macro branch from RecordPat to StructPat.
Files not reviewed (1)
  • rust/ql/test/extractor-tests/canonical_path/canonical_paths.expected: Language not supported

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

@github-actions github-actions bot added the Rust Pull requests that update Rust code label Mar 20, 2025
@@ -53,13 +53,13 @@ macro_rules! emit_detached {
(PathExpr, $self:ident, $node:ident, $label:ident) => {
$self.extract_path_canonical_destination(&$node, $label.into());
};
(RecordExpr, $self:ident, $node:ident, $label:ident) => {
(StructExpr, $self:ident, $node:ident, $label:ident) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

How could this even compile before?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's because that is a macro invocation on an arbitrary ident, matching it literally. So both the matching here and the idents passed at the macro call sites really can be anything, as they don't then appear in the expanded code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(or in less words, this is a bit of a hack 😆)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

as a bit of background, this could be solved more elegantly if https://rust-lang.github.io/rfcs/1210-impl-specialization.html get finished/implemented: right now the problem is that you can't give a blanket fallback trait implementation, which would be required here to catch most cases and do nothing. If specialization was a thing, we could do a trait with a default implementation doing nothing and then specialize that implementation on the ast classes listed here, without using a magic hacky macro.

@redsun82 redsun82 merged commit e2d6643 into main Mar 20, 2025
13 checks passed
@redsun82 redsun82 deleted the redsun82/rust-fix-canonical-paths-after-rename branch March 20, 2025 12:40
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.

2 participants