Skip to content

Commit 195fc5a

Browse files
committed
rustdoc: Add stability notices to impl items
Also fixes missing stability notices on methods with no docs.
1 parent 2940eb5 commit 195fc5a

File tree

2 files changed

+158
-17
lines changed

2 files changed

+158
-17
lines changed

src/librustdoc/html/render.rs

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,12 +1658,8 @@ fn plain_summary_line(s: Option<&str>) -> String {
16581658
}
16591659

16601660
fn document(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item) -> fmt::Result {
1661-
for stability in short_stability(item, cx, true) {
1662-
write!(w, "<div class='stability'>{}</div>", stability)?;
1663-
}
1664-
if let Some(s) = item.doc_value() {
1665-
write!(w, "<div class='docblock'>{}</div>", Markdown(s))?;
1666-
}
1661+
document_stability(w, cx, item)?;
1662+
document_full(w, item)?;
16671663
Ok(())
16681664
}
16691665

@@ -1680,6 +1676,20 @@ fn document_short(w: &mut fmt::Formatter, item: &clean::Item, link: AssocItemLin
16801676
Ok(())
16811677
}
16821678

1679+
fn document_full(w: &mut fmt::Formatter, item: &clean::Item) -> fmt::Result {
1680+
if let Some(s) = item.doc_value() {
1681+
write!(w, "<div class='docblock'>{}</div>", Markdown(s))?;
1682+
}
1683+
Ok(())
1684+
}
1685+
1686+
fn document_stability(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item) -> fmt::Result {
1687+
for stability in short_stability(item, cx, true) {
1688+
write!(w, "<div class='stability'>{}</div>", stability)?;
1689+
}
1690+
Ok(())
1691+
}
1692+
16831693
fn item_module(w: &mut fmt::Formatter, cx: &Context,
16841694
item: &clean::Item, items: &[clean::Item]) -> fmt::Result {
16851695
document(w, cx, item)?;
@@ -2640,20 +2650,23 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
26402650

26412651
if !is_static || render_static {
26422652
if !is_default_item {
2643-
2644-
if item.doc_value().is_some() {
2645-
document(w, cx, item)?;
2646-
} else {
2647-
// In case the item isn't documented,
2648-
// provide short documentation from the trait
2649-
if let Some(t) = trait_ {
2650-
if let Some(it) = t.items.iter()
2651-
.find(|i| i.name == item.name) {
2652-
document_short(w, it, link)?;
2653-
}
2653+
if let Some(t) = trait_ {
2654+
let it = t.items.iter().find(|i| i.name == item.name).unwrap();
2655+
// We need the stability of the item from the trait because
2656+
// impls can't have a stability.
2657+
document_stability(w, cx, it)?;
2658+
if item.doc_value().is_some() {
2659+
document_full(w, item)?;
2660+
} else {
2661+
// In case the item isn't documented,
2662+
// provide short documentation from the trait.
2663+
document_short(w, it, link)?;
26542664
}
2665+
} else {
2666+
document(w, cx, item)?;
26552667
}
26562668
} else {
2669+
document_stability(w, cx, item)?;
26572670
document_short(w, item, link)?;
26582671
}
26592672
}

src/test/rustdoc/deprecated-impls.rs

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
// Copyright 2015 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/struct.Foo0.html
14+
pub struct Foo0;
15+
16+
impl Foo0 {
17+
// @has - '//*[@class="stab deprecated"]' 'Deprecated since 1.0.1: fn_with_doc'
18+
// @has - 'fn_with_doc short'
19+
// @has - 'fn_with_doc full'
20+
/// fn_with_doc short
21+
///
22+
/// fn_with_doc full
23+
#[deprecated(since = "1.0.1", note = "fn_with_doc")]
24+
pub fn fn_with_doc() {}
25+
26+
// @has - '//*[@class="stab deprecated"]' 'Deprecated since 1.0.2: fn_without_doc'
27+
#[deprecated(since = "1.0.2", note = "fn_without_doc")]
28+
pub fn fn_without_doc() {}
29+
}
30+
31+
pub trait Bar {
32+
/// fn_empty_with_doc short
33+
///
34+
/// fn_empty_with_doc full
35+
#[deprecated(since = "1.0.3", note = "fn_empty_with_doc")]
36+
fn fn_empty_with_doc();
37+
38+
#[deprecated(since = "1.0.4", note = "fn_empty_without_doc")]
39+
fn fn_empty_without_doc();
40+
41+
/// fn_def_with_doc short
42+
///
43+
/// fn_def_with_doc full
44+
#[deprecated(since = "1.0.5", note = "fn_def_with_doc")]
45+
fn fn_def_with_doc() {}
46+
47+
#[deprecated(since = "1.0.6", note = "fn_def_without_doc")]
48+
fn fn_def_without_doc() {}
49+
50+
/// fn_def_def_with_doc short
51+
///
52+
/// fn_def_def_with_doc full
53+
#[deprecated(since = "1.0.7", note = "fn_def_def_with_doc")]
54+
fn fn_def_def_with_doc() {}
55+
56+
#[deprecated(since = "1.0.8", note = "fn_def_def_without_doc")]
57+
fn fn_def_def_without_doc() {}
58+
}
59+
60+
// @has foo/struct.Foo1.html
61+
pub struct Foo1;
62+
63+
impl Bar for Foo1 {
64+
// @has - '//*[@class="stab deprecated"]' 'Deprecated since 1.0.3: fn_empty_with_doc'
65+
// @has - 'fn_empty_with_doc_impl short'
66+
// @has - 'fn_empty_with_doc_impl full'
67+
/// fn_empty_with_doc_impl short
68+
///
69+
/// fn_empty_with_doc_impl full
70+
fn fn_empty_with_doc() {}
71+
72+
// @has - '//*[@class="stab deprecated"]' 'Deprecated since 1.0.4: fn_empty_without_doc'
73+
fn fn_empty_without_doc() {}
74+
75+
// @has - '//*[@class="stab deprecated"]' 'Deprecated since 1.0.5: fn_def_with_doc'
76+
// @has - 'fn_def_with_doc_impl short'
77+
// @has - 'fn_def_with_doc_impl full'
78+
/// fn_def_with_doc_impl short
79+
///
80+
/// fn_def_with_doc_impl full
81+
fn fn_def_with_doc() {}
82+
83+
// @has - '//*[@class="stab deprecated"]' 'Deprecated since 1.0.6: fn_def_without_doc'
84+
fn fn_def_without_doc() {}
85+
86+
// @has - '//*[@class="stab deprecated"]' 'Deprecated since 1.0.7: fn_def_def_with_doc'
87+
// @has - 'fn_def_def_with_doc short'
88+
// @!has - 'fn_def_def_with_doc full'
89+
90+
// @has - '//*[@class="stab deprecated"]' 'Deprecated since 1.0.8: fn_def_def_without_doc'
91+
}
92+
93+
// @has foo/struct.Foo2.html
94+
pub struct Foo2;
95+
96+
impl Bar for Foo2 {
97+
// @has - '//*[@class="stab deprecated"]' 'Deprecated since 1.0.3: fn_empty_with_doc'
98+
// @has - 'fn_empty_with_doc short'
99+
// @!has - 'fn_empty_with_doc full'
100+
fn fn_empty_with_doc() {}
101+
102+
// @has - '//*[@class="stab deprecated"]' 'Deprecated since 1.0.4: fn_empty_without_doc'
103+
// @has - 'fn_empty_without_doc_impl short'
104+
// @has - 'fn_empty_without_doc_impl full'
105+
/// fn_empty_without_doc_impl short
106+
///
107+
/// fn_empty_without_doc_impl full
108+
fn fn_empty_without_doc() {}
109+
110+
// @has - '//*[@class="stab deprecated"]' 'Deprecated since 1.0.5: fn_def_with_doc'
111+
// @has - 'fn_def_with_doc short'
112+
// @!has - 'fn_def_with full'
113+
fn fn_def_with_doc() {}
114+
115+
// @has - '//*[@class="stab deprecated"]' 'Deprecated since 1.0.6: fn_def_without_doc'
116+
// @has - 'fn_def_without_doc_impl short'
117+
// @has - 'fn_def_without_doc_impl full'
118+
/// fn_def_without_doc_impl short
119+
///
120+
/// fn_def_without_doc_impl full
121+
fn fn_def_without_doc() {}
122+
123+
// @has - '//*[@class="stab deprecated"]' 'Deprecated since 1.0.7: fn_def_def_with_doc'
124+
// @has - 'fn_def_def_with_doc short'
125+
// @!has - 'fn_def_def_with_doc full'
126+
127+
// @has - '//*[@class="stab deprecated"]' 'Deprecated since 1.0.8: fn_def_def_without_doc'
128+
}

0 commit comments

Comments
 (0)