about summary refs log tree commit diff
path: root/tests/ui/drop/tail-expr-drop-order-negative.rs
diff options
context:
space:
mode:
authorDing Xiang Fei <dingxiangfei2009@protonmail.ch>2024-04-12 23:24:45 +0800
committerDing Xiang Fei <dingxiangfei2009@protonmail.ch>2024-06-18 04:14:43 +0800
commit0f8c3f78825a1b6eb765b97f658b92252b55c5df (patch)
tree825b35aea3cd1ebbe53c2e9aaeec6012c30cb494 /tests/ui/drop/tail-expr-drop-order-negative.rs
parent11380368dc53d0b2fc3a627408818eff1973ce9a (diff)
downloadrust-0f8c3f78825a1b6eb765b97f658b92252b55c5df.tar.gz
rust-0f8c3f78825a1b6eb765b97f658b92252b55c5df.zip
tail expression behind terminating scope
Diffstat (limited to 'tests/ui/drop/tail-expr-drop-order-negative.rs')
-rw-r--r--tests/ui/drop/tail-expr-drop-order-negative.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/ui/drop/tail-expr-drop-order-negative.rs b/tests/ui/drop/tail-expr-drop-order-negative.rs
new file mode 100644
index 00000000000..c570b3a1ee2
--- /dev/null
+++ b/tests/ui/drop/tail-expr-drop-order-negative.rs
@@ -0,0 +1,17 @@
+//@ revisions: edition2021 edition2024
+//@ [edition2024] compile-flags: -Zunstable-options
+//@ [edition2024] edition: 2024
+//@ [edition2021] check-pass
+
+#![feature(shorter_tail_lifetimes)]
+
+fn why_would_you_do_this() -> bool {
+    let mut x = None;
+    // Make a temporary `RefCell` and put a `Ref` that borrows it in `x`.
+    x.replace(std::cell::RefCell::new(123).borrow()).is_some()
+    //[edition2024]~^ ERROR: temporary value dropped while borrowed
+}
+
+fn main() {
+    why_would_you_do_this();
+}