diff --git a/src/actions/hover.rs b/src/actions/hover.rs index 2e5d63bc51b..da46ae7507b 100644 --- a/src/actions/hover.rs +++ b/src/actions/hover.rs @@ -782,15 +782,19 @@ fn format_object(rustfmt: Rustfmt, fmt_config: &FmtConfig, the_type: String) -> format!("{}{{}}", trimmed) }; - let formatted = match rustfmt.format(object.clone(), config) { - Ok(lines) => match lines.rfind('{') { + let formatted = match std::panic::catch_unwind(|| rustfmt.format(object.clone(), config)) { + Ok(Ok(lines)) => match lines.rfind('{') { Some(pos) => lines[0..pos].into(), None => lines, }, - Err(e) => { + Ok(Err(e)) => { error!("format_object: error: {:?}, input: {:?}", e, object); trimmed.to_string() } + Err(_) => { + error!("format_object: rustfmt panicked on input: {:?}", object); + trimmed.to_string() + } }; // If it's a tuple, remove the trailing ';' and hide non-pub components @@ -2035,6 +2039,7 @@ pub mod test { #[test] fn test_tooltip() -> Result<(), Box> { + let _ = env_logger::try_init(); use self::test::{LineOutput, Test, TooltipTestHarness}; use std::env; @@ -2125,6 +2130,7 @@ pub mod test { #[test] #[ignore] fn test_tooltip_std() -> Result<(), Box> { + let _ = env_logger::try_init(); use self::test::{LineOutput, Test, TooltipTestHarness}; use std::env;