fix(hir): Use expression store of parent body if available - #23202
Merged
Conversation
Contributor
There was a problem hiding this comment.
The fix is correct (worth noting though that after #23196 the bug won't trigger anymore, but this change will still be correct) but can you please write a test?
Contributor
Author
|
Can't believe how I missed your message. I am writing one. Sorry for such a delay |
Suryansh-Dey
force-pushed
the
expression
branch
from
August 21, 2026 15:52
62377e2 to
77ed31e
Compare
Contributor
Author
|
Test added. Also fixed similar issue in |
Suryansh-Dey
force-pushed
the
expression
branch
from
August 21, 2026 16:13
77ed31e to
99a0e5f
Compare
This comment has been minimized.
This comment has been minimized.
ChayimFriedman2
requested changes
Aug 22, 2026
Suryansh-Dey
force-pushed
the
expression
branch
2 times, most recently
from
August 23, 2026 07:37
0335ad3 to
95f1bdb
Compare
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. |
Suryansh-Dey
force-pushed
the
expression
branch
from
August 23, 2026 07:45
95f1bdb to
cdb9251
Compare
Contributor
Author
|
ChayimFriedman2
approved these changes
Aug 23, 2026
| } | ||
|
|
||
| #[test] | ||
| fn resolve_array_type_with_anon_const_panic() { |
Contributor
There was a problem hiding this comment.
This probably shouldn't be here but I don't have a better place 😢
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Closes #23192
Reason of the issue:
Unlike named constants (like const C: ...), anonymous constants (like 2 + 2 inside an array type) do not get their own independent Body. Instead, they are stored directly inside the
ExpressionStoreof their parent owner.But in
crates/hir/src/source_analyzer.rsthe code that creates theTyLoweringContexthardcodes the owner to be the generic definition of the parent instead of checking that it is currently inside the Body of parent.Fix
Simply check if the type is inside an expression scope then assigns the Body as the owner instead of the Signature.
How to test
Re-run the repro provided in issue and it passes!

Run
cargo test -p hir-tyand all 1038 passed.