Skip to content

Commit 4072f44

Browse files
Make borrowck tail_expr_drop_order message more uniform
1 parent 6a9b44c commit 4072f44

7 files changed

+33
-23
lines changed

compiler/rustc_borrowck/messages.ftl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,10 @@ borrowck_suggest_create_fresh_reborrow =
213213
borrowck_suggest_iterate_over_slice =
214214
consider iterating over a slice of the `{$ty}`'s content to avoid moving into the `for` loop
215215
216-
borrowck_tail_expr_drop_order = a temporary value will be dropped here before the execution exits the block in Edition 2024, which will raise borrow checking error
217-
.label = consider using a `let` binding to create a longer lived value; or replacing the `{"{"} .. {"}"}` block with curly brackets `( .. )`; or folding the rest of the expression into the surrounding `unsafe {"{"} .. {"}"}`
216+
borrowck_tail_expr_drop_order = relative drop order changing in Rust 2024
217+
.label = this temporary value will be dropped at the end of the block
218+
.observer = however, the value is required to be live when it is used later
219+
.note = consider using a `let` binding to ensure the value will live long enough
218220
219221
borrowck_ty_no_impl_copy =
220222
{$is_partial_move ->

compiler/rustc_borrowck/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,8 +1198,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
11981198
this.infcx.tcx.emit_node_span_lint(
11991199
TAIL_EXPR_DROP_ORDER,
12001200
CRATE_HIR_ID,
1201-
place_span,
1202-
session_diagnostics::TailExprDropOrder { borrowed },
1201+
borrowed,
1202+
session_diagnostics::TailExprDropOrder { borrowed, observer: place_span },
12031203
);
12041204
// We may stop at the first case
12051205
Control::Break

compiler/rustc_borrowck/src/session_diagnostics.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,4 +486,6 @@ pub(crate) struct SimdIntrinsicArgConst {
486486
pub(crate) struct TailExprDropOrder {
487487
#[label]
488488
pub borrowed: Span,
489+
#[label(borrowck_observer)]
490+
pub observer: Span,
489491
}

tests/mir-opt/tail_expr_drop_order_unwind.method_1.ElaborateDrops.after.panic-abort.mir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ fn method_1(_1: Guard) -> () {
7474

7575
bb7: {
7676
backward incompatible drop(_2);
77+
backward incompatible drop(_4);
7778
backward incompatible drop(_5);
7879
goto -> bb21;
7980
}

tests/mir-opt/tail_expr_drop_order_unwind.method_1.ElaborateDrops.after.panic-unwind.mir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ fn method_1(_1: Guard) -> () {
7474

7575
bb7: {
7676
backward incompatible drop(_2);
77+
backward incompatible drop(_4);
7778
backward incompatible drop(_5);
7879
goto -> bb21;
7980
}

tests/ui/drop/lint-tail-expr-drop-order-borrowck.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@
77

88
fn should_lint_with_potential_borrowck_err() {
99
let _ = { String::new().as_str() }.len();
10-
//~^ ERROR: a temporary value will be dropped here
10+
//~^ ERROR: relative drop order changing
1111
//~| WARN: this changes meaning in Rust 2024
12-
//~| NOTE: consider using a `let` binding
12+
//~| NOTE: this temporary value will be dropped at the end of the block
13+
//~| however, the value is required to be live
1314
//~| NOTE: for more information, see
1415
}
1516

1617
fn should_lint_with_unsafe_block() {
1718
fn f(_: usize) {}
1819
f(unsafe { String::new().as_str() }.len());
19-
//~^ ERROR: a temporary value will be dropped here
20+
//~^ ERROR: relative drop order changing
2021
//~| WARN: this changes meaning in Rust 2024
21-
//~| NOTE: consider using a `let` binding
22+
//~| NOTE: this temporary value will be dropped at the end of the block
23+
//~| however, the value is required to be live
2224
//~| NOTE: for more information, see
2325
}
2426

@@ -27,9 +29,10 @@ fn should_lint_with_big_block() {
2729
fn f<T>(_: T) {}
2830
f({
2931
&mut || 0
30-
//~^ ERROR: a temporary value will be dropped here
32+
//~^ ERROR: relative drop order changing
3133
//~| WARN: this changes meaning in Rust 2024
32-
//~| NOTE: consider using a `let` binding
34+
//~| NOTE: this temporary value will be dropped at the end of the block
35+
//~| however, the value is required to be live
3336
//~| NOTE: for more information, see
3437
})
3538
}

tests/ui/drop/lint-tail-expr-drop-order-borrowck.stderr

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error: a temporary value will be dropped here before the execution exits the block in Edition 2024, which will raise borrow checking error
2-
--> $DIR/lint-tail-expr-drop-order-borrowck.rs:9:36
1+
error: relative drop order changing in Rust 2024
2+
--> $DIR/lint-tail-expr-drop-order-borrowck.rs:9:15
33
|
44
LL | let _ = { String::new().as_str() }.len();
5-
| ------------- ^
5+
| ^^^^^^^^^^^^^ - however, the value is required to be live when it is used later
66
| |
7-
| consider using a `let` binding to create a longer lived value; or replacing the `{ .. }` block with curly brackets `( .. )`; or folding the rest of the expression into the surrounding `unsafe { .. }`
7+
| this temporary value will be dropped at the end of the block
88
|
99
= warning: this changes meaning in Rust 2024
1010
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-tail-expr-scope.html>
@@ -14,24 +14,25 @@ note: the lint level is defined here
1414
LL | #![deny(tail_expr_drop_order)]
1515
| ^^^^^^^^^^^^^^^^^^^^
1616

17-
error: a temporary value will be dropped here before the execution exits the block in Edition 2024, which will raise borrow checking error
18-
--> $DIR/lint-tail-expr-drop-order-borrowck.rs:18:37
17+
error: relative drop order changing in Rust 2024
18+
--> $DIR/lint-tail-expr-drop-order-borrowck.rs:19:16
1919
|
2020
LL | f(unsafe { String::new().as_str() }.len());
21-
| ------------- ^
21+
| ^^^^^^^^^^^^^ - however, the value is required to be live when it is used later
2222
| |
23-
| consider using a `let` binding to create a longer lived value; or replacing the `{ .. }` block with curly brackets `( .. )`; or folding the rest of the expression into the surrounding `unsafe { .. }`
23+
| this temporary value will be dropped at the end of the block
2424
|
2525
= warning: this changes meaning in Rust 2024
2626
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-tail-expr-scope.html>
2727

28-
error: a temporary value will be dropped here before the execution exits the block in Edition 2024, which will raise borrow checking error
29-
--> $DIR/lint-tail-expr-drop-order-borrowck.rs:29:17
28+
error: relative drop order changing in Rust 2024
29+
--> $DIR/lint-tail-expr-drop-order-borrowck.rs:31:9
3030
|
3131
LL | &mut || 0
32-
| --------^
33-
| |
34-
| consider using a `let` binding to create a longer lived value; or replacing the `{ .. }` block with curly brackets `( .. )`; or folding the rest of the expression into the surrounding `unsafe { .. }`
32+
| ^^^^^^^^-
33+
| | |
34+
| | however, the value is required to be live when it is used later
35+
| this temporary value will be dropped at the end of the block
3536
|
3637
= warning: this changes meaning in Rust 2024
3738
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-tail-expr-scope.html>

0 commit comments

Comments
 (0)