about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTakayuki Maeda <takoyaki0316@gmail.com>2021-02-10 16:15:29 +0900
committerTakayuki Maeda <takoyaki0316@gmail.com>2021-02-10 16:15:29 +0900
commit5996ae1cfca619145ffb5e041592efdd097e6391 (patch)
tree07b1369d9bf10e6a7f9ee5dfcd1b78360adcfc98
parent932cc085e6ac277d58fbb6bebe05252b75d5dc54 (diff)
downloadrust-5996ae1cfca619145ffb5e041592efdd097e6391.tar.gz
rust-5996ae1cfca619145ffb5e041592efdd097e6391.zip
add some test cases
-rw-r--r--tests/ui/bytes_nth.fixed8
-rw-r--r--tests/ui/bytes_nth.rs8
-rw-r--r--tests/ui/bytes_nth.stderr22
3 files changed, 24 insertions, 14 deletions
diff --git a/tests/ui/bytes_nth.fixed b/tests/ui/bytes_nth.fixed
index 36bf8660a34..bf68a7bbbf1 100644
--- a/tests/ui/bytes_nth.fixed
+++ b/tests/ui/bytes_nth.fixed
@@ -1,9 +1,11 @@
 // run-rustfix
 
+#![allow(clippy::unnecessary_operation)]
 #![warn(clippy::bytes_nth)]
 
 fn main() {
-    let _ = "Hello".as_bytes().get(3);
-
-    let _ = String::from("Hello").as_bytes().get(3);
+    let s = String::from("String");
+    s.as_bytes().get(3);
+    &s.as_bytes().get(3);
+    s[..].as_bytes().get(3);
 }
diff --git a/tests/ui/bytes_nth.rs b/tests/ui/bytes_nth.rs
index 257344c2d32..629812cc02c 100644
--- a/tests/ui/bytes_nth.rs
+++ b/tests/ui/bytes_nth.rs
@@ -1,9 +1,11 @@
 // run-rustfix
 
+#![allow(clippy::unnecessary_operation)]
 #![warn(clippy::bytes_nth)]
 
 fn main() {
-    let _ = "Hello".bytes().nth(3);
-
-    let _ = String::from("Hello").bytes().nth(3);
+    let s = String::from("String");
+    s.bytes().nth(3);
+    &s.bytes().nth(3);
+    s[..].bytes().nth(3);
 }
diff --git a/tests/ui/bytes_nth.stderr b/tests/ui/bytes_nth.stderr
index b46a0736414..9a5742928cd 100644
--- a/tests/ui/bytes_nth.stderr
+++ b/tests/ui/bytes_nth.stderr
@@ -1,16 +1,22 @@
-error: called `.byte().nth()` on a `str`
-  --> $DIR/bytes_nth.rs:6:13
+error: called `.byte().nth()` on a `String`
+  --> $DIR/bytes_nth.rs:8:5
    |
-LL |     let _ = "Hello".bytes().nth(3);
-   |             ^^^^^^^^^^^^^^^^^^^^^^ help: try calling `.as_bytes().get()`: `"Hello".as_bytes().get(3)`
+LL |     s.bytes().nth(3);
+   |     ^^^^^^^^^^^^^^^^ help: try: `s.as_bytes().get(3)`
    |
    = note: `-D clippy::bytes-nth` implied by `-D warnings`
 
 error: called `.byte().nth()` on a `String`
-  --> $DIR/bytes_nth.rs:8:13
+  --> $DIR/bytes_nth.rs:9:6
+   |
+LL |     &s.bytes().nth(3);
+   |      ^^^^^^^^^^^^^^^^ help: try: `s.as_bytes().get(3)`
+
+error: called `.byte().nth()` on a `str`
+  --> $DIR/bytes_nth.rs:10:5
    |
-LL |     let _ = String::from("Hello").bytes().nth(3);
-   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try calling `.as_bytes().get()`: `String::from("Hello").as_bytes().get(3)`
+LL |     s[..].bytes().nth(3);
+   |     ^^^^^^^^^^^^^^^^^^^^ help: try: `s[..].as_bytes().get(3)`
 
-error: aborting due to 2 previous errors
+error: aborting due to 3 previous errors