summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/path_ends_with_ext.fixed
blob: 49767e242cee57eb8fd6cb1cfd0b782e2d101834 (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
28
29
30
31
32
33
34
35
36
#![warn(clippy::path_ends_with_ext)]
use std::path::Path;

macro_rules! arg {
    () => {
        ".md"
    };
}

fn test(path: &Path) {
    path.extension().is_some_and(|ext| ext == "md");
    //~^ ERROR: this looks like a failed attempt at checking for the file extension

    // some "extensions" are allowed by default
    path.ends_with(".git");

    // most legitimate "dotfiles" are longer than 3 chars, so we allow them as well
    path.ends_with(".bashrc");

    // argument from expn shouldn't trigger
    path.ends_with(arg!());

    path.ends_with("..");
    path.ends_with("./a");
    path.ends_with(".");
    path.ends_with("");
}

// is_some_and was stabilized in 1.70, so suggest map_or(false, ..) if under that
#[clippy::msrv = "1.69"]
fn under_msv(path: &Path) -> bool {
    path.extension().map_or(false, |ext| ext == "md")
    //~^ ERROR: this looks like a failed attempt at checking for the file extension
}

fn main() {}