about summary refs log tree commit diff
path: root/tests/ui/nll/nested-bodies-in-dead-code.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/nll/nested-bodies-in-dead-code.rs')
-rw-r--r--tests/ui/nll/nested-bodies-in-dead-code.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/ui/nll/nested-bodies-in-dead-code.rs b/tests/ui/nll/nested-bodies-in-dead-code.rs
new file mode 100644
index 00000000000..6ac68f5adbc
--- /dev/null
+++ b/tests/ui/nll/nested-bodies-in-dead-code.rs
@@ -0,0 +1,28 @@
+//@ edition: 2024
+
+// Regression test for #140583. We want to borrowck nested
+// bodies even if they are in dead code. While not necessary for
+// soundness, it is desirable to error in such cases.
+
+fn main() {
+    return;
+    |x: &str| -> &'static str { x };
+    //~^ ERROR lifetime may not live long enough
+    || {
+        || {
+            let temp = 1;
+            let p: &'static u32 = &temp;
+            //~^ ERROR `temp` does not live long enough
+        };
+    };
+    const {
+        let temp = 1;
+        let p: &'static u32 = &temp;
+        //~^ ERROR `temp` does not live long enough
+    };
+    async {
+        let temp = 1;
+        let p: &'static u32 = &temp;
+        //~^ ERROR `temp` does not live long enough
+    };
+}