about summary refs log tree commit diff
path: root/src/tools/clippy/tests/ui-toml
diff options
context:
space:
mode:
authorPhilipp Krones <hello@philkrones.com>2024-12-26 15:01:07 +0100
committerPhilipp Krones <hello@philkrones.com>2024-12-26 15:15:54 +0100
commit8a7d8ece322d2ecd106f7c650a35ed8df777e109 (patch)
tree6c9868547875b0dcc345330ee6cc7ca7b6055da6 /src/tools/clippy/tests/ui-toml
parent78af7da26d50d79b7f527b40182e4aaf541f1b37 (diff)
parent609cd310be44677ae31d452a17b0f8207e1abfe1 (diff)
downloadrust-8a7d8ece322d2ecd106f7c650a35ed8df777e109.tar.gz
rust-8a7d8ece322d2ecd106f7c650a35ed8df777e109.zip
Merge commit '609cd310be44677ae31d452a17b0f8207e1abfe1' into clippy-subtree-update
Diffstat (limited to 'src/tools/clippy/tests/ui-toml')
-rw-r--r--src/tools/clippy/tests/ui-toml/indexing_slicing/clippy.toml1
-rw-r--r--src/tools/clippy/tests/ui-toml/indexing_slicing/indexing_slicing.rs19
-rw-r--r--src/tools/clippy/tests/ui-toml/indexing_slicing/indexing_slicing.stderr12
-rw-r--r--src/tools/clippy/tests/ui-toml/large_include_file/large_include_file.rs1
-rw-r--r--src/tools/clippy/tests/ui-toml/large_include_file/large_include_file.stderr6
-rw-r--r--src/tools/clippy/tests/ui-toml/max_suggested_slice_pattern_length/index_refutable_slice.fixed24
-rw-r--r--src/tools/clippy/tests/ui-toml/max_suggested_slice_pattern_length/index_refutable_slice.rs2
-rw-r--r--src/tools/clippy/tests/ui-toml/max_suggested_slice_pattern_length/index_refutable_slice.stderr14
-rw-r--r--src/tools/clippy/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr3
9 files changed, 70 insertions, 12 deletions
diff --git a/src/tools/clippy/tests/ui-toml/indexing_slicing/clippy.toml b/src/tools/clippy/tests/ui-toml/indexing_slicing/clippy.toml
new file mode 100644
index 00000000000..7e83868332f
--- /dev/null
+++ b/src/tools/clippy/tests/ui-toml/indexing_slicing/clippy.toml
@@ -0,0 +1 @@
+allow-indexing-slicing-in-tests = true
diff --git a/src/tools/clippy/tests/ui-toml/indexing_slicing/indexing_slicing.rs b/src/tools/clippy/tests/ui-toml/indexing_slicing/indexing_slicing.rs
new file mode 100644
index 00000000000..0a0da88ea1f
--- /dev/null
+++ b/src/tools/clippy/tests/ui-toml/indexing_slicing/indexing_slicing.rs
@@ -0,0 +1,19 @@
+//@compile-flags: --test
+#![warn(clippy::indexing_slicing)]
+#![allow(clippy::no_effect)]
+
+fn main() {
+    let x = [1, 2, 3, 4];
+    let index: usize = 1;
+    &x[index..];
+}
+
+#[cfg(test)]
+mod tests {
+    #[test]
+    fn test_fn() {
+        let x = [1, 2, 3, 4];
+        let index: usize = 1;
+        &x[index..];
+    }
+}
diff --git a/src/tools/clippy/tests/ui-toml/indexing_slicing/indexing_slicing.stderr b/src/tools/clippy/tests/ui-toml/indexing_slicing/indexing_slicing.stderr
new file mode 100644
index 00000000000..5a4de8337b4
--- /dev/null
+++ b/src/tools/clippy/tests/ui-toml/indexing_slicing/indexing_slicing.stderr
@@ -0,0 +1,12 @@
+error: slicing may panic
+  --> tests/ui-toml/indexing_slicing/indexing_slicing.rs:8:6
+   |
+LL |     &x[index..];
+   |      ^^^^^^^^^^
+   |
+   = help: consider using `.get(n..)` or .get_mut(n..)` instead
+   = note: `-D clippy::indexing-slicing` implied by `-D warnings`
+   = help: to override `-D warnings` add `#[allow(clippy::indexing_slicing)]`
+
+error: aborting due to 1 previous error
+
diff --git a/src/tools/clippy/tests/ui-toml/large_include_file/large_include_file.rs b/src/tools/clippy/tests/ui-toml/large_include_file/large_include_file.rs
index 8a6dd36501c..184c6d17ba4 100644
--- a/src/tools/clippy/tests/ui-toml/large_include_file/large_include_file.rs
+++ b/src/tools/clippy/tests/ui-toml/large_include_file/large_include_file.rs
@@ -1,4 +1,5 @@
 #![warn(clippy::large_include_file)]
+#![allow(clippy::literal_string_with_formatting_args)]
 
 // Good
 const GOOD_INCLUDE_BYTES: &[u8; 68] = include_bytes!("../../ui/author.rs");
diff --git a/src/tools/clippy/tests/ui-toml/large_include_file/large_include_file.stderr b/src/tools/clippy/tests/ui-toml/large_include_file/large_include_file.stderr
index 9e1494a47bb..82b926cc53b 100644
--- a/src/tools/clippy/tests/ui-toml/large_include_file/large_include_file.stderr
+++ b/src/tools/clippy/tests/ui-toml/large_include_file/large_include_file.stderr
@@ -1,5 +1,5 @@
 error: attempted to include a large file
-  --> tests/ui-toml/large_include_file/large_include_file.rs:13:43
+  --> tests/ui-toml/large_include_file/large_include_file.rs:14:43
    |
 LL | const TOO_BIG_INCLUDE_BYTES: &[u8; 654] = include_bytes!("too_big.txt");
    |                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -9,7 +9,7 @@ LL | const TOO_BIG_INCLUDE_BYTES: &[u8; 654] = include_bytes!("too_big.txt");
    = help: to override `-D warnings` add `#[allow(clippy::large_include_file)]`
 
 error: attempted to include a large file
-  --> tests/ui-toml/large_include_file/large_include_file.rs:15:35
+  --> tests/ui-toml/large_include_file/large_include_file.rs:16:35
    |
 LL | const TOO_BIG_INCLUDE_STR: &str = include_str!("too_big.txt");
    |                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -17,7 +17,7 @@ LL | const TOO_BIG_INCLUDE_STR: &str = include_str!("too_big.txt");
    = note: the configuration allows a maximum size of 600 bytes
 
 error: attempted to include a large file
-  --> tests/ui-toml/large_include_file/large_include_file.rs:18:1
+  --> tests/ui-toml/large_include_file/large_include_file.rs:19:1
    |
 LL | #[doc = include_str!("too_big.txt")]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui-toml/max_suggested_slice_pattern_length/index_refutable_slice.fixed b/src/tools/clippy/tests/ui-toml/max_suggested_slice_pattern_length/index_refutable_slice.fixed
new file mode 100644
index 00000000000..36540bf1dcf
--- /dev/null
+++ b/src/tools/clippy/tests/ui-toml/max_suggested_slice_pattern_length/index_refutable_slice.fixed
@@ -0,0 +1,24 @@
+#![deny(clippy::index_refutable_slice)]
+
+fn below_limit() {
+    let slice: Option<&[u32]> = Some(&[1, 2, 3]);
+    if let Some([_, _, _, _, _, _, _, slice_7, ..]) = slice {
+        //~^ ERROR: binding can be a slice pattern
+        // This would usually not be linted but is included now due to the
+        // index limit in the config file
+        println!("{}", slice_7);
+    }
+}
+
+fn above_limit() {
+    let slice: Option<&[u32]> = Some(&[1, 2, 3]);
+    if let Some(slice) = slice {
+        // This will not be linted as 8 is above the limit
+        println!("{}", slice[8]);
+    }
+}
+
+fn main() {
+    below_limit();
+    above_limit();
+}
diff --git a/src/tools/clippy/tests/ui-toml/max_suggested_slice_pattern_length/index_refutable_slice.rs b/src/tools/clippy/tests/ui-toml/max_suggested_slice_pattern_length/index_refutable_slice.rs
index e64c8ff3290..da76bb20fd9 100644
--- a/src/tools/clippy/tests/ui-toml/max_suggested_slice_pattern_length/index_refutable_slice.rs
+++ b/src/tools/clippy/tests/ui-toml/max_suggested_slice_pattern_length/index_refutable_slice.rs
@@ -1,7 +1,5 @@
 #![deny(clippy::index_refutable_slice)]
 
-//@no-rustfix: need to change the suggestion to a multipart suggestion
-
 fn below_limit() {
     let slice: Option<&[u32]> = Some(&[1, 2, 3]);
     if let Some(slice) = slice {
diff --git a/src/tools/clippy/tests/ui-toml/max_suggested_slice_pattern_length/index_refutable_slice.stderr b/src/tools/clippy/tests/ui-toml/max_suggested_slice_pattern_length/index_refutable_slice.stderr
index 3ea600c7d7b..022deb330e6 100644
--- a/src/tools/clippy/tests/ui-toml/max_suggested_slice_pattern_length/index_refutable_slice.stderr
+++ b/src/tools/clippy/tests/ui-toml/max_suggested_slice_pattern_length/index_refutable_slice.stderr
@@ -1,5 +1,5 @@
 error: this binding can be a slice pattern to avoid indexing
-  --> tests/ui-toml/max_suggested_slice_pattern_length/index_refutable_slice.rs:7:17
+  --> tests/ui-toml/max_suggested_slice_pattern_length/index_refutable_slice.rs:5:17
    |
 LL |     if let Some(slice) = slice {
    |                 ^^^^^
@@ -9,14 +9,14 @@ note: the lint level is defined here
    |
 LL | #![deny(clippy::index_refutable_slice)]
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-help: try using a slice pattern here
+help: replace the binding and indexed access with a slice pattern
    |
-LL |     if let Some([_, _, _, _, _, _, _, slice_7, ..]) = slice {
-   |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-help: and replace the index expressions here
+LL ~     if let Some([_, _, _, _, _, _, _, slice_7, ..]) = slice {
+LL |
+LL |         // This would usually not be linted but is included now due to the
+LL |         // index limit in the config file
+LL ~         println!("{}", slice_7);
    |
-LL |         println!("{}", slice_7);
-   |                        ~~~~~~~
 
 error: aborting due to 1 previous error
 
diff --git a/src/tools/clippy/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr b/src/tools/clippy/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr
index 6fa583fc041..200129da25f 100644
--- a/src/tools/clippy/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr
+++ b/src/tools/clippy/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr
@@ -6,6 +6,7 @@ error: error reading Clippy's configuration file: unknown field `foobar`, expect
            allow-comparison-to-zero
            allow-dbg-in-tests
            allow-expect-in-tests
+           allow-indexing-slicing-in-tests
            allow-mixed-uninlined-format-args
            allow-one-hash-in-raw-strings
            allow-panic-in-tests
@@ -93,6 +94,7 @@ error: error reading Clippy's configuration file: unknown field `barfoo`, expect
            allow-comparison-to-zero
            allow-dbg-in-tests
            allow-expect-in-tests
+           allow-indexing-slicing-in-tests
            allow-mixed-uninlined-format-args
            allow-one-hash-in-raw-strings
            allow-panic-in-tests
@@ -180,6 +182,7 @@ error: error reading Clippy's configuration file: unknown field `allow_mixed_uni
            allow-comparison-to-zero
            allow-dbg-in-tests
            allow-expect-in-tests
+           allow-indexing-slicing-in-tests
            allow-mixed-uninlined-format-args
            allow-one-hash-in-raw-strings
            allow-panic-in-tests