summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/let_with_type_underscore.rs
blob: ae1a480bcfc553f36fe52f4f971818d191382c72 (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
37
38
39
40
41
42
//@aux-build: proc_macros.rs
#![allow(unused)]
#![warn(clippy::let_with_type_underscore)]
#![allow(clippy::let_unit_value, clippy::needless_late_init)]

extern crate proc_macros;

fn func() -> &'static str {
    ""
}

#[rustfmt::skip]
fn main() {
    // Will lint
    let x: _ = 1;
    let _: _ = 2;
    let x: _ = func();
    let x: _;
    x = ();

    let x = 1; // Will not lint, Rust infers this to an integer before Clippy
    let x = func();
    let x: Vec<_> = Vec::<u32>::new();
    let x: [_; 1] = [1];
    let x : _ = 1;

    // Do not lint from procedural macros
    proc_macros::with_span! {
        span
        let x: _ = ();
        // Late initialization
        let x: _;
        x = ();
        // Ensure weird formatting will not break it (hopefully)
        let x : _ = 1;
        let x
: _ = 1;
        let                   x :              
        _;
        x = ();
    };
}