rustdoc: Fix rendering associated constants
Associated constants were now showing up for traits and would panic if they were found on an inherent impl. This commit unblocks the nighly builders.
This commit is contained in:
parent
ac5f595d0a
commit
543b910f9b
@ -1787,6 +1787,9 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
|
||||
let types = t.items.iter().filter(|m| {
|
||||
match m.inner { clean::AssociatedTypeItem(..) => true, _ => false }
|
||||
}).collect::<Vec<_>>();
|
||||
let consts = t.items.iter().filter(|m| {
|
||||
match m.inner { clean::AssociatedConstItem(..) => true, _ => false }
|
||||
}).collect::<Vec<_>>();
|
||||
let required = t.items.iter().filter(|m| {
|
||||
match m.inner { clean::TyMethodItem(_) => true, _ => false }
|
||||
}).collect::<Vec<_>>();
|
||||
@ -1803,7 +1806,15 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
|
||||
try!(render_assoc_item(w, t, AssocItemLink::Anchor));
|
||||
try!(write!(w, ";\n"));
|
||||
}
|
||||
if !types.is_empty() && !required.is_empty() {
|
||||
if !types.is_empty() && !consts.is_empty() {
|
||||
try!(w.write_str("\n"));
|
||||
}
|
||||
for t in &consts {
|
||||
try!(write!(w, " "));
|
||||
try!(render_assoc_item(w, t, AssocItemLink::Anchor));
|
||||
try!(write!(w, ";\n"));
|
||||
}
|
||||
if !consts.is_empty() && !required.is_empty() {
|
||||
try!(w.write_str("\n"));
|
||||
}
|
||||
for m in &required {
|
||||
@ -1905,11 +1916,11 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
|
||||
}
|
||||
|
||||
fn assoc_const(w: &mut fmt::Formatter, it: &clean::Item,
|
||||
ty: &clean::Type, default: &Option<String>)
|
||||
ty: &clean::Type, default: Option<&String>)
|
||||
-> fmt::Result {
|
||||
try!(write!(w, "const {}", it.name.as_ref().unwrap()));
|
||||
try!(write!(w, ": {}", ty));
|
||||
if let Some(ref default) = *default {
|
||||
if let Some(default) = default {
|
||||
try!(write!(w, " = {}", default));
|
||||
}
|
||||
Ok(())
|
||||
@ -1971,7 +1982,7 @@ fn render_assoc_item(w: &mut fmt::Formatter, meth: &clean::Item,
|
||||
link)
|
||||
}
|
||||
clean::AssociatedConstItem(ref ty, ref default) => {
|
||||
assoc_const(w, meth, ty, default)
|
||||
assoc_const(w, meth, ty, default.as_ref())
|
||||
}
|
||||
clean::AssociatedTypeItem(ref bounds, ref default) => {
|
||||
assoc_type(w, meth, bounds, default)
|
||||
@ -2335,9 +2346,15 @@ fn render_impl(w: &mut fmt::Formatter, i: &Impl, link: AssocItemLink,
|
||||
clean::AssociatedConstItem(ref ty, ref default) => {
|
||||
let name = item.name.as_ref().unwrap();
|
||||
try!(write!(w, "<h4 id='assoc_const.{}' class='{}'><code>",
|
||||
*name,
|
||||
shortty(item)));
|
||||
try!(assoc_const(w, item, ty, default));
|
||||
*name, shortty(item)));
|
||||
try!(assoc_const(w, item, ty, default.as_ref()));
|
||||
try!(write!(w, "</code></h4>\n"));
|
||||
}
|
||||
clean::ConstantItem(ref c) => {
|
||||
let name = item.name.as_ref().unwrap();
|
||||
try!(write!(w, "<h4 id='assoc_const.{}' class='{}'><code>",
|
||||
*name, shortty(item)));
|
||||
try!(assoc_const(w, item, &c.type_, Some(&c.expr)));
|
||||
try!(write!(w, "</code></h4>\n"));
|
||||
}
|
||||
clean::AssociatedTypeItem(ref bounds, ref default) => {
|
||||
|
25
src/test/rustdoc/assoc-consts.rs
Normal file
25
src/test/rustdoc/assoc-consts.rs
Normal file
@ -0,0 +1,25 @@
|
||||
// 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 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(associated_consts)]
|
||||
|
||||
pub trait Foo {
|
||||
// @has assoc_consts/trait.Foo.html '//*[@class="rust trait"]' \
|
||||
// 'const FOO: usize;'
|
||||
const FOO: usize;
|
||||
}
|
||||
|
||||
pub struct Bar;
|
||||
|
||||
impl Bar {
|
||||
// @has assoc_consts/struct.Bar.html '//*[@id="assoc_const.BAR"]' \
|
||||
// 'const BAR: usize = 3'
|
||||
pub const BAR: usize = 3;
|
||||
}
|
Loading…
Reference in New Issue
Block a user