about summary refs log tree commit diff
path: root/src/tools/clippy/tests/ui/redundant_as_str.fixed
blob: 4c5f7893d42e01b9ea93d5fefd114a971a132abb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#![warn(clippy::redundant_as_str)]
#![allow(clippy::const_is_empty)]

fn main() {
    let string = "Hello, world!".to_owned();

    // These methods are redundant and the `as_str` can be removed
    let _redundant = string.as_bytes();
    //~^ redundant_as_str
    let _redundant = string.is_empty();
    //~^ redundant_as_str

    // These methods don't use `as_str` when they are redundant
    let _no_as_str = string.as_bytes();
    let _no_as_str = string.is_empty();

    // These methods are not redundant, and are equivalent 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 _is_str = borrowed_str.as_bytes();
    let _is_str = borrowed_str.is_empty();
}