diff options
| author | Michael Goulet <michael@errs.io> | 2024-12-20 17:47:53 +0000 |
|---|---|---|
| committer | Josh Stone <jistone@redhat.com> | 2025-01-02 14:28:32 -0800 |
| commit | 730b84074daddf85905b70f6df9ce438b02cdedc (patch) | |
| tree | ee07ee380f85a4f6f839d236112415075e2ccbaa /tests | |
| parent | f757f962962ce4ce2a004a6b32c7ec33996b5121 (diff) | |
| download | rust-730b84074daddf85905b70f6df9ce438b02cdedc.tar.gz rust-730b84074daddf85905b70f6df9ce438b02cdedc.zip | |
Handle DropKind::ForLint in coroutines correctly
(cherry picked from commit 42d1a4c48bd2c914f30fc6e97f9a1beda0c97729)
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/drop/tail_expr_drop_order-on-coroutine-unwind.rs | 29 | ||||
| -rw-r--r-- | tests/ui/drop/tail_expr_drop_order-on-coroutine-unwind.stderr | 52 |
2 files changed, 81 insertions, 0 deletions
diff --git a/tests/ui/drop/tail_expr_drop_order-on-coroutine-unwind.rs b/tests/ui/drop/tail_expr_drop_order-on-coroutine-unwind.rs new file mode 100644 index 00000000000..8d85cee19fd --- /dev/null +++ b/tests/ui/drop/tail_expr_drop_order-on-coroutine-unwind.rs @@ -0,0 +1,29 @@ +//@ edition: 2021 +//@ build-fail + +// Make sure we don't ICE when emitting the "lint" drop statement +// used for tail_expr_drop_order. + +#![deny(tail_expr_drop_order)] + +struct Drop; +impl std::ops::Drop for Drop { + fn drop(&mut self) {} +} + +async fn func() -> Result<(), Drop> { + todo!() +} + +async fn retry_db() -> Result<(), Drop> { + loop { + match func().await { + //~^ ERROR relative drop order changing in Rust 2024 + //~| WARNING this changes meaning in Rust 2024 + Ok(()) => return Ok(()), + Err(e) => {} + } + } +} + +fn main() {} diff --git a/tests/ui/drop/tail_expr_drop_order-on-coroutine-unwind.stderr b/tests/ui/drop/tail_expr_drop_order-on-coroutine-unwind.stderr new file mode 100644 index 00000000000..37220c40b8b --- /dev/null +++ b/tests/ui/drop/tail_expr_drop_order-on-coroutine-unwind.stderr @@ -0,0 +1,52 @@ +error: relative drop order changing in Rust 2024 + --> $DIR/tail_expr_drop_order-on-coroutine-unwind.rs:20:15 + | +LL | match func().await { + | ^^^^^^^----- + | | | + | | this value will be stored in a temporary; let us call it `#1` + | | `#1` will be dropped later as of Edition 2024 + | this value will be stored in a temporary; let us call it `#2` + | up until Edition 2021 `#2` is dropped last but will be dropped earlier in Edition 2024 +... +LL | Err(e) => {} + | - + | | + | `e` calls a custom destructor + | `e` will be dropped later as of Edition 2024 +LL | } +LL | } + | - now the temporary value is dropped here, before the local variables in the block or statement + | + = warning: this changes meaning in Rust 2024 + = note: for more information, see issue #123739 <https://github.com/rust-lang/rust/issues/123739> +note: `#2` invokes this custom destructor + --> $DIR/tail_expr_drop_order-on-coroutine-unwind.rs:10:1 + | +LL | / impl std::ops::Drop for Drop { +LL | | fn drop(&mut self) {} +LL | | } + | |_^ +note: `#1` invokes this custom destructor + --> $DIR/tail_expr_drop_order-on-coroutine-unwind.rs:10:1 + | +LL | / impl std::ops::Drop for Drop { +LL | | fn drop(&mut self) {} +LL | | } + | |_^ +note: `e` invokes this custom destructor + --> $DIR/tail_expr_drop_order-on-coroutine-unwind.rs:10:1 + | +LL | / impl std::ops::Drop for Drop { +LL | | fn drop(&mut self) {} +LL | | } + | |_^ + = note: most of the time, changing drop order is harmless; inspect the `impl Drop`s for side effects like releasing locks or sending messages +note: the lint level is defined here + --> $DIR/tail_expr_drop_order-on-coroutine-unwind.rs:7:9 + | +LL | #![deny(tail_expr_drop_order)] + | ^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + |
