Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

missing rust_2021_incompatible_closure_captures with manual drop and move closure #88476

Closed
ehuss opened this issue Aug 30, 2021 · 1 comment · Fixed by #88477
Closed

missing rust_2021_incompatible_closure_captures with manual drop and move closure #88476

ehuss opened this issue Aug 30, 2021 · 1 comment · Fixed by #88477
Assignees
Labels
A-closures Area: closures (`|args| { .. }`) A-diagnostics Area: Messages for errors, warnings, and lints A-edition-2021 Area: The 2021 edition C-bug Category: This is a bug.

Comments

@ehuss
Copy link
Contributor

ehuss commented Aug 30, 2021

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

@ehuss ehuss added A-diagnostics Area: Messages for errors, warnings, and lints A-closures Area: closures (`|args| { .. }`) C-bug Category: This is a bug. A-edition-2021 Area: The 2021 edition labels Aug 30, 2021
@arora-aman
Copy link
Member

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-closures Area: closures (`|args| { .. }`) A-diagnostics Area: Messages for errors, warnings, and lints A-edition-2021 Area: The 2021 edition C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
@ehuss @arora-aman and others