File tree 4 files changed +52
-16
lines changed
4 files changed +52
-16
lines changed Original file line number Diff line number Diff line change @@ -1009,6 +1009,15 @@ fn check_cycles(resolve: &Resolve) -> CargoResult<()> {
1009
1009
for id in resolve. iter ( ) {
1010
1010
let map = graph. entry ( id) . or_insert_with ( BTreeMap :: new) ;
1011
1011
for ( dep_id, listings) in resolve. deps_not_replaced ( id) {
1012
+ // We don't want to allow a package to depend on itself as a path.
1013
+ // See https://github.com/rust-lang/cargo/issues/9518 for more details.
1014
+ if id == dep_id && dep_id. source_id ( ) . is_path ( ) {
1015
+ anyhow:: bail!(
1016
+ "cyclic package dependency: package `{}` depends on itself." ,
1017
+ id,
1018
+ ) ;
1019
+ }
1020
+
1012
1021
let transitive_dep = listings. iter ( ) . find ( |d| d. is_transitive ( ) ) ;
1013
1022
1014
1023
if let Some ( transitive_dep) = transitive_dep. cloned ( ) {
Original file line number Diff line number Diff line change @@ -1660,9 +1660,34 @@ fn self_dependency() {
1660
1660
. with_status ( 101 )
1661
1661
. with_stderr (
1662
1662
"\
1663
- [ERROR] cyclic package dependency: package `test v0.0.0 ([CWD])` depends on itself. Cycle:
1664
- package `test v0.0.0 ([CWD])`
1665
- ... which satisfies path dependency `test` of package `test v0.0.0 ([..])`" ,
1663
+ [ERROR] cyclic package dependency: package `test v0.0.0 ([CWD])` depends on itself.",
1664
+ )
1665
+ . run ( ) ;
1666
+ }
1667
+
1668
+ #[ cargo_test]
1669
+ fn dev_self_dependency ( ) {
1670
+ let p = project ( )
1671
+ . file (
1672
+ "Cargo.toml" ,
1673
+ r#"
1674
+ [project]
1675
+ name = "foo"
1676
+ version = "0.1.0"
1677
+ authors = []
1678
+
1679
+ [dev-dependencies]
1680
+ foo = { path = "." }
1681
+ "# ,
1682
+ )
1683
+ . file ( "src/lib.rs" , "" )
1684
+ . build ( ) ;
1685
+
1686
+ p. cargo ( "check" )
1687
+ . with_status ( 101 )
1688
+ . with_stderr (
1689
+ "\
1690
+ [ERROR] cyclic package dependency: package `foo v0.1.0 ([CWD])` depends on itself.",
1666
1691
)
1667
1692
. run ( ) ;
1668
1693
}
Original file line number Diff line number Diff line change @@ -695,18 +695,14 @@ fn cyclical_dev_dep() {
695
695
)
696
696
. build ( ) ;
697
697
698
- // Old way unifies features.
699
- p. cargo ( "run true" ) . run ( ) ;
700
- // dev feature should always be enabled in tests.
701
- p. cargo ( "test" ) . run ( ) ;
702
-
703
- // New behavior.
704
- switch_to_resolver_2 ( & p) ;
705
- // Should decouple main.
706
- p. cargo ( "run false" ) . run ( ) ;
707
-
708
- // And this should be no different.
709
- p. cargo ( "test" ) . run ( ) ;
698
+ // TODO: Figure out how to properly fix this test case.
699
+ p. cargo ( "run true" )
700
+ . with_status ( 101 )
701
+ . with_stderr (
702
+ "\
703
+ [ERROR] cyclic package dependency: package `foo v0.1.0 ([CWD])` depends on itself.",
704
+ )
705
+ . run ( ) ;
710
706
}
711
707
712
708
#[ cargo_test]
Original file line number Diff line number Diff line change @@ -3366,7 +3366,13 @@ fn cyclic_dev() {
3366
3366
. file ( "tests/foo.rs" , "extern crate foo;" )
3367
3367
. build ( ) ;
3368
3368
3369
- p. cargo ( "test --workspace" ) . run ( ) ;
3369
+ p. cargo ( "test --workspace" )
3370
+ . with_status ( 101 )
3371
+ . with_stderr (
3372
+ "\
3373
+ [ERROR] cyclic package dependency: package `foo v0.1.0 ([CWD])` depends on itself.",
3374
+ )
3375
+ . run ( ) ;
3370
3376
}
3371
3377
3372
3378
#[ cargo_test]
You can’t perform that action at this time.
0 commit comments