diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 8fb3b570f8a4b..d61855011d36b 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -2198,8 +2198,7 @@ fn document(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item) -> fmt::Re info!("Documenting {}", name); } document_stability(w, cx, item)?; - let prefix = render_assoc_const_value(item); - document_full(w, item, cx, &prefix)?; + document_full(w, item, cx, "")?; Ok(()) } @@ -2231,20 +2230,6 @@ fn document_short(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item, link Ok(()) } -fn render_assoc_const_value(item: &clean::Item) -> String { - match item.inner { - clean::AssociatedConstItem(ref ty, Some(ref default)) => { - highlight::render_with_highlighting( - &format!("{}: {:#} = {}", item.name.as_ref().unwrap(), ty, default), - None, - None, - None, - ) - } - _ => String::new(), - } -} - fn document_full(w: &mut fmt::Formatter, item: &clean::Item, cx: &Context, prefix: &str) -> fmt::Result { if let Some(s) = cx.shared.maybe_collapsed_doc_value(item) { @@ -2594,27 +2579,15 @@ fn short_stability(item: &clean::Item, cx: &Context, show_reason: bool) -> Vec(&'a str); - -impl<'a> fmt::Display for Initializer<'a> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let Initializer(s) = *self; - if s.is_empty() { return Ok(()); } - write!(f, " = ")?; - write!(f, "{}", Escape(s)) - } -} - fn item_constant(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, c: &clean::Constant) -> fmt::Result { write!(w, "
")?;
     render_attributes(w, it)?;
     write!(w, "{vis}const \
-               {name}: {typ}{init}
", + {name}: {typ}", vis = VisSpace(&it.visibility), name = it.name.as_ref().unwrap(), - typ = c.type_, - init = Initializer(&c.expr))?; + typ = c.type_)?; document(w, cx, it) } @@ -2623,12 +2596,11 @@ fn item_static(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, write!(w, "
")?;
     render_attributes(w, it)?;
     write!(w, "{vis}static {mutability}\
-               {name}: {typ}{init}
", + {name}: {typ}", vis = VisSpace(&it.visibility), mutability = MutableSpace(s.mutability), name = it.name.as_ref().unwrap(), - typ = s.type_, - init = Initializer(&s.expr))?; + typ = s.type_)?; document(w, cx, it) } @@ -3860,7 +3832,13 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi write!(w, "

", id, item_type)?; write!(w, "

\n")?; + let src = if let Some(l) = (Item { cx, item }).src_href() { + format!("[src]", + l, "goto source code") + } else { + String::new() + }; + write!(w, "{}\n", src)?; } clean::AssociatedTypeItem(ref bounds, ref default) => { let id = cx.derive_id(format!("{}.{}", item_type, name)); @@ -3875,8 +3853,6 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi } if render_method_item || render_mode == RenderMode::Normal { - let prefix = render_assoc_const_value(item); - if !is_default_item { if let Some(t) = trait_ { // The trait item may have been stripped so we might not @@ -3886,23 +3862,23 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi // because impls can't have a stability. document_stability(w, cx, it)?; if item.doc_value().is_some() { - document_full(w, item, cx, &prefix)?; + document_full(w, item, cx, "")?; } else if show_def_docs { // In case the item isn't documented, // provide short documentation from the trait. - document_short(w, cx, it, link, &prefix)?; + document_short(w, cx, it, link, "")?; } } } else { document_stability(w, cx, item)?; if show_def_docs { - document_full(w, item, cx, &prefix)?; + document_full(w, item, cx, "")?; } } } else { document_stability(w, cx, item)?; if show_def_docs { - document_short(w, cx, item, link, &prefix)?; + document_short(w, cx, item, link, "")?; } } } diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 70782973e426d..f57fb4b5cdb10 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -1990,7 +1990,8 @@ if (!next) { return; } - if ((checkIfThereAreMethods(next.childNodes) || hasClass(e, 'method')) && + if ((hasClass(e, 'method') || hasClass(e, 'associatedconstant') || + checkIfThereAreMethods(next.childNodes)) && (hasClass(next, 'docblock') || hasClass(e, 'impl') || (hasClass(next, 'stability') && @@ -1999,10 +2000,8 @@ } }; onEach(document.getElementsByClassName('method'), func); + onEach(document.getElementsByClassName('associatedconstant'), func); onEach(document.getElementsByClassName('impl'), func); - onEach(document.getElementsByClassName('impl-items'), function(e) { - onEach(e.getElementsByClassName('associatedconstant'), func); - }); function createToggle(otherMessage, fontSize, extraClass) { var span = document.createElement('span'); diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index 57a111daa8977..5ed91e63cdce9 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -559,6 +559,14 @@ a { text-decoration: underline; } +.invisible > .srclink { + position: absolute; + top: 0; + right: 0; + font-size: 17px; + font-weight: normal; +} + .block a.current.crate { font-weight: 500; } .search-container { diff --git a/src/test/rustdoc/assoc-consts.rs b/src/test/rustdoc/assoc-consts.rs index 2edf61288f588..71e7db5f4a543 100644 --- a/src/test/rustdoc/assoc-consts.rs +++ b/src/test/rustdoc/assoc-consts.rs @@ -13,7 +13,6 @@ pub trait Foo { // @has assoc_consts/trait.Foo.html '//*[@class="rust trait"]' \ // 'const FOO: usize;' // @has - '//*[@id="associatedconstant.FOO"]' 'const FOO: usize' - // @has - '//*[@class="docblock"]' 'FOO: usize = 12' const FOO: usize = 12; // @has - '//*[@id="associatedconstant.FOO_NO_DEFAULT"]' 'const FOO_NO_DEFAULT: bool' const FOO_NO_DEFAULT: bool; @@ -27,10 +26,8 @@ pub struct Bar; impl Foo for Bar { // @has assoc_consts/struct.Bar.html '//code' 'impl Foo for Bar' // @has - '//*[@id="associatedconstant.FOO"]' 'const FOO: usize' - // @has - '//*[@class="docblock"]' 'FOO: usize = 12' const FOO: usize = 12; // @has - '//*[@id="associatedconstant.FOO_NO_DEFAULT"]' 'const FOO_NO_DEFAULT: bool' - // @has - '//*[@class="docblock"]' 'FOO_NO_DEFAULT: bool = false' const FOO_NO_DEFAULT: bool = false; // @!has - FOO_HIDDEN #[doc(hidden)] @@ -40,7 +37,6 @@ impl Foo for Bar { impl Bar { // @has assoc_consts/struct.Bar.html '//*[@id="associatedconstant.BAR"]' \ // 'const BAR: usize' - // @has - '//*[@class="docblock"]' 'BAR: usize = 3' pub const BAR: usize = 3; } @@ -49,7 +45,6 @@ pub struct Baz<'a, U: 'a, T>(T, &'a [U]); impl Bar { // @has assoc_consts/struct.Bar.html '//*[@id="associatedconstant.BAZ"]' \ // "const BAZ: Baz<'static, u8, u32>" - // @has - '//*[@class="docblock"]' "BAZ: Baz<'static, u8, u32> = Baz(321, &[1, 2, 3])" pub const BAZ: Baz<'static, u8, u32> = Baz(321, &[1, 2, 3]); } @@ -58,7 +53,6 @@ pub fn f(_: &(ToString + 'static)) {} impl Bar { // @has assoc_consts/struct.Bar.html '//*[@id="associatedconstant.F"]' \ // "const F: fn(_: &(ToString + 'static))" - // @has - '//*[@class="docblock"]' "F: fn(_: &(ToString + 'static)) = f" pub const F: fn(_: &(ToString + 'static)) = f; } @@ -81,17 +75,14 @@ pub trait Qux { /// Docs for QUX1 in trait. const QUX1: i8; // @has - '//*[@id="associatedconstant.QUX_DEFAULT0"]' 'const QUX_DEFAULT0: u16' - // @has - '//*[@class="docblock"]' "QUX_DEFAULT0: u16 = 1" // @has - '//*[@class="docblock"]' "Docs for QUX_DEFAULT0 in trait." /// Docs for QUX_DEFAULT0 in trait. const QUX_DEFAULT0: u16 = 1; // @has - '//*[@id="associatedconstant.QUX_DEFAULT1"]' 'const QUX_DEFAULT1: i16' - // @has - '//*[@class="docblock"]' "QUX_DEFAULT1: i16 = 2" // @has - '//*[@class="docblock"]' "Docs for QUX_DEFAULT1 in trait." /// Docs for QUX_DEFAULT1 in trait. const QUX_DEFAULT1: i16 = 2; // @has - '//*[@id="associatedconstant.QUX_DEFAULT2"]' 'const QUX_DEFAULT2: u32' - // @has - '//*[@class="docblock"]' "QUX_DEFAULT2: u32 = 3" // @has - '//*[@class="docblock"]' "Docs for QUX_DEFAULT2 in trait." /// Docs for QUX_DEFAULT2 in trait. const QUX_DEFAULT2: u32 = 3; @@ -100,25 +91,20 @@ pub trait Qux { // @has assoc_consts/struct.Bar.html '//code' 'impl Qux for Bar' impl Qux for Bar { // @has - '//*[@id="associatedconstant.QUX0"]' 'const QUX0: u8' - // @has - '//*[@class="docblock"]' "QUX0: u8 = 4" // @has - '//*[@class="docblock"]' "Docs for QUX0 in trait." /// Docs for QUX0 in trait. const QUX0: u8 = 4; // @has - '//*[@id="associatedconstant.QUX1"]' 'const QUX1: i8' - // @has - '//*[@class="docblock"]' "QUX1: i8 = 5" // @has - '//*[@class="docblock"]' "Docs for QUX1 in impl." /// Docs for QUX1 in impl. const QUX1: i8 = 5; // @has - '//*[@id="associatedconstant.QUX_DEFAULT0"]' 'const QUX_DEFAULT0: u16' - // @has - '//*[@class="docblock"]' "QUX_DEFAULT0: u16 = 6" // @has - '//*[@class="docblock"]' "Docs for QUX_DEFAULT0 in trait." const QUX_DEFAULT0: u16 = 6; // @has - '//*[@id="associatedconstant.QUX_DEFAULT1"]' 'const QUX_DEFAULT1: i16' - // @has - '//*[@class="docblock"]' "QUX_DEFAULT1: i16 = 7" // @has - '//*[@class="docblock"]' "Docs for QUX_DEFAULT1 in impl." /// Docs for QUX_DEFAULT1 in impl. const QUX_DEFAULT1: i16 = 7; // @has - '//*[@id="associatedconstant.QUX_DEFAULT2"]' 'const QUX_DEFAULT2: u32' - // @has - '//*[@class="docblock"]' "QUX_DEFAULT2: u32 = 3" // @has - '//*[@class="docblock"]' "Docs for QUX_DEFAULT2 in trait." } diff --git a/src/test/rustdoc/const-doc.rs b/src/test/rustdoc/const-doc.rs index 9884e3d2c1995..b8bded7621e53 100644 --- a/src/test/rustdoc/const-doc.rs +++ b/src/test/rustdoc/const-doc.rs @@ -23,7 +23,7 @@ pub struct ContentType { impl ContentType { // @has const_doc/struct.ContentType.html - // @has - '//*[@class="docblock"]' 'Any: ContentType = ContentType{ttype: Foo{f: ' + // @has - '//*[@id="associatedconstant.Any"]' 'const Any: ContentType' pub const Any: ContentType = ContentType { ttype: Foo { f: PhantomData, }, subtype: Foo { f: PhantomData, }, params: None, }; diff --git a/src/test/rustdoc/escape-rust-expr.rs b/src/test/rustdoc/escape-rust-expr.rs index 7f9a2bf175a5f..4594eb95ea18e 100644 --- a/src/test/rustdoc/escape-rust-expr.rs +++ b/src/test/rustdoc/escape-rust-expr.rs @@ -11,5 +11,5 @@ // Test that we HTML-escape Rust expressions, where HTML special chars // can occur, and we know it's definitely not markup. -// @has escape_rust_expr/constant.CONST_S.html '//pre[@class="rust const"]' '"