]> git.lizzy.rs Git - rust.git/commitdiff
add some test cases
authorTakayuki Maeda <takoyaki0316@gmail.com>
Wed, 10 Feb 2021 07:15:29 +0000 (16:15 +0900)
committerTakayuki Maeda <takoyaki0316@gmail.com>
Wed, 10 Feb 2021 07:15:29 +0000 (16:15 +0900)
tests/ui/bytes_nth.fixed
tests/ui/bytes_nth.rs
tests/ui/bytes_nth.stderr

index 36bf8660a34c0c41ea15231b06f98c42eea0d6b7..bf68a7bbbf1d4e1b398b25216a0ee8009cb7dde0 100644 (file)
@@ -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);
 }
index 257344c2d32952e490ecdf08e1cc1af519136f9e..629812cc02cb899961fb384c7d51cb698713a698 100644 (file)
@@ -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);
 }
index b46a0736414b05d553a868bc20dd3a5b38f3f994..9a5742928cd617da55eadb98ded6f012b9553f3e 100644 (file)
@@ -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