about summary refs log tree commit diff
path: root/src/tools/clippy/tests/ui/min_ident_chars.rs
blob: e2f82e2a182f66b363e822ca66ac2fae2f6829f4 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
//@aux-build:proc_macros.rs
#![allow(irrefutable_let_patterns, nonstandard_style, unused)]
#![allow(clippy::struct_field_names)]
#![warn(clippy::min_ident_chars)]

extern crate proc_macros;
use proc_macros::{external, with_span};

struct A {
    //~^ min_ident_chars
    a: u32,
    //~^ min_ident_chars
    i: u32,
    A: u32,
    //~^ min_ident_chars
    I: u32,
    //~^ min_ident_chars
}

struct B(u32);
//~^ min_ident_chars

struct O {
    //~^ min_ident_chars
    o: u32,
    //~^ min_ident_chars
}

struct i;

enum C {
    //~^ min_ident_chars
    D,
    //~^ min_ident_chars
    E,
    //~^ min_ident_chars
    F,
    //~^ min_ident_chars
    j,
}

struct Vec4 {
    x: u32,
    y: u32,
    z: u32,
    w: u32,
}

struct AA<T, E>(T, E);

trait Trait {
    const A: u32 = 0;
    //~^ min_ident_chars
    type A;
    //~^ min_ident_chars
    fn a() {}
    //~^ min_ident_chars
}

fn main() {
    // Allowed idents
    let w = 1;
    // Ok, not this one
    // let i = 1;
    let j = 1;
    let n = 1;
    let z = 1;
    let y = 1;
    let z = 1;
    // Implicitly disallowed idents
    let h = 1;
    //~^ min_ident_chars
    let e = 2;
    //~^ min_ident_chars
    let l = 3;
    //~^ min_ident_chars
    let l = 4;
    //~^ min_ident_chars
    let o = 6;
    //~^ min_ident_chars
    // 2 len does not lint
    let hi = 0;
    // Lint
    let (h, o, w) = (1, 2, 3);
    //~^ min_ident_chars
    //~| min_ident_chars
    for (a, (r, e)) in (0..1000).enumerate().enumerate() {}
    //~^ min_ident_chars
    //~| min_ident_chars
    //~| min_ident_chars
    let you = Vec4 { x: 1, y: 2, z: 3, w: 4 };
    while let (d, o, _i, n, g) = (true, true, false, false, true) {}
    //~^ min_ident_chars
    //~| min_ident_chars
    //~| min_ident_chars
    let today = true;
    // Ideally this wouldn't lint, but this would (likely) require global analysis, outta scope
    // of this lint regardless
    let o = 1;
    //~^ min_ident_chars
    let o = O { o };
    //~^ min_ident_chars

    for j in 0..1000 {}
    for _ in 0..10 {}

    // Do not lint code from external macros
    external! { for j in 0..1000 {} }
    // Do not lint code from procedural macros
    with_span! {
        span
        for j in 0..1000 {}
    }
}

fn b() {}
//~^ min_ident_chars
fn wrong_pythagoras(a: f32, b: f32) -> f32 {
    //~^ min_ident_chars
    //~| min_ident_chars
    a * a + a * b
}

mod issue_11163 {
    struct Array<T, const N: usize>([T; N]);
}

struct Issue13396;

impl core::fmt::Display for Issue13396 {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "Issue13396")
    }
}

impl core::fmt::Debug for Issue13396 {
    fn fmt(&self, g: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        //~^ min_ident_chars
        write!(g, "Issue13396")
    }
}

fn issue13396() {
    let a = |f: i8| f;
    //~^ min_ident_chars
    //~| min_ident_chars
}

trait D {
    //~^ min_ident_chars
    fn f(g: i32);
    //~^ min_ident_chars
    //~| min_ident_chars
    fn long(long: i32);

    fn g(arg: i8) {
        //~^ min_ident_chars
        fn c(d: u8) {}
        //~^ min_ident_chars
        //~| min_ident_chars
    }
}

impl D for Issue13396 {
    fn f(g: i32) {
        fn h() {}
        //~^ min_ident_chars
        fn inner(a: i32) {}
        //~^ min_ident_chars
        let a = |f: String| f;
        //~^ min_ident_chars
        //~| min_ident_chars
    }
    fn long(long: i32) {}
}