Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustdoc: Show must_use attribute #22224

Merged
merged 1 commit into from
Feb 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1849,6 +1849,7 @@ fn render_method(w: &mut fmt::Formatter, meth: &clean::Item) -> fmt::Result {
fn item_struct(w: &mut fmt::Formatter, it: &clean::Item,
s: &clean::Struct) -> fmt::Result {
try!(write!(w, "<pre class='rust struct'>"));
try!(render_attributes(w, it));
try!(render_struct(w,
it,
Some(&s.generics),
Expand Down Expand Up @@ -1885,7 +1886,9 @@ fn item_struct(w: &mut fmt::Formatter, it: &clean::Item,

fn item_enum(w: &mut fmt::Formatter, it: &clean::Item,
e: &clean::Enum) -> fmt::Result {
try!(write!(w, "<pre class='rust enum'>{}enum {}{}{}",
try!(write!(w, "<pre class='rust enum'>"));
try!(render_attributes(w, it));
try!(write!(w, "{}enum {}{}{}",
VisSpace(it.visibility),
it.name.as_ref().unwrap(),
e.generics,
Expand Down Expand Up @@ -1982,6 +1985,21 @@ fn item_enum(w: &mut fmt::Formatter, it: &clean::Item,
Ok(())
}

fn render_attributes(w: &mut fmt::Formatter, it: &clean::Item) -> fmt::Result {
for attr in &it.attrs {
match *attr {
clean::Word(ref s) if *s == "must_use" => {
try!(write!(w, "#[{}]\n", s));
}
clean::NameValue(ref k, ref v) if *k == "must_use" => {
try!(write!(w, "#[{} = \"{}\"]\n", k, v));
}
_ => ()
}
}
Ok(())
}

fn render_struct(w: &mut fmt::Formatter, it: &clean::Item,
g: Option<&clean::Generics>,
ty: doctree::StructType,
Expand Down
5 changes: 5 additions & 0 deletions src/test/run-make/rustdoc-must-use/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-include ../tools.mk

all: lib.rs
$(HOST_RPATH_ENV) $(RUSTDOC) -w html -o $(TMPDIR)/doc lib.rs
$(HTMLDOCCK) $(TMPDIR)/doc lib.rs
23 changes: 23 additions & 0 deletions src/test/run-make/rustdoc-must-use/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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.

#![crate_type="lib"]

// @has lib/struct.Struct.html //pre '#[must_use]'
#[must_use]
pub struct Struct {
field: i32,
}

// @has lib/enum.Enum.html //pre '#[must_use = "message"]'
#[must_use = "message"]
pub enum Enum {
Variant(i32),
}