Skip to content

Commit 0df39bf

Browse files
Fix ?Sized where bound not being displayed at the correct place
1 parent bdae618 commit 0df39bf

File tree

4 files changed

+41
-5
lines changed

4 files changed

+41
-5
lines changed

src/librustdoc/clean/inline.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,7 @@ fn build_static(cx: &DocContext, did: DefId, mutable: bool) -> clean::Static {
448448
///
449449
/// The inverse of this filtering logic can be found in the `Clean`
450450
/// implementation for `AssociatedType`
451-
fn filter_non_trait_generics(trait_did: DefId, mut g: clean::Generics)
452-
-> clean::Generics {
451+
fn filter_non_trait_generics(trait_did: DefId, mut g: clean::Generics) -> clean::Generics {
453452
for pred in &mut g.where_predicates {
454453
match *pred {
455454
clean::WherePredicate::BoundPredicate {

src/librustdoc/clean/mod.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,16 +1190,36 @@ impl<'tcx> Clean<Type> for ty::ProjectionTy<'tcx> {
11901190
pub struct Generics {
11911191
pub lifetimes: Vec<Lifetime>,
11921192
pub type_params: Vec<TyParam>,
1193-
pub where_predicates: Vec<WherePredicate>
1193+
pub where_predicates: Vec<WherePredicate>,
11941194
}
11951195

11961196
impl Clean<Generics> for hir::Generics {
11971197
fn clean(&self, cx: &DocContext) -> Generics {
1198-
Generics {
1198+
let mut g = Generics {
11991199
lifetimes: self.lifetimes.clean(cx),
12001200
type_params: self.ty_params.clean(cx),
12011201
where_predicates: self.where_clause.predicates.clean(cx)
1202+
};
1203+
1204+
// Some duplicates are generated for ?Sized bounds between type params and where
1205+
// predicates. The point in here is to move the bounds definitions from type params
1206+
// to where predicates when such cases occur.
1207+
for where_pred in &mut g.where_predicates {
1208+
match *where_pred {
1209+
WherePredicate::BoundPredicate { ty: Generic(ref name), ref mut bounds } => {
1210+
if bounds.is_empty() {
1211+
for type_params in &mut g.type_params {
1212+
if &type_params.name == name {
1213+
mem::swap(bounds, &mut type_params.bounds);
1214+
break
1215+
}
1216+
}
1217+
}
1218+
}
1219+
_ => continue,
1220+
}
12021221
}
1222+
g
12031223
}
12041224
}
12051225

@@ -1225,7 +1245,7 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics,
12251245
let mut where_predicates = preds.predicates.to_vec().clean(cx);
12261246

12271247
// Type parameters and have a Sized bound by default unless removed with
1228-
// ?Sized. Scan through the predicates and mark any type parameter with
1248+
// ?Sized. Scan through the predicates and mark any type parameter with
12291249
// a Sized bound, removing the bounds as we find them.
12301250
//
12311251
// Note that associated types also have a sized bound by default, but we

src/librustdoc/clean/simplify.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ pub fn where_clauses(cx: &DocContext, clauses: Vec<WP>) -> Vec<WP> {
3838
let mut lifetimes = Vec::new();
3939
let mut equalities = Vec::new();
4040
let mut tybounds = Vec::new();
41+
4142
for clause in clauses {
4243
match clause {
4344
WP::BoundPredicate { ty, bounds } => {

src/test/rustdoc/where-sized.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![crate_name = "foo"]
12+
13+
// @has foo/fn.foo.html
14+
// @has - '//*[@class="rust fn"]' 'pub fn foo<X, Y: ?Sized>(_: &X)'
15+
// @has - '//*[@class="rust fn"]' 'where X: ?Sized,'
16+
pub fn foo<X, Y: ?Sized>(_: &X) where X: ?Sized {}

0 commit comments

Comments
 (0)