Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If the only path is a loop then counted as the shortest path. #12977

Merged
merged 2 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/cargo/util/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,12 @@ impl<'s, N: Eq + Ord + Clone + 's, E: Default + Clone + 's> Graph<N, E> {
));
}
let last = result.last().unwrap().0;
// fixme: this may sometimes be wrong when there are cycles.
epage marked this conversation as resolved.
Show resolved Hide resolved
if !fn_edge(&self, last).next().is_none() {
let set: Vec<_> = result.iter().map(|(k, _)| k).collect();
if !fn_edge(&self, last)
epage marked this conversation as resolved.
Show resolved Hide resolved
.filter(|(e, _)| !set.contains(&e))
.next()
.is_none()
{
self.print_for_test();
unreachable!("The last element in the path should not have outgoing edges");
}
Expand All @@ -188,6 +192,14 @@ fn path_to_case() {
);
}

#[test]
fn path_to_self() {
// Extracted from #12941
let mut new: Graph<i32, ()> = Graph::new();
new.link(0, 0);
assert_eq!(new.path_to_bottom(&0), vec![(&0, None)]);
}

impl<N: Eq + Ord + Clone, E: Default + Clone> Default for Graph<N, E> {
fn default() -> Graph<N, E> {
Graph::new()
Expand Down
28 changes: 28 additions & 0 deletions tests/testsuite/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3555,6 +3555,34 @@ fn cyclic_dev() {
p.cargo("test --workspace").run();
}

#[cargo_test]
fn cyclical_dep_with_missing_feature() {
// Checks for error handling when a cyclical dev-dependency specify a
// feature that doesn't exist.
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"

[dev-dependencies]
foo = { path = ".", features = ["missing"] }
"#,
)
.file("src/lib.rs", "")
.build();
p.cargo("check")
.with_status(101)
.with_stderr(
"thread 'main' panicked at src/cargo/util/graph.rs:149:20:
the only path was a cycle, no dependency graph has this shape
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace",
)
.run();
}

#[cargo_test]
fn publish_a_crate_without_tests() {
Package::new("testless", "0.1.0")
Expand Down