Skip to content

Commit

Permalink
Remove except in suspicious_else_formatting
Browse files Browse the repository at this point in the history
This was causing two different ICEs in rust-lang#3741.
The first was fixed in rust-lang#3925.

The second one is fixed with this commit: We just don't `expect`
anymore. If the snippet doesn't contain an `else`, we stop emitting the
lint because it's not a suspiciously formatted else anyway.
  • Loading branch information
phansch committed Apr 14, 2019
1 parent d516925 commit 96c34e8
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions clippy_lints/src/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,23 +165,23 @@ fn check_else(cx: &EarlyContext<'_>, expr: &ast::Expr) {
// the snippet should look like " else \n " with maybe comments anywhere
// it’s bad when there is a ‘\n’ after the “else”
if let Some(else_snippet) = snippet_opt(cx, else_span) {
let else_pos = else_snippet.find("else").expect("there must be a `else` here");
if let Some(else_pos) = else_snippet.find("else") {
if else_snippet[else_pos..].contains('\n') {
let else_desc = if unsugar_if(else_).is_some() { "if" } else { "{..}" };

if else_snippet[else_pos..].contains('\n') {
let else_desc = if unsugar_if(else_).is_some() { "if" } else { "{..}" };

span_note_and_lint(
cx,
SUSPICIOUS_ELSE_FORMATTING,
else_span,
&format!("this is an `else {}` but the formatting might hide it", else_desc),
else_span,
&format!(
"to remove this lint, remove the `else` or remove the new line between \
`else` and `{}`",
else_desc,
),
);
span_note_and_lint(
cx,
SUSPICIOUS_ELSE_FORMATTING,
else_span,
&format!("this is an `else {}` but the formatting might hide it", else_desc),
else_span,
&format!(
"to remove this lint, remove the `else` or remove the new line between \
`else` and `{}`",
else_desc,
),
);
}
}
}
}
Expand Down

0 comments on commit 96c34e8

Please sign in to comment.