Skip to content

Commit 61d286e

Browse files
committed
Auto merge of rust-lang#59033 - GuillaumeGomez:duplicated-bounds, r=Dylan-DPC
Fix duplicated bounds printing in rustdoc Fixes rust-lang#56331. Once again, I couldn't find out how to reproduce it with a small code so no test... :-/ r? @QuietMisdreavus
2 parents 7096ff0 + 140bb5d commit 61d286e

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/librustdoc/html/format.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::borrow::Cow;
99
use std::fmt;
1010

1111
use rustc::hir::def_id::DefId;
12+
use rustc::util::nodemap::FxHashSet;
1213
use rustc_target::spec::abi::Abi;
1314
use rustc::hir;
1415

@@ -107,8 +108,10 @@ impl<'a, T: fmt::Display> fmt::Display for CommaSep<'a, T> {
107108

108109
impl<'a> fmt::Display for GenericBounds<'a> {
109110
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
111+
let mut bounds_dup = FxHashSet::default();
110112
let &GenericBounds(bounds) = self;
111-
for (i, bound) in bounds.iter().enumerate() {
113+
114+
for (i, bound) in bounds.iter().filter(|b| bounds_dup.insert(b.to_string())).enumerate() {
112115
if i > 0 {
113116
f.write_str(" + ")?;
114117
}
@@ -206,16 +209,13 @@ impl<'a> fmt::Display for WhereClause<'a> {
206209
clause.push_str(&format!("{}: {}", ty, GenericBounds(bounds)));
207210
}
208211
}
209-
&clean::WherePredicate::RegionPredicate { ref lifetime,
210-
ref bounds } => {
211-
clause.push_str(&format!("{}: ", lifetime));
212-
for (i, lifetime) in bounds.iter().enumerate() {
213-
if i > 0 {
214-
clause.push_str(" + ");
215-
}
216-
217-
clause.push_str(&lifetime.to_string());
218-
}
212+
&clean::WherePredicate::RegionPredicate { ref lifetime, ref bounds } => {
213+
clause.push_str(&format!("{}: {}",
214+
lifetime,
215+
bounds.iter()
216+
.map(|b| b.to_string())
217+
.collect::<Vec<_>>()
218+
.join(" + ")));
219219
}
220220
&clean::WherePredicate::EqPredicate { ref lhs, ref rhs } => {
221221
if f.alternate() {

0 commit comments

Comments
 (0)