Skip to content
This repository was archived by the owner on Nov 24, 2023. It is now read-only.

Commit 9121d77

Browse files
committed
Add test for redundant_closure_call lint
1 parent 0adacf8 commit 9121d77

File tree

3 files changed

+361
-0
lines changed

3 files changed

+361
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fn main() {
2+
let a = 42;
3+
4+
let b = 42;
5+
6+
let c = "x";
7+
}
+345
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,345 @@
1+
{
2+
"message": "Try not to call a closure in the expression where it is declared.",
3+
"code": {
4+
"code": "redundant_closure_call",
5+
"explanation": null
6+
},
7+
"level": "warning",
8+
"spans": [
9+
{
10+
"file_name": "./tests/fixtures/redundant_closure_call.rs",
11+
"byte_start": 24,
12+
"byte_end": 33,
13+
"line_start": 2,
14+
"line_end": 2,
15+
"column_start": 13,
16+
"column_end": 22,
17+
"is_primary": true,
18+
"text": [
19+
{
20+
"text": " let a = (|| 42)();",
21+
"highlight_start": 13,
22+
"highlight_end": 22
23+
}
24+
],
25+
"label": null,
26+
"suggested_replacement": null,
27+
"expansion": null
28+
}
29+
],
30+
"children": [
31+
{
32+
"message": "#[warn(redundant_closure_call)] on by default",
33+
"code": null,
34+
"level": "note",
35+
"spans": [],
36+
"children": [],
37+
"rendered": null
38+
},
39+
{
40+
"message": "Try doing something like: ",
41+
"code": null,
42+
"level": "help",
43+
"spans": [
44+
{
45+
"file_name": "./tests/fixtures/redundant_closure_call.rs",
46+
"byte_start": 24,
47+
"byte_end": 33,
48+
"line_start": 2,
49+
"line_end": 2,
50+
"column_start": 13,
51+
"column_end": 22,
52+
"is_primary": true,
53+
"text": [
54+
{
55+
"text": " let a = (|| 42)();",
56+
"highlight_start": 13,
57+
"highlight_end": 22
58+
}
59+
],
60+
"label": null,
61+
"suggested_replacement": "42",
62+
"expansion": null
63+
}
64+
],
65+
"children": [],
66+
"rendered": null
67+
}
68+
],
69+
"rendered": "warning: Try not to call a closure in the expression where it is declared.\n --> ./tests/fixtures/redundant_closure_call.rs:2:13\n |\n2 | let a = (|| 42)();\n | ^^^^^^^^^ help: Try doing something like: : `42`\n |\n = note: #[warn(redundant_closure_call)] on by default\n\n"
70+
}
71+
{
72+
"message": "Try not to call a closure in the expression where it is declared.",
73+
"code": {
74+
"code": "redundant_closure_call",
75+
"explanation": null
76+
},
77+
"level": "warning",
78+
"spans": [
79+
{
80+
"file_name": "./tests/fixtures/redundant_closure_call.rs",
81+
"byte_start": 48,
82+
"byte_end": 70,
83+
"line_start": 4,
84+
"line_end": 6,
85+
"column_start": 13,
86+
"column_end": 8,
87+
"is_primary": true,
88+
"text": [
89+
{
90+
"text": " let b = (||",
91+
"highlight_start": 13,
92+
"highlight_end": 16
93+
},
94+
{
95+
"text": " 42",
96+
"highlight_start": 1,
97+
"highlight_end": 11
98+
},
99+
{
100+
"text": " )();",
101+
"highlight_start": 1,
102+
"highlight_end": 8
103+
}
104+
],
105+
"label": null,
106+
"suggested_replacement": null,
107+
"expansion": null
108+
}
109+
],
110+
"children": [
111+
{
112+
"message": "Try doing something like: ",
113+
"code": null,
114+
"level": "help",
115+
"spans": [
116+
{
117+
"file_name": "./tests/fixtures/redundant_closure_call.rs",
118+
"byte_start": 48,
119+
"byte_end": 70,
120+
"line_start": 4,
121+
"line_end": 6,
122+
"column_start": 13,
123+
"column_end": 8,
124+
"is_primary": true,
125+
"text": [
126+
{
127+
"text": " let b = (||",
128+
"highlight_start": 13,
129+
"highlight_end": 16
130+
},
131+
{
132+
"text": " 42",
133+
"highlight_start": 1,
134+
"highlight_end": 11
135+
},
136+
{
137+
"text": " )();",
138+
"highlight_start": 1,
139+
"highlight_end": 8
140+
}
141+
],
142+
"label": null,
143+
"suggested_replacement": "42",
144+
"expansion": null
145+
}
146+
],
147+
"children": [],
148+
"rendered": null
149+
}
150+
],
151+
"rendered": "warning: Try not to call a closure in the expression where it is declared.\n --> ./tests/fixtures/redundant_closure_call.rs:4:13\n |\n4 | let b = (||\n | _____________^\n5 | | 42\n6 | | )();\n | |_______^ help: Try doing something like: : `42`\n\n"
152+
}
153+
{
154+
"message": "Try not to call a closure in the expression where it is declared.",
155+
"code": {
156+
"code": "redundant_closure_call",
157+
"explanation": null
158+
},
159+
"level": "warning",
160+
"spans": [
161+
{
162+
"file_name": "./tests/fixtures/redundant_closure_call.rs",
163+
"byte_start": 85,
164+
"byte_end": 95,
165+
"line_start": 8,
166+
"line_end": 8,
167+
"column_start": 13,
168+
"column_end": 23,
169+
"is_primary": true,
170+
"text": [
171+
{
172+
"text": " let c = (|| \"x\")();",
173+
"highlight_start": 13,
174+
"highlight_end": 23
175+
}
176+
],
177+
"label": null,
178+
"suggested_replacement": null,
179+
"expansion": null
180+
}
181+
],
182+
"children": [
183+
{
184+
"message": "Try doing something like: ",
185+
"code": null,
186+
"level": "help",
187+
"spans": [
188+
{
189+
"file_name": "./tests/fixtures/redundant_closure_call.rs",
190+
"byte_start": 85,
191+
"byte_end": 95,
192+
"line_start": 8,
193+
"line_end": 8,
194+
"column_start": 13,
195+
"column_end": 23,
196+
"is_primary": true,
197+
"text": [
198+
{
199+
"text": " let c = (|| \"x\")();",
200+
"highlight_start": 13,
201+
"highlight_end": 23
202+
}
203+
],
204+
"label": null,
205+
"suggested_replacement": "\"x\"",
206+
"expansion": null
207+
}
208+
],
209+
"children": [],
210+
"rendered": null
211+
}
212+
],
213+
"rendered": "warning: Try not to call a closure in the expression where it is declared.\n --> ./tests/fixtures/redundant_closure_call.rs:8:13\n |\n8 | let c = (|| \"x\")();\n | ^^^^^^^^^^ help: Try doing something like: : `\"x\"`\n\n"
214+
}
215+
{
216+
"message": "unused variable: `a`",
217+
"code": {
218+
"code": "unused_variables",
219+
"explanation": null
220+
},
221+
"level": "warning",
222+
"spans": [
223+
{
224+
"file_name": "./tests/fixtures/redundant_closure_call.rs",
225+
"byte_start": 20,
226+
"byte_end": 21,
227+
"line_start": 2,
228+
"line_end": 2,
229+
"column_start": 9,
230+
"column_end": 10,
231+
"is_primary": true,
232+
"text": [
233+
{
234+
"text": " let a = (|| 42)();",
235+
"highlight_start": 9,
236+
"highlight_end": 10
237+
}
238+
],
239+
"label": null,
240+
"suggested_replacement": null,
241+
"expansion": null
242+
}
243+
],
244+
"children": [
245+
{
246+
"message": "#[warn(unused_variables)] on by default",
247+
"code": null,
248+
"level": "note",
249+
"spans": [],
250+
"children": [],
251+
"rendered": null
252+
},
253+
{
254+
"message": "to avoid this warning, consider using `_a` instead",
255+
"code": null,
256+
"level": "note",
257+
"spans": [],
258+
"children": [],
259+
"rendered": null
260+
}
261+
],
262+
"rendered": "warning: unused variable: `a`\n --> ./tests/fixtures/redundant_closure_call.rs:2:9\n |\n2 | let a = (|| 42)();\n | ^\n |\n = note: #[warn(unused_variables)] on by default\n = note: to avoid this warning, consider using `_a` instead\n\n"
263+
}
264+
{
265+
"message": "unused variable: `b`",
266+
"code": {
267+
"code": "unused_variables",
268+
"explanation": null
269+
},
270+
"level": "warning",
271+
"spans": [
272+
{
273+
"file_name": "./tests/fixtures/redundant_closure_call.rs",
274+
"byte_start": 44,
275+
"byte_end": 45,
276+
"line_start": 4,
277+
"line_end": 4,
278+
"column_start": 9,
279+
"column_end": 10,
280+
"is_primary": true,
281+
"text": [
282+
{
283+
"text": " let b = (||",
284+
"highlight_start": 9,
285+
"highlight_end": 10
286+
}
287+
],
288+
"label": null,
289+
"suggested_replacement": null,
290+
"expansion": null
291+
}
292+
],
293+
"children": [
294+
{
295+
"message": "to avoid this warning, consider using `_b` instead",
296+
"code": null,
297+
"level": "note",
298+
"spans": [],
299+
"children": [],
300+
"rendered": null
301+
}
302+
],
303+
"rendered": "warning: unused variable: `b`\n --> ./tests/fixtures/redundant_closure_call.rs:4:9\n |\n4 | let b = (||\n | ^\n |\n = note: to avoid this warning, consider using `_b` instead\n\n"
304+
}
305+
{
306+
"message": "unused variable: `c`",
307+
"code": {
308+
"code": "unused_variables",
309+
"explanation": null
310+
},
311+
"level": "warning",
312+
"spans": [
313+
{
314+
"file_name": "./tests/fixtures/redundant_closure_call.rs",
315+
"byte_start": 81,
316+
"byte_end": 82,
317+
"line_start": 8,
318+
"line_end": 8,
319+
"column_start": 9,
320+
"column_end": 10,
321+
"is_primary": true,
322+
"text": [
323+
{
324+
"text": " let c = (|| \"x\")();",
325+
"highlight_start": 9,
326+
"highlight_end": 10
327+
}
328+
],
329+
"label": null,
330+
"suggested_replacement": null,
331+
"expansion": null
332+
}
333+
],
334+
"children": [
335+
{
336+
"message": "to avoid this warning, consider using `_c` instead",
337+
"code": null,
338+
"level": "note",
339+
"spans": [],
340+
"children": [],
341+
"rendered": null
342+
}
343+
],
344+
"rendered": "warning: unused variable: `c`\n --> ./tests/fixtures/redundant_closure_call.rs:8:9\n |\n8 | let c = (|| \"x\")();\n | ^\n |\n = note: to avoid this warning, consider using `_c` instead\n\n"
345+
}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
fn main() {
2+
let a = (|| 42)();
3+
4+
let b = (||
5+
42
6+
)();
7+
8+
let c = (|| "x")();
9+
}

0 commit comments

Comments
 (0)