Skip to content

Generators sometimes skip dropping  #45328

@arielb1

Description

@arielb1

This code prints malloc twice and free once:

#![feature(generators, generator_trait)]

use std::ops::Generator;

fn main() {
    let mut gen = || {
        (NoisyDrop::new(),
         yield,
         NoisyDrop::new(),
         yield
         );
    };
    gen.resume();
    gen.resume();
    drop(gen);
}

struct NoisyDrop;

impl NoisyDrop {
    fn new() -> Self {
        println!("malloc");
        NoisyDrop
    }
}

impl Drop for NoisyDrop {
    fn drop(&mut self) {
        println!("free");
    }
}

Metadata

Metadata

Assignees

Labels

A-coroutinesArea: CoroutinesC-bugCategory: This is a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions