Skip to content

fix: Failed to lookup MACRO_CALL@... in this Semantics due to include! - #22933

Merged
Veykril merged 1 commit into
rust-lang:masterfrom
Wilfred:fix/inline-macro-included-file
Jul 28, 2026
Merged

fix: Failed to lookup MACRO_CALL@... in this Semantics due to include!#22933
Veykril merged 1 commit into
rust-lang:masterfrom
Wilfred:fix/inline-macro-included-file

Conversation

@Wilfred

@Wilfred Wilfred commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

SemanticsImpl::find_file assumes that its caches always contain the file that
has the current SyntaxNode.

For macros foo!() we only have two files to worry about: the macro
call site and the macro definition site. Hoewver, for
include!("foo.rs") we also need to consider the included file.

Ensure that the file cache is consistently populated for include!()
invocations macro expansion, and add a test.

AI disclosure: GPT-5.5 used to minimise a repro from a real project
and write the initial implementation. Comments and commit message are
entirely mine.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 27, 2026
let InMacroFile { file_id, value } = exp_info.expanded();
Self::cache(&mut self.root_to_file_cache, value, file_id.into());

// Ensure that the cache contains syntax nodes from the macro call site.

@ChayimFriedman2 ChayimFriedman2 Jul 27, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The problem is not in this method. The problem is in whatever calls it but doesn't have the macro node in the Semantics.

View changes since the review

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is actually specific to include! I think, because its arg is a different file than the macro call resides in

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Aha, yep, all the crashes I can see were with include!().

I've rewritten the comments accordingly and added an explicit if macro_file.is_include_macro(db) check to make this explicit.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yea that seems like the better solution for now

SemanticsImpl::find_file assumes that its caches always contain the file that
has the current SyntaxNode.

For macros `foo!()` we only have two files to worry about: the macro
call site and the macro definition site. Hoewver, for
include!("foo.rs") we also need to consider the included file.

Ensure that the file cache is consistently populated for include!()
invocations macro expansion, and add a test.

AI disclosure: GPT-5.5 used to minimise a repro from a real project
and write the initial implementation. Comments and commit message are
entirely mine.
@Wilfred
Wilfred force-pushed the fix/inline-macro-included-file branch from 5af94fb to 0c11196 Compare July 28, 2026 12:29
@rustbot

rustbot commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@Wilfred Wilfred changed the title fix: Failed to lookup MACRO_CALL@... in this Semantics fix: Failed to lookup MACRO_CALL@... in this Semantics due to include! Jul 28, 2026

@Veykril Veykril left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@Veykril
Veykril added this pull request to the merge queue Jul 28, 2026
Merged via the queue into rust-lang:master with commit 30e7997 Jul 28, 2026
18 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants