about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDev381 <49997896+Dev380@users.noreply.github.com>2023-09-18 16:32:22 -0400
committerDev381 <49997896+Dev380@users.noreply.github.com>2023-09-18 16:32:22 -0400
commit00ca47b97d59ab3384c9786e5b38f0262f413384 (patch)
tree1171da96be14174af8c8ee4532f30602a1936c5f
parentf2ab16eac139522ac5a9c6606c81e5967aec6d79 (diff)
Add more examples and comments to redundant_as_str test
-rw-r--r--tests/ui/redundant_as_str.fixed9
-rw-r--r--tests/ui/redundant_as_str.rs19
-rw-r--r--tests/ui/redundant_as_str.stderr19
3 files changed, 20 insertions, 27 deletions
diff --git a/tests/ui/redundant_as_str.fixed b/tests/ui/redundant_as_str.fixed
deleted file mode 100644
index c8e44d1c39e..00000000000
--- a/tests/ui/redundant_as_str.fixed
+++ /dev/null
@@ -1,9 +0,0 @@
-#![warn(clippy::redundant_as_str)]
-
-fn main() {
-    let _redundant = "Hello, world!".to_owned().as_bytes();
-    let _redundant = "Hello, world!".to_owned().is_empty();
-
-    let _ok = "Hello, world!".to_owned().as_bytes();
-    let _ok = "Hello, world!".to_owned().is_empty();
-}
diff --git a/tests/ui/redundant_as_str.rs b/tests/ui/redundant_as_str.rs
index e9aa8441913..35b6bdb3c5e 100644
--- a/tests/ui/redundant_as_str.rs
+++ b/tests/ui/redundant_as_str.rs
@@ -1,9 +1,20 @@
 #![warn(clippy::redundant_as_str)]
 
 fn main() {
-    let _redundant = "Hello, world!".to_owned().as_str().as_bytes();
-    let _redundant = "Hello, world!".to_owned().as_str().is_empty();
+	let string = "Hello, world!".to_owned();
 
-    let _ok = "Hello, world!".to_owned().as_bytes();
-    let _ok = "Hello, world!".to_owned().is_empty();
+	// These methods are redundant and the `as_str` can be removed.
+    let _redundant = string.as_str().as_bytes();
+    let _redundant = string.as_str().is_empty();
+
+	// These methods are not redundant, and are equivelant to
+	// doing dereferencing the string and applying the method.
+    let _not_redundant = string.as_str().escape_unicode();
+    let _not_redundant = string.as_str().trim();
+    let _not_redundant = string.as_str().split_whitespace();
+
+	// These methods don't use `as_str` and are applied on a `str` directly.
+	let borrowed_str = "Hello, world"!
+    let _no_as_str = borrowed_str.as_bytes();
+    let _no_as_str = borrowed_str.is_empty();
 }
diff --git a/tests/ui/redundant_as_str.stderr b/tests/ui/redundant_as_str.stderr
index 32b5232385d..e7da34650f2 100644
--- a/tests/ui/redundant_as_str.stderr
+++ b/tests/ui/redundant_as_str.stderr
@@ -1,17 +1,8 @@
-error: this `as_str` is redundant and can be removed as the method immediately following exists on `String` too
-  --> $DIR/redundant_as_str.rs:4:49
+error: expected one of `.`, `;`, `?`, `else`, or an operator, found `!`
+  --> $DIR/redundant_as_str.rs:17:35
    |
-LL |     let _redundant = "Hello, world!".to_owned().as_str().as_bytes();
-   |                                                 ^^^^^^^^^^^^^^^^^ help: try: `as_bytes`
-   |
-   = note: `-D clippy::redundant-as-str` implied by `-D warnings`
-   = help: to override `-D warnings` add `#[allow(clippy::redundant_as_str)]`
-
-error: this `as_str` is redundant and can be removed as the method immediately following exists on `String` too
-  --> $DIR/redundant_as_str.rs:5:49
-   |
-LL |     let _redundant = "Hello, world!".to_owned().as_str().is_empty();
-   |                                                 ^^^^^^^^^^^^^^^^^ help: try: `is_empty`
+LL |     let borrowed_str = "Hello, world"!
+   |                                      ^ expected one of `.`, `;`, `?`, `else`, or an operator
 
-error: aborting due to 2 previous errors
+error: aborting due to previous error