Dropping with arguments ("higher RAII")

I agree with your conclusion, this is just not happening. This is the kind of thing that even though it's not a breaking change, it's so disruptive that we'd have to add it to the Rust 2.0 breakage whishlist.

It's a fair trade-off.

We already have control-flow checks all around the compiler for lifetimes and other stuff, I'm sure we can (ab)use that to add checks to control-flow statements for HigherDrop types.

In Rust, types are not expected to always be dropped, they must be safe to forget; this would include HigherDrop types. For panics, it might be sensible to add an uncallable function (like Drop::drop()) to HigherDrop that doesn't require arguments and takes by mutable reference. When it comes to .await points, correct me if I'm wrong, but when you drop a Future that has not been driven to completion, the data it holds is forgotten, not dropped (playground); it is up to manual Future implementations to do so. Thus, I don't get why .await points would be a problem.

The data of Futures is dropped. The async function in your playground example is just never polled, so it never executes and never constructs a Foo.

If you give it a Foo as an argument or hold the local variable over an await point and then only poll it once, then you'll see the "Dropped!" message.

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.