Skip to content

Fix panics involving mutable references to ZSTs#45

Merged
coord-e merged 2 commits intomainfrom
coord-e/fix-closure-field-2
Feb 9, 2026
Merged

Fix panics involving mutable references to ZSTs#45
coord-e merged 2 commits intomainfrom
coord-e/fix-closure-field-2

Conversation

@coord-e
Copy link
Owner

@coord-e coord-e commented Feb 9, 2026

fix #39
fix #40

  1. The temporary variables are referenced by another part of the environment and therefore should not be omitted in Env::dependencies.
  2. local_def::Analyzer::reassign_local_mutabilities adjusts the mutability of locals for optimization purposes. It treats variables that are defined (alive) at the entry of a BB and mutated within that BB as mutable ones. However, for ZSTs, it is possible for them to be mut-borrowed without initialization. (To be precise, let _1: (); bb0: { _1 = (); } should not mark _1 as mut, so this fix is imprecise, but it's a rare case anyway and shouldn't have a performance impact...)

Copy link

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

Fixes panics when the analyzer/refinement pipeline encounters mutable references to zero-sized types (ZSTs), specifically around closure types with no captures and the unit type ().

Changes:

  • Update Env::dependencies() to stop dropping singleton-sorted temp vars, preventing “unbound var” panics during clause building.
  • Update local_def::Analyzer::reassign_local_mutabilities() to treat ZST locals as mutable when needed, avoiding incorrect optimization assumptions.
  • Add new UI tests covering &mut () and &mut to a no-capture closure in both pass/fail suites.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/refine/env.rs Keeps singleton temp vars in dependency mapping to avoid missing mapped variables during clause construction.
src/analyze/local_def.rs Marks ZST locals as mutable in mutability reassignment to avoid panics/incorrect handling of mut-borrows.
tests/ui/pass/mut_empty_tuple.rs New passing regression test for &mut ().
tests/ui/pass/closure_mut_param.rs New passing regression test for &mut to a ZST closure type.
tests/ui/fail/mut_empty_tuple.rs New failing (Unsat) test variant for &mut ().
tests/ui/fail/closure_mut_param.rs New failing (Unsat) test variant for &mut to a closure parameter that is invoked.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@coord-e coord-e force-pushed the coord-e/fix-closure-field-2 branch from 2c20328 to 3bd747c Compare February 9, 2026 15:47
@coord-e coord-e merged commit 4e2836c into main Feb 9, 2026
6 checks passed
@coord-e coord-e deleted the coord-e/fix-closure-field-2 branch February 9, 2026 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant