Skip to content

fix: Recover from MIR field projections on slices#22756

Closed
northaxosky wants to merge 1 commit into
rust-lang:masterfrom
northaxosky:fix/mir-field-ty-slice-panic
Closed

fix: Recover from MIR field projections on slices#22756
northaxosky wants to merge 1 commit into
rust-lang:masterfrom
northaxosky:fix/mir-field-ty-slice-panic

Conversation

@northaxosky

Copy link
Copy Markdown

MIR borrow checking can encounter a Field projection whose base type is a slice while computing diagnostics. field_ty treated that as an invariant violation and panicked with can't project out of [T].

A Field projection contains no index with which to select an array or slice element, so it cannot produce a meaningful field type. Recover with the error type for array and slice bases, while retaining the invariant check for other unexpected types.

The regression test directly exercises PlaceTy([bool]).projection_ty(Field(0)). It panics before this change and returns the error type afterward.

Test: cargo test -p hir-ty

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 10, 2026
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 10, 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.

2 participants