diff --git a/src/doc/book/structs.md b/src/doc/book/structs.md index dcf74cbb0a7c4..f10fb6274c61c 100644 --- a/src/doc/book/structs.md +++ b/src/doc/book/structs.md @@ -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. ``` diff --git a/src/doc/reference.md b/src/doc/reference.md index 8aefabe61fdf6..ab4da862033d3 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -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: diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 0a2e363965347..a05db9b489ca1 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -139,7 +139,7 @@ //! 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; @@ -147,17 +147,17 @@ //! # 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: @@ -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 diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 291fc8dfa9680..751ed7d443d29 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -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 { + 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> { diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index c591c09bf20e2..6f8c6aa7094dd 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -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, "{}", - shortty, url, fqp.join("::"), self.text) + write!(f, "{}", + shortty, url, shortty, fqp.join("::"), self.text) } else { write!(f, "{}", self.text) }, diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 6234d89024441..ae4c94d4b38c0 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1818,7 +1818,7 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context, write!(w, " {name}{unsafety_flag} + title='{title_type} {title}'>{name}{unsafety_flag} {stab_docs} {docs} @@ -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))?; } } @@ -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, "
{vis}const \
+    write!(w, "
")?;
+    render_attributes(w, it)?;
+    write!(w, "{vis}const \
                {name}: {typ}{init}
", vis = VisSpace(&it.visibility), name = it.name.as_ref().unwrap(), @@ -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, "
{vis}static {mutability}\
+    write!(w, "
")?;
+    render_attributes(w, it)?;
+    write!(w, "{vis}static {mutability}\
                {name}: {typ}{init}
", vis = VisSpace(&it.visibility), mutability = MutableSpace(s.mutability), @@ -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, "
{vis}{constness}{unsafety}{abi}fn \
+    write!(w, "
")?;
+    render_attributes(w, it)?;
+    write!(w, "{vis}{constness}{unsafety}{abi}fn \
                {name}{generics}{decl}{where_clause}
", vis = VisSpace(&it.visibility), constness = ConstnessSpace(vis_constness), @@ -2006,7 +2013,9 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, } // Output the trait definition - write!(w, "
{}{}trait {}{}{}{} ",
+    write!(w, "
")?;
+    render_attributes(w, it)?;
+    write!(w, "{}{}trait {}{}{}{} ",
            VisSpace(&it.visibility),
            UnsafetySpace(t.unsafety),
            it.name.as_ref().unwrap(),
@@ -2369,13 +2378,16 @@ fn item_struct(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
                 write!(w, "
                            ",
+                           ",
                        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, "",
+                        stab = stability_class)?;
+                }
                 document(w, cx, field)?;
             }
         }
@@ -2406,11 +2418,14 @@ fn item_union(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
         write!(w, "

Fields

")?; for (field, ty) in fields { write!(w, "{name}: {ty} - ", + ", 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, "", + stab = stability_class)?; + } document(w, cx, field)?; } } @@ -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, "
type {}{}{where_clause} = {type_};
", + write!(w, "
")?;
+    render_attributes(w, it)?;
+    write!(w, "type {}{}{where_clause} = {type_};
", it.name.as_ref().unwrap(), t.generics, where_clause = WhereClause(&t.generics, indent), diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index 930cf401e7450..349bddc87405c 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -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, 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(); diff --git a/src/libstd/collections/mod.rs b/src/libstd/collections/mod.rs index b9e92a01b2f8e..8884d0688b8b7 100644 --- a/src/libstd/collections/mod.rs +++ b/src/libstd/collections/mod.rs @@ -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. diff --git a/src/test/run-make/issue-22131/Makefile b/src/test/run-make/issue-22131/Makefile index f65cc9e06a329..64af91b487b32 100644 --- a/src/test/run-make/issue-22131/Makefile +++ b/src/test/run-make/issue-22131/Makefile @@ -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' diff --git a/src/test/rustdoc/attributes.rs b/src/test/rustdoc/attributes.rs new file mode 100644 index 0000000000000..22e509001137e --- /dev/null +++ b/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 or the MIT license +// , 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, +} diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 1a3d7a190be36..d0aba8a0b0a7e 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -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 {