Skip to content

Commit 81bd267

Browse files
committed
Auto merge of #39769 - GuillaumeGomez:rollup, r=GuillaumeGomez
Rollup of 7 pull requests - Successful merges: #39654, #39662, #39697, #39740, #39743, #39756, #39760 - Failed merges:
2 parents 282fa87 + 2f3dc95 commit 81bd267

File tree

11 files changed

+110
-63
lines changed

11 files changed

+110
-63
lines changed

src/doc/book/structs.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ fn main() {
117117
}
118118
```
119119

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

124124
```

src/doc/reference.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -2819,12 +2819,8 @@ Point3d {y: 0, z: 10, .. base};
28192819
#### Struct field init shorthand
28202820

28212821
When initializing a data structure (struct, enum, union) with named fields,
2822-
allow writing `fieldname` as a shorthand for `fieldname: fieldname`. This
2823-
allows a compact syntax for initialization, with less duplication.
2824-
2825-
In the initializer for a `struct` with named fields, a `union` with named
2826-
fields, or an enum variant with named fields, accept an identifier `field` as a
2827-
shorthand for `field: field`.
2822+
it is allowed to write `fieldname` as a shorthand for `fieldname: fieldname`.
2823+
This allows a compact syntax with less duplication.
28282824

28292825
Example:
28302826

src/libcore/result.rs

+15-23
Original file line numberDiff line numberDiff line change
@@ -139,25 +139,25 @@
139139
//! assert!(file.write_all(b"important message").is_ok());
140140
//! ```
141141
//!
142-
//! Or propagate the error up the call stack with [`try!`]:
142+
//! Or propagate the error up the call stack with [`?`]:
143143
//!
144144
//! ```
145145
//! # use std::fs::File;
146146
//! # use std::io::prelude::*;
147147
//! # use std::io;
148148
//! # #[allow(dead_code)]
149149
//! fn write_message() -> io::Result<()> {
150-
//! let mut file = try!(File::create("valuable_data.txt"));
151-
//! try!(file.write_all(b"important message"));
150+
//! let mut file = File::create("valuable_data.txt")?;
151+
//! file.write_all(b"important message")?;
152152
//! Ok(())
153153
//! }
154154
//! ```
155155
//!
156-
//! # The `try!` macro
156+
//! # The `?` syntax
157157
//!
158158
//! When writing code that calls many functions that return the
159-
//! [`Result`] type, the error handling can be tedious. The [`try!`]
160-
//! macro hides some of the boilerplate of propagating errors up the
159+
//! [`Result`] type, the error handling can be tedious. The [`?`]
160+
//! syntax hides some of the boilerplate of propagating errors up the
161161
//! call stack.
162162
//!
163163
//! It replaces this:
@@ -208,37 +208,29 @@
208208
//! }
209209
//!
210210
//! fn write_info(info: &Info) -> io::Result<()> {
211-
//! let mut file = try!(File::create("my_best_friends.txt"));
211+
//! let mut file = File::create("my_best_friends.txt")?;
212212
//! // Early return on error
213-
//! try!(file.write_all(format!("name: {}\n", info.name).as_bytes()));
214-
//! try!(file.write_all(format!("age: {}\n", info.age).as_bytes()));
215-
//! try!(file.write_all(format!("rating: {}\n", info.rating).as_bytes()));
213+
//! file.write_all(format!("name: {}\n", info.name).as_bytes())?;
214+
//! file.write_all(format!("age: {}\n", info.age).as_bytes())?;
215+
//! file.write_all(format!("rating: {}\n", info.rating).as_bytes())?;
216216
//! Ok(())
217217
//! }
218218
//! ```
219219
//!
220220
//! *It's much nicer!*
221221
//!
222-
//! Wrapping an expression in [`try!`] will result in the unwrapped
222+
//! Ending the expression with [`?`] will result in the unwrapped
223223
//! success ([`Ok`]) value, unless the result is [`Err`], in which case
224-
//! [`Err`] is returned early from the enclosing function. Its simple definition
225-
//! makes it clear:
224+
//! [`Err`] is returned early from the enclosing function.
226225
//!
227-
//! ```
228-
//! macro_rules! try {
229-
//! ($e:expr) => (match $e { Ok(e) => e, Err(e) => return Err(e) })
230-
//! }
231-
//! ```
232-
//!
233-
//! [`try!`] is imported by the prelude and is available everywhere, but it can only
234-
//! be used in functions that return [`Result`] because of the early return of
235-
//! [`Err`] that it provides.
226+
//! [`?`] can only be used in functions that return [`Result`] because of the
227+
//! early return of [`Err`] that it provides.
236228
//!
237229
//! [`expect`]: enum.Result.html#method.expect
238230
//! [`Write`]: ../../std/io/trait.Write.html
239231
//! [`write_all`]: ../../std/io/trait.Write.html#method.write_all
240232
//! [`io::Result`]: ../../std/io/type.Result.html
241-
//! [`try!`]: ../../std/macro.try.html
233+
//! [`?`]: ../../std/macro.try.html
242234
//! [`Result`]: enum.Result.html
243235
//! [`Ok(T)`]: enum.Result.html#variant.Ok
244236
//! [`Err(E)`]: enum.Result.html#variant.Err

src/librustdoc/clean/mod.rs

+16-9
Original file line numberDiff line numberDiff line change
@@ -327,17 +327,24 @@ impl Item {
327327
}
328328
}
329329

330-
pub fn stability_class(&self) -> String {
331-
self.stability.as_ref().map(|ref s| {
332-
let mut base = match s.level {
333-
stability::Unstable => "unstable".to_string(),
334-
stability::Stable => String::new(),
335-
};
330+
pub fn stability_class(&self) -> Option<String> {
331+
self.stability.as_ref().and_then(|ref s| {
332+
let mut classes = Vec::with_capacity(2);
333+
334+
if s.level == stability::Unstable {
335+
classes.push("unstable");
336+
}
337+
336338
if !s.deprecated_since.is_empty() {
337-
base.push_str(" deprecated");
339+
classes.push("deprecated");
338340
}
339-
base
340-
}).unwrap_or(String::new())
341+
342+
if classes.len() != 0 {
343+
Some(classes.join(" "))
344+
} else {
345+
None
346+
}
347+
})
341348
}
342349

343350
pub fn stable_since(&self) -> Option<&str> {

src/librustdoc/html/format.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -550,8 +550,8 @@ impl<'a> fmt::Display for HRef<'a> {
550550
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
551551
match href(self.did) {
552552
Some((url, shortty, fqp)) => if !f.alternate() {
553-
write!(f, "<a class='{}' href='{}' title='{}'>{}</a>",
554-
shortty, url, fqp.join("::"), self.text)
553+
write!(f, "<a class='{}' href='{}' title='{} {}'>{}</a>",
554+
shortty, url, shortty, fqp.join("::"), self.text)
555555
} else {
556556
write!(f, "{}", self.text)
557557
},

src/librustdoc/html/render.rs

+28-11
Original file line numberDiff line numberDiff line change
@@ -1818,7 +1818,7 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
18181818
write!(w, "
18191819
<tr class='{stab} module-item'>
18201820
<td><a class='{class}' href='{href}'
1821-
title='{title}'>{name}</a>{unsafety_flag}</td>
1821+
title='{title_type} {title}'>{name}</a>{unsafety_flag}</td>
18221822
<td class='docblock-short'>
18231823
{stab_docs} {docs}
18241824
</td>
@@ -1827,9 +1827,10 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
18271827
stab_docs = stab_docs,
18281828
docs = shorter(Some(&Markdown(doc_value).to_string())),
18291829
class = myitem.type_(),
1830-
stab = myitem.stability_class(),
1830+
stab = myitem.stability_class().unwrap_or("".to_string()),
18311831
unsafety_flag = unsafety_flag,
18321832
href = item_path(myitem.type_(), myitem.name.as_ref().unwrap()),
1833+
title_type = myitem.type_(),
18331834
title = full_path(cx, myitem))?;
18341835
}
18351836
}
@@ -1936,7 +1937,9 @@ impl<'a> fmt::Display for Initializer<'a> {
19361937

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

19481951
fn item_static(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
19491952
s: &clean::Static) -> fmt::Result {
1950-
write!(w, "<pre class='rust static'>{vis}static {mutability}\
1953+
write!(w, "<pre class='rust static'>")?;
1954+
render_attributes(w, it)?;
1955+
write!(w, "{vis}static {mutability}\
19511956
{name}: {typ}{init}</pre>",
19521957
vis = VisSpace(&it.visibility),
19531958
mutability = MutableSpace(s.mutability),
@@ -1971,7 +1976,9 @@ fn item_function(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
19711976
AbiSpace(f.abi),
19721977
it.name.as_ref().unwrap(),
19731978
f.generics).len();
1974-
write!(w, "<pre class='rust fn'>{vis}{constness}{unsafety}{abi}fn \
1979+
write!(w, "<pre class='rust fn'>")?;
1980+
render_attributes(w, it)?;
1981+
write!(w, "{vis}{constness}{unsafety}{abi}fn \
19751982
{name}{generics}{decl}{where_clause}</pre>",
19761983
vis = VisSpace(&it.visibility),
19771984
constness = ConstnessSpace(vis_constness),
@@ -2006,7 +2013,9 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
20062013
}
20072014

20082015
// Output the trait definition
2009-
write!(w, "<pre class='rust trait'>{}{}trait {}{}{}{} ",
2016+
write!(w, "<pre class='rust trait'>")?;
2017+
render_attributes(w, it)?;
2018+
write!(w, "{}{}trait {}{}{}{} ",
20102019
VisSpace(&it.visibility),
20112020
UnsafetySpace(t.unsafety),
20122021
it.name.as_ref().unwrap(),
@@ -2369,13 +2378,16 @@ fn item_struct(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
23692378
write!(w, "<span id='{id}' class='{item_type}'>
23702379
<span id='{ns_id}' class='invisible'>
23712380
<code>{name}: {ty}</code>
2372-
</span></span><span class='stab {stab}'></span>",
2381+
</span></span>",
23732382
item_type = ItemType::StructField,
23742383
id = id,
23752384
ns_id = ns_id,
2376-
stab = field.stability_class(),
23772385
name = field.name.as_ref().unwrap(),
23782386
ty = ty)?;
2387+
if let Some(stability_class) = field.stability_class() {
2388+
write!(w, "<span class='stab {stab}'></span>",
2389+
stab = stability_class)?;
2390+
}
23792391
document(w, cx, field)?;
23802392
}
23812393
}
@@ -2406,11 +2418,14 @@ fn item_union(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
24062418
write!(w, "<h2 class='fields'>Fields</h2>")?;
24072419
for (field, ty) in fields {
24082420
write!(w, "<span id='{shortty}.{name}' class='{shortty}'><code>{name}: {ty}</code>
2409-
</span><span class='stab {stab}'></span>",
2421+
</span>",
24102422
shortty = ItemType::StructField,
2411-
stab = field.stability_class(),
24122423
name = field.name.as_ref().unwrap(),
24132424
ty = ty)?;
2425+
if let Some(stability_class) = field.stability_class() {
2426+
write!(w, "<span class='stab {stab}'></span>",
2427+
stab = stability_class)?;
2428+
}
24142429
document(w, cx, field)?;
24152430
}
24162431
}
@@ -3001,7 +3016,9 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
30013016
fn item_typedef(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
30023017
t: &clean::Typedef) -> fmt::Result {
30033018
let indent = format!("type {}{:#} ", it.name.as_ref().unwrap(), t.generics).len();
3004-
write!(w, "<pre class='rust typedef'>type {}{}{where_clause} = {type_};</pre>",
3019+
write!(w, "<pre class='rust typedef'>")?;
3020+
render_attributes(w, it)?;
3021+
write!(w, "type {}{}{where_clause} = {type_};</pre>",
30053022
it.name.as_ref().unwrap(),
30063023
t.generics,
30073024
where_clause = WhereClause(&t.generics, indent),

src/librustdoc/test.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,12 @@ impl Collector {
418418
should_panic: bool, no_run: bool, should_ignore: bool,
419419
as_test_harness: bool, compile_fail: bool, error_codes: Vec<String>,
420420
line: usize, filename: String) {
421-
let name = format!("{} - line {}", filename, line);
422-
self.cnt += 1;
421+
let name = if self.use_headers {
422+
let s = self.current_header.as_ref().map(|s| &**s).unwrap_or("");
423+
format!("{} - {} (line {})", filename, s, line)
424+
} else {
425+
format!("{} - {} (line {})", filename, self.names.join("::"), line)
426+
};
423427
let cfgs = self.cfgs.clone();
424428
let libs = self.libs.clone();
425429
let externs = self.externs.clone();

src/libstd/collections/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
//! * You want to find the largest or smallest key that is smaller or larger
6969
//! than something.
7070
//! * You want to be able to get all of the entries in order on-demand.
71-
//! * You want a sorted map.
71+
//! * You want a map sorted by its keys.
7272
//!
7373
//! ### Use the `Set` variant of any of these `Map`s when:
7474
//! * You just want to remember which keys you've seen.

src/test/run-make/issue-22131/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ all: foo.rs
44
$(RUSTC) --cfg 'feature="bar"' --crate-type lib foo.rs
55
$(HOST_RPATH_ENV) '$(RUSTDOC)' --test --cfg 'feature="bar"' \
66
-L $(TMPDIR) foo.rs |\
7-
grep -q 'foo.rs - line 11 ... ok'
7+
grep -q 'foo.rs - foo (line 11) ... ok'

src/test/rustdoc/attributes.rs

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2017 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_name = "foo"]
12+
13+
// @has foo/fn.f.html '//*[@class="docblock attributes"]' '#[no_mangle]'
14+
#[no_mangle]
15+
pub extern "C" fn f() {}
16+
17+
// @has foo/fn.g.html '//*[@class="docblock attributes"]' '#[export_name = "bar"]'
18+
#[export_name = "bar"]
19+
pub extern "C" fn g() {}
20+
21+
// @has foo/enum.Foo.html '//*[@class="docblock attributes"]' '#[repr(i64)]'
22+
// @has foo/enum.Foo.html '//*[@class="docblock attributes"]' '#[must_use]'
23+
#[repr(i64)]
24+
#[must_use]
25+
pub enum Foo {
26+
Bar,
27+
}

src/tools/compiletest/src/runtest.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -1998,16 +1998,20 @@ actual:\n\
19981998
for _ in res.stdout.split("\n")
19991999
.filter(|s| s.starts_with("test "))
20002000
.inspect(|s| {
2001-
let tmp: Vec<&str> = s.split(" - line ").collect();
2001+
let tmp: Vec<&str> = s.split(" - ").collect();
20022002
if tmp.len() == 2 {
20032003
let path = tmp[0].rsplit("test ").next().unwrap();
20042004
if let Some(ref mut v) = files.get_mut(path) {
20052005
tested += 1;
2006-
let line = tmp[1].split(" ...")
2007-
.next()
2008-
.unwrap_or("0")
2009-
.parse()
2010-
.unwrap_or(0);
2006+
let mut iter = tmp[1].split("(line ");
2007+
iter.next();
2008+
let line = iter.next()
2009+
.unwrap_or(")")
2010+
.split(")")
2011+
.next()
2012+
.unwrap_or("0")
2013+
.parse()
2014+
.unwrap_or(0);
20112015
if let Ok(pos) = v.binary_search(&line) {
20122016
v.remove(pos);
20132017
} else {

0 commit comments

Comments
 (0)