about summary refs log tree commit diff
path: root/src/tools/clippy/tests/ui-toml/large_stack_frames
diff options
context:
space:
mode:
authorPhilipp Krones <hello@philkrones.com>2023-09-25 11:28:58 +0200
committerPhilipp Krones <hello@philkrones.com>2023-09-25 11:28:58 +0200
commit3112e373aca4250d1444957ab4ded626cb99ee91 (patch)
treea97bedf47bfc5f2786fdf248fbbbb71287eb7700 /src/tools/clippy/tests/ui-toml/large_stack_frames
parent67ad3c23941d2296448d7b38b16eccd1b3e38925 (diff)
parent7671c283a50b5d1168841f3014b14000f01dd204 (diff)
Merge commit '7671c283a50b5d1168841f3014b14000f01dd204' into clippyup
Diffstat (limited to 'src/tools/clippy/tests/ui-toml/large_stack_frames')
-rw-r--r--src/tools/clippy/tests/ui-toml/large_stack_frames/clippy.toml1
-rw-r--r--src/tools/clippy/tests/ui-toml/large_stack_frames/large_stack_frames.rs17
-rw-r--r--src/tools/clippy/tests/ui-toml/large_stack_frames/large_stack_frames.stderr15
3 files changed, 33 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui-toml/large_stack_frames/clippy.toml b/src/tools/clippy/tests/ui-toml/large_stack_frames/clippy.toml
new file mode 100644
index 00000000000..584335dc28f
--- /dev/null
+++ b/src/tools/clippy/tests/ui-toml/large_stack_frames/clippy.toml
@@ -0,0 +1 @@
+stack-size-threshold = 1000
diff --git a/src/tools/clippy/tests/ui-toml/large_stack_frames/large_stack_frames.rs b/src/tools/clippy/tests/ui-toml/large_stack_frames/large_stack_frames.rs
new file mode 100644
index 00000000000..39798ffea49
--- /dev/null
+++ b/src/tools/clippy/tests/ui-toml/large_stack_frames/large_stack_frames.rs
@@ -0,0 +1,17 @@
+#![warn(clippy::large_stack_frames)]
+
+// We use this helper function instead of writing [0; 4294967297] directly to represent a
+// case that large_stack_arrays can't catch
+fn create_array<const N: usize>() -> [u8; N] {
+    [0; N]
+}
+
+fn f() {
+    let _x = create_array::<1000>();
+}
+fn f2() {
+    //~^ ERROR: this function allocates a large amount of stack space
+    let _x = create_array::<1001>();
+}
+
+fn main() {}
diff --git a/src/tools/clippy/tests/ui-toml/large_stack_frames/large_stack_frames.stderr b/src/tools/clippy/tests/ui-toml/large_stack_frames/large_stack_frames.stderr
new file mode 100644
index 00000000000..67ee57ab672
--- /dev/null
+++ b/src/tools/clippy/tests/ui-toml/large_stack_frames/large_stack_frames.stderr
@@ -0,0 +1,15 @@
+error: this function allocates a large amount of stack space
+  --> $DIR/large_stack_frames.rs:12:1
+   |
+LL | / fn f2() {
+LL | |
+LL | |     let _x = create_array::<1001>();
+LL | | }
+   | |_^
+   |
+   = note: allocating large amounts of stack space can overflow the stack
+   = note: `-D clippy::large-stack-frames` implied by `-D warnings`
+   = help: to override `-D warnings` add `#[allow(clippy::large_stack_frames)]`
+
+error: aborting due to previous error
+