Skip to content

Comprehensions: f-string element leaks, HashMap[str, _] comprehension double-frees, ? over a Vec clause fails MIR lowering #1736

Closed

Description

@ehartford

Spec: §13.6 (comprehensions), §2.5 (drop exactly once).

Three comprehension memory/lowering bugs, all reproducible on main's installed compiler and on gen-push-impl (none involve generators):

  1. An f-string element leaks:
fn main:
    let a = [f"a{i}" for i in 0..3]
    print(a.len())

with run --debug-alloc → leak count=2 (two 16-byte blocks, origin unknown).

  1. A HashMap comprehension with str keys double-frees:
use std.collections.{HashMap}
fn main:
    let hm: HashMap[str, i32] = [f"k{i}": i for i in 0..3]
    print(hm.len())

→ DOUBLE FREE … first_drop=drop#struct __drop_struct_16 second_drop=drop#struct __drop_struct_….

  1. ? in the element of a comprehension over a Vec does not lower:
fn check(w: &str) -> Result[str, str]:
    if w == "w2": return Err(w.clone())
    Ok(w ++ "!")
fn all_checked(ws: &Vec[str]) -> Result[Vec[str], str]:
    let v = [check(w)? for w in ws]
    Ok(v)

→ "MIR lowering failed for function 'all_checked'" (WITH_MIR_AUDIT: [mir-lower-fail] kind=64 at the element). The same ? over a range or a generator clause works (the early-exit leak of the collection itself is fixed in 63d6807 on gen-push-fixes).

Expected: leak count 0, no double free, and the Vec clause lowers like the range clause.

Metadata

Metadata

Assignees

No one assigned

    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