diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:03 +0000 |
commit | 64d98f8ee037282c35007b64c2649055c56af1db (patch) | |
tree | 5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /tests/ui/span/issue-23338-locals-die-before-temps-of-body.rs | |
parent | Adding debian version 1.67.1+dfsg1-1. (diff) | |
download | rustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip |
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/span/issue-23338-locals-die-before-temps-of-body.rs')
-rw-r--r-- | tests/ui/span/issue-23338-locals-die-before-temps-of-body.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/ui/span/issue-23338-locals-die-before-temps-of-body.rs b/tests/ui/span/issue-23338-locals-die-before-temps-of-body.rs new file mode 100644 index 000000000..a92ea4ddc --- /dev/null +++ b/tests/ui/span/issue-23338-locals-die-before-temps-of-body.rs @@ -0,0 +1,28 @@ +// This is just checking that we still reject code where temp values +// are borrowing values for longer than they will be around. +// +// Compare to run-pass/issue-23338-params-outlive-temps-of-body.rs + +use std::cell::RefCell; + +fn foo(x: RefCell<String>) -> String { + let y = x; + y.borrow().clone() +} +//~^^ ERROR `y` does not live long enough + +fn foo2(x: RefCell<String>) -> String { + let ret = { + let y = x; + y.borrow().clone() + }; + //~^^ ERROR `y` does not live long enough + ret +} + +fn main() { + let r = RefCell::new(format!("data")); + assert_eq!(foo(r), "data"); + let r = RefCell::new(format!("data")); + assert_eq!(foo2(r), "data"); +} |