Skip to content

Values moved into run closure not having drop called #1058

@KeyMaster-

Description

@KeyMaster-

It appears that values moved into the closure provided to run don't get drop called when the event loop terminates
The example below shows a minimal example. The droppable is moved into the closure and used, but when I close the window, I don't see a "Dropping." message being printed indicating that the value has been dropped as the program terminates.
In contrast, the scope at the start of main shows that in a usual scope, drop gets called correctly.

I may be misunderstanding some of the expected behaviour of drop though, if so I'd appreciate a clarification on this.

Example: (tested on winit 0.20.0-alpha2, MacOS 10.14.4)

use winit::{
  event::{Event, WindowEvent},
  event_loop::{ControlFlow, EventLoop},
  window::WindowBuilder
};

struct Droppable {
  x: i32
}

impl Drop for Droppable {
  fn drop(&mut self) {
    println!("Dropping.");
  }
}

fn main() {
  {
    let _test_droppable = Droppable { x: 7 };
  }

  let event_loop = EventLoop::new();
  let _window = WindowBuilder::new().build(&event_loop).unwrap();

  let droppable = Droppable {
    x: 7
  };

  event_loop.run(move |event, _, control_flow| {
    println!("x is {}", droppable.x);
    match event {
      Event::WindowEvent  {
        event: WindowEvent::CloseRequested,
        ..
      } => *control_flow = ControlFlow::Exit,
      _ => *control_flow = ControlFlow::Wait,
    }
  });
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    B - bugDang, that shouldn't have happenedC - needs investigationIssue must be confirmed and researchedDS - appkitAffects the AppKit/macOS backendH - good first issueIdeal for new contributors

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions