Skip to content

Commit 43b129a

Browse files
committed
Auto merge of #9277 - ehuss:beta-1.51-backports, r=alexcrichton
[beta] 1.51 backports Backports of: * #9275: Fix --feature pkg/feat for V1 resolver for non-member * #9276: Fix doc duplicate removal of root units.
2 parents 35a2a43 + 77a13c0 commit 43b129a

File tree

4 files changed

+109
-11
lines changed

4 files changed

+109
-11
lines changed

Diff for: src/cargo/core/workspace.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,8 @@ impl<'cfg> Workspace<'cfg> {
10761076
for feature in requested_features.features.iter() {
10771077
if let Some(index) = feature.find('/') {
10781078
let name = &feature[..index];
1079-
if specs.iter().any(|spec| spec.name() == name) {
1079+
let is_member = self.members().any(|member| member.name() == name);
1080+
if is_member && specs.iter().any(|spec| spec.name() == name) {
10801081
member_specific_features
10811082
.entry(name)
10821083
.or_default()

Diff for: src/cargo/ops/cargo_compile.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -1527,8 +1527,11 @@ fn remove_duplicate_doc(
15271527
// Keep track of units to remove so that they can be efficiently removed
15281528
// from the unit_deps.
15291529
let mut removed_units: HashSet<Unit> = HashSet::new();
1530-
let mut remove = |units: Vec<Unit>, reason: &str| {
1531-
for unit in units {
1530+
let mut remove = |units: Vec<Unit>, reason: &str, cb: &dyn Fn(&Unit) -> bool| -> Vec<Unit> {
1531+
let (to_remove, remaining_units): (Vec<Unit>, Vec<Unit>) = units
1532+
.into_iter()
1533+
.partition(|unit| cb(unit) && !root_units.contains(unit));
1534+
for unit in to_remove {
15321535
log::debug!(
15331536
"removing duplicate doc due to {} for package {} target `{}`",
15341537
reason,
@@ -1538,6 +1541,7 @@ fn remove_duplicate_doc(
15381541
unit_graph.remove(&unit);
15391542
removed_units.insert(unit);
15401543
}
1544+
remaining_units
15411545
};
15421546
// Iterate over the duplicates and try to remove them from unit_graph.
15431547
for (_crate_name, mut units) in all_docs {
@@ -1550,14 +1554,11 @@ fn remove_duplicate_doc(
15501554
.iter()
15511555
.all(CompileKind::is_host)
15521556
{
1553-
let (to_remove, remaining_units): (Vec<Unit>, Vec<Unit>) =
1554-
units.into_iter().partition(|unit| unit.kind.is_host());
15551557
// Note these duplicates may not be real duplicates, since they
15561558
// might get merged in rebuild_unit_graph_shared. Either way, it
15571559
// shouldn't hurt to remove them early (although the report in the
15581560
// log might be confusing).
1559-
remove(to_remove, "host/target merger");
1560-
units = remaining_units;
1561+
units = remove(units, "host/target merger", &|unit| unit.kind.is_host());
15611562
if units.len() == 1 {
15621563
continue;
15631564
}
@@ -1579,10 +1580,9 @@ fn remove_duplicate_doc(
15791580
units.sort_by(|a, b| a.pkg.version().partial_cmp(b.pkg.version()).unwrap());
15801581
// Remove any entries with version < newest.
15811582
let newest_version = units.last().unwrap().pkg.version().clone();
1582-
let (to_remove, keep_units): (Vec<Unit>, Vec<Unit>) = units
1583-
.into_iter()
1584-
.partition(|unit| unit.pkg.version() < &newest_version);
1585-
remove(to_remove, "older version");
1583+
let keep_units = remove(units, "older version", &|unit| {
1584+
unit.pkg.version() < &newest_version
1585+
});
15861586
remaining_units.extend(keep_units);
15871587
} else {
15881588
remaining_units.extend(units);

Diff for: tests/testsuite/collisions.rs

+66
Original file line numberDiff line numberDiff line change
@@ -478,3 +478,69 @@ fn collision_doc_target() {
478478
)
479479
.run();
480480
}
481+
482+
#[cargo_test]
483+
fn collision_with_root() {
484+
// Check for a doc collision between a root package and a dependency.
485+
// In this case, `foo-macro` comes from both the workspace and crates.io.
486+
// This checks that the duplicate correction code doesn't choke on this
487+
// by removing the root unit.
488+
Package::new("foo-macro", "1.0.0").publish();
489+
490+
let p = project()
491+
.file(
492+
"Cargo.toml",
493+
r#"
494+
[workspace]
495+
members = ["abc", "foo-macro"]
496+
"#,
497+
)
498+
.file(
499+
"abc/Cargo.toml",
500+
r#"
501+
[package]
502+
name = "abc"
503+
version = "1.0.0"
504+
505+
[dependencies]
506+
foo-macro = "1.0"
507+
"#,
508+
)
509+
.file("abc/src/lib.rs", "")
510+
.file(
511+
"foo-macro/Cargo.toml",
512+
r#"
513+
[package]
514+
name = "foo-macro"
515+
version = "1.0.0"
516+
517+
[lib]
518+
proc-macro = true
519+
520+
[dependencies]
521+
abc = {path="../abc"}
522+
"#,
523+
)
524+
.file("foo-macro/src/lib.rs", "")
525+
.build();
526+
527+
p.cargo("doc")
528+
.with_stderr_unordered("\
529+
[UPDATING] [..]
530+
[DOWNLOADING] crates ...
531+
[DOWNLOADED] foo-macro v1.0.0 [..]
532+
warning: output filename collision.
533+
The lib target `foo-macro` in package `foo-macro v1.0.0` has the same output filename as the lib target `foo-macro` in package `foo-macro v1.0.0 [..]`.
534+
Colliding filename is: [CWD]/target/doc/foo_macro/index.html
535+
The targets should have unique names.
536+
This is a known bug where multiple crates with the same name use
537+
the same path; see <https://github.com/rust-lang/cargo/issues/6313>.
538+
[CHECKING] foo-macro v1.0.0
539+
[DOCUMENTING] foo-macro v1.0.0
540+
[CHECKING] abc v1.0.0 [..]
541+
[DOCUMENTING] foo-macro v1.0.0 [..]
542+
[DOCUMENTING] abc v1.0.0 [..]
543+
[FINISHED] [..]
544+
")
545+
.run();
546+
}

Diff for: tests/testsuite/package_features.rs

+31
Original file line numberDiff line numberDiff line change
@@ -458,3 +458,34 @@ fn resolver1_member_features() {
458458
.with_stdout("m1-feature set")
459459
.run();
460460
}
461+
462+
#[cargo_test]
463+
fn resolver1_non_member_optional_feature() {
464+
// --features x/y for an optional dependency `x` with the v1 resolver.
465+
Package::new("bar", "1.0.0")
466+
.feature("feat1", &[])
467+
.file(
468+
"src/lib.rs",
469+
r#"
470+
#[cfg(not(feature = "feat1"))]
471+
compile_error!("feat1 should be activated");
472+
"#,
473+
)
474+
.publish();
475+
let p = project()
476+
.file(
477+
"Cargo.toml",
478+
r#"
479+
[package]
480+
name = "foo"
481+
version = "0.1.0"
482+
483+
[dependencies]
484+
bar = { version="1.0", optional=true }
485+
"#,
486+
)
487+
.file("src/lib.rs", "")
488+
.build();
489+
490+
p.cargo("check -p bar --features bar/feat1").run();
491+
}

0 commit comments

Comments
 (0)