Skip to content

Commit 9d1c776

Browse files
authored
Unrolled build for rust-lang#121855
Rollup merge of rust-lang#121855 - GuillaumeGomez:trait-item-info, r=notriddle Correctly generate item info of trait items Fixes rust-lang#121772. The `document_info` function was wrongly used when documenting a trait item. r? `@notriddle`
2 parents 5257aee + b119189 commit 9d1c776

File tree

3 files changed

+38
-13
lines changed

3 files changed

+38
-13
lines changed

src/librustdoc/html/render/mod.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -1680,7 +1680,7 @@ fn render_impl(
16801680
write!(
16811681
&mut doc_buffer,
16821682
"{}",
1683-
document_short(item, cx, link, parent, rendering_params.show_def_docs,)
1683+
document_short(item, cx, link, parent, rendering_params.show_def_docs)
16841684
);
16851685
}
16861686
}
@@ -2043,15 +2043,13 @@ pub(crate) fn render_impl_summary(
20432043
w.write_str("</h3>");
20442044

20452045
let is_trait = inner_impl.trait_.is_some();
2046-
if is_trait {
2047-
if let Some(portability) = portability(&i.impl_item, Some(parent)) {
2048-
write!(
2049-
w,
2050-
"<span class=\"item-info\">\
2051-
<div class=\"stab portability\">{portability}</div>\
2052-
</span>",
2053-
);
2054-
}
2046+
if is_trait && let Some(portability) = portability(&i.impl_item, Some(parent)) {
2047+
write!(
2048+
w,
2049+
"<span class=\"item-info\">\
2050+
<div class=\"stab portability\">{portability}</div>\
2051+
</span>",
2052+
);
20552053
}
20562054

20572055
w.write_str("</section>");

src/librustdoc/html/render/print_item.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use crate::html::format::{
3333
};
3434
use crate::html::layout::Page;
3535
use crate::html::markdown::{HeadingOffset, MarkdownSummaryLine};
36+
use crate::html::render::{document_full, document_item_info};
3637
use crate::html::url_parts_builder::UrlPartsBuilder;
3738
use crate::html::{highlight, static_files};
3839

@@ -818,8 +819,10 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
818819
info!("Documenting {name} on {ty_name:?}", ty_name = t.name);
819820
let item_type = m.type_();
820821
let id = cx.derive_id(format!("{item_type}.{name}"));
822+
821823
let mut content = Buffer::empty_from(w);
822-
write!(&mut content, "{}", document(cx, m, Some(t), HeadingOffset::H5));
824+
write!(content, "{}", document_full(m, cx, HeadingOffset::H5));
825+
823826
let toggled = !content.is_empty();
824827
if toggled {
825828
let method_toggle_class = if item_type.is_method() { " method-toggle" } else { "" };
@@ -836,8 +839,8 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
836839
cx,
837840
RenderMode::Normal,
838841
);
839-
w.write_str("</h4>");
840-
w.write_str("</section>");
842+
w.write_str("</h4></section>");
843+
document_item_info(cx, m, Some(t)).render_into(w).unwrap();
841844
if toggled {
842845
write!(w, "</summary>");
843846
w.push_buffer(content);

tests/rustdoc/trait-item-info.rs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// This is a regression test for <https://github.com/rust-lang/rust/issues/121772>.
2+
// The goal is to ensure that the item information is always part of the `<summary>`
3+
// if there is one.
4+
5+
#![crate_name = "foo"]
6+
#![feature(staged_api)]
7+
8+
#![unstable(feature = "test", issue = "none")]
9+
10+
// @has 'foo/trait.Foo.html'
11+
12+
#[stable(feature = "rust2", since = "2.2.2")]
13+
pub trait Foo {
14+
// @has - '//div[@class="methods"]/span[@class="item-info"]' 'bla'
15+
// Should not be in a `<details>` because there is no doc.
16+
#[unstable(feature = "bla", reason = "bla", issue = "111")]
17+
fn bla() {}
18+
19+
// @has - '//details[@class="toggle method-toggle"]/summary/span[@class="item-info"]' 'bar'
20+
// Should have a `<summary>` in the `<details>` containing the unstable info.
21+
/// doc
22+
#[unstable(feature = "bar", reason = "bla", issue = "222")]
23+
fn bar() {}
24+
}

0 commit comments

Comments
 (0)