Skip to content

Commit f2302da

Browse files
committed
Auto merge of #53409 - GuillaumeGomez:associated-const-value, r=QuietMisdreavus
Don't show associated const value anymore Part of #44348. Before: <img width="1440" alt="screen shot 2018-08-16 at 00 48 30" src="https://user-images.githubusercontent.com/3050060/44177414-20ef1480-a0ee-11e8-80d4-7caf082cf0de.png"> After: <img width="1440" alt="screen shot 2018-08-16 at 00 48 23" src="https://user-images.githubusercontent.com/3050060/44177417-251b3200-a0ee-11e8-956a-4229275e3342.png"> cc @nox r? @QuietMisdreavus
2 parents 06d2448 + 8614179 commit f2302da

File tree

9 files changed

+31
-73
lines changed

9 files changed

+31
-73
lines changed

src/librustdoc/html/render.rs

+16-40
Original file line numberDiff line numberDiff line change
@@ -2213,8 +2213,7 @@ fn document(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item) -> fmt::Re
22132213
info!("Documenting {}", name);
22142214
}
22152215
document_stability(w, cx, item)?;
2216-
let prefix = render_assoc_const_value(item);
2217-
document_full(w, item, cx, &prefix)?;
2216+
document_full(w, item, cx, "")?;
22182217
Ok(())
22192218
}
22202219

@@ -2246,20 +2245,6 @@ fn document_short(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item, link
22462245
Ok(())
22472246
}
22482247

2249-
fn render_assoc_const_value(item: &clean::Item) -> String {
2250-
match item.inner {
2251-
clean::AssociatedConstItem(ref ty, Some(ref default)) => {
2252-
highlight::render_with_highlighting(
2253-
&format!("{}: {:#} = {}", item.name.as_ref().unwrap(), ty, default),
2254-
None,
2255-
None,
2256-
None,
2257-
)
2258-
}
2259-
_ => String::new(),
2260-
}
2261-
}
2262-
22632248
fn document_full(w: &mut fmt::Formatter, item: &clean::Item,
22642249
cx: &Context, prefix: &str) -> fmt::Result {
22652250
if let Some(s) = cx.shared.maybe_collapsed_doc_value(item) {
@@ -2609,27 +2594,15 @@ fn short_stability(item: &clean::Item, cx: &Context, show_reason: bool) -> Vec<S
26092594
stability
26102595
}
26112596

2612-
struct Initializer<'a>(&'a str);
2613-
2614-
impl<'a> fmt::Display for Initializer<'a> {
2615-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2616-
let Initializer(s) = *self;
2617-
if s.is_empty() { return Ok(()); }
2618-
write!(f, "<code> = </code>")?;
2619-
write!(f, "<code>{}</code>", Escape(s))
2620-
}
2621-
}
2622-
26232597
fn item_constant(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
26242598
c: &clean::Constant) -> fmt::Result {
26252599
write!(w, "<pre class='rust const'>")?;
26262600
render_attributes(w, it)?;
26272601
write!(w, "{vis}const \
2628-
{name}: {typ}{init}</pre>",
2602+
{name}: {typ}</pre>",
26292603
vis = VisSpace(&it.visibility),
26302604
name = it.name.as_ref().unwrap(),
2631-
typ = c.type_,
2632-
init = Initializer(&c.expr))?;
2605+
typ = c.type_)?;
26332606
document(w, cx, it)
26342607
}
26352608

@@ -2638,12 +2611,11 @@ fn item_static(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
26382611
write!(w, "<pre class='rust static'>")?;
26392612
render_attributes(w, it)?;
26402613
write!(w, "{vis}static {mutability}\
2641-
{name}: {typ}{init}</pre>",
2614+
{name}: {typ}</pre>",
26422615
vis = VisSpace(&it.visibility),
26432616
mutability = MutableSpace(s.mutability),
26442617
name = it.name.as_ref().unwrap(),
2645-
typ = s.type_,
2646-
init = Initializer(&s.expr))?;
2618+
typ = s.type_)?;
26472619
document(w, cx, it)
26482620
}
26492621

@@ -3878,7 +3850,13 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
38783850
write!(w, "<h4 id='{}' class=\"{}\">", id, item_type)?;
38793851
write!(w, "<span id='{}' class='invisible'><code>", ns_id)?;
38803852
assoc_const(w, item, ty, default.as_ref(), link.anchor(&id))?;
3881-
write!(w, "</code></span></h4>\n")?;
3853+
let src = if let Some(l) = (Item { cx, item }).src_href() {
3854+
format!("<a class='srclink' href='{}' title='{}'>[src]</a>",
3855+
l, "goto source code")
3856+
} else {
3857+
String::new()
3858+
};
3859+
write!(w, "</code>{}</span></h4>\n", src)?;
38823860
}
38833861
clean::AssociatedTypeItem(ref bounds, ref default) => {
38843862
let id = cx.derive_id(format!("{}.{}", item_type, name));
@@ -3893,8 +3871,6 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
38933871
}
38943872

38953873
if render_method_item || render_mode == RenderMode::Normal {
3896-
let prefix = render_assoc_const_value(item);
3897-
38983874
if !is_default_item {
38993875
if let Some(t) = trait_ {
39003876
// The trait item may have been stripped so we might not
@@ -3904,23 +3880,23 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
39043880
// because impls can't have a stability.
39053881
document_stability(w, cx, it)?;
39063882
if item.doc_value().is_some() {
3907-
document_full(w, item, cx, &prefix)?;
3883+
document_full(w, item, cx, "")?;
39083884
} else if show_def_docs {
39093885
// In case the item isn't documented,
39103886
// provide short documentation from the trait.
3911-
document_short(w, cx, it, link, &prefix)?;
3887+
document_short(w, cx, it, link, "")?;
39123888
}
39133889
}
39143890
} else {
39153891
document_stability(w, cx, item)?;
39163892
if show_def_docs {
3917-
document_full(w, item, cx, &prefix)?;
3893+
document_full(w, item, cx, "")?;
39183894
}
39193895
}
39203896
} else {
39213897
document_stability(w, cx, item)?;
39223898
if show_def_docs {
3923-
document_short(w, cx, item, link, &prefix)?;
3899+
document_short(w, cx, item, link, "")?;
39243900
}
39253901
}
39263902
}

src/librustdoc/html/static/main.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -2028,7 +2028,8 @@
20282028
if (!next) {
20292029
return;
20302030
}
2031-
if ((checkIfThereAreMethods(next.childNodes) || hasClass(e, 'method')) &&
2031+
if ((hasClass(e, 'method') || hasClass(e, 'associatedconstant') ||
2032+
checkIfThereAreMethods(next.childNodes)) &&
20322033
(hasClass(next, 'docblock') ||
20332034
hasClass(e, 'impl') ||
20342035
(hasClass(next, 'stability') &&
@@ -2037,10 +2038,8 @@
20372038
}
20382039
};
20392040
onEach(document.getElementsByClassName('method'), func);
2041+
onEach(document.getElementsByClassName('associatedconstant'), func);
20402042
onEach(document.getElementsByClassName('impl'), func);
2041-
onEach(document.getElementsByClassName('impl-items'), function(e) {
2042-
onEach(e.getElementsByClassName('associatedconstant'), func);
2043-
});
20442043

20452044
function createToggle(otherMessage, fontSize, extraClass) {
20462045
var span = document.createElement('span');

src/librustdoc/html/static/rustdoc.css

+8
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,14 @@ a {
575575
text-decoration: underline;
576576
}
577577

578+
.invisible > .srclink {
579+
position: absolute;
580+
top: 0;
581+
right: 0;
582+
font-size: 17px;
583+
font-weight: normal;
584+
}
585+
578586
.block a.current.crate { font-weight: 500; }
579587

580588
.search-container {

src/test/rustdoc/assoc-consts.rs

-14
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ pub trait Foo {
1313
// @has assoc_consts/trait.Foo.html '//*[@class="rust trait"]' \
1414
// 'const FOO: usize;'
1515
// @has - '//*[@id="associatedconstant.FOO"]' 'const FOO: usize'
16-
// @has - '//*[@class="docblock"]' 'FOO: usize = 12'
1716
const FOO: usize = 12;
1817
// @has - '//*[@id="associatedconstant.FOO_NO_DEFAULT"]' 'const FOO_NO_DEFAULT: bool'
1918
const FOO_NO_DEFAULT: bool;
@@ -27,10 +26,8 @@ pub struct Bar;
2726
impl Foo for Bar {
2827
// @has assoc_consts/struct.Bar.html '//code' 'impl Foo for Bar'
2928
// @has - '//*[@id="associatedconstant.FOO"]' 'const FOO: usize'
30-
// @has - '//*[@class="docblock"]' 'FOO: usize = 12'
3129
const FOO: usize = 12;
3230
// @has - '//*[@id="associatedconstant.FOO_NO_DEFAULT"]' 'const FOO_NO_DEFAULT: bool'
33-
// @has - '//*[@class="docblock"]' 'FOO_NO_DEFAULT: bool = false'
3431
const FOO_NO_DEFAULT: bool = false;
3532
// @!has - FOO_HIDDEN
3633
#[doc(hidden)]
@@ -40,7 +37,6 @@ impl Foo for Bar {
4037
impl Bar {
4138
// @has assoc_consts/struct.Bar.html '//*[@id="associatedconstant.BAR"]' \
4239
// 'const BAR: usize'
43-
// @has - '//*[@class="docblock"]' 'BAR: usize = 3'
4440
pub const BAR: usize = 3;
4541
}
4642

@@ -49,7 +45,6 @@ pub struct Baz<'a, U: 'a, T>(T, &'a [U]);
4945
impl Bar {
5046
// @has assoc_consts/struct.Bar.html '//*[@id="associatedconstant.BAZ"]' \
5147
// "const BAZ: Baz<'static, u8, u32>"
52-
// @has - '//*[@class="docblock"]' "BAZ: Baz<'static, u8, u32> = Baz(321, &[1, 2, 3])"
5348
pub const BAZ: Baz<'static, u8, u32> = Baz(321, &[1, 2, 3]);
5449
}
5550

@@ -58,7 +53,6 @@ pub fn f(_: &(ToString + 'static)) {}
5853
impl Bar {
5954
// @has assoc_consts/struct.Bar.html '//*[@id="associatedconstant.F"]' \
6055
// "const F: fn(_: &(ToString + 'static))"
61-
// @has - '//*[@class="docblock"]' "F: fn(_: &(ToString + 'static)) = f"
6256
pub const F: fn(_: &(ToString + 'static)) = f;
6357
}
6458

@@ -81,17 +75,14 @@ pub trait Qux {
8175
/// Docs for QUX1 in trait.
8276
const QUX1: i8;
8377
// @has - '//*[@id="associatedconstant.QUX_DEFAULT0"]' 'const QUX_DEFAULT0: u16'
84-
// @has - '//*[@class="docblock"]' "QUX_DEFAULT0: u16 = 1"
8578
// @has - '//*[@class="docblock"]' "Docs for QUX_DEFAULT0 in trait."
8679
/// Docs for QUX_DEFAULT0 in trait.
8780
const QUX_DEFAULT0: u16 = 1;
8881
// @has - '//*[@id="associatedconstant.QUX_DEFAULT1"]' 'const QUX_DEFAULT1: i16'
89-
// @has - '//*[@class="docblock"]' "QUX_DEFAULT1: i16 = 2"
9082
// @has - '//*[@class="docblock"]' "Docs for QUX_DEFAULT1 in trait."
9183
/// Docs for QUX_DEFAULT1 in trait.
9284
const QUX_DEFAULT1: i16 = 2;
9385
// @has - '//*[@id="associatedconstant.QUX_DEFAULT2"]' 'const QUX_DEFAULT2: u32'
94-
// @has - '//*[@class="docblock"]' "QUX_DEFAULT2: u32 = 3"
9586
// @has - '//*[@class="docblock"]' "Docs for QUX_DEFAULT2 in trait."
9687
/// Docs for QUX_DEFAULT2 in trait.
9788
const QUX_DEFAULT2: u32 = 3;
@@ -100,25 +91,20 @@ pub trait Qux {
10091
// @has assoc_consts/struct.Bar.html '//code' 'impl Qux for Bar'
10192
impl Qux for Bar {
10293
// @has - '//*[@id="associatedconstant.QUX0"]' 'const QUX0: u8'
103-
// @has - '//*[@class="docblock"]' "QUX0: u8 = 4"
10494
// @has - '//*[@class="docblock"]' "Docs for QUX0 in trait."
10595
/// Docs for QUX0 in trait.
10696
const QUX0: u8 = 4;
10797
// @has - '//*[@id="associatedconstant.QUX1"]' 'const QUX1: i8'
108-
// @has - '//*[@class="docblock"]' "QUX1: i8 = 5"
10998
// @has - '//*[@class="docblock"]' "Docs for QUX1 in impl."
11099
/// Docs for QUX1 in impl.
111100
const QUX1: i8 = 5;
112101
// @has - '//*[@id="associatedconstant.QUX_DEFAULT0"]' 'const QUX_DEFAULT0: u16'
113-
// @has - '//*[@class="docblock"]' "QUX_DEFAULT0: u16 = 6"
114102
// @has - '//*[@class="docblock"]' "Docs for QUX_DEFAULT0 in trait."
115103
const QUX_DEFAULT0: u16 = 6;
116104
// @has - '//*[@id="associatedconstant.QUX_DEFAULT1"]' 'const QUX_DEFAULT1: i16'
117-
// @has - '//*[@class="docblock"]' "QUX_DEFAULT1: i16 = 7"
118105
// @has - '//*[@class="docblock"]' "Docs for QUX_DEFAULT1 in impl."
119106
/// Docs for QUX_DEFAULT1 in impl.
120107
const QUX_DEFAULT1: i16 = 7;
121108
// @has - '//*[@id="associatedconstant.QUX_DEFAULT2"]' 'const QUX_DEFAULT2: u32'
122-
// @has - '//*[@class="docblock"]' "QUX_DEFAULT2: u32 = 3"
123109
// @has - '//*[@class="docblock"]' "Docs for QUX_DEFAULT2 in trait."
124110
}

src/test/rustdoc/const-doc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub struct ContentType {
2323

2424
impl ContentType {
2525
// @has const_doc/struct.ContentType.html
26-
// @has - '//*[@class="docblock"]' 'Any: ContentType = ContentType{ttype: Foo{f: '
26+
// @has - '//*[@id="associatedconstant.Any"]' 'const Any: ContentType'
2727
pub const Any: ContentType = ContentType { ttype: Foo { f: PhantomData, },
2828
subtype: Foo { f: PhantomData, },
2929
params: None, };

src/test/rustdoc/escape-rust-expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
// Test that we HTML-escape Rust expressions, where HTML special chars
1212
// can occur, and we know it's definitely not markup.
1313

14-
// @has escape_rust_expr/constant.CONST_S.html '//pre[@class="rust const"]' '"<script>"'
14+
// @!has escape_rust_expr/constant.CONST_S.html '//pre[@class="rust const"]' '"<script>"'
1515
pub const CONST_S: &'static str = "<script>";

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

-5
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,13 @@ extern crate assoc_items;
1919
// @has foo/struct.MyStruct.html
2020
// @!has - 'PrivateConst'
2121
// @has - '//*[@id="associatedconstant.PublicConst"]' 'pub const PublicConst: u8'
22-
// @has - '//*[@class="docblock"]' 'PublicConst: u8 = 123'
2322
// @has - '//*[@class="docblock"]' 'docs for PublicConst'
2423
// @!has - 'private_method'
2524
// @has - '//*[@id="method.public_method"]' 'pub fn public_method()'
2625
// @has - '//*[@class="docblock"]' 'docs for public_method'
2726
// @has - '//*[@id="associatedconstant.ConstNoDefault"]' 'const ConstNoDefault: i16'
28-
// @has - '//*[@class="docblock"]' 'ConstNoDefault: i16 = -123'
2927
// @has - '//*[@class="docblock"]' 'dox for ConstNoDefault'
3028
// @has - '//*[@id="associatedconstant.ConstWithDefault"]' 'const ConstWithDefault: u16'
31-
// @has - '//*[@class="docblock"]' 'ConstWithDefault: u16 = 12345'
3229
// @has - '//*[@class="docblock"]' 'docs for ConstWithDefault'
3330
// @has - '//*[@id="associatedtype.TypeNoDefault"]' 'type TypeNoDefault = i32'
3431
// @has - '//*[@class="docblock"]' 'dox for TypeNoDefault'
@@ -44,11 +41,9 @@ pub use assoc_items::MyStruct;
4441
// @has - '//*[@id="associatedconstant.ConstNoDefault"]' 'const ConstNoDefault: i16'
4542
// @has - '//*[@class="docblock"]' 'docs for ConstNoDefault'
4643
// @has - '//*[@id="associatedconstant.ConstWithDefault"]' 'const ConstWithDefault: u16'
47-
// @has - '//*[@class="docblock"]' 'ConstWithDefault: u16 = 12345'
4844
// @has - '//*[@class="docblock"]' 'docs for ConstWithDefault'
4945
// @has - '//*[@id="associatedtype.TypeNoDefault"]' 'type TypeNoDefault'
5046
// @has - '//*[@class="docblock"]' 'docs for TypeNoDefault'
51-
// @has - '//*[@id="associatedtype.TypeWithDefault"]' 'type TypeWithDefault = u32'
5247
// @has - '//*[@class="docblock"]' 'docs for TypeWithDefault'
5348
// @has - '//*[@id="tymethod.method_no_default"]' 'fn method_no_default()'
5449
// @has - '//*[@class="docblock"]' 'docs for method_no_default'

src/test/rustdoc/issue-28478.rs

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ pub trait Bar {
1616
// @has - '//*[@href="#associatedtype.Bar"]' 'Bar'
1717
type Bar = ();
1818
// @has - '//*[@id="associatedconstant.Baz"]' 'const Baz: usize'
19-
// @has - '//*[@class="docblock"]' 'Baz: usize = 7'
2019
// @has - '//*[@href="#associatedconstant.Baz"]' 'Baz'
2120
const Baz: usize = 7;
2221
// @has - '//*[@id="tymethod.bar"]' 'fn bar'

src/test/rustdoc/issue-33302.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,17 @@ macro_rules! make {
1717
pub struct S;
1818

1919
// @has issue_33302/constant.CST.html \
20-
// '//pre[@class="rust const"]' 'pub const CST: i32 = 4 * 4'
20+
// '//pre[@class="rust const"]' 'pub const CST: i32'
2121
pub const CST: i32 = ($n * $n);
2222
// @has issue_33302/static.ST.html \
23-
// '//pre[@class="rust static"]' 'pub static ST: i32 = 4 * 4'
23+
// '//pre[@class="rust static"]' 'pub static ST: i32'
2424
pub static ST: i32 = ($n * $n);
2525

2626
pub trait T<X> {
2727
fn ignore(_: &X) {}
2828
const C: X;
2929
// @has issue_33302/trait.T.html \
3030
// '//*[@class="rust trait"]' 'const D: i32'
31-
// @has - '//*[@class="docblock"]' 'D: i32 = 4 * 4'
3231
// @has - '//*[@id="associatedconstant.D"]' 'const D: i32'
3332
const D: i32 = ($n * $n);
3433
}
@@ -37,7 +36,6 @@ macro_rules! make {
3736
// '//h3[@class="impl"]' 'impl T<[i32; 16]> for S'
3837
// @has - '//*[@id="associatedconstant.C"]' 'const C: [i32; 16]'
3938
// @has - '//*[@id="associatedconstant.D"]' 'const D: i32'
40-
// @has - '//*[@class="docblock"]' 'C: [i32; 16] = [0; 4 * 4]'
4139
impl T<[i32; ($n * $n)]> for S {
4240
const C: [i32; ($n * $n)] = [0; ($n * $n)];
4341
}
@@ -46,7 +44,6 @@ macro_rules! make {
4644
// '//h3[@class="impl"]' 'impl T<[i32; 16]> for S'
4745
// @has - '//*[@id="associatedconstant.C-1"]' 'const C: (i32,)'
4846
// @has - '//*[@id="associatedconstant.D-1"]' 'const D: i32'
49-
// @has - '//*[@class="docblock"]' 'C: (i32,) = (4,)'
5047
impl T<(i32,)> for S {
5148
const C: (i32,) = ($n,);
5249
}
@@ -55,8 +52,6 @@ macro_rules! make {
5552
// '//h3[@class="impl"]' 'impl T<(i32, i32)> for S'
5653
// @has - '//*[@id="associatedconstant.C-2"]' 'const C: (i32, i32)'
5754
// @has - '//*[@id="associatedconstant.D-2"]' 'const D: i32'
58-
// @has - '//*[@class="docblock"]' 'C: (i32, i32) = (4, 4)'
59-
// @has - '//*[@class="docblock"]' 'D: i32 = 4 / 4'
6055
impl T<(i32, i32)> for S {
6156
const C: (i32, i32) = ($n, $n);
6257
const D: i32 = ($n / $n);

0 commit comments

Comments
 (0)