From 03b487f0f93ac32835149d4c1a0fb420341134f8 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Mon, 10 Aug 2026 16:30:20 +0800 Subject: feat(pathf): enforce pedantic lints and update API ergonomics - Add `#[must_use]` to public constructors and getters - Change `init_with_config` to accept `&PathfinderConfig` instead of owned value - Refactor `map_or_else` and `or_insert_with` for clippy compliance - Add `#![deny(clippy::pedantic)]` and `#![deny(clippy::nursery)]` - Document error cases in public API docs - Simplify duplicated dispatcher_clap analysis logic --- mingling_pathf/src/module_pathf.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'mingling_pathf/src/module_pathf.rs') diff --git a/mingling_pathf/src/module_pathf.rs b/mingling_pathf/src/module_pathf.rs index f0a06d1..ebb7979 100644 --- a/mingling_pathf/src/module_pathf.rs +++ b/mingling_pathf/src/module_pathf.rs @@ -25,11 +25,13 @@ pub struct MappingItem { impl MappingItem { /// Returns the path of the source file (relative to the crate root, with `./` prefix). + #[must_use] pub fn file_path(&self) -> &Path { &self.file_path } /// Returns the effective module path corresponding to this file (e.g., `"crate::foo::bar"`). + #[must_use] pub fn module_path(&self) -> &str { &self.module_path } @@ -50,6 +52,12 @@ pub struct ModulePathMapping { /// Analyzes the module structure of a crate and returns the effective module path for each source file. /// /// `crate_dir` is the crate root directory (i.e., the directory containing `Cargo.toml`). +/// +/// # Errors +/// +/// Returns an error if the `src/` directory does not exist, no entry point file is found, +/// a source file cannot be read or parsed, a child module file cannot be resolved, or +/// an I/O error occurs while traversing the crate directory. pub fn analyze(crate_dir: &Path) -> Result { let src_dir = crate_dir.join("src"); if !src_dir.is_dir() { @@ -121,11 +129,8 @@ impl Context { } fn relative_path(&self, abs: &Path) -> PathBuf { - if let Ok(rel) = abs.strip_prefix(&self.crate_dir) { - PathBuf::from("./").join(rel) - } else { - abs.to_path_buf() - } + abs.strip_prefix(&self.crate_dir) + .map_or_else(|_| abs.to_path_buf(), |rel| PathBuf::from("./").join(rel)) } } @@ -276,7 +281,7 @@ fn collect_reexports(tree: &UseTree, results: &mut Vec) { UseTree::Rename(rename) => { results.push(rename.ident.to_string()); } - _ => {} + UseTree::Glob(_) => {} } } -- cgit