Skip to content

Commit 995b159

Browse files
committed
rustdoc: Show must_use attribute
1 parent 5936278 commit 995b159

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

src/librustdoc/html/render.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1849,6 +1849,7 @@ fn render_method(w: &mut fmt::Formatter, meth: &clean::Item) -> fmt::Result {
18491849
fn item_struct(w: &mut fmt::Formatter, it: &clean::Item,
18501850
s: &clean::Struct) -> fmt::Result {
18511851
try!(write!(w, "<pre class='rust struct'>"));
1852+
try!(render_attributes(w, it));
18521853
try!(render_struct(w,
18531854
it,
18541855
Some(&s.generics),
@@ -1885,7 +1886,9 @@ fn item_struct(w: &mut fmt::Formatter, it: &clean::Item,
18851886

18861887
fn item_enum(w: &mut fmt::Formatter, it: &clean::Item,
18871888
e: &clean::Enum) -> fmt::Result {
1888-
try!(write!(w, "<pre class='rust enum'>{}enum {}{}{}",
1889+
try!(write!(w, "<pre class='rust enum'>"));
1890+
try!(render_attributes(w, it));
1891+
try!(write!(w, "{}enum {}{}{}",
18891892
VisSpace(it.visibility),
18901893
it.name.as_ref().unwrap(),
18911894
e.generics,
@@ -1982,6 +1985,21 @@ fn item_enum(w: &mut fmt::Formatter, it: &clean::Item,
19821985
Ok(())
19831986
}
19841987

1988+
fn render_attributes(w: &mut fmt::Formatter, it: &clean::Item) -> fmt::Result {
1989+
for attr in &it.attrs {
1990+
match *attr {
1991+
clean::Word(ref s) if *s == "must_use" => {
1992+
try!(write!(w, "#[{}]\n", s));
1993+
}
1994+
clean::NameValue(ref k, ref v) if *k == "must_use" => {
1995+
try!(write!(w, "#[{} = \"{}\"]\n", k, v));
1996+
}
1997+
_ => ()
1998+
}
1999+
}
2000+
Ok(())
2001+
}
2002+
19852003
fn render_struct(w: &mut fmt::Formatter, it: &clean::Item,
19862004
g: Option<&clean::Generics>,
19872005
ty: doctree::StructType,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-include ../tools.mk
2+
3+
all: lib.rs
4+
$(HOST_RPATH_ENV) $(RUSTDOC) -w html -o $(TMPDIR)/doc lib.rs
5+
$(HTMLDOCCK) $(TMPDIR)/doc lib.rs
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2015 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_type="lib"]
12+
13+
// @has lib/struct.Struct.html //pre '#[must_use]'
14+
#[must_use]
15+
pub struct Struct {
16+
field: i32,
17+
}
18+
19+
// @has lib/enum.Enum.html //pre '#[must_use = "message"]'
20+
#[must_use = "message"]
21+
pub enum Enum {
22+
Variant(i32),
23+
}

0 commit comments

Comments
 (0)