From 78ea25d48fa1316e19dd2429859a750684322995 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Kijewski?= Date: Mon, 16 Dec 2024 19:27:48 +0100 Subject: [PATCH] derive: use `file_info` in `find_template` --- rinja_derive/src/config.rs | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/rinja_derive/src/config.rs b/rinja_derive/src/config.rs index 6bfa17bcd..9c45b6e3b 100644 --- a/rinja_derive/src/config.rs +++ b/rinja_derive/src/config.rs @@ -182,38 +182,32 @@ impl Config { start_at: Option<&Path>, file_info: Option>, ) -> Result, CompileError> { - fn _find_template(config: &Config, path: &str, start_at: Option<&Path>) -> Option { + let path = 'find_path: { if let Some(root) = start_at { let relative = root.with_file_name(path); if relative.exists() { - return Some(relative); + break 'find_path relative; } } - - for dir in &config.dirs { + for dir in &self.dirs { let rooted = dir.join(path); if rooted.exists() { - return Some(rooted); + break 'find_path rooted; } } - - None - } - - let Some(path) = _find_template(self, path, start_at) else { return Err(CompileError::new( - format!( + format_args!( "template {:?} not found in directories {:?}", - path, self.dirs + path, self.dirs, ), file_info, )); }; match path.canonicalize() { - Ok(p) => Ok(p.into()), - Err(e) => Err(CompileError::no_file_info( - format_args!("could not canonicalize path {path:?}: {e}"), - None, + Ok(path) => Ok(path.into()), + Err(err) => Err(CompileError::new( + format_args!("could not canonicalize path {path:?}: {err}"), + file_info, )), } }