Skip to content

An owned str temporary interpolated in an f-string leaks: f"{t.slice(0, 2)}" #1390

Closed

Description

@ehartford

Found during #1363 (fixture authoring).

fn check(t: &str):
    print(f"{t.slice(0, 2)}")
fn main:
    let s = "abc" ++ "def"
    check(&s)

with run --debug-alloc (installed v0.15.2.1 and origin/main 8c859a7): prints ab, then debug-alloc: leak count=1.
Binding first (let h = t.slice(0, 2) then f"{h}") is leak count=0.

Expected: the interpolated call result is a statement temporary and is dropped after the f-string is built.

Activity

  1. ehartford commented on Sep 23, 2026

    @ehartford
    ContributorAuthor

    Same leak through the eliminators, on origin/main 5848ae9 (stage1 built from it), run --debug-alloc:

    fn plain_opt -> Option[str]: Some("hi".clone() ++ "!")
    fn none_opt -> Option[str]: None
    fn main: print(f"{plain_opt() ?? "none".clone()}")
    
    spelling verdict
    f"{plain_opt() ?? "none".clone()}" leak count=1
    f"{plain_opt() ?? "none"}" leak count=1
    f"{none_opt() ?? "none".clone()}" leak count=1
    f"{plain_opt().unwrap_or("none".clone())}" leak count=1
    let x = plain_opt() ?? "none".clone() then f"{x}" leak count=0
    print(plain_opt() ?? "none".clone()) leak count=0
    f"{plain()}" with fn plain -> str leak count=0

    The owned result of a ??/unwrap_or join interpolated directly is never dropped. Found while writing the D60 debug-alloc fixture (test/debug_alloc/da_d60_tail_assignment_moves.w binds the joined value first).

  2. ehartford commented on Sep 23, 2026

    @ehartford
    ContributorAuthor

    Also through .await (origin/main 5848ae9 stage1, run --debug-alloc):

    async fn name -> str:
        var s = "hi".clone() ++ "!"
        s
    fn main: print(f"{name().await}")
    

    prints hi!, leak count=1. let v = name().await then print(v) is leak count=0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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