Shouldn't disjoint capture issue warning when done over types implementing Drop?

Hello!

Just stumbled upon disjoint capture: Rust Playground produces

4
0
1
The answer is 42
2
3
5

on 2021 edition, while 2015 and 2018 produce

4
0
1
2
3
5

I understand why this optimization was introduced. But. Shouldn't it produce warning? Cases like Send, Sync etc. can be tracked by compiler. But moving drop execution point simply breaks code in certain cases. At runtime.

UPDATE: If you replace u32 with any non-copy type like string, it works just as expected: Rust Playground . Looks like footgun to me.

Thanks

2 Likes

Could be a hole in the rust_2021_incompatible_closure_captures, or at least, I couldn't get that lint to fire.

Perhaps related to this:

3 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.