Skip to content

Commit 2284b7a

Browse files
committed
added assertions to make sure the path code is correct in graphs
1 parent 245e69c commit 2284b7a

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/cargo/util/graph.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,18 @@ impl<N: Eq + Ord + Clone, E: Default + Clone> Graph<N, E> {
106106
result.push(p);
107107
pkg = p.0;
108108
}
109+
#[cfg(debug_assertions)]
110+
{
111+
for x in result.windows(2) {
112+
let [(n1, _), (n2, Some(e12))] = x else {
113+
unreachable!()
114+
};
115+
assert!(std::ptr::eq(self.edge(n1, n2).unwrap(), *e12));
116+
}
117+
let last = result.last().unwrap().0;
118+
// fixme: this may be wrong when there are cycles, but we dont have them in tests.
119+
assert!(!self.nodes.contains_key(last));
120+
}
109121
result
110122
}
111123

@@ -134,6 +146,21 @@ impl<N: Eq + Ord + Clone, E: Default + Clone> Graph<N, E> {
134146
result.push(p);
135147
pkg = p.0;
136148
}
149+
#[cfg(debug_assertions)]
150+
{
151+
for x in result.windows(2) {
152+
let [(n2, _), (n1, Some(e12))] = x else {
153+
unreachable!()
154+
};
155+
assert!(std::ptr::eq(self.edge(n1, n2).unwrap(), *e12));
156+
}
157+
let last = result.last().unwrap().0;
158+
// fixme: this may be wrong when there are cycles, but we dont have them in tests.
159+
assert!(!self
160+
.nodes
161+
.iter()
162+
.any(|(_, adjacent)| adjacent.contains_key(last)));
163+
}
137164
result
138165
}
139166
}

0 commit comments

Comments
 (0)