about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--clippy_lints/src/formatting.rs32
1 files changed, 16 insertions, 16 deletions
diff --git a/clippy_lints/src/formatting.rs b/clippy_lints/src/formatting.rs
index 08376bc49d2..9a58d414ae4 100644
--- a/clippy_lints/src/formatting.rs
+++ b/clippy_lints/src/formatting.rs
@@ -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,
+                            ),
+                        );
+                    }
                 }
             }
         }