summaryrefslogtreecommitdiffstats
path: root/vendor/stacker/tests/simple.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /vendor/stacker/tests/simple.rs
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/stacker/tests/simple.rs')
-rw-r--r--vendor/stacker/tests/simple.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/vendor/stacker/tests/simple.rs b/vendor/stacker/tests/simple.rs
new file mode 100644
index 000000000..d4c7820d6
--- /dev/null
+++ b/vendor/stacker/tests/simple.rs
@@ -0,0 +1,27 @@
+extern crate stacker;
+
+const RED_ZONE: usize = 100 * 1024; // 100k
+const STACK_PER_RECURSION: usize = 1 * 1024 * 1024; // 1MB
+
+pub fn ensure_sufficient_stack<R, F: FnOnce() -> R + std::panic::UnwindSafe>(f: F) -> R {
+ stacker::maybe_grow(RED_ZONE, STACK_PER_RECURSION, f)
+}
+
+#[inline(never)]
+fn recurse(n: usize) {
+ let x = [42u8; 50000];
+ if n != 0 {
+ ensure_sufficient_stack(|| recurse(n - 1));
+ }
+ drop(x);
+}
+
+#[test]
+fn foo() {
+ let limit = if cfg!(target_arch = "wasm32") {
+ 2000
+ } else {
+ 10000
+ };
+ recurse(limit);
+}