mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-07 20:58:39 +00:00
Remove except
in suspicious_else_formatting
This was causing two different ICEs in #3741. The first was fixed in #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.
This commit is contained in:
parent
d516925ec8
commit
96c34e85c4
@ -165,23 +165,23 @@ fn check_else(cx: &EarlyContext<'_>, expr: &ast::Expr) {
|
|||||||
// the snippet should look like " else \n " with maybe comments anywhere
|
// the snippet should look like " else \n " with maybe comments anywhere
|
||||||
// it’s bad when there is a ‘\n’ after the “else”
|
// it’s bad when there is a ‘\n’ after the “else”
|
||||||
if let Some(else_snippet) = snippet_opt(cx, else_span) {
|
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') {
|
span_note_and_lint(
|
||||||
let else_desc = if unsugar_if(else_).is_some() { "if" } else { "{..}" };
|
cx,
|
||||||
|
SUSPICIOUS_ELSE_FORMATTING,
|
||||||
span_note_and_lint(
|
else_span,
|
||||||
cx,
|
&format!("this is an `else {}` but the formatting might hide it", else_desc),
|
||||||
SUSPICIOUS_ELSE_FORMATTING,
|
else_span,
|
||||||
else_span,
|
&format!(
|
||||||
&format!("this is an `else {}` but the formatting might hide it", else_desc),
|
"to remove this lint, remove the `else` or remove the new line between \
|
||||||
else_span,
|
`else` and `{}`",
|
||||||
&format!(
|
else_desc,
|
||||||
"to remove this lint, remove the `else` or remove the new line between \
|
),
|
||||||
`else` and `{}`",
|
);
|
||||||
else_desc,
|
}
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user