Skip to content

Commit 1f9423a

Browse files
authored
Auto merge of #34292 - ollie27:rustdoc_depr_impl, r=GuillaumeGomez
rustdoc: Add stability notices to impl items Also fixes missing stability notices on methods with no docs. For example [`f64::is_positive`](https://doc.rust-lang.org/nightly/std/primitive.f64.html#method.is_positive) is missing its deprecation message.
2 parents 222e337 + 195fc5a commit 1f9423a

File tree

2 files changed

+158
-17
lines changed

2 files changed

+158
-17
lines changed

src/librustdoc/html/render.rs

+30-17
Original file line numberDiff line numberDiff line change
@@ -1656,12 +1656,8 @@ fn plain_summary_line(s: Option<&str>) -> String {
16561656
}
16571657

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

@@ -1678,6 +1674,20 @@ fn document_short(w: &mut fmt::Formatter, item: &clean::Item, link: AssocItemLin
16781674
Ok(())
16791675
}
16801676

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

26392649
if !is_static || render_static {
26402650
if !is_default_item {
2641-
2642-
if item.doc_value().is_some() {
2643-
document(w, cx, item)?;
2644-
} else {
2645-
// In case the item isn't documented,
2646-
// provide short documentation from the trait
2647-
if let Some(t) = trait_ {
2648-
if let Some(it) = t.items.iter()
2649-
.find(|i| i.name == item.name) {
2650-
document_short(w, it, link)?;
2651-
}
2651+
if let Some(t) = trait_ {
2652+
let it = t.items.iter().find(|i| i.name == item.name).unwrap();
2653+
// We need the stability of the item from the trait because
2654+
// impls can't have a stability.
2655+
document_stability(w, cx, it)?;
2656+
if item.doc_value().is_some() {
2657+
document_full(w, item)?;
2658+
} else {
2659+
// In case the item isn't documented,
2660+
// provide short documentation from the trait.
2661+
document_short(w, it, link)?;
26522662
}
2663+
} else {
2664+
document(w, cx, item)?;
26532665
}
26542666
} else {
2667+
document_stability(w, cx, item)?;
26552668
document_short(w, item, link)?;
26562669
}
26572670
}

src/test/rustdoc/deprecated-impls.rs

+128
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)