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:
- https://tiny.cc/oaaiuz/reg/stakker_async_await-0.0.1/log.txt
- https://tiny.cc/oaaiuz/reg/mobc-0.7.3/log.txt
- https://tiny.cc/oaaiuz/reg/sodium-rust-2.1.1/log.txt
- https://tiny.cc/oaaiuz/reg/glommio-0.5.1/log.txt
- https://tiny.cc/oaaiuz/reg/vapix-0.1.0/log.txt
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