Skip to content

Commit

Permalink
Auto merge of #39769 - GuillaumeGomez:rollup, r=GuillaumeGomez
Browse files Browse the repository at this point in the history
Rollup of 7 pull requests

- Successful merges: #39654, #39662, #39697, #39740, #39743, #39756, #39760
- Failed merges:
  • Loading branch information
bors committed Feb 12, 2017
2 parents 282fa87 + 2f3dc95 commit 81bd267
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 63 deletions.
4 changes: 2 additions & 2 deletions src/doc/book/structs.md
Expand Up @@ -117,8 +117,8 @@ fn main() {
}
```

Initialization of a data structure (struct, enum, union) can be simplified if
fields of the data structure are initialized with variables which has same
Initialization of a data structure (struct, enum, union) can be simplified when
fields of the data structure are initialized with variables of the same
names as the fields.

```
Expand Down
8 changes: 2 additions & 6 deletions src/doc/reference.md
Expand Up @@ -2819,12 +2819,8 @@ Point3d {y: 0, z: 10, .. base};
#### Struct field init shorthand

When initializing a data structure (struct, enum, union) with named fields,
allow writing `fieldname` as a shorthand for `fieldname: fieldname`. This
allows a compact syntax for initialization, with less duplication.

In the initializer for a `struct` with named fields, a `union` with named
fields, or an enum variant with named fields, accept an identifier `field` as a
shorthand for `field: field`.
it is allowed to write `fieldname` as a shorthand for `fieldname: fieldname`.
This allows a compact syntax with less duplication.

Example:

Expand Down
38 changes: 15 additions & 23 deletions src/libcore/result.rs
Expand Up @@ -139,25 +139,25 @@
//! assert!(file.write_all(b"important message").is_ok());
//! ```
//!
//! Or propagate the error up the call stack with [`try!`]:
//! Or propagate the error up the call stack with [`?`]:
//!
//! ```
//! # use std::fs::File;
//! # use std::io::prelude::*;
//! # use std::io;
//! # #[allow(dead_code)]
//! fn write_message() -> io::Result<()> {
//! let mut file = try!(File::create("valuable_data.txt"));
//! try!(file.write_all(b"important message"));
//! let mut file = File::create("valuable_data.txt")?;
//! file.write_all(b"important message")?;
//! Ok(())
//! }
//! ```
//!
//! # The `try!` macro
//! # The `?` syntax
//!
//! When writing code that calls many functions that return the
//! [`Result`] type, the error handling can be tedious. The [`try!`]
//! macro hides some of the boilerplate of propagating errors up the
//! [`Result`] type, the error handling can be tedious. The [`?`]
//! syntax hides some of the boilerplate of propagating errors up the
//! call stack.
//!
//! It replaces this:
Expand Down Expand Up @@ -208,37 +208,29 @@
//! }
//!
//! fn write_info(info: &Info) -> io::Result<()> {
//! let mut file = try!(File::create("my_best_friends.txt"));
//! let mut file = File::create("my_best_friends.txt")?;
//! // Early return on error
//! try!(file.write_all(format!("name: {}\n", info.name).as_bytes()));
//! try!(file.write_all(format!("age: {}\n", info.age).as_bytes()));
//! try!(file.write_all(format!("rating: {}\n", info.rating).as_bytes()));
//! file.write_all(format!("name: {}\n", info.name).as_bytes())?;
//! file.write_all(format!("age: {}\n", info.age).as_bytes())?;
//! file.write_all(format!("rating: {}\n", info.rating).as_bytes())?;
//! Ok(())
//! }
//! ```
//!
//! *It's much nicer!*
//!
//! Wrapping an expression in [`try!`] will result in the unwrapped
//! Ending the expression with [`?`] will result in the unwrapped
//! success ([`Ok`]) value, unless the result is [`Err`], in which case
//! [`Err`] is returned early from the enclosing function. Its simple definition
//! makes it clear:
//! [`Err`] is returned early from the enclosing function.
//!
//! ```
//! macro_rules! try {
//! ($e:expr) => (match $e { Ok(e) => e, Err(e) => return Err(e) })
//! }
//! ```
//!
//! [`try!`] is imported by the prelude and is available everywhere, but it can only
//! be used in functions that return [`Result`] because of the early return of
//! [`Err`] that it provides.
//! [`?`] can only be used in functions that return [`Result`] because of the
//! early return of [`Err`] that it provides.
//!
//! [`expect`]: enum.Result.html#method.expect
//! [`Write`]: ../../std/io/trait.Write.html
//! [`write_all`]: ../../std/io/trait.Write.html#method.write_all
//! [`io::Result`]: ../../std/io/type.Result.html
//! [`try!`]: ../../std/macro.try.html
//! [`?`]: ../../std/macro.try.html
//! [`Result`]: enum.Result.html
//! [`Ok(T)`]: enum.Result.html#variant.Ok
//! [`Err(E)`]: enum.Result.html#variant.Err
Expand Down
25 changes: 16 additions & 9 deletions src/librustdoc/clean/mod.rs
Expand Up @@ -327,17 +327,24 @@ impl Item {
}
}

pub fn stability_class(&self) -> String {
self.stability.as_ref().map(|ref s| {
let mut base = match s.level {
stability::Unstable => "unstable".to_string(),
stability::Stable => String::new(),
};
pub fn stability_class(&self) -> Option<String> {
self.stability.as_ref().and_then(|ref s| {
let mut classes = Vec::with_capacity(2);

if s.level == stability::Unstable {
classes.push("unstable");
}

if !s.deprecated_since.is_empty() {
base.push_str(" deprecated");
classes.push("deprecated");
}
base
}).unwrap_or(String::new())

if classes.len() != 0 {
Some(classes.join(" "))
} else {
None
}
})
}

pub fn stable_since(&self) -> Option<&str> {
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/format.rs
Expand Up @@ -550,8 +550,8 @@ impl<'a> fmt::Display for HRef<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match href(self.did) {
Some((url, shortty, fqp)) => if !f.alternate() {
write!(f, "<a class='{}' href='{}' title='{}'>{}</a>",
shortty, url, fqp.join("::"), self.text)
write!(f, "<a class='{}' href='{}' title='{} {}'>{}</a>",
shortty, url, shortty, fqp.join("::"), self.text)
} else {
write!(f, "{}", self.text)
},
Expand Down
39 changes: 28 additions & 11 deletions src/librustdoc/html/render.rs
Expand Up @@ -1818,7 +1818,7 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
write!(w, "
<tr class='{stab} module-item'>
<td><a class='{class}' href='{href}'
title='{title}'>{name}</a>{unsafety_flag}</td>
title='{title_type} {title}'>{name}</a>{unsafety_flag}</td>
<td class='docblock-short'>
{stab_docs} {docs}
</td>
Expand All @@ -1827,9 +1827,10 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
stab_docs = stab_docs,
docs = shorter(Some(&Markdown(doc_value).to_string())),
class = myitem.type_(),
stab = myitem.stability_class(),
stab = myitem.stability_class().unwrap_or("".to_string()),
unsafety_flag = unsafety_flag,
href = item_path(myitem.type_(), myitem.name.as_ref().unwrap()),
title_type = myitem.type_(),
title = full_path(cx, myitem))?;
}
}
Expand Down Expand Up @@ -1936,7 +1937,9 @@ impl<'a> fmt::Display for Initializer<'a> {

fn item_constant(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
c: &clean::Constant) -> fmt::Result {
write!(w, "<pre class='rust const'>{vis}const \
write!(w, "<pre class='rust const'>")?;
render_attributes(w, it)?;
write!(w, "{vis}const \
{name}: {typ}{init}</pre>",
vis = VisSpace(&it.visibility),
name = it.name.as_ref().unwrap(),
Expand All @@ -1947,7 +1950,9 @@ fn item_constant(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,

fn item_static(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
s: &clean::Static) -> fmt::Result {
write!(w, "<pre class='rust static'>{vis}static {mutability}\
write!(w, "<pre class='rust static'>")?;
render_attributes(w, it)?;
write!(w, "{vis}static {mutability}\
{name}: {typ}{init}</pre>",
vis = VisSpace(&it.visibility),
mutability = MutableSpace(s.mutability),
Expand All @@ -1971,7 +1976,9 @@ fn item_function(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
AbiSpace(f.abi),
it.name.as_ref().unwrap(),
f.generics).len();
write!(w, "<pre class='rust fn'>{vis}{constness}{unsafety}{abi}fn \
write!(w, "<pre class='rust fn'>")?;
render_attributes(w, it)?;
write!(w, "{vis}{constness}{unsafety}{abi}fn \
{name}{generics}{decl}{where_clause}</pre>",
vis = VisSpace(&it.visibility),
constness = ConstnessSpace(vis_constness),
Expand Down Expand Up @@ -2006,7 +2013,9 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
}

// Output the trait definition
write!(w, "<pre class='rust trait'>{}{}trait {}{}{}{} ",
write!(w, "<pre class='rust trait'>")?;
render_attributes(w, it)?;
write!(w, "{}{}trait {}{}{}{} ",
VisSpace(&it.visibility),
UnsafetySpace(t.unsafety),
it.name.as_ref().unwrap(),
Expand Down Expand Up @@ -2369,13 +2378,16 @@ fn item_struct(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
write!(w, "<span id='{id}' class='{item_type}'>
<span id='{ns_id}' class='invisible'>
<code>{name}: {ty}</code>
</span></span><span class='stab {stab}'></span>",
</span></span>",
item_type = ItemType::StructField,
id = id,
ns_id = ns_id,
stab = field.stability_class(),
name = field.name.as_ref().unwrap(),
ty = ty)?;
if let Some(stability_class) = field.stability_class() {
write!(w, "<span class='stab {stab}'></span>",
stab = stability_class)?;
}
document(w, cx, field)?;
}
}
Expand Down Expand Up @@ -2406,11 +2418,14 @@ fn item_union(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
write!(w, "<h2 class='fields'>Fields</h2>")?;
for (field, ty) in fields {
write!(w, "<span id='{shortty}.{name}' class='{shortty}'><code>{name}: {ty}</code>
</span><span class='stab {stab}'></span>",
</span>",
shortty = ItemType::StructField,
stab = field.stability_class(),
name = field.name.as_ref().unwrap(),
ty = ty)?;
if let Some(stability_class) = field.stability_class() {
write!(w, "<span class='stab {stab}'></span>",
stab = stability_class)?;
}
document(w, cx, field)?;
}
}
Expand Down Expand Up @@ -3001,7 +3016,9 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
fn item_typedef(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
t: &clean::Typedef) -> fmt::Result {
let indent = format!("type {}{:#} ", it.name.as_ref().unwrap(), t.generics).len();
write!(w, "<pre class='rust typedef'>type {}{}{where_clause} = {type_};</pre>",
write!(w, "<pre class='rust typedef'>")?;
render_attributes(w, it)?;
write!(w, "type {}{}{where_clause} = {type_};</pre>",
it.name.as_ref().unwrap(),
t.generics,
where_clause = WhereClause(&t.generics, indent),
Expand Down
8 changes: 6 additions & 2 deletions src/librustdoc/test.rs
Expand Up @@ -418,8 +418,12 @@ impl Collector {
should_panic: bool, no_run: bool, should_ignore: bool,
as_test_harness: bool, compile_fail: bool, error_codes: Vec<String>,
line: usize, filename: String) {
let name = format!("{} - line {}", filename, line);
self.cnt += 1;
let name = if self.use_headers {
let s = self.current_header.as_ref().map(|s| &**s).unwrap_or("");
format!("{} - {} (line {})", filename, s, line)
} else {
format!("{} - {} (line {})", filename, self.names.join("::"), line)
};
let cfgs = self.cfgs.clone();
let libs = self.libs.clone();
let externs = self.externs.clone();
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/collections/mod.rs
Expand Up @@ -68,7 +68,7 @@
//! * You want to find the largest or smallest key that is smaller or larger
//! than something.
//! * You want to be able to get all of the entries in order on-demand.
//! * You want a sorted map.
//! * You want a map sorted by its keys.
//!
//! ### Use the `Set` variant of any of these `Map`s when:
//! * You just want to remember which keys you've seen.
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-make/issue-22131/Makefile
Expand Up @@ -4,4 +4,4 @@ all: foo.rs
$(RUSTC) --cfg 'feature="bar"' --crate-type lib foo.rs
$(HOST_RPATH_ENV) '$(RUSTDOC)' --test --cfg 'feature="bar"' \
-L $(TMPDIR) foo.rs |\
grep -q 'foo.rs - line 11 ... ok'
grep -q 'foo.rs - foo (line 11) ... ok'
27 changes: 27 additions & 0 deletions src/test/rustdoc/attributes.rs
@@ -0,0 +1,27 @@
// Copyright 2017 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_name = "foo"]

// @has foo/fn.f.html '//*[@class="docblock attributes"]' '#[no_mangle]'
#[no_mangle]
pub extern "C" fn f() {}

// @has foo/fn.g.html '//*[@class="docblock attributes"]' '#[export_name = "bar"]'
#[export_name = "bar"]
pub extern "C" fn g() {}

// @has foo/enum.Foo.html '//*[@class="docblock attributes"]' '#[repr(i64)]'
// @has foo/enum.Foo.html '//*[@class="docblock attributes"]' '#[must_use]'
#[repr(i64)]
#[must_use]
pub enum Foo {
Bar,
}
16 changes: 10 additions & 6 deletions src/tools/compiletest/src/runtest.rs
Expand Up @@ -1998,16 +1998,20 @@ actual:\n\
for _ in res.stdout.split("\n")
.filter(|s| s.starts_with("test "))
.inspect(|s| {
let tmp: Vec<&str> = s.split(" - line ").collect();
let tmp: Vec<&str> = s.split(" - ").collect();
if tmp.len() == 2 {
let path = tmp[0].rsplit("test ").next().unwrap();
if let Some(ref mut v) = files.get_mut(path) {
tested += 1;
let line = tmp[1].split(" ...")
.next()
.unwrap_or("0")
.parse()
.unwrap_or(0);
let mut iter = tmp[1].split("(line ");
iter.next();
let line = iter.next()
.unwrap_or(")")
.split(")")
.next()
.unwrap_or("0")
.parse()
.unwrap_or(0);
if let Ok(pos) = v.binary_search(&line) {
v.remove(pos);
} else {
Expand Down

0 comments on commit 81bd267

Please sign in to comment.