From be6c21f26771d19b9307a18074b686008d8ac8eb Mon Sep 17 00:00:00 2001 From: Sam Payson Date: Sun, 5 Jun 2016 10:20:33 -0700 Subject: [PATCH 01/11] Revise wording in Rc documentation. The term "thread-local" has a widely-accepted meaning which is not the meaning it's used for here. --- src/liballoc/rc.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index cf4fb459bc104..d582de5740cb8 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -10,7 +10,7 @@ #![allow(deprecated)] -//! Thread-local reference-counted boxes (the `Rc` type). +//! Unsynchronized reference-counted boxes (the `Rc` type). //! //! The `Rc` type provides shared ownership of an immutable value. //! Destruction is deterministic, and will occur as soon as the last owner is From dd8151f5e2bd12964f6ed99c8a0d91e7e6c3d3a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E5=86=89=E6=B3=A2?= Date: Sat, 2 Jul 2016 15:19:09 +0800 Subject: [PATCH 02/11] doc: make the conditional-compilation example work If not, the error `does not have these features: foo` confused. r? @steveklabnik --- src/doc/book/conditional-compilation.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/doc/book/conditional-compilation.md b/src/doc/book/conditional-compilation.md index a6ff75db89b88..a175d7cc38b87 100644 --- a/src/doc/book/conditional-compilation.md +++ b/src/doc/book/conditional-compilation.md @@ -41,8 +41,12 @@ they get set in the [`[features]` section][features] of your `Cargo.toml`: # no features by default default = [] +# Add feature "foo" here, then you can use it. +# Our "foo" feature depends on nothings else. +foo = [] + # The “secure-password” feature depends on the bcrypt package. -secure-password = ["bcrypt"] +# secure-password = ["bcrypt"] ``` When you do this, Cargo passes along a flag to `rustc`: From 0d78f6b40f0cf8650bf3c40b65fa774533054d12 Mon Sep 17 00:00:00 2001 From: ggomez Date: Tue, 5 Jul 2016 11:36:43 +0200 Subject: [PATCH 03/11] Fix `std::path::Path::file_name()` doc --- src/libstd/path.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/libstd/path.rs b/src/libstd/path.rs index ad4cdef615847..2d19561139b58 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -1529,8 +1529,7 @@ impl Path { /// The final component of the path, if it is a normal file. /// - /// If the path terminates in `.`, `..`, or consists solely of a root of - /// prefix, `file_name` will return `None`. + /// If the path terminates in `..`, `file_name` will return `None`. /// /// # Examples /// @@ -1543,6 +1542,17 @@ impl Path { /// /// assert_eq!(Some(os_str), path.file_name()); /// ``` + /// + /// # Other examples + /// + /// ``` + /// use std::path::Path; + /// use std::ffi::OsStr; + /// + /// assert_eq!(Some(OsStr::new("foo.txt")), Path::new("foo.txt/.").file_name()); + /// assert_eq!(Some(OsStr::new("foo.txt")), Path::new("foo.txt/.//").file_name()); + /// assert_eq!(None, Path::new("foo.txt/..").file_name()); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn file_name(&self) -> Option<&OsStr> { self.components().next_back().and_then(|p| { From 630e4eb4c50a9a13b452c6182b7db0160bb2b379 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 6 Jul 2016 01:34:58 +0200 Subject: [PATCH 04/11] Improve DoubleEndedIterator examples --- src/libcore/iter/traits.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/libcore/iter/traits.rs b/src/libcore/iter/traits.rs index 3549bd6a3bc68..9b5c2128f1eaf 100644 --- a/src/libcore/iter/traits.rs +++ b/src/libcore/iter/traits.rs @@ -371,13 +371,16 @@ pub trait Extend { /// Basic usage: /// /// ``` -/// let numbers = vec![1, 2, 3]; +/// let numbers = vec![1, 2, 3, 4, 5, 6]; /// /// let mut iter = numbers.iter(); /// /// assert_eq!(Some(&1), iter.next()); -/// assert_eq!(Some(&3), iter.next_back()); -/// assert_eq!(Some(&2), iter.next_back()); +/// assert_eq!(Some(&6), iter.next_back()); +/// assert_eq!(Some(&5), iter.next_back()); +/// assert_eq!(Some(&2), iter.next()); +/// assert_eq!(Some(&3), iter.next()); +/// assert_eq!(Some(&4), iter.next()); /// assert_eq!(None, iter.next()); /// assert_eq!(None, iter.next_back()); /// ``` @@ -395,13 +398,16 @@ pub trait DoubleEndedIterator: Iterator { /// Basic usage: /// /// ``` - /// let numbers = vec![1, 2, 3]; + /// let numbers = vec![1, 2, 3, 4, 5, 6]; /// /// let mut iter = numbers.iter(); /// /// assert_eq!(Some(&1), iter.next()); - /// assert_eq!(Some(&3), iter.next_back()); - /// assert_eq!(Some(&2), iter.next_back()); + /// assert_eq!(Some(&6), iter.next_back()); + /// assert_eq!(Some(&5), iter.next_back()); + /// assert_eq!(Some(&2), iter.next()); + /// assert_eq!(Some(&3), iter.next()); + /// assert_eq!(Some(&4), iter.next()); /// assert_eq!(None, iter.next()); /// assert_eq!(None, iter.next_back()); /// ``` From 7f3068e52f1943d612923f819dc8d0e996faaaf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E5=86=89=E6=B3=A2?= Date: Wed, 6 Jul 2016 13:52:40 +0800 Subject: [PATCH 05/11] typo nothings -> nothing --- src/doc/book/conditional-compilation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/book/conditional-compilation.md b/src/doc/book/conditional-compilation.md index a175d7cc38b87..2857d7e64c500 100644 --- a/src/doc/book/conditional-compilation.md +++ b/src/doc/book/conditional-compilation.md @@ -42,7 +42,7 @@ they get set in the [`[features]` section][features] of your `Cargo.toml`: default = [] # Add feature "foo" here, then you can use it. -# Our "foo" feature depends on nothings else. +# Our "foo" feature depends on nothing else. foo = [] # The “secure-password” feature depends on the bcrypt package. From 5e31617621a69c787aca12239a5b2ff4e6947f74 Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Fri, 1 Jul 2016 23:40:45 +0000 Subject: [PATCH 06/11] Remove outdated checks for empty braced struct expressions (i.e. `UnitStruct {}`). --- src/libsyntax/parse/parser.rs | 83 +++++------------------------------ 1 file changed, 11 insertions(+), 72 deletions(-) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 20a54228d016c..29950340ebc4d 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -495,64 +495,6 @@ impl<'a> Parser<'a> { } } - /// Check for erroneous `ident { }`; if matches, signal error and - /// recover (without consuming any expected input token). Returns - /// true if and only if input was consumed for recovery. - pub fn check_for_erroneous_unit_struct_expecting(&mut self, - expected: &[token::Token]) - -> bool { - if self.token == token::OpenDelim(token::Brace) - && expected.iter().all(|t| *t != token::OpenDelim(token::Brace)) - && self.look_ahead(1, |t| *t == token::CloseDelim(token::Brace)) { - // matched; signal non-fatal error and recover. - let span = self.span; - self.span_err(span, "unit-like struct construction is written with no trailing `{ }`"); - self.eat(&token::OpenDelim(token::Brace)); - self.eat(&token::CloseDelim(token::Brace)); - true - } else { - false - } - } - - /// Commit to parsing a complete expression `e` expected to be - /// followed by some token from the set edible + inedible. Recover - /// from anticipated input errors, discarding erroneous characters. - pub fn commit_expr(&mut self, e: &Expr, edible: &[token::Token], - inedible: &[token::Token]) -> PResult<'a, ()> { - debug!("commit_expr {:?}", e); - if let ExprKind::Path(..) = e.node { - // might be unit-struct construction; check for recoverableinput error. - let expected = edible.iter() - .cloned() - .chain(inedible.iter().cloned()) - .collect::>(); - self.check_for_erroneous_unit_struct_expecting(&expected[..]); - } - self.expect_one_of(edible, inedible) - } - - pub fn commit_expr_expecting(&mut self, e: &Expr, edible: token::Token) -> PResult<'a, ()> { - self.commit_expr(e, &[edible], &[]) - } - - /// Commit to parsing a complete statement `s`, which expects to be - /// followed by some token from the set edible + inedible. Check - /// for recoverable input errors, discarding erroneous characters. - pub fn commit_stmt(&mut self, edible: &[token::Token], - inedible: &[token::Token]) -> PResult<'a, ()> { - if self.last_token - .as_ref() - .map_or(false, |t| t.is_ident() || t.is_path()) { - let expected = edible.iter() - .cloned() - .chain(inedible.iter().cloned()) - .collect::>(); - self.check_for_erroneous_unit_struct_expecting(&expected); - } - self.expect_one_of(edible, inedible) - } - /// returns the span of expr, if it was not interpolated or the span of the interpolated token fn interpolated_or_expr_span(&self, expr: PResult<'a, P>) @@ -1247,7 +1189,7 @@ impl<'a> Parser<'a> { let default = if self.check(&token::Eq) { self.bump(); let expr = self.parse_expr()?; - self.commit_expr_expecting(&expr, token::Semi)?; + self.expect(&token::Semi)?; Some(expr) } else { self.expect(&token::Semi)?; @@ -2195,8 +2137,7 @@ impl<'a> Parser<'a> { let mut trailing_comma = false; while self.token != token::CloseDelim(token::Paren) { es.push(self.parse_expr()?); - self.commit_expr(&es.last().unwrap(), &[], - &[token::Comma, token::CloseDelim(token::Paren)])?; + self.expect_one_of(&[], &[token::Comma, token::CloseDelim(token::Paren)])?; if self.check(&token::Comma) { trailing_comma = true; @@ -2407,9 +2348,8 @@ impl<'a> Parser<'a> { } } - match self.commit_expr(&fields.last().unwrap().expr, - &[token::Comma], - &[token::CloseDelim(token::Brace)]) { + match self.expect_one_of(&[token::Comma], + &[token::CloseDelim(token::Brace)]) { Ok(()) => {} Err(mut e) => { e.emit(); @@ -2662,7 +2602,7 @@ impl<'a> Parser<'a> { self.bump(); let ix = self.parse_expr()?; hi = self.span.hi; - self.commit_expr_expecting(&ix, token::CloseDelim(token::Bracket))?; + self.expect(&token::CloseDelim(token::Bracket))?; let index = self.mk_index(e, ix); e = self.mk_expr(lo, hi, index, ThinVec::new()) } @@ -3329,8 +3269,7 @@ impl<'a> Parser<'a> { let lo = self.last_span.lo; let discriminant = self.parse_expr_res(Restrictions::RESTRICTION_NO_STRUCT_LITERAL, None)?; - if let Err(mut e) = self.commit_expr_expecting(&discriminant, - token::OpenDelim(token::Brace)) { + if let Err(mut e) = self.expect(&token::OpenDelim(token::Brace)) { if self.token == token::Token::Semi { e.span_note(match_span, "did you mean to remove this `match` keyword?"); } @@ -3376,7 +3315,7 @@ impl<'a> Parser<'a> { && self.token != token::CloseDelim(token::Brace); if require_comma { - self.commit_expr(&expr, &[token::Comma], &[token::CloseDelim(token::Brace)])?; + self.expect_one_of(&[token::Comma], &[token::CloseDelim(token::Brace)])?; } else { self.eat(&token::Comma); } @@ -4118,7 +4057,7 @@ impl<'a> Parser<'a> { _ => { // all other kinds of statements: let mut hi = span.hi; if classify::stmt_ends_with_semi(&node) { - self.commit_stmt(&[token::Semi], &[])?; + self.expect(&token::Semi)?; hi = self.last_span.hi; } @@ -4196,7 +4135,7 @@ impl<'a> Parser<'a> { if classify::expr_requires_semi_to_be_stmt(&e) { // Just check for errors and recover; do not eat semicolon yet. if let Err(mut e) = - self.commit_stmt(&[], &[token::Semi, token::CloseDelim(token::Brace)]) + self.expect_one_of(&[], &[token::Semi, token::CloseDelim(token::Brace)]) { e.emit(); self.recover_stmt(); @@ -4863,7 +4802,7 @@ impl<'a> Parser<'a> { let typ = self.parse_ty_sum()?; self.expect(&token::Eq)?; let expr = self.parse_expr()?; - self.commit_expr_expecting(&expr, token::Semi)?; + self.expect(&token::Semi)?; (name, ast::ImplItemKind::Const(typ, expr)) } else { let (name, inner_attrs, node) = self.parse_impl_method(&vis)?; @@ -5287,7 +5226,7 @@ impl<'a> Parser<'a> { let ty = self.parse_ty_sum()?; self.expect(&token::Eq)?; let e = self.parse_expr()?; - self.commit_expr_expecting(&e, token::Semi)?; + self.expect(&token::Semi)?; let item = match m { Some(m) => ItemKind::Static(ty, m, e), None => ItemKind::Const(ty, e), From 98e3120ad218b8d9c50e25a525dcff689c515776 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sat, 2 Jul 2016 09:50:19 -0400 Subject: [PATCH 07/11] Add doc examples for `io::Error::from_raw_os_error`. --- src/libstd/io/error.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/libstd/io/error.rs b/src/libstd/io/error.rs index e142c78569bd7..05ae8ed5b0b66 100644 --- a/src/libstd/io/error.rs +++ b/src/libstd/io/error.rs @@ -214,6 +214,30 @@ impl Error { } /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples + /// + /// On Linux: + /// + /// ``` + /// # if cfg!(target_os = "linux") { + /// use std::io; + /// + /// let error = io::Error::from_raw_os_error(98); + /// assert_eq!(error.kind(), io::ErrorKind::AddrInUse); + /// # } + /// ``` + /// + /// On Windows: + /// + /// ``` + /// # if cfg!(windows) { + /// use std::io; + /// + /// let error = io::Error::from_raw_os_error(10048); + /// assert_eq!(error.kind(), io::ErrorKind::AddrInUse); + /// # } + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn from_raw_os_error(code: i32) -> Error { Error { repr: Repr::Os(code) } From d30662f3e78ddc65f6ecafd20e4b6ecd3033e466 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E5=86=89=E6=B3=A2?= Date: Thu, 7 Jul 2016 10:34:33 +0800 Subject: [PATCH 08/11] doc:remove useless conditional compilation feature --- src/doc/book/conditional-compilation.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/doc/book/conditional-compilation.md b/src/doc/book/conditional-compilation.md index 2857d7e64c500..78ab3c18e4561 100644 --- a/src/doc/book/conditional-compilation.md +++ b/src/doc/book/conditional-compilation.md @@ -44,9 +44,6 @@ default = [] # Add feature "foo" here, then you can use it. # Our "foo" feature depends on nothing else. foo = [] - -# The “secure-password” feature depends on the bcrypt package. -# secure-password = ["bcrypt"] ``` When you do this, Cargo passes along a flag to `rustc`: From 1f99c29c77c1f5010364af2839ab2a1cc50600d3 Mon Sep 17 00:00:00 2001 From: Phlogistic Fugu Date: Thu, 7 Jul 2016 01:19:05 -0700 Subject: [PATCH 09/11] more windows documentation in getting-started - minor pronoun fix We -> You - PATH troubleshooting - dir output is vertical (but did not include timestamps) - executables not in %PATH% require .\ --- src/doc/book/getting-started.md | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/doc/book/getting-started.md b/src/doc/book/getting-started.md index e7d05a8d93a56..700ab2be58932 100644 --- a/src/doc/book/getting-started.md +++ b/src/doc/book/getting-started.md @@ -11,7 +11,7 @@ an Internet connection to run the commands in this section, as we’ll be downloading Rust from the Internet. We’ll be showing off a number of commands using a terminal, and those lines all -start with `$`. We don't need to type in the `$`s, they are there to indicate +start with `$`. You don't need to type in the `$`s, they are there to indicate the start of each command. We’ll see many tutorials and examples around the web that follow this convention: `$` for commands run as our regular user, and `#` for commands we should be running as an administrator. @@ -159,9 +159,11 @@ You should see the version number, commit hash, and commit date. If you do, Rust has been installed successfully! Congrats! If you don't and you're on Windows, check that Rust is in your %PATH% system -variable. If it isn't, run the installer again, select "Change" on the "Change, -repair, or remove installation" page and ensure "Add to PATH" is installed on -the local hard drive. +variable: `$ echo %PATH%`. If it isn't, run the installer again, select "Change" +on the "Change, repair, or remove installation" page and ensure "Add to PATH" is +installed on the local hard drive. If you need to configure your path manually, +you can find the Rust executables in a directory like +`"C:\Program Files\Rust stable GNU 1.x\bin"`. Rust does not do its own linking, and so you’ll need to have a linker installed. Doing so will depend on your specific system, consult its @@ -339,7 +341,8 @@ On Windows, you'd enter: ```bash $ dir -main.exe main.rs +main.exe +main.rs ``` This shows we have two files: the source code, with an `.rs` extension, and the @@ -347,7 +350,7 @@ executable (`main.exe` on Windows, `main` everywhere else). All that's left to do from here is run the `main` or `main.exe` file, like this: ```bash -$ ./main # or main.exe on Windows +$ ./main # or .\main.exe on Windows ``` If *main.rs* were your "Hello, world!" program, this would print `Hello, From 0314d179aa07905cc3bd4ec3206be28ff11696f9 Mon Sep 17 00:00:00 2001 From: Ivan Nejgebauer Date: Thu, 7 Jul 2016 12:03:31 +0200 Subject: [PATCH 10/11] Use hints with getaddrinfo() in std::net::lokup_host() When resolving a hostname, pass a hints struct where ai_socktype is set to SOCK_STREAM in order to eliminate repeated results for each protocol family. --- src/libstd/sys/common/net.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/libstd/sys/common/net.rs b/src/libstd/sys/common/net.rs index 274e495d70eb6..26925b12f93d6 100644 --- a/src/libstd/sys/common/net.rs +++ b/src/libstd/sys/common/net.rs @@ -152,9 +152,19 @@ pub fn lookup_host(host: &str) -> io::Result { init(); let c_host = CString::new(host)?; + let hints = c::addrinfo { + ai_flags: 0, + ai_family: 0, + ai_socktype: c::SOCK_STREAM, + ai_protocol: 0, + ai_addrlen: 0, + ai_addr: ptr::null_mut(), + ai_canonname: ptr::null_mut(), + ai_next: ptr::null_mut() + }; let mut res = ptr::null_mut(); unsafe { - cvt_gai(c::getaddrinfo(c_host.as_ptr(), ptr::null(), ptr::null(), + cvt_gai(c::getaddrinfo(c_host.as_ptr(), ptr::null(), &hints, &mut res))?; Ok(LookupHost { original: res, cur: res }) } From 46e7c9ec74ec437ca64bc095e7196f59e0d74148 Mon Sep 17 00:00:00 2001 From: Sam Payson Date: Thu, 7 Jul 2016 08:40:15 -0700 Subject: [PATCH 11/11] Changed wording per aturon's comments. --- src/liballoc/rc.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index d582de5740cb8..b505162dc0a9b 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -10,7 +10,8 @@ #![allow(deprecated)] -//! Unsynchronized reference-counted boxes (the `Rc` type). +//! Unsynchronized reference-counted boxes (the `Rc` type) which are usable +//! only within a single thread. //! //! The `Rc` type provides shared ownership of an immutable value. //! Destruction is deterministic, and will occur as soon as the last owner is