Skip to content

Commit 251ec62

Browse files
committed
Auto merge of #50953 - GuillaumeGomez:attributes-in-other-places, r=QuietMisdreavus
Add attributes for trait and methods as well Fixes #48485. r? @QuietMisdreavus
2 parents 3515dab + 26ad95c commit 251ec62

File tree

4 files changed

+53
-13
lines changed

4 files changed

+53
-13
lines changed

src/librustdoc/html/render.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3055,6 +3055,7 @@ fn render_assoc_item(w: &mut fmt::Formatter,
30553055
} else {
30563056
(0, true)
30573057
};
3058+
render_attributes(w, meth)?;
30583059
write!(w, "{}{}{}{}fn <a href='{href}' class='fnname'>{name}</a>\
30593060
{generics}{decl}{where_clause}",
30603061
VisSpace(&meth.visibility),

src/librustdoc/html/static/main.js

+8-10
Original file line numberDiff line numberDiff line change
@@ -2041,16 +2041,16 @@
20412041

20422042
autoCollapseAllImpls(getPageId());
20432043

2044-
function createToggleWrapper() {
2044+
function createToggleWrapper(tog) {
20452045
var span = document.createElement('span');
20462046
span.className = 'toggle-label';
20472047
span.style.display = 'none';
20482048
span.innerHTML = '&nbsp;Expand&nbsp;attributes';
2049-
toggle.appendChild(span);
2049+
tog.appendChild(span);
20502050

20512051
var wrapper = document.createElement('div');
20522052
wrapper.className = 'toggle-wrapper toggle-attributes';
2053-
wrapper.appendChild(toggle);
2053+
wrapper.appendChild(tog);
20542054
return wrapper;
20552055
}
20562056

@@ -2078,13 +2078,11 @@
20782078
});
20792079
}
20802080

2081-
onEach(document.getElementById('main').getElementsByTagName('pre'), function(e) {
2082-
onEach(e.getElementsByClassName('attributes'), function(i_e) {
2083-
i_e.parentNode.insertBefore(createToggleWrapper(), i_e);
2084-
if (getCurrentValue("rustdoc-item-attributes") !== "false") {
2085-
collapseDocs(i_e.previousSibling.childNodes[0], "toggle");
2086-
}
2087-
});
2081+
onEach(document.getElementById('main').getElementsByClassName('attributes'), function(i_e) {
2082+
i_e.parentNode.insertBefore(createToggleWrapper(toggle.cloneNode(true)), i_e);
2083+
if (getCurrentValue("rustdoc-item-attributes") !== "false") {
2084+
collapseDocs(i_e.previousSibling.childNodes[0], "toggle");
2085+
}
20882086
});
20892087

20902088
onEach(document.getElementsByClassName('rust-example-rendered'), function(e) {

src/librustdoc/html/static/rustdoc.css

+12-3
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ h3 > .collapse-toggle, h4 > .collapse-toggle {
771771

772772
.toggle-wrapper {
773773
position: relative;
774-
margin-top: 5px;
774+
margin-top: 0;
775775
}
776776

777777
.toggle-wrapper.collapsed {
@@ -854,10 +854,19 @@ span.since {
854854

855855
.attributes {
856856
display: block;
857-
margin: 0px 0px 0px 30px !important;
857+
margin-top: 0px !important;
858+
margin-right: 0px;
859+
margin-bottom: 0px !important;
860+
margin-left: 30px;
858861
}
859862
.toggle-attributes.collapsed {
860-
margin-bottom: 5px;
863+
margin-bottom: 0;
864+
}
865+
.impl-items > .toggle-attributes {
866+
margin-left: 20px;
867+
}
868+
.impl-items .attributes {
869+
font-weight: 500;
861870
}
862871

863872
:target > code {

src/test/rustdoc/trait-attributes.rs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2018 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+
// ignore-tidy-linelength
14+
15+
pub trait Foo {
16+
// @has foo/trait.Foo.html '//h3[@id="tymethod.foo"]//div[@class="docblock attributes"]' '#[must_use]'
17+
#[must_use]
18+
fn foo();
19+
}
20+
21+
#[must_use]
22+
pub struct Bar;
23+
24+
impl Bar {
25+
// @has foo/struct.Bar.html '//h4[@id="method.bar"]//div[@class="docblock attributes"]' '#[must_use]'
26+
#[must_use]
27+
pub fn bar() {}
28+
29+
// @has foo/struct.Bar.html '//h4[@id="method.bar2"]//div[@class="docblock attributes"]' '#[must_use]'
30+
#[must_use]
31+
pub fn bar2() {}
32+
}

0 commit comments

Comments
 (0)