Skip to content

Missing drop in FnOnce adapter for closures #29946

Closed
@eefriedman

Description

@eefriedman
struct Foo(i32);
impl Foo {
    pub fn dowork(&self) {
        println!("foo: doing work {}", self.0);
    }
}

impl Drop for Foo {
    fn drop(&mut self) {
        println!("foo: drop {}", self.0);
    }
}

fn f<T: FnOnce()>(t: T) {
    t()
}

fn main() {
    let x = Foo(1);
    let x = move || x.dowork();
    f(x);
}

playpen

Somehow, the Foo object leaks: my guess is that it has something to do with the way we generate code for the FnOnce() trait for closures which also implement Fn().

Originally reported at #28796 (comment) .

Metadata

Metadata

Assignees

Labels

A-destructorsArea: Destructors (`Drop`, …)P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions