Skip to content

Commit 7a3c7b2

Browse files
Don't display full blanket implementation and put it into its own section
1 parent ef7d6fc commit 7a3c7b2

File tree

8 files changed

+59
-24
lines changed

8 files changed

+59
-24
lines changed

src/librustdoc/clean/auto_trait.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
198198
.collect();
199199

200200
let ty = self.get_real_ty(def_id, def_ctor, &real_name, generics);
201-
let predicates = infcx.tcx.predicates_of(def_id);
201+
let predicates = infcx.tcx.predicates_of(impl_def_id);
202202

203203
traits.push(Item {
204204
source: infcx.tcx.def_span(impl_def_id).clean(self.cx),
@@ -218,7 +218,9 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
218218
.collect::<Vec<_>>()
219219
.clean(self.cx),
220220
polarity: None,
221-
synthetic: true,
221+
synthetic: false,
222+
blanket_impl: Some(infcx.tcx.type_of(impl_def_id)
223+
.clean(self.cx)),
222224
}),
223225
});
224226
debug!("{:?} => {}", trait_ref, may_apply);
@@ -345,6 +347,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
345347
items: Vec::new(),
346348
polarity,
347349
synthetic: true,
350+
blanket_impl: None,
348351
}),
349352
});
350353
}

src/librustdoc/clean/inline.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ pub fn build_impl(cx: &DocContext, did: DefId, ret: &mut Vec<clean::Item>) {
414414
items: trait_items,
415415
polarity: Some(polarity.clean(cx)),
416416
synthetic: false,
417+
blanket_impl: None,
417418
}),
418419
source: tcx.def_span(did).clean(cx),
419420
name: None,

src/librustdoc/clean/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3881,6 +3881,7 @@ pub struct Impl {
38813881
pub items: Vec<Item>,
38823882
pub polarity: Option<ImplPolarity>,
38833883
pub synthetic: bool,
3884+
pub blanket_impl: Option<Type>,
38843885
}
38853886

38863887
pub fn get_auto_traits_with_node_id(cx: &DocContext, id: ast::NodeId, name: String) -> Vec<Item> {
@@ -3948,6 +3949,7 @@ impl Clean<Vec<Item>> for doctree::Impl {
39483949
items,
39493950
polarity: Some(self.polarity.clean(cx)),
39503951
synthetic: false,
3952+
blanket_impl: None,
39513953
})
39523954
});
39533955
ret

src/librustdoc/html/format.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,11 @@ fn fmt_impl(i: &clean::Impl,
769769
write!(f, " for ")?;
770770
}
771771

772-
fmt_type(&i.for_, f, use_absolute)?;
772+
if let Some(ref ty) = i.blanket_impl {
773+
fmt_type(ty, f, use_absolute)?;
774+
} else {
775+
fmt_type(&i.for_, f, use_absolute)?;
776+
}
773777

774778
fmt::Display::fmt(&WhereClause { gens: &i.generics, indent: 0, end_newline: true }, f)?;
775779
Ok(())

src/librustdoc/html/render.rs

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ pub enum ExternalLocation {
177177
}
178178

179179
/// Metadata about implementations for a type or trait.
180-
#[derive(Clone)]
180+
#[derive(Clone, Debug)]
181181
pub struct Impl {
182182
pub impl_item: clean::Item,
183183
}
@@ -2900,18 +2900,18 @@ fn item_trait(
29002900
render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All)?;
29012901

29022902
let cache = cache();
2903-
let impl_header = "
2904-
<h2 id='implementors' class='small-section-header'>
2905-
Implementors<a href='#implementors' class='anchor'></a>
2906-
</h2>
2907-
<ul class='item-list' id='implementors-list'>
2903+
let impl_header = "\
2904+
<h2 id='implementors' class='small-section-header'>\
2905+
Implementors<a href='#implementors' class='anchor'></a>\
2906+
</h2>\
2907+
<ul class='item-list' id='implementors-list'>\
29082908
";
29092909

2910-
let synthetic_impl_header = "
2911-
<h2 id='synthetic-implementors' class='small-section-header'>
2912-
Auto implementors<a href='#synthetic-implementors' class='anchor'></a>
2913-
</h2>
2914-
<ul class='item-list' id='synthetic-implementors-list'>
2910+
let synthetic_impl_header = "\
2911+
<h2 id='synthetic-implementors' class='small-section-header'>\
2912+
Auto implementors<a href='#synthetic-implementors' class='anchor'></a>\
2913+
</h2>\
2914+
<ul class='item-list' id='synthetic-implementors-list'>\
29152915
";
29162916

29172917
let mut synthetic_types = Vec::new();
@@ -2942,9 +2942,9 @@ fn item_trait(
29422942
.map_or(true, |d| cache.paths.contains_key(&d)));
29432943

29442944

2945-
let (synthetic, concrete) = local.iter()
2946-
.partition::<Vec<_>, _>(|i| i.inner_impl().synthetic);
2947-
2945+
let (synthetic, concrete): (Vec<&&Impl>, Vec<&&Impl>) = local.iter()
2946+
.filter(|i| i.inner_impl().blanket_impl.is_none())
2947+
.partition(|i| i.inner_impl().synthetic);
29482948

29492949
if !foreign.is_empty() {
29502950
write!(w, "
@@ -3626,9 +3626,12 @@ fn render_assoc_items(w: &mut fmt::Formatter,
36263626
render_deref_methods(w, cx, impl_, containing_item, has_deref_mut)?;
36273627
}
36283628

3629-
let (synthetic, concrete) = traits
3629+
let (synthetic, concrete): (Vec<&&Impl>, Vec<&&Impl>) = traits
36303630
.iter()
3631-
.partition::<Vec<_>, _>(|t| t.inner_impl().synthetic);
3631+
.partition(|t| t.inner_impl().synthetic);
3632+
let (blanket_impl, concrete) = concrete
3633+
.into_iter()
3634+
.partition(|t| t.inner_impl().blanket_impl.is_some());
36323635

36333636
struct RendererStruct<'a, 'b, 'c>(&'a Context, Vec<&'b &'b Impl>, &'c clean::Item);
36343637

@@ -3658,6 +3661,18 @@ fn render_assoc_items(w: &mut fmt::Formatter,
36583661
render_impls(cx, w, &synthetic, containing_item)?;
36593662
write!(w, "</div>")?;
36603663
}
3664+
3665+
if !blanket_impl.is_empty() {
3666+
write!(w, "\
3667+
<h2 id='blanket-implementations' class='small-section-header'>\
3668+
Blanket Implementations\
3669+
<a href='#blanket-implementations' class='anchor'></a>\
3670+
</h2>\
3671+
<div id='blanket-implementations-list'>\
3672+
")?;
3673+
render_impls(cx, w, &blanket_impl, containing_item)?;
3674+
write!(w, "</div>")?;
3675+
}
36613676
}
36623677
Ok(())
36633678
}
@@ -4203,12 +4218,16 @@ fn sidebar_assoc_items(it: &clean::Item) -> String {
42034218
.collect::<String>()
42044219
};
42054220

4206-
let (synthetic, concrete) = v
4221+
let (synthetic, concrete): (Vec<&Impl>, Vec<&Impl>) = v
42074222
.iter()
42084223
.partition::<Vec<_>, _>(|i| i.inner_impl().synthetic);
4224+
let (blanket_impl, concrete): (Vec<&Impl>, Vec<&Impl>) = concrete
4225+
.into_iter()
4226+
.partition::<Vec<_>, _>(|i| i.inner_impl().blanket_impl.is_some());
42094227

42104228
let concrete_format = format_impls(concrete);
42114229
let synthetic_format = format_impls(synthetic);
4230+
let blanket_format = format_impls(blanket_impl);
42124231

42134232
if !concrete_format.is_empty() {
42144233
out.push_str("<a class=\"sidebar-title\" href=\"#implementations\">\
@@ -4221,6 +4240,12 @@ fn sidebar_assoc_items(it: &clean::Item) -> String {
42214240
Auto Trait Implementations</a>");
42224241
out.push_str(&format!("<div class=\"sidebar-links\">{}</div>", synthetic_format));
42234242
}
4243+
4244+
if !blanket_format.is_empty() {
4245+
out.push_str("<a class=\"sidebar-title\" href=\"#blanket-implementations\">\
4246+
Blanket Implementations</a>");
4247+
out.push_str(&format!("<div class=\"sidebar-links\">{}</div>", blanket_format));
4248+
}
42244249
}
42254250
}
42264251

src/test/rustdoc/generic-impl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212

1313
use std::fmt;
1414

15-
// @!has foo/struct.Bar.html '//h3[@id="impl-ToString"]//code' 'impl<T> ToString for Bar'
15+
// @!has foo/struct.Bar.html '//h3[@id="impl-ToString"]//code' 'impl<T> ToString for T'
1616
pub struct Bar;
1717

18-
// @has foo/struct.Foo.html '//h3[@id="impl-ToString"]//code' 'impl<T> ToString for Foo'
18+
// @has foo/struct.Foo.html '//h3[@id="impl-ToString"]//code' 'impl<T> ToString for T'
1919
pub struct Foo;
2020

2121
impl fmt::Display for Foo {

src/test/rustdoc/synthetic_auto/basic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// @has - '//code' 'impl<T> Send for Foo<T> where T: Send'
1313
// @has - '//code' 'impl<T> Sync for Foo<T> where T: Sync'
1414
// @count - '//*[@id="implementations-list"]/*[@class="impl"]' 0
15-
// @count - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]' 9
15+
// @count - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]' 2
1616
pub struct Foo<T> {
1717
field: T,
1818
}

src/test/rustdoc/synthetic_auto/manual.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// 'impl<T> Send for Foo<T>'
1717
//
1818
// @count - '//*[@id="implementations-list"]/*[@class="impl"]' 1
19-
// @count - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]' 8
19+
// @count - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]' 1
2020
pub struct Foo<T> {
2121
field: T,
2222
}

0 commit comments

Comments
 (0)