This repository has been archived by the owner on Nov 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for redundant_closure_call lint
- Loading branch information
Showing
3 changed files
with
361 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
fn main() { | ||
let a = 42; | ||
|
||
let b = 42; | ||
|
||
let c = "x"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,345 @@ | ||
{ | ||
"message": "Try not to call a closure in the expression where it is declared.", | ||
"code": { | ||
"code": "redundant_closure_call", | ||
"explanation": null | ||
}, | ||
"level": "warning", | ||
"spans": [ | ||
{ | ||
"file_name": "./tests/fixtures/redundant_closure_call.rs", | ||
"byte_start": 24, | ||
"byte_end": 33, | ||
"line_start": 2, | ||
"line_end": 2, | ||
"column_start": 13, | ||
"column_end": 22, | ||
"is_primary": true, | ||
"text": [ | ||
{ | ||
"text": " let a = (|| 42)();", | ||
"highlight_start": 13, | ||
"highlight_end": 22 | ||
} | ||
], | ||
"label": null, | ||
"suggested_replacement": null, | ||
"expansion": null | ||
} | ||
], | ||
"children": [ | ||
{ | ||
"message": "#[warn(redundant_closure_call)] on by default", | ||
"code": null, | ||
"level": "note", | ||
"spans": [], | ||
"children": [], | ||
"rendered": null | ||
}, | ||
{ | ||
"message": "Try doing something like: ", | ||
"code": null, | ||
"level": "help", | ||
"spans": [ | ||
{ | ||
"file_name": "./tests/fixtures/redundant_closure_call.rs", | ||
"byte_start": 24, | ||
"byte_end": 33, | ||
"line_start": 2, | ||
"line_end": 2, | ||
"column_start": 13, | ||
"column_end": 22, | ||
"is_primary": true, | ||
"text": [ | ||
{ | ||
"text": " let a = (|| 42)();", | ||
"highlight_start": 13, | ||
"highlight_end": 22 | ||
} | ||
], | ||
"label": null, | ||
"suggested_replacement": "42", | ||
"expansion": null | ||
} | ||
], | ||
"children": [], | ||
"rendered": null | ||
} | ||
], | ||
"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" | ||
} | ||
{ | ||
"message": "Try not to call a closure in the expression where it is declared.", | ||
"code": { | ||
"code": "redundant_closure_call", | ||
"explanation": null | ||
}, | ||
"level": "warning", | ||
"spans": [ | ||
{ | ||
"file_name": "./tests/fixtures/redundant_closure_call.rs", | ||
"byte_start": 48, | ||
"byte_end": 70, | ||
"line_start": 4, | ||
"line_end": 6, | ||
"column_start": 13, | ||
"column_end": 8, | ||
"is_primary": true, | ||
"text": [ | ||
{ | ||
"text": " let b = (||", | ||
"highlight_start": 13, | ||
"highlight_end": 16 | ||
}, | ||
{ | ||
"text": " 42", | ||
"highlight_start": 1, | ||
"highlight_end": 11 | ||
}, | ||
{ | ||
"text": " )();", | ||
"highlight_start": 1, | ||
"highlight_end": 8 | ||
} | ||
], | ||
"label": null, | ||
"suggested_replacement": null, | ||
"expansion": null | ||
} | ||
], | ||
"children": [ | ||
{ | ||
"message": "Try doing something like: ", | ||
"code": null, | ||
"level": "help", | ||
"spans": [ | ||
{ | ||
"file_name": "./tests/fixtures/redundant_closure_call.rs", | ||
"byte_start": 48, | ||
"byte_end": 70, | ||
"line_start": 4, | ||
"line_end": 6, | ||
"column_start": 13, | ||
"column_end": 8, | ||
"is_primary": true, | ||
"text": [ | ||
{ | ||
"text": " let b = (||", | ||
"highlight_start": 13, | ||
"highlight_end": 16 | ||
}, | ||
{ | ||
"text": " 42", | ||
"highlight_start": 1, | ||
"highlight_end": 11 | ||
}, | ||
{ | ||
"text": " )();", | ||
"highlight_start": 1, | ||
"highlight_end": 8 | ||
} | ||
], | ||
"label": null, | ||
"suggested_replacement": "42", | ||
"expansion": null | ||
} | ||
], | ||
"children": [], | ||
"rendered": null | ||
} | ||
], | ||
"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" | ||
} | ||
{ | ||
"message": "Try not to call a closure in the expression where it is declared.", | ||
"code": { | ||
"code": "redundant_closure_call", | ||
"explanation": null | ||
}, | ||
"level": "warning", | ||
"spans": [ | ||
{ | ||
"file_name": "./tests/fixtures/redundant_closure_call.rs", | ||
"byte_start": 85, | ||
"byte_end": 95, | ||
"line_start": 8, | ||
"line_end": 8, | ||
"column_start": 13, | ||
"column_end": 23, | ||
"is_primary": true, | ||
"text": [ | ||
{ | ||
"text": " let c = (|| \"x\")();", | ||
"highlight_start": 13, | ||
"highlight_end": 23 | ||
} | ||
], | ||
"label": null, | ||
"suggested_replacement": null, | ||
"expansion": null | ||
} | ||
], | ||
"children": [ | ||
{ | ||
"message": "Try doing something like: ", | ||
"code": null, | ||
"level": "help", | ||
"spans": [ | ||
{ | ||
"file_name": "./tests/fixtures/redundant_closure_call.rs", | ||
"byte_start": 85, | ||
"byte_end": 95, | ||
"line_start": 8, | ||
"line_end": 8, | ||
"column_start": 13, | ||
"column_end": 23, | ||
"is_primary": true, | ||
"text": [ | ||
{ | ||
"text": " let c = (|| \"x\")();", | ||
"highlight_start": 13, | ||
"highlight_end": 23 | ||
} | ||
], | ||
"label": null, | ||
"suggested_replacement": "\"x\"", | ||
"expansion": null | ||
} | ||
], | ||
"children": [], | ||
"rendered": null | ||
} | ||
], | ||
"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" | ||
} | ||
{ | ||
"message": "unused variable: `a`", | ||
"code": { | ||
"code": "unused_variables", | ||
"explanation": null | ||
}, | ||
"level": "warning", | ||
"spans": [ | ||
{ | ||
"file_name": "./tests/fixtures/redundant_closure_call.rs", | ||
"byte_start": 20, | ||
"byte_end": 21, | ||
"line_start": 2, | ||
"line_end": 2, | ||
"column_start": 9, | ||
"column_end": 10, | ||
"is_primary": true, | ||
"text": [ | ||
{ | ||
"text": " let a = (|| 42)();", | ||
"highlight_start": 9, | ||
"highlight_end": 10 | ||
} | ||
], | ||
"label": null, | ||
"suggested_replacement": null, | ||
"expansion": null | ||
} | ||
], | ||
"children": [ | ||
{ | ||
"message": "#[warn(unused_variables)] on by default", | ||
"code": null, | ||
"level": "note", | ||
"spans": [], | ||
"children": [], | ||
"rendered": null | ||
}, | ||
{ | ||
"message": "to avoid this warning, consider using `_a` instead", | ||
"code": null, | ||
"level": "note", | ||
"spans": [], | ||
"children": [], | ||
"rendered": null | ||
} | ||
], | ||
"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" | ||
} | ||
{ | ||
"message": "unused variable: `b`", | ||
"code": { | ||
"code": "unused_variables", | ||
"explanation": null | ||
}, | ||
"level": "warning", | ||
"spans": [ | ||
{ | ||
"file_name": "./tests/fixtures/redundant_closure_call.rs", | ||
"byte_start": 44, | ||
"byte_end": 45, | ||
"line_start": 4, | ||
"line_end": 4, | ||
"column_start": 9, | ||
"column_end": 10, | ||
"is_primary": true, | ||
"text": [ | ||
{ | ||
"text": " let b = (||", | ||
"highlight_start": 9, | ||
"highlight_end": 10 | ||
} | ||
], | ||
"label": null, | ||
"suggested_replacement": null, | ||
"expansion": null | ||
} | ||
], | ||
"children": [ | ||
{ | ||
"message": "to avoid this warning, consider using `_b` instead", | ||
"code": null, | ||
"level": "note", | ||
"spans": [], | ||
"children": [], | ||
"rendered": null | ||
} | ||
], | ||
"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" | ||
} | ||
{ | ||
"message": "unused variable: `c`", | ||
"code": { | ||
"code": "unused_variables", | ||
"explanation": null | ||
}, | ||
"level": "warning", | ||
"spans": [ | ||
{ | ||
"file_name": "./tests/fixtures/redundant_closure_call.rs", | ||
"byte_start": 81, | ||
"byte_end": 82, | ||
"line_start": 8, | ||
"line_end": 8, | ||
"column_start": 9, | ||
"column_end": 10, | ||
"is_primary": true, | ||
"text": [ | ||
{ | ||
"text": " let c = (|| \"x\")();", | ||
"highlight_start": 9, | ||
"highlight_end": 10 | ||
} | ||
], | ||
"label": null, | ||
"suggested_replacement": null, | ||
"expansion": null | ||
} | ||
], | ||
"children": [ | ||
{ | ||
"message": "to avoid this warning, consider using `_c` instead", | ||
"code": null, | ||
"level": "note", | ||
"spans": [], | ||
"children": [], | ||
"rendered": null | ||
} | ||
], | ||
"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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
fn main() { | ||
let a = (|| 42)(); | ||
|
||
let b = (|| | ||
42 | ||
)(); | ||
|
||
let c = (|| "x")(); | ||
} |