Skip to content

Commit 3510db4

Browse files
committed
Auto merge of #59033 - GuillaumeGomez:duplicated-bounds, r=<try>
Fix duplicated bounds printing in rustdoc Fixes #56331. Once again, I couldn't find out how to reproduce it with a small code so no test... :-/ r? @QuietMisdreavus
2 parents 070cebd + 140bb5d commit 3510db4

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

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

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

0 commit comments

Comments
 (0)