Use span_suggestion
in loops lints
This commit is contained in:
parent
7b1a0a9434
commit
783437eef0
13
src/loops.rs
13
src/loops.rs
@ -271,14 +271,17 @@ impl LateLintPass for LoopsPass {
|
||||
} else {
|
||||
expr_block(cx, &arms[0].body, Some(other_stuff.join("\n ")), "..")
|
||||
};
|
||||
span_help_and_lint(cx,
|
||||
span_lint_and_then(cx,
|
||||
WHILE_LET_LOOP,
|
||||
expr.span,
|
||||
"this loop could be written as a `while let` loop",
|
||||
&format!("try\nwhile let {} = {} {}",
|
||||
snippet(cx, arms[0].pats[0].span, ".."),
|
||||
snippet(cx, matchexpr.span, ".."),
|
||||
loop_body));
|
||||
|db| {
|
||||
let sug = format!("while let {} = {} {}",
|
||||
snippet(cx, arms[0].pats[0].span, ".."),
|
||||
snippet(cx, matchexpr.span, ".."),
|
||||
loop_body);
|
||||
db.span_suggestion(expr.span, "try", sug);
|
||||
});
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
|
@ -6,7 +6,10 @@
|
||||
|
||||
fn main() {
|
||||
let y = Some(true);
|
||||
loop { //~ERROR
|
||||
loop {
|
||||
//~^ERROR this loop could be written as a `while let` loop
|
||||
//~|HELP try
|
||||
//~|SUGGESTION while let Some(_x) = y {
|
||||
if let Some(_x) = y {
|
||||
let _v = 1;
|
||||
} else {
|
||||
@ -19,13 +22,19 @@ fn main() {
|
||||
}
|
||||
break;
|
||||
}
|
||||
loop { //~ERROR
|
||||
loop {
|
||||
//~^ERROR this loop could be written as a `while let` loop
|
||||
//~|HELP try
|
||||
//~|SUGGESTION while let Some(_x) = y {
|
||||
match y {
|
||||
Some(_x) => true,
|
||||
None => break
|
||||
};
|
||||
}
|
||||
loop { //~ERROR
|
||||
loop {
|
||||
//~^ERROR this loop could be written as a `while let` loop
|
||||
//~|HELP try
|
||||
//~|SUGGESTION while let Some(x) = y {
|
||||
let x = match y {
|
||||
Some(x) => x,
|
||||
None => break
|
||||
@ -33,7 +42,10 @@ fn main() {
|
||||
let _x = x;
|
||||
let _str = "foo";
|
||||
}
|
||||
loop { //~ERROR
|
||||
loop {
|
||||
//~^ERROR this loop could be written as a `while let` loop
|
||||
//~|HELP try
|
||||
//~|SUGGESTION while let Some(x) = y {
|
||||
let x = match y {
|
||||
Some(x) => x,
|
||||
None => break,
|
||||
|
Loading…
x
Reference in New Issue
Block a user