Skip to content

Commit 1d32a52

Browse files
fine-tune the drop span and messages
1 parent cff8c01 commit 1d32a52

File tree

4 files changed

+134
-174
lines changed

4 files changed

+134
-174
lines changed

compiler/rustc_mir_transform/messages.ftl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ mir_transform_must_not_suspend = {$pre}`{$def_path}`{$post} held across a suspen
2626
mir_transform_operation_will_panic = this operation will panic at runtime
2727
2828
mir_transform_tail_expr_drop_order = relative drop order changing in Rust 2024
29-
.temporaries = in Rust 2024, this temporary will be dropped first
29+
.temporaries = in Rust 2024, this temporary value will be dropped first
3030
.observers = in Rust 2024, this local variable or temporary value will be dropped second
3131
.note_dtors =
32-
dropping the temporary runs this custom `Drop` impl, which will run first in Rust 2024
32+
dropping the temporary value runs this custom `Drop` impl, which will run first in Rust 2024
3333
.note_observer_dtors =
3434
dropping the local runs this custom `Drop` impl, which will run second in Rust 2024
3535
.drop_location =
36-
temporary will be dropped on exiting the block, before the block's local variables
36+
now the temporary value is dropped here, before the local variables in the block or statement
3737
.note_epilogue = most of the time, changing drop order is harmless; inspect the `impl Drop`s for side effects
3838
.label_local_epilogue = {$is_dropped_first_edition_2024 ->
3939
[true] up until Edition 2021 `{$name}` is dropped last but will be dropped earlier in Edition 2024

compiler/rustc_mir_transform/src/lint_tail_expr_drop_order.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ impl<'a, 'mir, 'tcx> DropsReachable<'a, 'mir, 'tcx> {
129129
if self.drop_span.is_none() {
130130
// FIXME(@dingxiangfei2009): it turns out that `self.body.source_scopes` are still a bit wonky.
131131
// There is a high chance that this span still points to a block rather than a statement semicolon.
132-
*self.drop_span =
133-
Some(self.body.source_scopes[terminator.source_info.scope].span);
132+
*self.drop_span = Some(terminator.source_info.span);
134133
}
135134
// Now we have discovered a simple control flow path from a future drop point
136135
// to the current drop point.

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ impl LoudDropper {
3535
}
3636

3737
fn should_lint() -> i32 {
38-
//~^ NOTE: temporary will be dropped on exiting the block, before the block's local variables
3938
let x = LoudDropper;
4039
//~^ NOTE: `x` calls a custom destructor
4140
//~| NOTE: `x` will be dropped later since Edition 2024
@@ -48,6 +47,7 @@ fn should_lint() -> i32 {
4847
//~| NOTE: most of the time, changing drop order is harmless; inspect the `impl Drop`s for side effects
4948
//~| NOTE: for more information, see issue #123739
5049
}
50+
//~^ NOTE: now the temporary value is dropped here, before the local variables in the block or statement
5151

5252
fn should_not_lint_closure() -> impl FnOnce() -> i32 {
5353
let x = LoudDropper;
@@ -60,7 +60,6 @@ fn should_not_lint_closure() -> impl FnOnce() -> i32 {
6060

6161
fn should_lint_in_nested_items() {
6262
fn should_lint_me() -> i32 {
63-
//~^ NOTE: temporary will be dropped on exiting the block, before the block's local variables
6463
let x = LoudDropper;
6564
//~^ NOTE: `x` calls a custom destructor
6665
//~| NOTE: `x` will be dropped later since Edition 2024
@@ -73,6 +72,7 @@ fn should_lint_in_nested_items() {
7372
//~| NOTE: most of the time, changing drop order is harmless; inspect the `impl Drop`s for side effects
7473
//~| NOTE: for more information, see issue #123739
7574
}
75+
//~^ NOTE: now the temporary value is dropped here, before the local variables in the block or statement
7676
}
7777

7878
fn should_not_lint_params(x: LoudDropper) -> i32 {
@@ -88,7 +88,6 @@ fn should_not_lint() -> i32 {
8888
}
8989

9090
fn should_lint_in_nested_block() -> i32 {
91-
//~^ NOTE: temporary will be dropped on exiting the block, before the block's local variables
9291
let x = LoudDropper;
9392
//~^ NOTE: `x` calls a custom destructor
9493
//~| NOTE: `x` will be dropped later since Edition 2024
@@ -100,6 +99,7 @@ fn should_lint_in_nested_block() -> i32 {
10099
//~| NOTE: most of the time, changing drop order is harmless; inspect the `impl Drop`s for side effects
101100
//~| NOTE: for more information, see issue #123739
102101
}
102+
//~^ NOTE: now the temporary value is dropped here, before the local variables in the block or statement
103103

104104
fn should_not_lint_in_match_arm() -> i32 {
105105
let x = LoudDropper;
@@ -134,7 +134,6 @@ fn should_not_lint_when_moved() -> i32 {
134134
}
135135

136136
fn should_lint_into_async_body() -> i32 {
137-
//~^ NOTE: temporary will be dropped on exiting the block, before the block's local variables
138137
async fn f() {
139138
async fn f() {}
140139
let x = LoudDropper;
@@ -153,9 +152,9 @@ fn should_lint_into_async_body() -> i32 {
153152
//~| NOTE: most of the time, changing drop order is harmless; inspect the `impl Drop`s for side effects
154153
//~| NOTE: for more information, see issue #123739
155154
}
155+
//~^ NOTE: now the temporary value is dropped here, before the local variables in the block or statement
156156

157157
fn should_lint_generics<T: Default>() -> &'static str {
158-
//~^ NOTE: temporary will be dropped on exiting the block, before the block's local variables
159158
fn extract<T>(_: &T) -> &'static str {
160159
todo!()
161160
}
@@ -170,9 +169,9 @@ fn should_lint_generics<T: Default>() -> &'static str {
170169
//~| NOTE: most of the time, changing drop order is harmless; inspect the `impl Drop`s for side effects
171170
//~| NOTE: for more information, see issue #123739
172171
}
172+
//~^ NOTE: now the temporary value is dropped here, before the local variables in the block or statement
173173

174174
fn should_lint_adt() -> i32 {
175-
//~^ NOTE: temporary will be dropped on exiting the block, before the block's local variables
176175
let x: Result<LoudDropper, ()> = Ok(LoudDropper);
177176
//~^ NOTE: `x` calls a custom destructor
178177
//~| NOTE: `x` will be dropped later since Edition 2024
@@ -184,14 +183,14 @@ fn should_lint_adt() -> i32 {
184183
//~| NOTE: most of the time, changing drop order is harmless; inspect the `impl Drop`s for side effects
185184
//~| NOTE: for more information, see issue #123739
186185
}
186+
//~^ NOTE: now the temporary value is dropped here, before the local variables in the block or statement
187187

188188
fn should_not_lint_insign_dtor() -> i32 {
189189
let x = String::new();
190190
LoudDropper.get()
191191
}
192192

193193
fn should_lint_with_dtor_span() -> i32 {
194-
//~^ NOTE: temporary will be dropped on exiting the block, before the block's local variables
195194
struct LoudDropper3;
196195
impl Drop for LoudDropper3 {
197196
//~^ NOTE: `#1` invokes this custom destructor
@@ -228,9 +227,9 @@ fn should_lint_with_dtor_span() -> i32 {
228227
//~| NOTE: most of the time, changing drop order is harmless; inspect the `impl Drop`s for side effects
229228
//~| NOTE: for more information, see issue #123739
230229
}
230+
//~^ NOTE: now the temporary value is dropped here, before the local variables in the block or statement
231231

232232
fn should_lint_with_transient_drops() {
233-
//~^ NOTE: temporary will be dropped on exiting the block, before the block's local variables
234233
drop((
235234
{
236235
LoudDropper.get()
@@ -247,6 +246,7 @@ fn should_lint_with_transient_drops() {
247246
//~| NOTE: `_x` will be dropped later since Edition 2024
248247
},
249248
));
249+
//~^ NOTE: now the temporary value is dropped here, before the local variables in the block or statement
250250
}
251251

252252
fn main() {}

0 commit comments

Comments
 (0)