diff --git a/Makefile.in b/Makefile.in index e41ce56b9ed..9bc44639227 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` diff --git a/src/doc/reference.md b/src/doc/reference.md index 228af394838..6262618a030 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`. diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 1367db16314..e7d84efdaa2 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/libstd/env.rs b/src/libstd/env.rs index aa6a6d548b3..3a543a947b5 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")] @@ -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. @@ -492,7 +491,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 /// diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 6bdfdcd364a..61334f30924 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/libstd/path.rs b/src/libstd/path.rs index 35118bde96b..94967bfb96a 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() { @@ -393,11 +393,8 @@ fn iter_after(mut iter: I, mut prefix: J) -> Option 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, diff --git a/src/test/compile-fail/no-method-suggested-traits.rs b/src/test/compile-fail/no-method-suggested-traits.rs index 08c848a09ab..1683db811cf 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 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 00000000000..e4439087946 --- /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 or the MIT license +// , 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 { + 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); +}