From 2284b7a8858e82873fa0c76be61967366bbcbf6c Mon Sep 17 00:00:00 2001 From: Jacob Finkelman Date: Tue, 19 Sep 2023 20:22:13 +0000 Subject: [PATCH] added assertions to make sure the path code is correct in graphs --- src/cargo/util/graph.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/cargo/util/graph.rs b/src/cargo/util/graph.rs index ff4018201..b3214ee86 100644 --- a/src/cargo/util/graph.rs +++ b/src/cargo/util/graph.rs @@ -106,6 +106,18 @@ impl Graph { result.push(p); pkg = p.0; } + #[cfg(debug_assertions)] + { + for x in result.windows(2) { + let [(n1, _), (n2, Some(e12))] = x else { + unreachable!() + }; + assert!(std::ptr::eq(self.edge(n1, n2).unwrap(), *e12)); + } + let last = result.last().unwrap().0; + // fixme: this may be wrong when there are cycles, but we dont have them in tests. + assert!(!self.nodes.contains_key(last)); + } result } @@ -134,6 +146,21 @@ impl Graph { result.push(p); pkg = p.0; } + #[cfg(debug_assertions)] + { + for x in result.windows(2) { + let [(n2, _), (n1, Some(e12))] = x else { + unreachable!() + }; + assert!(std::ptr::eq(self.edge(n1, n2).unwrap(), *e12)); + } + let last = result.last().unwrap().0; + // fixme: this may be wrong when there are cycles, but we dont have them in tests. + assert!(!self + .nodes + .iter() + .any(|(_, adjacent)| adjacent.contains_key(last))); + } result } }