@@ -1298,3 +1298,157 @@ fn override_plus_dep() {
12981298 . with_stderr_contains ( "error: cyclic package dependency: [..]" )
12991299 . run ( ) ;
13001300}
1301+
1302+ #[ cargo_test]
1303+ fn override_generic_matching_other_versions ( ) {
1304+ Package :: new ( "bar" , "0.1.0+a" ) . publish ( ) ;
1305+
1306+ let bar = git:: repo ( & paths:: root ( ) . join ( "override" ) )
1307+ . file ( "Cargo.toml" , & basic_manifest ( "bar" , "0.1.0" ) )
1308+ . file ( "src/lib.rs" , "pub fn bar() {}" )
1309+ . build ( ) ;
1310+
1311+ let p = project ( )
1312+ . file (
1313+ "Cargo.toml" ,
1314+ & format ! (
1315+ r#"
1316+ [package]
1317+ name = "foo"
1318+ version = "0.0.1"
1319+ authors = []
1320+
1321+ [dependencies]
1322+ bar = "0.1.0"
1323+
1324+ [replace]
1325+ "bar:0.1.0" = {{ git = '{}' }}
1326+ "# ,
1327+ bar. url( )
1328+ ) ,
1329+ )
1330+ . file (
1331+ "src/lib.rs" ,
1332+ "extern crate bar; pub fn foo() { bar::bar(); }" ,
1333+ )
1334+ . build ( ) ;
1335+
1336+ p. cargo ( "check" )
1337+ . with_stderr (
1338+ "\
1339+ [UPDATING] `dummy-registry` index
1340+ [UPDATING] git repository `[..]`
1341+ [ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([..]/foo)`
1342+
1343+ Caused by:
1344+ replacement specification `https://github.com/rust-lang/crates.io-index#bar@0.1.0` matched 0.1.0+a and tried to override it with 0.1.0
1345+ avoid matching unrelated packages by being more specific
1346+ " ,
1347+ )
1348+ . with_status ( 101 )
1349+ . run ( ) ;
1350+ }
1351+
1352+ #[ cargo_test]
1353+ fn override_respects_spec_metadata ( ) {
1354+ Package :: new ( "bar" , "0.1.0+a" ) . publish ( ) ;
1355+
1356+ let bar = git:: repo ( & paths:: root ( ) . join ( "override" ) )
1357+ . file ( "Cargo.toml" , & basic_manifest ( "bar" , "0.1.0+a" ) )
1358+ . file ( "src/lib.rs" , "pub fn bar() {}" )
1359+ . build ( ) ;
1360+
1361+ let p = project ( )
1362+ . file (
1363+ "Cargo.toml" ,
1364+ & format ! (
1365+ r#"
1366+ [package]
1367+ name = "foo"
1368+ version = "0.0.1"
1369+ authors = []
1370+
1371+ [dependencies]
1372+ bar = "0.1.0"
1373+
1374+ [replace]
1375+ "bar:0.1.0+notTheBuild" = {{ git = '{}' }}
1376+ "# ,
1377+ bar. url( )
1378+ ) ,
1379+ )
1380+ . file (
1381+ "src/lib.rs" ,
1382+ "extern crate bar; pub fn foo() { bar::bar(); }" ,
1383+ )
1384+ . build ( ) ;
1385+
1386+ p. cargo ( "check" )
1387+ . with_stderr (
1388+ "\
1389+ [UPDATING] `dummy-registry` index
1390+ [WARNING] package replacement is not used: https://github.com/rust-lang/crates.io-index#bar@0.1.0+notTheBuild
1391+ [DOWNLOADING] crates ...
1392+ [DOWNLOADED] bar v0.1.0+a (registry `dummy-registry`)
1393+ [CHECKING] bar v0.1.0+a
1394+ [CHECKING] foo v0.0.1 ([..]/foo)
1395+ [..]
1396+ [..]
1397+ [..]
1398+ [..]
1399+ [..]
1400+ [..]
1401+ [..]
1402+ error: could not compile `foo` (lib) due to previous error
1403+ " ,
1404+ )
1405+ . with_status ( 101 )
1406+ . run ( ) ;
1407+ }
1408+
1409+ #[ cargo_test]
1410+ fn override_spec_metadata_is_optional ( ) {
1411+ Package :: new ( "bar" , "0.1.0+a" ) . publish ( ) ;
1412+
1413+ let bar = git:: repo ( & paths:: root ( ) . join ( "override" ) )
1414+ . file ( "Cargo.toml" , & basic_manifest ( "bar" , "0.1.0+a" ) )
1415+ . file ( "src/lib.rs" , "pub fn bar() {}" )
1416+ . build ( ) ;
1417+
1418+ let p = project ( )
1419+ . file (
1420+ "Cargo.toml" ,
1421+ & format ! (
1422+ r#"
1423+ [package]
1424+ name = "foo"
1425+ version = "0.0.1"
1426+ authors = []
1427+
1428+ [dependencies]
1429+ bar = "0.1.0"
1430+
1431+ [replace]
1432+ "bar:0.1.0" = {{ git = '{}' }}
1433+ "# ,
1434+ bar. url( )
1435+ ) ,
1436+ )
1437+ . file (
1438+ "src/lib.rs" ,
1439+ "extern crate bar; pub fn foo() { bar::bar(); }" ,
1440+ )
1441+ . build ( ) ;
1442+
1443+ p. cargo ( "check" )
1444+ . with_stderr (
1445+ "\
1446+ [UPDATING] `dummy-registry` index
1447+ [UPDATING] git repository `[..]`
1448+ [CHECKING] bar v0.1.0+a (file://[..])
1449+ [CHECKING] foo v0.0.1 ([CWD])
1450+ [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
1451+ " ,
1452+ )
1453+ . run ( ) ;
1454+ }
0 commit comments