diff --git a/rinja_derive/src/config.rs b/rinja_derive/src/config.rs index 398971c4..1e631f0d 100644 --- a/rinja_derive/src/config.rs +++ b/rinja_derive/src/config.rs @@ -298,38 +298,32 @@ where vals.iter().map(|s| s.to_string()).collect() } -#[allow(clippy::match_wild_err_arm)] pub(crate) fn get_template_source( tpl_path: &Path, import_from: Option<(&Rc, &str, &str)>, -) -> std::result::Result { - match fs::read_to_string(tpl_path) { - Err(_) => { - if let Some((node_file, file_source, node_source)) = import_from { - Err(CompileError::new( - format!( - "unable to open template file '{}'", - tpl_path.to_str().unwrap(), - ), - Some(FileInfo::new( - node_file, - Some(file_source), - Some(node_source), - )), - )) - } else { - Err(CompileError::no_file_info(format!( - "unable to open template file '{}'", - tpl_path.to_str().unwrap() - ))) - } - } - Ok(mut source) => { - if source.ends_with('\n') { - let _ = source.pop(); - } - Ok(source) +) -> Result { + if let Ok(mut source) = fs::read_to_string(tpl_path) { + if source.ends_with('\n') { + let _ = source.pop(); } + Ok(source) + } else if let Some((node_file, file_source, node_source)) = import_from { + Err(CompileError::new( + format!( + "unable to open template file '{}'", + tpl_path.to_str().unwrap(), + ), + Some(FileInfo::new( + node_file, + Some(file_source), + Some(node_source), + )), + )) + } else { + Err(CompileError::no_file_info(format!( + "unable to open template file '{}'", + tpl_path.to_str().unwrap(), + ))) } }