Skip to content

Commit 1ea8fc5

Browse files
authored
Rollup merge of #62734 - GuillaumeGomez:hide-default-methods, r=Mark-Simulacrum
Hide trait default methods Fixes #62499. However, the question remains: do we want to extend it to this point or not? r? @QuietMisdreavus
2 parents 7445622 + f7656b6 commit 1ea8fc5

File tree

6 files changed

+24
-21
lines changed

6 files changed

+24
-21
lines changed

src/librustdoc/html/render.rs

+14-11
Original file line numberDiff line numberDiff line change
@@ -2405,13 +2405,14 @@ fn document(w: &mut fmt::Formatter<'_>, cx: &Context, item: &clean::Item) -> fmt
24052405
}
24062406

24072407
/// Render md_text as markdown.
2408-
fn render_markdown(w: &mut fmt::Formatter<'_>,
2409-
cx: &Context,
2410-
md_text: &str,
2411-
links: Vec<(String, String)>,
2412-
prefix: &str,
2413-
is_hidden: bool)
2414-
-> fmt::Result {
2408+
fn render_markdown(
2409+
w: &mut fmt::Formatter<'_>,
2410+
cx: &Context,
2411+
md_text: &str,
2412+
links: Vec<(String, String)>,
2413+
prefix: &str,
2414+
is_hidden: bool,
2415+
) -> fmt::Result {
24152416
let mut ids = cx.id_map.borrow_mut();
24162417
write!(w, "<div class='docblock{}'>{}{}</div>",
24172418
if is_hidden { " hidden" } else { "" },
@@ -2425,7 +2426,8 @@ fn document_short(
24252426
cx: &Context,
24262427
item: &clean::Item,
24272428
link: AssocItemLink<'_>,
2428-
prefix: &str, is_hidden: bool
2429+
prefix: &str,
2430+
is_hidden: bool,
24292431
) -> fmt::Result {
24302432
if let Some(s) = item.doc_value() {
24312433
let markdown = if s.contains('\n') {
@@ -4084,9 +4086,10 @@ fn render_impl(w: &mut fmt::Formatter<'_>, cx: &Context, i: &Impl, link: AssocIt
40844086
RenderMode::ForDeref { mut_: deref_mut_ } => should_render_item(&item, deref_mut_),
40854087
};
40864088

4087-
let (is_hidden, extra_class) = if trait_.is_none() ||
4088-
item.doc_value().is_some() ||
4089-
item.inner.is_associated() {
4089+
let (is_hidden, extra_class) = if (trait_.is_none() ||
4090+
item.doc_value().is_some() ||
4091+
item.inner.is_associated()) &&
4092+
!is_default_item {
40904093
(false, "")
40914094
} else {
40924095
(true, " hidden")

src/librustdoc/html/static/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
// Local js definitions:
55
/* global addClass, getCurrentValue, hasClass */
6-
/* global isHidden onEach, removeClass, updateLocalStorage */
6+
/* global isHidden, onEach, removeClass, updateLocalStorage */
77

88
if (!String.prototype.startsWith) {
99
String.prototype.startsWith = function(searchString, position) {

src/test/rustdoc/assoc-consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,5 @@ impl Qux for Bar {
9595
/// Docs for QUX_DEFAULT1 in impl.
9696
const QUX_DEFAULT1: i16 = 7;
9797
// @has - '//*[@id="associatedconstant.QUX_DEFAULT2"]' 'const QUX_DEFAULT2: u32'
98-
// @has - '//*[@class="docblock"]' "Docs for QUX_DEFAULT2 in trait."
98+
// @has - '//*[@class="docblock hidden"]' "Docs for QUX_DEFAULT2 in trait."
9999
}

src/test/rustdoc/inline_cross/assoc-items.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ extern crate assoc_items;
1616
// @has - '//*[@id="associatedconstant.ConstNoDefault"]' 'const ConstNoDefault: i16'
1717
// @has - '//*[@class="docblock"]' 'dox for ConstNoDefault'
1818
// @has - '//*[@id="associatedconstant.ConstWithDefault"]' 'const ConstWithDefault: u16'
19-
// @has - '//*[@class="docblock"]' 'docs for ConstWithDefault'
19+
// @has - '//*[@class="docblock hidden"]' 'docs for ConstWithDefault'
2020
// @has - '//*[@id="associatedtype.TypeNoDefault"]' 'type TypeNoDefault = i32'
2121
// @has - '//*[@class="docblock"]' 'dox for TypeNoDefault'
2222
// @has - '//*[@id="associatedtype.TypeWithDefault"]' 'type TypeWithDefault = u32'
23-
// @has - '//*[@class="docblock"]' 'docs for TypeWithDefault'
23+
// @has - '//*[@class="docblock hidden"]' 'docs for TypeWithDefault'
2424
// @has - '//*[@id="method.method_no_default"]' 'fn method_no_default()'
2525
// @has - '//*[@class="docblock"]' 'dox for method_no_default'
2626
// @has - '//*[@id="method.method_with_default"]' 'fn method_with_default()'
27-
// @has - '//*[@class="docblock"]' 'docs for method_with_default'
27+
// @has - '//*[@class="docblock hidden"]' 'docs for method_with_default'
2828
pub use assoc_items::MyStruct;
2929

3030
// @has foo/trait.MyTrait.html

src/test/rustdoc/inline_cross/impl-inline-without-trait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ extern crate impl_inline_without_trait;
88

99
// @has 'foo/struct.MyStruct.html'
1010
// @has - '//*[@id="method.my_trait_method"]' 'fn my_trait_method()'
11-
// @has - '//*[@class="docblock"]' 'docs for my_trait_method'
11+
// @has - '//*[@class="docblock hidden"]' 'docs for my_trait_method'
1212
pub use impl_inline_without_trait::MyStruct;

src/test/rustdoc/manual_impl.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ pub trait T {
2424
// @has - '//*[@class="docblock"]' 'Docs associated with the S1 trait implementation.'
2525
// @has - '//*[@class="docblock"]' 'Docs associated with the S1 trait a_method implementation.'
2626
// @!has - '//*[@class="docblock"]' 'Docs associated with the trait a_method definition.'
27-
// @has - '//*[@class="docblock"]' 'Docs associated with the trait b_method definition.'
28-
// @has - '//*[@class="docblock"]' 'Docs associated with the trait c_method definition.'
27+
// @has - '//*[@class="docblock hidden"]' 'Docs associated with the trait b_method definition.'
28+
// @has - '//*[@class="docblock hidden"]' 'Docs associated with the trait c_method definition.'
2929
// @!has - '//*[@class="docblock"]' 'There is another line'
30-
// @has - '//*[@class="docblock"]' 'Read more'
30+
// @has - '//*[@class="docblock hidden"]' 'Read more'
3131
pub struct S1(usize);
3232

3333
/// Docs associated with the S1 trait implementation.
@@ -44,7 +44,7 @@ impl T for S1 {
4444
// @has - '//*[@class="docblock"]' 'Docs associated with the S2 trait c_method implementation.'
4545
// @!has - '//*[@class="docblock"]' 'Docs associated with the trait a_method definition.'
4646
// @!has - '//*[@class="docblock"]' 'Docs associated with the trait c_method definition.'
47-
// @has - '//*[@class="docblock"]' 'Docs associated with the trait b_method definition.'
47+
// @has - '//*[@class="docblock hidden"]' 'Docs associated with the trait b_method definition.'
4848
pub struct S2(usize);
4949

5050
/// Docs associated with the S2 trait implementation.

0 commit comments

Comments
 (0)