Skip to content

Compiler panic in cfgir/borrows/state.rs: check_use_borrowed_by panics on tmp local with short-circuit operator after borrow-edge overflow #25846

@jubnzv

Description

@jubnzv

The compiler panics with an ICE in cfgir/borrows/state.rs:416 when a function has 11+ conditional reference reassignments (exceeding MAX_EDGE_SET_SIZE=10 in the borrow graph), followed by a short-circuit boolean expression (&& or ||). The borrow edge set overflows, and the subsequent short-circuit expression introduces a temporary local that check_use_borrowed_by doesn't handle in the DisplayVar::Tmp panic arm.

It requires 11 or more conditional reference reassignments to overflow MAX_EDGE_SET_SIZE (10) in move-borrow-graph.

MRE:

module 0x42::m;

public fun f(test: bool): &u64 {
    let (a, b, c, d, e, f, g, h, i, j, k) = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    let mut x = &a;
    if (test) x = &b;
    if (test) x = &c;
    if (test) x = &d;
    if (test) x = &e;
    if (test) x = &f;
    if (test) x = &g;
    if (test) x = &h;
    if (test) x = &i;
    if (test) x = &j;
    if (test) x = &k;
    test && test;
    x
}

Reproduce steps:

cd external-crates/move
cargo +nightly run --release -p move-compiler --bin move-check -- mre.move

Output:

thread 'main' (4189346) panicked at crates/move-compiler/src/cfgir/borrows/state.rs:416:36:
ICE invalid use of tmp local %#39 with borrows BorrowGraph(
    {
        RefID(
            0,
        ): Ref {
            borrowed_by: BorrowEdges(
                {
                    RefID(
                        62,
                    ): BorrowEdgeSet {
                        edges: {
                            BorrowEdgeNoLoc {
                                strong: true,
                                path: [
                                    Local(
                                        "e#0#0",
                                    ),
                                    Field(
                                        "10",
                                    ),
                                ],
                            },
                        },
                        overflown: false,
                    },
                    RefID(
                        64,
                    ): BorrowEdgeSet {
                        edges: {
                            BorrowEdgeNoLoc {
                                strong: true,
                                path: [
                                    Local(
                                        "e#0#0",
                                    ),
                                    Field(
                                        "11",
                                    ),
                                ],
                            },
                        },
                        overflown: false,
                    },
                    RefID(
                        66,
                    ): BorrowEdgeSet {
                        edges: {
                            BorrowEdgeNoLoc {
                                strong: false,
                                path: [],
                            },
                        },
                        overflown: true,
                    },
                },
            ),
            borrows_from: {},
            mutable: true,
        },
        RefID(
            62,
        ): Ref {
            borrowed_by: BorrowEdges(
                {},
            ),
            borrows_from: {
                RefID(
                    0,
                ),
            },
            mutable: false,
        },
        RefID(
            64,
        ): Ref {
            borrowed_by: BorrowEdges(
                {},
            ),
            borrows_from: {
                RefID(
                    0,
                ),
            },
            mutable: false,
        },
        RefID(
            66,
        ): Ref {
            borrowed_by: BorrowEdges(
                {},
            ),
            borrows_from: {
                RefID(
                    0,
                ),
            },
            mutable: false,
        },
    },
)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Expected behavior: a borrow-checking diagnostic error, not an ICE.

Git commit: fc75182
Build: release
cargo 1.91.0-nightly (840b83a10 2025-07-30)
rustc 1.91.0-nightly (3672a55b7 2025-08-13)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions