Skip to content

Commit a9eb3ef

Browse files
borsehuss
authored andcommitted
Auto merge of #9595 - ehuss:ws-doc-collision-back-compat, r=alexcrichton
Relax doc collision error. #9526 moved the `cargo doc` output name collision code to be shared with the other collision detection code. However, the way it detected collisions wasn't quite the same, and started generating errors for situations that were just warnings before. It was intended that the code should behave the same, so this PR relaxes the checks to be more like the original code. (It's still not 100% the same, but should be close enough.) Closes #9564
1 parent 6ef861d commit a9eb3ef

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

src/cargo/core/compiler/context/mod.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -507,17 +507,35 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
507507
.collect::<Vec<_>>();
508508
// Sort for consistent error messages.
509509
keys.sort_unstable();
510+
// These are kept separate to retain compatibility with older
511+
// versions, which generated an error when there was a duplicate lib
512+
// or bin (but the old code did not check bin<->lib collisions). To
513+
// retain backwards compatibility, this only generates an error for
514+
// duplicate libs or duplicate bins (but not both). Ideally this
515+
// shouldn't be here, but since there isn't a complete workaround,
516+
// yet, this retains the old behavior.
517+
let mut doc_libs = HashMap::new();
518+
let mut doc_bins = HashMap::new();
510519
for unit in keys {
520+
if unit.mode.is_doc() && self.is_primary_package(unit) {
521+
// These situations have been an error since before 1.0, so it
522+
// is not a warning like the other situations.
523+
if unit.target.is_lib() {
524+
if let Some(prev) = doc_libs.insert((unit.target.crate_name(), unit.kind), unit)
525+
{
526+
doc_collision_error(unit, prev)?;
527+
}
528+
} else if let Some(prev) =
529+
doc_bins.insert((unit.target.crate_name(), unit.kind), unit)
530+
{
531+
doc_collision_error(unit, prev)?;
532+
}
533+
}
511534
for output in self.outputs(unit)?.iter() {
512535
if let Some(other_unit) = output_collisions.insert(output.path.clone(), unit) {
513536
if unit.mode.is_doc() {
514537
// See https://github.com/rust-lang/rust/issues/56169
515538
// and https://github.com/rust-lang/rust/issues/61378
516-
if self.is_primary_package(unit) {
517-
// This has been an error since before 1.0, so it
518-
// is not a warning like the other situations.
519-
doc_collision_error(unit, other_unit)?;
520-
}
521539
report_collision(unit, other_unit, &output.path, rustdoc_suggestion)?;
522540
} else {
523541
report_collision(unit, other_unit, &output.path, suggestion)?;

tests/testsuite/doc.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -271,14 +271,19 @@ fn doc_multiple_targets_same_name() {
271271
.build();
272272

273273
p.cargo("doc --workspace")
274-
.with_status(101)
275-
.with_stderr(
274+
.with_stderr_unordered(
276275
"\
277-
error: document output filename collision
278-
The bin `foo_lib` in package `foo v0.1.0 ([ROOT]/foo/foo)` has the same name as \
279-
the lib `foo_lib` in package `bar v0.1.0 ([ROOT]/foo/bar)`.
280-
Only one may be documented at once since they output to the same path.
281-
Consider documenting only one, renaming one, or marking one with `doc = false` in Cargo.toml.
276+
warning: output filename collision.
277+
The bin target `foo_lib` in package `foo v0.1.0 ([ROOT]/foo/foo)` \
278+
has the same output filename as the lib target `foo_lib` in package \
279+
`bar v0.1.0 ([ROOT]/foo/bar)`.
280+
Colliding filename is: [ROOT]/foo/target/doc/foo_lib/index.html
281+
The targets should have unique names.
282+
This is a known bug where multiple crates with the same name use
283+
the same path; see <https://github.com/rust-lang/cargo/issues/6313>.
284+
[DOCUMENTING] bar v0.1.0 ([ROOT]/foo/bar)
285+
[DOCUMENTING] foo v0.1.0 ([ROOT]/foo/foo)
286+
[FINISHED] [..]
282287
",
283288
)
284289
.run();

0 commit comments

Comments
 (0)