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

Commit

Permalink
Add test for redundant_closure_call lint
Browse files Browse the repository at this point in the history
  • Loading branch information
killercup committed Jan 18, 2018
1 parent 0adacf8 commit 9121d77
Show file tree
Hide file tree
Showing 3 changed files with 361 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/fixtures/redundant_closure_call.fixed.rs
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";
}
345 changes: 345 additions & 0 deletions tests/fixtures/redundant_closure_call.json
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"
}
9 changes: 9 additions & 0 deletions tests/fixtures/redundant_closure_call.rs
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")();
}

0 comments on commit 9121d77

Please sign in to comment.