Skip to content

Commit faafbac

Browse files
authored
Unrolled build for rust-lang#134575
Rollup merge of rust-lang#134575 - compiler-errors:drop-lint-coro, r=nikomatsakis Handle `DropKind::ForLint` in coroutines correctly Fixes rust-lang#134566 Fixes rust-lang#134541
2 parents 73c278f + 42d1a4c commit faafbac

File tree

3 files changed

+91
-10
lines changed

3 files changed

+91
-10
lines changed

compiler/rustc_mir_build/src/builder/scope.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -1481,14 +1481,6 @@ fn build_scope_drops<'tcx>(
14811481
block = next;
14821482
}
14831483
DropKind::ForLint => {
1484-
// If the operand has been moved, and we are not on an unwind
1485-
// path, then don't generate the drop. (We only take this into
1486-
// account for non-unwind paths so as not to disturb the
1487-
// caching mechanism.)
1488-
if scope.moved_locals.iter().any(|&o| o == local) {
1489-
continue;
1490-
}
1491-
14921484
// As in the `DropKind::Storage` case below:
14931485
// normally lint-related drops are not emitted for unwind,
14941486
// so we can just leave `unwind_to` unmodified, but in some
@@ -1500,6 +1492,14 @@ fn build_scope_drops<'tcx>(
15001492
unwind_to = unwind_drops.drops[unwind_to].next;
15011493
}
15021494

1495+
// If the operand has been moved, and we are not on an unwind
1496+
// path, then don't generate the drop. (We only take this into
1497+
// account for non-unwind paths so as not to disturb the
1498+
// caching mechanism.)
1499+
if scope.moved_locals.iter().any(|&o| o == local) {
1500+
continue;
1501+
}
1502+
15031503
cfg.push(block, Statement {
15041504
source_info,
15051505
kind: StatementKind::BackwardIncompatibleDropHint {
@@ -1552,7 +1552,7 @@ impl<'a, 'tcx: 'a> Builder<'a, 'tcx> {
15521552
let mut unwind_indices = IndexVec::from_elem_n(unwind_target, 1);
15531553
for (drop_idx, drop_node) in drops.drops.iter_enumerated().skip(1) {
15541554
match drop_node.data.kind {
1555-
DropKind::Storage => {
1555+
DropKind::Storage | DropKind::ForLint => {
15561556
if is_coroutine {
15571557
let unwind_drop = self
15581558
.scopes
@@ -1563,7 +1563,7 @@ impl<'a, 'tcx: 'a> Builder<'a, 'tcx> {
15631563
unwind_indices.push(unwind_indices[drop_node.next]);
15641564
}
15651565
}
1566-
DropKind::Value | DropKind::ForLint => {
1566+
DropKind::Value => {
15671567
let unwind_drop = self
15681568
.scopes
15691569
.unwind_drops
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//@ edition: 2021
2+
//@ build-fail
3+
4+
// Make sure we don't ICE when emitting the "lint" drop statement
5+
// used for tail_expr_drop_order.
6+
7+
#![deny(tail_expr_drop_order)]
8+
9+
struct Drop;
10+
impl std::ops::Drop for Drop {
11+
fn drop(&mut self) {}
12+
}
13+
14+
async fn func() -> Result<(), Drop> {
15+
todo!()
16+
}
17+
18+
async fn retry_db() -> Result<(), Drop> {
19+
loop {
20+
match func().await {
21+
//~^ ERROR relative drop order changing in Rust 2024
22+
//~| WARNING this changes meaning in Rust 2024
23+
Ok(()) => return Ok(()),
24+
Err(e) => {}
25+
}
26+
}
27+
}
28+
29+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
error: relative drop order changing in Rust 2024
2+
--> $DIR/tail_expr_drop_order-on-coroutine-unwind.rs:20:15
3+
|
4+
LL | match func().await {
5+
| ^^^^^^^-----
6+
| | |
7+
| | this value will be stored in a temporary; let us call it `#1`
8+
| | `#1` will be dropped later as of Edition 2024
9+
| this value will be stored in a temporary; let us call it `#2`
10+
| up until Edition 2021 `#2` is dropped last but will be dropped earlier in Edition 2024
11+
...
12+
LL | Err(e) => {}
13+
| -
14+
| |
15+
| `e` calls a custom destructor
16+
| `e` will be dropped later as of Edition 2024
17+
LL | }
18+
LL | }
19+
| - now the temporary value is dropped here, before the local variables in the block or statement
20+
|
21+
= warning: this changes meaning in Rust 2024
22+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-tail-expr-scope.html>
23+
note: `#2` invokes this custom destructor
24+
--> $DIR/tail_expr_drop_order-on-coroutine-unwind.rs:10:1
25+
|
26+
LL | / impl std::ops::Drop for Drop {
27+
LL | | fn drop(&mut self) {}
28+
LL | | }
29+
| |_^
30+
note: `#1` invokes this custom destructor
31+
--> $DIR/tail_expr_drop_order-on-coroutine-unwind.rs:10:1
32+
|
33+
LL | / impl std::ops::Drop for Drop {
34+
LL | | fn drop(&mut self) {}
35+
LL | | }
36+
| |_^
37+
note: `e` invokes this custom destructor
38+
--> $DIR/tail_expr_drop_order-on-coroutine-unwind.rs:10:1
39+
|
40+
LL | / impl std::ops::Drop for Drop {
41+
LL | | fn drop(&mut self) {}
42+
LL | | }
43+
| |_^
44+
= note: most of the time, changing drop order is harmless; inspect the `impl Drop`s for side effects like releasing locks or sending messages
45+
note: the lint level is defined here
46+
--> $DIR/tail_expr_drop_order-on-coroutine-unwind.rs:7:9
47+
|
48+
LL | #![deny(tail_expr_drop_order)]
49+
| ^^^^^^^^^^^^^^^^^^^^
50+
51+
error: aborting due to 1 previous error
52+

0 commit comments

Comments
 (0)