diff --git a/src/libsyntax/errors/snippet/mod.rs b/src/libsyntax/errors/snippet/mod.rs index ada336b29a4..0c8b4f2046a 100644 --- a/src/libsyntax/errors/snippet/mod.rs +++ b/src/libsyntax/errors/snippet/mod.rs @@ -229,10 +229,9 @@ impl From<(S1, Style, S2, Style, RenderedLineKind)> for RenderedLine impl RenderedLine { fn trim_last(&mut self) { - if !self.text.is_empty() { - let last_text = &mut self.text.last_mut().unwrap().text; - let len = last_text.trim_right().len(); - last_text.truncate(len); + if let Some(last_text) = self.text.last_mut() { + let len = last_text.text.trim_right().len(); + last_text.text.truncate(len); } } }