Skip to content

fix: Recover from MIR field projections on slices#22758

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

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

Conversation

@northaxosky

@northaxosky northaxosky commented Jul 10, 2026

Copy link
Copy Markdown

Fixes #22757

MIR diagnostic borrow checking can encounter a Field projection whose base place has an array or slice type. PlaceTy::field_ty previously treated that as an invariant violation and panicked with:

text can't project out of [T] ​

A Field projection contains a field index but no array or slice element index, so it cannot produce a meaningful element-field type. This change treats array and slice bases as failed MIR type recovery and propagates an error type. Other unexpected base types retain the existing invariant check.

The regression test exercises the production PlaceTy::projection_ty path with a slice base and a Field projection. Before the fix it panics with can't project out of [bool]; afterward it returns the error type.

Tests:

text cargo test -p hir-ty ​

All 998 hir-ty tests pass.

@rustbot rustbot added 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

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MIR borrow checker panics on a field projection from a slice

2 participants