Skip to content

missing rust_2021_incompatible_closure_captures with manual drop and move closure #88476

Closed

Description

I tried this code:

#![warn(rust_2021_incompatible_closure_captures)]
#![allow(unused)]
use std::rc::Rc;

struct Foo(Rc<i32>);

impl Drop for Foo {
    fn drop(self: &mut Foo) {}
}

pub fn foo() {
    let f = Foo(Rc::new(1));
    let x = move || {
        println!("{:?}", f.0);
    };
}

This does not issue a warning for rust_2021_incompatible_closure_captures, however it fails to compile with capture_disjoint_fields enabled:

error[E0509]: cannot move out of type `Foo`, which implements the `Drop` trait
  --> src/lib.rs:13:13
   |
13 |     let x = move || {
   |             ^^^^^^^
   |             |
   |             cannot move out of here
   |             move out of `f.0` occurs here
14 |         println!("{:?}", f.0);
   |                          ---
   |                          |
   |                          move occurs because `f.0` has type `Rc<i32>`, which does not implement the `Copy` trait
   |                          move occurs due to use in closure

I would expect rust_2021_incompatible_closure_captures to give a suggestion to add let _ = &f.

Found in the 2021 crater run for:

I'm uncertain if this is a duplicate of #88444 or #88114, they seem very similar, but this case is specific to implementing Drop.

Meta

rustc --version --verbose:

rustc 1.56.0-nightly (5eacec9ec 2021-08-28)
binary: rustc
commit-hash: 5eacec9ec7e112a0de1011519a57c45586d58414
commit-date: 2021-08-28
host: x86_64-apple-darwin
release: 1.56.0-nightly
LLVM version: 13.0.0

cc @rust-lang/wg-rfc-2229

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

Metadata

Assignees

Labels

A-closuresArea: Closures (`|…| { … }`)A-diagnosticsArea: Messages for errors, warnings, and lintsA-edition-2021Area: The 2021 editionC-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