@@ -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) ?;
0 commit comments