about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlex Macleod <alex@macleod.io>2023-02-28 12:45:19 +0000
committerJosh Stone <jistone@redhat.com>2023-03-03 09:32:47 -0800
commit2410b0dfdfb299888a2f2e8b6400501fab881f64 (patch)
treea78cfc5caa77f820858719ac81bcb0ab1105f579
parent005892a58956034b15d54b71b85ffad48139775f (diff)
downloadrust-2410b0dfdfb299888a2f2e8b6400501fab881f64.tar.gz
rust-2410b0dfdfb299888a2f2e8b6400501fab881f64.zip
Fix array-size-threshold config deserialization error
-rw-r--r--src/tools/clippy/clippy_lints/src/lib.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/utils/conf.rs2
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-10044.rs3
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-10044.stderr10
-rw-r--r--src/tools/clippy/tests/ui/large_stack_arrays.rs1
-rw-r--r--src/tools/clippy/tests/ui/large_stack_arrays.stderr10
-rw-r--r--tests/ui-toml/array_size_threshold/array_size_threshold.rs10
-rw-r--r--tests/ui-toml/array_size_threshold/array_size_threshold.stderr29
-rw-r--r--tests/ui-toml/array_size_threshold/clippy.toml1
9 files changed, 52 insertions, 16 deletions
diff --git a/src/tools/clippy/clippy_lints/src/lib.rs b/src/tools/clippy/clippy_lints/src/lib.rs
index d8e2ae02c5a..e93f27bee94 100644
--- a/src/tools/clippy/clippy_lints/src/lib.rs
+++ b/src/tools/clippy/clippy_lints/src/lib.rs
@@ -768,7 +768,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
     store.register_late_pass(|_| Box::new(mutable_debug_assertion::DebugAssertWithMutCall));
     store.register_late_pass(|_| Box::new(exit::Exit));
     store.register_late_pass(|_| Box::new(to_digit_is_some::ToDigitIsSome));
-    let array_size_threshold = conf.array_size_threshold;
+    let array_size_threshold = u128::from(conf.array_size_threshold);
     store.register_late_pass(move |_| Box::new(large_stack_arrays::LargeStackArrays::new(array_size_threshold)));
     store.register_late_pass(move |_| Box::new(large_const_arrays::LargeConstArrays::new(array_size_threshold)));
     store.register_late_pass(|_| Box::new(floating_point_arithmetic::FloatingPointArithmetic));
diff --git a/src/tools/clippy/clippy_lints/src/utils/conf.rs b/src/tools/clippy/clippy_lints/src/utils/conf.rs
index c1589c771c4..3e7d0028c0f 100644
--- a/src/tools/clippy/clippy_lints/src/utils/conf.rs
+++ b/src/tools/clippy/clippy_lints/src/utils/conf.rs
@@ -333,7 +333,7 @@ define_Conf! {
     /// Lint: LARGE_STACK_ARRAYS, LARGE_CONST_ARRAYS.
     ///
     /// The maximum allowed size for arrays on the stack
-    (array_size_threshold: u128 = 512_000),
+    (array_size_threshold: u64 = 512_000),
     /// Lint: VEC_BOX.
     ///
     /// The size of the boxed type in bytes, where boxing in a `Vec` is allowed
diff --git a/src/tools/clippy/tests/ui/crashes/ice-10044.rs b/src/tools/clippy/tests/ui/crashes/ice-10044.rs
deleted file mode 100644
index 65f38fe7118..00000000000
--- a/src/tools/clippy/tests/ui/crashes/ice-10044.rs
+++ /dev/null
@@ -1,3 +0,0 @@
-fn main() {
-    [0; usize::MAX];
-}
diff --git a/src/tools/clippy/tests/ui/crashes/ice-10044.stderr b/src/tools/clippy/tests/ui/crashes/ice-10044.stderr
deleted file mode 100644
index 731f8265ad6..00000000000
--- a/src/tools/clippy/tests/ui/crashes/ice-10044.stderr
+++ /dev/null
@@ -1,10 +0,0 @@
-error: statement with no effect
-  --> $DIR/ice-10044.rs:2:5
-   |
-LL |     [0; usize::MAX];
-   |     ^^^^^^^^^^^^^^^^
-   |
-   = note: `-D clippy::no-effect` implied by `-D warnings`
-
-error: aborting due to previous error
-
diff --git a/src/tools/clippy/tests/ui/large_stack_arrays.rs b/src/tools/clippy/tests/ui/large_stack_arrays.rs
index 6790765f803..99787ffd3d3 100644
--- a/src/tools/clippy/tests/ui/large_stack_arrays.rs
+++ b/src/tools/clippy/tests/ui/large_stack_arrays.rs
@@ -24,6 +24,7 @@ fn main() {
         [S { data: [0; 32] }; 5000],
         [Some(""); 20_000_000],
         [E::T(0); 5000],
+        [0u8; usize::MAX],
     );
 
     let good = (
diff --git a/src/tools/clippy/tests/ui/large_stack_arrays.stderr b/src/tools/clippy/tests/ui/large_stack_arrays.stderr
index c7bf941ad00..24e90094982 100644
--- a/src/tools/clippy/tests/ui/large_stack_arrays.stderr
+++ b/src/tools/clippy/tests/ui/large_stack_arrays.stderr
@@ -31,5 +31,13 @@ LL |         [E::T(0); 5000],
    |
    = help: consider allocating on the heap with `vec![E::T(0); 5000].into_boxed_slice()`
 
-error: aborting due to 4 previous errors
+error: allocating a local array larger than 512000 bytes
+  --> $DIR/large_stack_arrays.rs:27:9
+   |
+LL |         [0u8; usize::MAX],
+   |         ^^^^^^^^^^^^^^^^^
+   |
+   = help: consider allocating on the heap with `vec![0u8; usize::MAX].into_boxed_slice()`
+
+error: aborting due to 5 previous errors
 
diff --git a/tests/ui-toml/array_size_threshold/array_size_threshold.rs b/tests/ui-toml/array_size_threshold/array_size_threshold.rs
new file mode 100644
index 00000000000..7f623c7a9ec
--- /dev/null
+++ b/tests/ui-toml/array_size_threshold/array_size_threshold.rs
@@ -0,0 +1,10 @@
+#![allow(unused)]
+#![warn(clippy::large_const_arrays, clippy::large_stack_arrays)]
+
+const ABOVE: [u8; 11] = [0; 11];
+const BELOW: [u8; 10] = [0; 10];
+
+fn main() {
+    let above = [0u8; 11];
+    let below = [0u8; 10];
+}
diff --git a/tests/ui-toml/array_size_threshold/array_size_threshold.stderr b/tests/ui-toml/array_size_threshold/array_size_threshold.stderr
new file mode 100644
index 00000000000..ac017b20916
--- /dev/null
+++ b/tests/ui-toml/array_size_threshold/array_size_threshold.stderr
@@ -0,0 +1,29 @@
+error: large array defined as const
+  --> $DIR/array_size_threshold.rs:4:1
+   |
+LL | const ABOVE: [u8; 11] = [0; 11];
+   | -----^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   | |
+   | help: make this a static item: `static`
+   |
+   = note: `-D clippy::large-const-arrays` implied by `-D warnings`
+
+error: allocating a local array larger than 10 bytes
+  --> $DIR/array_size_threshold.rs:4:25
+   |
+LL | const ABOVE: [u8; 11] = [0; 11];
+   |                         ^^^^^^^
+   |
+   = help: consider allocating on the heap with `vec![0; 11].into_boxed_slice()`
+   = note: `-D clippy::large-stack-arrays` implied by `-D warnings`
+
+error: allocating a local array larger than 10 bytes
+  --> $DIR/array_size_threshold.rs:8:17
+   |
+LL |     let above = [0u8; 11];
+   |                 ^^^^^^^^^
+   |
+   = help: consider allocating on the heap with `vec![0u8; 11].into_boxed_slice()`
+
+error: aborting due to 3 previous errors
+
diff --git a/tests/ui-toml/array_size_threshold/clippy.toml b/tests/ui-toml/array_size_threshold/clippy.toml
new file mode 100644
index 00000000000..3f1fe9a1209
--- /dev/null
+++ b/tests/ui-toml/array_size_threshold/clippy.toml
@@ -0,0 +1 @@
+array-size-threshold = 10