From 8adc3f74f53a59d62ac914e920d5547a3e460924 Mon Sep 17 00:00:00 2001 From: Corey Farwell <coreyf@rwell.org> Date: Wed, 24 Feb 2016 22:34:23 -0500 Subject: [PATCH 01/10] Prefer `slice::get` over length check with indexing. --- src/libstd/path.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 35118bde96bb9..e1393ce6aab97 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -226,7 +226,7 @@ mod platform { } _ => (), } - } else if path.len() > 1 && path[1] == b':' { + } else if path.get(1) == Some(b':') { // C: let c = path[0]; if c.is_ascii() && (c as char).is_alphabetic() { From c82be2f4cb909a70b870ab2fb176e54a91e5372f Mon Sep 17 00:00:00 2001 From: Corey Farwell <coreyf@rwell.org> Date: Wed, 24 Feb 2016 22:50:23 -0500 Subject: [PATCH 02/10] Prefer 'match' pattern guard over conditional within body. --- src/libstd/path.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/libstd/path.rs b/src/libstd/path.rs index e1393ce6aab97..81d9d0a7f103b 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -393,11 +393,8 @@ fn iter_after<A, I, J>(mut iter: I, mut prefix: J) -> Option<I> loop { let mut iter_next = iter.clone(); match (iter_next.next(), prefix.next()) { - (Some(x), Some(y)) => { - if x != y { - return None; - } - } + (Some(ref x), Some(ref y)) if x == y => (), + (Some(_), Some(_)) => return None, (Some(_), None) => return Some(iter), (None, None) => return Some(iter), (None, Some(_)) => return None, From bdecd9d904fb4e62fb2cdb7bfba088b2a47d7646 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar <manishsmail@gmail.com> Date: Thu, 25 Feb 2016 10:21:32 +0530 Subject: [PATCH 03/10] mention debug-assertions --- Makefile.in | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Makefile.in b/Makefile.in index e41ce56b9ed0c..9bc4463922732 100644 --- a/Makefile.in +++ b/Makefile.in @@ -100,6 +100,10 @@ # // Having trouble figuring out which test is failing? Turn off parallel tests # make check-stage1-std RUST_TEST_THREADS=1 # +# // To make debug!() and other logging calls visible, reconfigure: +# ./configure --enable-debug-assertions +# make .... +# # If you really feel like getting your hands dirty, then: # # run `make nitty-gritty` From d472b69da129af3950289170e13032d9c7913000 Mon Sep 17 00:00:00 2001 From: Georg Brandl <georg@python.org> Date: Thu, 25 Feb 2016 08:30:42 +0100 Subject: [PATCH 04/10] Document the null-char/null-byte escape in the reference It appears in the examples, but is not covered by any of the cases in the prose description. --- src/doc/reference.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/doc/reference.md b/src/doc/reference.md index 228af39483832..6262618a030a3 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -236,6 +236,8 @@ following forms: * A _whitespace escape_ is one of the characters `U+006E` (`n`), `U+0072` (`r`), or `U+0074` (`t`), denoting the Unicode values `U+000A` (LF), `U+000D` (CR) or `U+0009` (HT) respectively. +* The _null escape_ is the character `U+0030` (`0`) and denotes the Unicode + value `U+0000` (NUL). * The _backslash escape_ is the character `U+005C` (`\`) which must be escaped in order to denote *itself*. @@ -297,6 +299,8 @@ following forms: * A _whitespace escape_ is one of the characters `U+006E` (`n`), `U+0072` (`r`), or `U+0074` (`t`), denoting the bytes values `0x0A` (ASCII LF), `0x0D` (ASCII CR) or `0x09` (ASCII HT) respectively. +* The _null escape_ is the character `U+0030` (`0`) and denotes the byte + value `0x00` (ASCII NUL). * The _backslash escape_ is the character `U+005C` (`\`) which must be escaped in order to denote its ASCII encoding `0x5C`. From 52ed15fb7c7f3771a8a277c616a75f6ba26f050e Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe <tshepang@gmail.com> Date: Thu, 25 Feb 2016 22:52:02 +0200 Subject: [PATCH 05/10] doc: add missing comma --- src/libstd/env.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/env.rs b/src/libstd/env.rs index aa6a6d548b31a..40f5e4c834554 100644 --- a/src/libstd/env.rs +++ b/src/libstd/env.rs @@ -492,7 +492,7 @@ pub fn temp_dir() -> PathBuf { /// /// Acquiring the path to the current executable is a platform-specific operation /// that can fail for a good number of reasons. Some errors can include, but not -/// be limited to filesystem operations failing or general syscall failures. +/// be limited to, filesystem operations failing or general syscall failures. /// /// # Examples /// From 6c21b1bad62bdf289196df01a85ceea0703284c8 Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe <tshepang@gmail.com> Date: Thu, 25 Feb 2016 23:14:20 +0200 Subject: [PATCH 06/10] doc: that explanation was a mess --- src/libstd/env.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libstd/env.rs b/src/libstd/env.rs index aa6a6d548b31a..be61994ac39ef 100644 --- a/src/libstd/env.rs +++ b/src/libstd/env.rs @@ -482,8 +482,7 @@ pub fn temp_dir() -> PathBuf { os_imp::temp_dir() } -/// Returns the filesystem path to the current executable which is running but -/// with the executable name. +/// Returns the full filesystem path to the current running executable. /// /// The path returned is not necessarily a "real path" to the executable as /// there may be intermediate symlinks. From 5eb46d9a01473875dd26f89d2f52ea4b57fa98e5 Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe <tshepang@gmail.com> Date: Thu, 25 Feb 2016 23:19:47 +0200 Subject: [PATCH 07/10] doc: follow the idiom of adding a trailing comma --- src/libstd/env.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/env.rs b/src/libstd/env.rs index aa6a6d548b31a..0bf099714d835 100644 --- a/src/libstd/env.rs +++ b/src/libstd/env.rs @@ -442,7 +442,7 @@ impl Error for JoinPathsError { /// /// match env::home_dir() { /// Some(ref p) => println!("{}", p.display()), -/// None => println!("Impossible to get your home dir!") +/// None => println!("Impossible to get your home dir!"), /// } /// ``` #[stable(feature = "env", since = "1.0.0")] From 5db43169deb39407223f8b5cd06f11cde686e628 Mon Sep 17 00:00:00 2001 From: Ulrik Sverdrup <bluss@users.noreply.github.com> Date: Fri, 26 Feb 2016 01:23:07 +0100 Subject: [PATCH 08/10] suggest: Put the `use` in suggested code inside the quotes Change import a trait suggestion from: help: candidate #1: use `std::io::Write` to help: candidate #1: `use std::io::Write` so that the code can be copied directly. --- src/librustc_typeck/check/method/suggest.rs | 2 +- .../compile-fail/no-method-suggested-traits.rs | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 1367db16314e2..e7d84efdaa2f7 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -271,7 +271,7 @@ fn suggest_traits_to_import<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, for (i, trait_did) in candidates.iter().enumerate() { err.fileline_help(span, - &format!("candidate #{}: use `{}`", + &format!("candidate #{}: `use {}`", i + 1, fcx.tcx().item_path_str(*trait_did))); } diff --git a/src/test/compile-fail/no-method-suggested-traits.rs b/src/test/compile-fail/no-method-suggested-traits.rs index 08c848a09ab09..1683db811cf04 100644 --- a/src/test/compile-fail/no-method-suggested-traits.rs +++ b/src/test/compile-fail/no-method-suggested-traits.rs @@ -34,31 +34,31 @@ fn main() { 1u32.method(); //~^ HELP following traits are implemented but not in scope, perhaps add a `use` for one of them //~^^ ERROR no method named - //~^^^ HELP `foo::Bar` - //~^^^^ HELP `no_method_suggested_traits::foo::PubPub` + //~^^^ HELP `use foo::Bar` + //~^^^^ HELP `use no_method_suggested_traits::foo::PubPub` std::rc::Rc::new(&mut Box::new(&1u32)).method(); //~^ HELP following traits are implemented but not in scope, perhaps add a `use` for one of them //~^^ ERROR no method named - //~^^^ HELP `foo::Bar` - //~^^^^ HELP `no_method_suggested_traits::foo::PubPub` + //~^^^ HELP `use foo::Bar` + //~^^^^ HELP `use no_method_suggested_traits::foo::PubPub` 'a'.method(); //~^ ERROR no method named //~^^ HELP the following trait is implemented but not in scope, perhaps add a `use` for it: - //~^^^ HELP `foo::Bar` + //~^^^ HELP `use foo::Bar` std::rc::Rc::new(&mut Box::new(&'a')).method(); //~^ ERROR no method named //~^^ HELP the following trait is implemented but not in scope, perhaps add a `use` for it: - //~^^^ HELP `foo::Bar` + //~^^^ HELP `use foo::Bar` 1i32.method(); //~^ ERROR no method named //~^^ HELP the following trait is implemented but not in scope, perhaps add a `use` for it: - //~^^^ HELP `no_method_suggested_traits::foo::PubPub` + //~^^^ HELP `use no_method_suggested_traits::foo::PubPub` std::rc::Rc::new(&mut Box::new(&1i32)).method(); //~^ ERROR no method named //~^^ HELP the following trait is implemented but not in scope, perhaps add a `use` for it: - //~^^^ HELP `no_method_suggested_traits::foo::PubPub` + //~^^^ HELP `use no_method_suggested_traits::foo::PubPub` Foo.method(); //~^ ERROR no method named From 6cfafad3c56736a62e1043a8d01f7f2c74384008 Mon Sep 17 00:00:00 2001 From: Ulrik Sverdrup <bluss@users.noreply.github.com> Date: Fri, 26 Feb 2016 02:53:47 +0100 Subject: [PATCH 09/10] Make sure formatter errors are emitted by the default Write::write_fmt Previously, if an error was returned from the formatter that did not originate in an underlying writer error, Write::write_fmt would return successfully even if the formatting did not complete (was interrupted by an `fmt::Error` return). Now we choose to emit an io::Error with kind Other for formatter errors. Since this may reveal error returns from `write!()` and similar that previously passed silently, it's a kind of a [breaking-change]. --- src/libstd/io/mod.rs | 9 ++++- src/test/run-pass/write-fmt-errors.rs | 54 +++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 src/test/run-pass/write-fmt-errors.rs diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index abb47b694184c..4baf02063a395 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -1055,7 +1055,14 @@ pub trait Write { let mut output = Adaptor { inner: self, error: Ok(()) }; match fmt::write(&mut output, fmt) { Ok(()) => Ok(()), - Err(..) => output.error + Err(..) => { + // check if the error came from the underlying `Write` or not + if output.error.is_err() { + output.error + } else { + Err(Error::new(ErrorKind::Other, "formatter error")) + } + } } } diff --git a/src/test/run-pass/write-fmt-errors.rs b/src/test/run-pass/write-fmt-errors.rs new file mode 100644 index 0000000000000..e4439087946c1 --- /dev/null +++ b/src/test/run-pass/write-fmt-errors.rs @@ -0,0 +1,54 @@ +// Copyright 2016 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. + +use std::fmt; +use std::io::{self, Error, Write, sink}; + +struct ErrorDisplay; + +impl fmt::Display for ErrorDisplay { + fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result { + Err(fmt::Error) + } +} + +struct ErrorWriter; + +const FORMAT_ERROR: io::ErrorKind = io::ErrorKind::Other; +const WRITER_ERROR: io::ErrorKind = io::ErrorKind::NotConnected; + +impl Write for ErrorWriter { + fn write(&mut self, _buf: &[u8]) -> io::Result<usize> { + Err(Error::new(WRITER_ERROR, "not connected")) + } + + fn flush(&mut self) -> io::Result<()> { Ok(()) } +} + +fn main() { + // Test that the error from the formatter is propagated. + let res = write!(sink(), "{} {} {}", 1, ErrorDisplay, "bar"); + assert!(res.is_err(), "formatter error did not propagate"); + assert_eq!(res.unwrap_err().kind(), FORMAT_ERROR); + + // Test that an underlying error is propagated + let res = write!(ErrorWriter, "abc"); + assert!(res.is_err(), "writer error did not propagate"); + + // Writer error + let res = write!(ErrorWriter, "abc {}", ErrorDisplay); + assert!(res.is_err(), "writer error did not propagate"); + assert_eq!(res.unwrap_err().kind(), WRITER_ERROR); + + // Formatter error + let res = write!(ErrorWriter, "{} abc", ErrorDisplay); + assert!(res.is_err(), "formatter error did not propagate"); + assert_eq!(res.unwrap_err().kind(), FORMAT_ERROR); +} From 3c9a26853cca8783892d5b2373e9de63b5f488b5 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar <manishsmail@gmail.com> Date: Fri, 26 Feb 2016 17:05:46 +0530 Subject: [PATCH 10/10] fixup #31878 --- src/libstd/path.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 81d9d0a7f103b..94967bfb96ad3 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -226,7 +226,7 @@ mod platform { } _ => (), } - } else if path.get(1) == Some(b':') { + } else if path.get(1) == Some(& b':') { // C: let c = path[0]; if c.is_ascii() && (c as char).is_alphabetic() {