about summary refs log tree commit diff
path: root/tests/ui/drop
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2025-01-06 03:25:45 +0000
committerMichael Goulet <michael@errs.io>2025-01-08 16:02:44 +0000
commitc55eefe8bc51f302cfc89d375198ca7211d4709b (patch)
tree40024a316d1007e00dd46abd862919d604cc563d /tests/ui/drop
parent4a099b29cdb6a7841019406f0f2b5035a1fd9a08 (diff)
downloadrust-c55eefe8bc51f302cfc89d375198ca7211d4709b.tar.gz
rust-c55eefe8bc51f302cfc89d375198ca7211d4709b.zip
Try to explain borrow for tail expr temporary drop order change in 2024
Diffstat (limited to 'tests/ui/drop')
-rw-r--r--tests/ui/drop/lint-tail-expr-drop-order-borrowck.rs26
-rw-r--r--tests/ui/drop/lint-tail-expr-drop-order-borrowck.stderr38
2 files changed, 45 insertions, 19 deletions
diff --git a/tests/ui/drop/lint-tail-expr-drop-order-borrowck.rs b/tests/ui/drop/lint-tail-expr-drop-order-borrowck.rs
index 1bd5655d7fe..6f64d83f8a0 100644
--- a/tests/ui/drop/lint-tail-expr-drop-order-borrowck.rs
+++ b/tests/ui/drop/lint-tail-expr-drop-order-borrowck.rs
@@ -7,18 +7,20 @@
 
 fn should_lint_with_potential_borrowck_err() {
     let _ = { String::new().as_str() }.len();
-    //~^ ERROR: a temporary value will be dropped here
+    //~^ ERROR: relative drop order changing
     //~| WARN: this changes meaning in Rust 2024
-    //~| NOTE: consider using a `let` binding
+    //~| NOTE: this temporary value will be dropped at the end of the block
+    //~| borrow later used by call
     //~| NOTE: for more information, see
 }
 
 fn should_lint_with_unsafe_block() {
     fn f(_: usize) {}
     f(unsafe { String::new().as_str() }.len());
-    //~^ ERROR: a temporary value will be dropped here
+    //~^ ERROR: relative drop order changing
     //~| WARN: this changes meaning in Rust 2024
-    //~| NOTE: consider using a `let` binding
+    //~| NOTE: this temporary value will be dropped at the end of the block
+    //~| borrow later used by call
     //~| NOTE: for more information, see
 }
 
@@ -27,11 +29,23 @@ fn should_lint_with_big_block() {
     fn f<T>(_: T) {}
     f({
         &mut || 0
-        //~^ ERROR: a temporary value will be dropped here
+        //~^ ERROR: relative drop order changing
         //~| WARN: this changes meaning in Rust 2024
-        //~| NOTE: consider using a `let` binding
+        //~| NOTE: this temporary value will be dropped at the end of the block
+        //~| borrow later used here
         //~| NOTE: for more information, see
     })
 }
 
+fn another_temp_that_is_copy_in_arg() {
+    fn f() {}
+    fn g(_: &()) {}
+    g({ &f() });
+    //~^ ERROR: relative drop order changing
+    //~| WARN: this changes meaning in Rust 2024
+    //~| NOTE: this temporary value will be dropped at the end of the block
+    //~| borrow later used by call
+    //~| NOTE: for more information, see
+}
+
 fn main() {}
diff --git a/tests/ui/drop/lint-tail-expr-drop-order-borrowck.stderr b/tests/ui/drop/lint-tail-expr-drop-order-borrowck.stderr
index 98ef0547c90..a55e366dd0b 100644
--- a/tests/ui/drop/lint-tail-expr-drop-order-borrowck.stderr
+++ b/tests/ui/drop/lint-tail-expr-drop-order-borrowck.stderr
@@ -1,10 +1,10 @@
-error: a temporary value will be dropped here before the execution exits the block in Edition 2024, which will raise borrow checking error
-  --> $DIR/lint-tail-expr-drop-order-borrowck.rs:9:36
+error: relative drop order changing in Rust 2024
+  --> $DIR/lint-tail-expr-drop-order-borrowck.rs:9:15
    |
 LL |     let _ = { String::new().as_str() }.len();
-   |               -------------        ^
+   |               ^^^^^^^^^^^^^            --- borrow later used by call
    |               |
-   |               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 { .. }`
+   |               this temporary value will be dropped at the end of the block
    |
    = warning: this changes meaning in Rust 2024
    = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-tail-expr-scope.html>
@@ -14,27 +14,39 @@ note: the lint level is defined here
 LL | #![deny(tail_expr_drop_order)]
    |         ^^^^^^^^^^^^^^^^^^^^
 
-error: a temporary value will be dropped here before the execution exits the block in Edition 2024, which will raise borrow checking error
-  --> $DIR/lint-tail-expr-drop-order-borrowck.rs:18:37
+error: relative drop order changing in Rust 2024
+  --> $DIR/lint-tail-expr-drop-order-borrowck.rs:19:16
    |
 LL |     f(unsafe { String::new().as_str() }.len());
-   |                -------------        ^
+   |                ^^^^^^^^^^^^^            --- borrow later used by call
    |                |
-   |                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 { .. }`
+   |                this temporary value will be dropped at the end of the block
    |
    = warning: this changes meaning in Rust 2024
    = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-tail-expr-scope.html>
 
-error: a temporary value will be dropped here before the execution exits the block in Edition 2024, which will raise borrow checking error
-  --> $DIR/lint-tail-expr-drop-order-borrowck.rs:29:17
+error: relative drop order changing in Rust 2024
+  --> $DIR/lint-tail-expr-drop-order-borrowck.rs:31:9
    |
 LL |         &mut || 0
-   |         --------^
+   |         ^^^^^^^^^
    |         |
-   |         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 { .. }`
+   |         this temporary value will be dropped at the end of the block
+   |         borrow later used here
    |
    = warning: this changes meaning in Rust 2024
    = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-tail-expr-scope.html>
 
-error: aborting due to 3 previous errors
+error: relative drop order changing in Rust 2024
+  --> $DIR/lint-tail-expr-drop-order-borrowck.rs:43:9
+   |
+LL |     g({ &f() });
+   |     -   ^^^^ this temporary value will be dropped at the end of the block
+   |     |
+   |     borrow later used by call
+   |
+   = warning: this changes meaning in Rust 2024
+   = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-tail-expr-scope.html>
+
+error: aborting due to 4 previous errors