From de08a762e551c281d7d40b743bbda89923744ebb Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 2 Aug 2026 17:48:06 -0700 Subject: [PATCH 1/2] Collect more path dependencies from dev deps and target deps --- src/run.rs | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/run.rs b/src/run.rs index 9f8f689..26f0fd4 100644 --- a/src/run.rs +++ b/src/run.rs @@ -130,22 +130,27 @@ impl Runner { let mut features = features::find(); - let path_dependencies = source_manifest - .dependencies - .iter() - .filter_map(|(name, dep)| { - let path = dep.path.as_ref()?; - if packages.iter().any(|p| &p.name == name) { + let mut path_dependencies = Vec::new(); + let mut collect_path_dependencies = |dependencies: &Map| { + for (name, dep) in dependencies { + if let Some(path) = &dep.path // Skip path dependencies coming from the workspace itself - None - } else { - Some(PathDependency { + && !packages.iter().any(|p| &p.name == name) + && let Ok(normalized_path) = path.canonicalize() + { + path_dependencies.push(PathDependency { name: name.clone(), - normalized_path: path.canonicalize().ok()?, - }) + normalized_path, + }); } - }) - .collect(); + } + }; + collect_path_dependencies(&source_manifest.dependencies); + collect_path_dependencies(&source_manifest.dev_dependencies); + for target in source_manifest.target.values() { + collect_path_dependencies(&target.dependencies); + collect_path_dependencies(&target.dev_dependencies); + } let crate_name = &source_manifest.package.name; let project_dir = path!(target_dir / "tests" / "trybuild" / crate_name /); From 527ecc9557b726fcf5f2ba4505a97436196fb436 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 2 Aug 2026 18:09:47 -0700 Subject: [PATCH 2/2] Accept old snapshots without more path dependencies --- fuzz/fuzz_targets/normalize.rs | 4 +++- src/normalize.rs | 28 +++++++++++++---------- src/run.rs | 42 ++++++++++++++++++++++------------ src/tests.rs | 1 + 4 files changed, 47 insertions(+), 28 deletions(-) diff --git a/fuzz/fuzz_targets/normalize.rs b/fuzz/fuzz_targets/normalize.rs index 4db4c18..b9c347b 100644 --- a/fuzz/fuzz_targets/normalize.rs +++ b/fuzz/fuzz_targets/normalize.rs @@ -9,7 +9,7 @@ mod directory; mod normalize; use crate::directory::Directory; -use crate::normalize::Context; +use crate::normalize::{Context, Normalization}; use crate::run::PathDependency; use libfuzzer_sys::fuzz_target; use std::path::Path; @@ -18,6 +18,7 @@ mod run { pub struct PathDependency { pub name: String, pub normalized_path: super::Directory, + pub normalization: super::Normalization, } } @@ -34,6 +35,7 @@ fuzz_target!(|string: &str| { path_dependencies: &[PathDependency { name: String::from("diesel"), normalized_path: Directory::new("/home/user/documents/rust/diesel/diesel"), + normalization: Normalization::PathDependencies, }], }; let _ = normalize::diagnostics(string, context); diff --git a/src/normalize.rs b/src/normalize.rs index b25f1a1..fbfd4d0 100644 --- a/src/normalize.rs +++ b/src/normalize.rs @@ -21,8 +21,8 @@ pub(crate) struct Context<'a> { macro_rules! normalizations { ($($name:ident,)*) => { - #[derive(PartialOrd, PartialEq, Copy, Clone)] - enum Normalization { + #[derive(PartialOrd, PartialEq, Copy, Clone, Debug)] + pub(crate) enum Normalization { $($name,)* } @@ -65,6 +65,7 @@ normalizations! { HeadingNote, UnindentSuggestion, CustomRegistry, + MorePathDependencies, // New normalization steps are to be inserted here at the end so that any // snapshots saved before your normalization change remain passing. } @@ -265,16 +266,19 @@ impl<'a> Filter<'a> { } if self.normalization >= PathDependencies && !other_crate { for path_dep in self.context.path_dependencies { - let path_dep_pat = path_dep - .normalized_path - .to_string_lossy() - .to_ascii_lowercase() - .replace('\\', "/"); - if let Some(i) = line_lower.find(&path_dep_pat) { - let var = format!("${}", path_dep.name.to_uppercase().replace('-', "_")); - line.replace_range(i..i + path_dep_pat.len() - 1, &var); - other_crate = true; - break; + if self.normalization >= path_dep.normalization { + let path_dep_pat = path_dep + .normalized_path + .to_string_lossy() + .to_ascii_lowercase() + .replace('\\', "/"); + if let Some(i) = line_lower.find(&path_dep_pat) { + let var = + format!("${}", path_dep.name.to_uppercase().replace('-', "_")); + line.replace_range(i..i + path_dep_pat.len() - 1, &var); + other_crate = true; + break; + } } } } diff --git a/src/run.rs b/src/run.rs index 26f0fd4..11c1593 100644 --- a/src/run.rs +++ b/src/run.rs @@ -7,7 +7,7 @@ use crate::expand::{ExpandedTest, expand_globs}; use crate::flock::Lock; use crate::manifest::{Bin, Manifest, Name, Package, Workspace}; use crate::message::{self, Fail, Warn}; -use crate::normalize::{self, Context, Variations}; +use crate::normalize::{self, Context, Normalization, Variations}; use crate::path::CanonicalPath; use crate::{Expected, Runner, Test, features}; use serde_derive::Deserialize; @@ -39,6 +39,7 @@ pub(crate) struct Project { pub(crate) struct PathDependency { pub name: String, pub normalized_path: Directory, + pub normalization: Normalization, } struct Report { @@ -131,25 +132,36 @@ impl Runner { let mut features = features::find(); let mut path_dependencies = Vec::new(); - let mut collect_path_dependencies = |dependencies: &Map| { - for (name, dep) in dependencies { - if let Some(path) = &dep.path + let mut collect_path_dependencies = + |dependencies: &Map, normalization: Normalization| { + for (name, dep) in dependencies { + if let Some(path) = &dep.path // Skip path dependencies coming from the workspace itself && !packages.iter().any(|p| &p.name == name) && let Ok(normalized_path) = path.canonicalize() - { - path_dependencies.push(PathDependency { - name: name.clone(), - normalized_path, - }); + { + path_dependencies.push(PathDependency { + name: name.clone(), + normalized_path, + normalization, + }); + } } - } - }; - collect_path_dependencies(&source_manifest.dependencies); - collect_path_dependencies(&source_manifest.dev_dependencies); + }; + collect_path_dependencies( + &source_manifest.dependencies, + Normalization::PathDependencies, + ); + collect_path_dependencies( + &source_manifest.dev_dependencies, + Normalization::MorePathDependencies, + ); for target in source_manifest.target.values() { - collect_path_dependencies(&target.dependencies); - collect_path_dependencies(&target.dev_dependencies); + collect_path_dependencies(&target.dependencies, Normalization::MorePathDependencies); + collect_path_dependencies( + &target.dev_dependencies, + Normalization::MorePathDependencies, + ); } let crate_name = &source_manifest.package.name; diff --git a/src/tests.rs b/src/tests.rs index 812c8a6..0138887 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -18,6 +18,7 @@ macro_rules! test_normalize { path_dependencies: &[crate::run::PathDependency { name: String::from("diesel"), normalized_path: crate::directory::Directory::new("/home/user/documents/rust/diesel/diesel"), + normalization: crate::normalize::Normalization::PathDependencies, }], }; let original = $original;