diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 46002c089cf9f..fdc4d5d75b3d9 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -3037,15 +3037,14 @@ fn item_trait( let item_type = m.type_(); let id = cx.derive_id(format!("{}.{}", item_type, name)); let ns_id = cx.derive_id(format!("{}.{}", name, item_type.name_space())); - write!(w, "{extra}

\ -

")?; document(w, cx, m)?; Ok(()) } @@ -3237,13 +3236,14 @@ fn assoc_type(w: &mut W, it: &clean::Item, Ok(()) } -fn render_stability_since_raw<'a>(w: &mut fmt::Formatter, - ver: Option<&'a str>, - containing_ver: Option<&'a str>) -> fmt::Result { +fn render_stability_since_raw<'a, T: fmt::Write>( + w: &mut T, + ver: Option<&'a str>, + containing_ver: Option<&'a str>, +) -> fmt::Result { if let Some(v) = ver { if containing_ver != ver && v.len() > 0 { - write!(w, "
{0}
", - v)? + write!(w, "
{0}
", v)? } } Ok(()) @@ -3373,11 +3373,10 @@ fn item_struct(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, let ns_id = cx.derive_id(format!("{}.{}", field.name.as_ref().unwrap(), ItemType::StructField.name_space())); - write!(w, " - - ", + write!(w, "\ + \ + {name}: {ty}\ + ", item_type = ItemType::StructField, id = id, ns_id = ns_id, @@ -3509,7 +3508,7 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, ItemType::Variant.name_space())); write!(w, "\ \ - ")?; + write!(w, "")?; document(w, cx, variant)?; use clean::{Variant, VariantKind}; @@ -3552,8 +3551,8 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, ItemType::StructField.name_space())); write!(w, "\ \ - ", + {f}: {t}\ + ", id = id, ns_id = ns_id, f = field.name.as_ref().unwrap(), @@ -3998,7 +3997,7 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi id, i.inner_impl())?; } write!(w, "", id)?; - write!(w, "")?; + write!(w, "")?; let since = i.impl_item.stability.as_ref().map(|s| &s.since[..]); if let Some(l) = (Item { item: &i.impl_item, cx: cx }).src_href() { write!(w, "
")?; @@ -4008,7 +4007,7 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi } else { render_stability_since_raw(w, since, outer_version)?; } - write!(w, "
")?; + write!(w, "
")?; if let Some(ref dox) = cx.shared.maybe_collapsed_doc_value(&i.impl_item) { let mut ids = cx.id_map.borrow_mut(); write!(w, "
{}
", @@ -4044,52 +4043,73 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi let ns_id = cx.derive_id(format!("{}.{}", name, item_type.name_space())); write!(w, "

", id, item_type, extra_class)?; write!(w, "{}", spotlight_decl(decl)?)?; - write!(w, "

")?; } } clean::TypedefItem(ref tydef, _) => { let id = cx.derive_id(format!("{}.{}", ItemType::AssociatedType, name)); let ns_id = cx.derive_id(format!("{}.{}", name, item_type.name_space())); write!(w, "

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

\n")?; + write!(w, "")?; } clean::AssociatedConstItem(ref ty, ref default) => { + let mut version = String::new(); + + render_stability_since_raw(&mut version, item.stable_since(), outer_version)?; + let id = cx.derive_id(format!("{}.{}", item_type, name)); let ns_id = cx.derive_id(format!("{}.{}", name, item_type.name_space())); write!(w, "

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

", src)?; + } } clean::AssociatedTypeItem(ref bounds, ref default) => { let id = cx.derive_id(format!("{}.{}", item_type, name)); let ns_id = cx.derive_id(format!("{}.{}", name, item_type.name_space())); write!(w, "

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

\n")?; + write!(w, "")?; } clean::StrippedItem(..) => return Ok(()), _ => panic!("can't make docs for trait item with name {:?}", item.name) diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index 1480c54ce4084..7a3682503f7a5 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -611,7 +611,7 @@ a { text-decoration: underline; } -.invisible > .srclink { +.invisible > .srclink, h4 > code + .srclink { position: absolute; top: 0; right: 0; diff --git a/src/test/rustdoc/assoc-consts-version.rs b/src/test/rustdoc/assoc-consts-version.rs new file mode 100644 index 0000000000000..2295be2725814 --- /dev/null +++ b/src/test/rustdoc/assoc-consts-version.rs @@ -0,0 +1,26 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// ignore-tidy-linelength + +#![crate_name = "foo"] + +#![feature(staged_api)] + +#![stable(since="1.1.1", feature="rust1")] + +#[stable(since="1.1.1", feature="rust1")] +pub struct SomeStruct; + +impl SomeStruct { + // @has 'foo/struct.SomeStruct.html' '//*[@id="SOME_CONST.v"]//div[@class="since"]' '1.1.2' + #[stable(since="1.1.2", feature="rust2")] + pub const SOME_CONST: usize = 0; +} diff --git a/src/test/rustdoc/assoc-types.rs b/src/test/rustdoc/assoc-types.rs index d152be33f4c74..100bf7af0e9b3 100644 --- a/src/test/rustdoc/assoc-types.rs +++ b/src/test/rustdoc/assoc-types.rs @@ -15,9 +15,9 @@ // @has assoc_types/trait.Index.html pub trait Index { // @has - '//*[@id="associatedtype.Output"]//code' 'type Output: ?Sized' - // @has - '//*[@id="Output.t"]//code' 'type Output: ?Sized' + // @has - '//code[@id="Output.t"]' 'type Output: ?Sized' type Output: ?Sized; - // @has - '//*[@id="index.v"]//code' 'fn index' + // @has - '//code[@id="index.v"]' 'fn index' // @has - '//*[@id="tymethod.index"]//code' \ // "fn index<'a>(&'a self, index: I) -> &'a Self::Output" // @has - '//*[@id="tymethod.index"]//code//a[@href="../assoc_types/trait.Index.html#associatedtype.Output"]' \