fork/rust

git clone https://git.julia.blue/fork/rust

borsAuto merge of #103046 - JanBeh:PR_clarify_cmp_terminology, r=workingjubilee3bcad65fbf6

master
885 B24 linesraw
1#![warn(clippy::redundant_as_str)]
2
3fn main() {
4    let string = "Hello, world!".to_owned();
5
6    // These methods are redundant and the `as_str` can be removed
7    let _redundant = string.as_bytes();
8    let _redundant = string.is_empty();
9
10    // These methods don't use `as_str` when they are redundant
11    let _no_as_str = string.as_bytes();
12    let _no_as_str = string.is_empty();
13
14    // These methods are not redundant, and are equivelant to
15    // doing dereferencing the string and applying the method
16    let _not_redundant = string.as_str().escape_unicode();
17    let _not_redundant = string.as_str().trim();
18    let _not_redundant = string.as_str().split_whitespace();
19
20    // These methods don't use `as_str` and are applied on a `str` directly
21    let borrowed_str = "Hello, world!";
22    let _is_str = borrowed_str.as_bytes();
23    let _is_str = borrowed_str.is_empty();
24}