From c49d0906da09972f447013834dcf891ec887151b Mon Sep 17 00:00:00 2001 From: Tobias Bucher Date: Fri, 21 Apr 2017 10:32:13 +0200 Subject: [PATCH 01/12] Specify behavior of `write_all` for `ErrorKind::Interrupted` errors Also spell out that read and write operations should be retried on `ErrorKind::Interrupted` errors. Fixes #38494. --- src/libstd/io/mod.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index cd096c115ba5a..39a0602eab826 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -466,6 +466,9 @@ pub trait Read { /// variant will be returned. If an error is returned then it must be /// guaranteed that no bytes were read. /// + /// An error of the `ErrorKind::Interrupted` kind is non-fatal and the read + /// operation should be retried if there is nothing else to do. + /// /// # Examples /// /// [`File`][file]s implement `Read`: @@ -481,7 +484,7 @@ pub trait Read { /// let mut f = File::open("foo.txt")?; /// let mut buffer = [0; 10]; /// - /// // read 10 bytes + /// // read up to 10 bytes /// f.read(&mut buffer[..])?; /// # Ok(()) /// # } @@ -885,6 +888,9 @@ pub trait Write { /// It is **not** considered an error if the entire buffer could not be /// written to this writer. /// + /// An error of the `ErrorKind::Interrupted` kind is non-fatal and the + /// write operation should be retried if there is nothing else to do. + /// /// # Examples /// /// ``` @@ -894,6 +900,7 @@ pub trait Write { /// # fn foo() -> std::io::Result<()> { /// let mut buffer = File::create("foo.txt")?; /// + /// // Writes some prefix of the byte string, not necessarily all of it. /// buffer.write(b"some bytes")?; /// # Ok(()) /// # } @@ -929,14 +936,17 @@ pub trait Write { /// Attempts to write an entire buffer into this write. /// - /// This method will continuously call `write` while there is more data to - /// write. This method will not return until the entire buffer has been - /// successfully written or an error occurs. The first error generated from - /// this method will be returned. + /// This method will continuously call `write` until there is no more data + /// to be written or an error of non-`ErrorKind::Interrupted` kind is + /// returned. This method will not return until the entire buffer has been + /// successfully written or such an error occurs. The first error that is + /// not of `ErrorKind::Interrupted` kind generated from this method will be + /// returned. /// /// # Errors /// - /// This function will return the first error that `write` returns. + /// This function will return the first error of + /// non-`ErrorKind::Interrupted` kind that `write` returns. /// /// # Examples /// From f852e3fcbcdbcc42d7eb215b08bb3539f76b8ca1 Mon Sep 17 00:00:00 2001 From: steveklabnik Date: Mon, 24 Apr 2017 07:47:00 -0400 Subject: [PATCH 02/12] use the word 'length' in Vec::len's docs Fixes #37866 --- src/libcollections/vec.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 6deb87ae77204..1d443b19d80a7 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -1147,7 +1147,8 @@ impl Vec { self.truncate(0) } - /// Returns the number of elements in the vector. + /// Returns the number of elements in the vector, also referred to + /// as its 'length'. /// /// # Examples /// From 957d51aecb3eb4960129b38b147cff0b8d0fae5c Mon Sep 17 00:00:00 2001 From: Tobias Bucher Date: Tue, 25 Apr 2017 01:02:59 +0200 Subject: [PATCH 03/12] Fix a copy-paste error in `Instant::sub_duration` Fixes #41514. --- src/libstd/sys/unix/time.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/sys/unix/time.rs b/src/libstd/sys/unix/time.rs index a08cec38f732d..a1ad94872de5c 100644 --- a/src/libstd/sys/unix/time.rs +++ b/src/libstd/sys/unix/time.rs @@ -157,7 +157,7 @@ mod inner { pub fn sub_duration(&self, other: &Duration) -> Instant { Instant { t: self.t.checked_sub(dur2intervals(other)) - .expect("overflow when adding duration to instant"), + .expect("overflow when subtracting duration from instant"), } } } From 70e673952ee7544576e2912efe9735bc4617e447 Mon Sep 17 00:00:00 2001 From: Andrew Gaspar Date: Mon, 20 Feb 2017 11:10:32 -0800 Subject: [PATCH 04/12] Adds rust-windbg.cmd script --- src/bootstrap/dist.rs | 7 ++++++- src/etc/rust-windbg.cmd | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 src/etc/rust-windbg.cmd diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index 4328c4e3f1d4c..ada8d4df604e3 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -254,7 +254,12 @@ pub fn debugger_scripts(build: &Build, install(&build.src.join("src/etc/").join(file), &dst, 0o644); }; if host.contains("windows-msvc") { - // no debugger scripts + // windbg debugger scripts + install(&build.src.join("src/etc/rust-windbg.cmd"), &sysroot.join("bin"), + 0o755); + + cp_debugger_script("natvis/libcore.natvis"); + cp_debugger_script("natvis/libcollections.natvis"); } else { cp_debugger_script("debugger_pretty_printers_common.py"); diff --git a/src/etc/rust-windbg.cmd b/src/etc/rust-windbg.cmd new file mode 100644 index 0000000000000..4cdd6b9860996 --- /dev/null +++ b/src/etc/rust-windbg.cmd @@ -0,0 +1,18 @@ +@echo off +setlocal + +REM Copyright 2014 The Rust Project Developers. See the COPYRIGHT +REM file at the top-level directory of this distribution and at +REM http://rust-lang.org/COPYRIGHT. +REM +REM Licensed under the Apache License, Version 2.0 or the MIT license +REM , at your +REM option. This file may not be copied, modified, or distributed +REM except according to those terms. + +for /f "delims=" %%i in ('rustc --print=sysroot') do set rustc_sysroot=%%i + +set rust_etc=%rustc_sysroot%\lib\rustlib\etc + +windbg -c ".nvload %rust_etc%\libcore.natvis;.nvload %rust_etc%\libcollections.natvis;" %* \ No newline at end of file From a765dcaf5378cbd6cfa71f3fdeede82eeca4fc26 Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Sat, 22 Apr 2017 01:14:18 -0700 Subject: [PATCH 05/12] Add internal accessor methods to io::{Chain, Take}. Resolves #29067. --- src/libstd/io/mod.rs | 131 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index cd096c115ba5a..cf548346b176c 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -1494,6 +1494,83 @@ pub struct Chain { done_first: bool, } +impl Chain { + /// Consumes the `Chain`, returning the wrapped readers. + /// + /// # Examples + /// + /// ``` + /// #![feature(more_io_inner_methods)] + /// + /// # use std::io; + /// use std::io::prelude::*; + /// use std::fs::File; + /// + /// # fn foo() -> io::Result<()> { + /// let mut foo_file = File::open("foo.txt")?; + /// let mut bar_file = File::open("bar.txt")?; + /// + /// let chain = foo_file.chain(bar_file); + /// let (foo_file, bar_file) = chain.into_inner(); + /// # Ok(()) + /// # } + /// ``` + #[unstable(feature = "more_io_inner_methods", issue="0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } + + /// Gets references to the underlying readers in this `Chain`. + /// + /// # Examples + /// + /// ``` + /// #![feature(more_io_inner_methods)] + /// + /// # use std::io; + /// use std::io::prelude::*; + /// use std::fs::File; + /// + /// # fn foo() -> io::Result<()> { + /// let mut foo_file = File::open("foo.txt")?; + /// let mut bar_file = File::open("bar.txt")?; + /// + /// let chain = foo_file.chain(bar_file); + /// let (foo_file, bar_file) = chain.get_ref(); + /// # Ok(()) + /// # } + /// ``` + #[unstable(feature = "more_io_inner_methods", issue="0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } + + /// Gets mutable references to the underlying readers in this `Chain`. + /// + /// # Examples + /// + /// ``` + /// #![feature(more_io_inner_methods)] + /// + /// # use std::io; + /// use std::io::prelude::*; + /// use std::fs::File; + /// + /// # fn foo() -> io::Result<()> { + /// let mut foo_file = File::open("foo.txt")?; + /// let mut bar_file = File::open("bar.txt")?; + /// + /// let mut chain = foo_file.chain(bar_file); + /// let (foo_file, bar_file) = chain.get_mut(); + /// # Ok(()) + /// # } + /// ``` + #[unstable(feature = "more_io_inner_methods", issue="0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } +} + #[stable(feature = "std_debug", since = "1.16.0")] impl fmt::Debug for Chain { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -1606,6 +1683,60 @@ impl Take { pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying reader. + /// + /// # Examples + /// + /// ``` + /// #![feature(more_io_inner_methods)] + /// + /// use std::io; + /// use std::io::prelude::*; + /// use std::fs::File; + /// + /// # fn foo() -> io::Result<()> { + /// let mut file = File::open("foo.txt")?; + /// + /// let mut buffer = [0; 5]; + /// let mut handle = file.take(5); + /// handle.read(&mut buffer)?; + /// + /// let file = handle.get_ref(); + /// # Ok(()) + /// # } + /// ``` + #[unstable(feature = "more_io_inner_methods", issue="0")] + pub fn get_ref(&self) -> &T { + &self.inner + } + + /// Gets a mutable reference to the underlying reader. + /// + /// # Examples + /// + /// ``` + /// #![feature(more_io_inner_methods)] + /// + /// use std::io; + /// use std::io::prelude::*; + /// use std::fs::File; + /// + /// # fn foo() -> io::Result<()> { + /// let mut file = File::open("foo.txt")?; + /// + /// let mut buffer = [0; 5]; + /// let mut handle = file.take(5); + /// handle.read(&mut buffer)?; + /// + /// let file = handle.get_mut(); + /// # Ok(()) + /// # } + /// ``` + #[unstable(feature = "more_io_inner_methods", issue="0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } } #[stable(feature = "rust1", since = "1.0.0")] From aab87e3e9e71696d475a0b2c57f0dee7f702fc27 Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Sat, 22 Apr 2017 03:35:53 -0700 Subject: [PATCH 06/12] Add more_io_inner_methods feature to unstable book. --- src/doc/unstable-book/src/SUMMARY.md | 1 + .../src/library-features/more-io-inner-methods.md | 9 +++++++++ 2 files changed, 10 insertions(+) create mode 100644 src/doc/unstable-book/src/library-features/more-io-inner-methods.md diff --git a/src/doc/unstable-book/src/SUMMARY.md b/src/doc/unstable-book/src/SUMMARY.md index 6134757304170..9b77d99403fdb 100644 --- a/src/doc/unstable-book/src/SUMMARY.md +++ b/src/doc/unstable-book/src/SUMMARY.md @@ -160,6 +160,7 @@ - [linked_list_extras](library-features/linked-list-extras.md) - [lookup_host](library-features/lookup-host.md) - [manually_drop](library-features/manually-drop.md) + - [more_io_inner_methods](library-features/more-io-inner-methods.md) - [mpsc_select](library-features/mpsc-select.md) - [n16](library-features/n16.md) - [never_type_impls](library-features/never-type-impls.md) diff --git a/src/doc/unstable-book/src/library-features/more-io-inner-methods.md b/src/doc/unstable-book/src/library-features/more-io-inner-methods.md new file mode 100644 index 0000000000000..1b56a8b395c69 --- /dev/null +++ b/src/doc/unstable-book/src/library-features/more-io-inner-methods.md @@ -0,0 +1,9 @@ +# `more_io_inner_methods` + +The tracking issue for this feature is: None. + +------------------------ + +This feature enables several internal accessor methods on structures in +`std::io` including `Take::{get_ref, get_mut}` and `Chain::{into_inner, get_ref, +get_mut}`. From 76397aea50a506ac177b74d352a0ebbe99d4cdc6 Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Mon, 24 Apr 2017 16:46:05 -0700 Subject: [PATCH 07/12] Reference tracking issue for more_io_inner_methods. --- .../src/library-features/more-io-inner-methods.md | 4 +++- src/libstd/io/mod.rs | 10 +++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/doc/unstable-book/src/library-features/more-io-inner-methods.md b/src/doc/unstable-book/src/library-features/more-io-inner-methods.md index 1b56a8b395c69..c84f40e7ee551 100644 --- a/src/doc/unstable-book/src/library-features/more-io-inner-methods.md +++ b/src/doc/unstable-book/src/library-features/more-io-inner-methods.md @@ -1,6 +1,8 @@ # `more_io_inner_methods` -The tracking issue for this feature is: None. +The tracking issue for this feature is: [#41519] + +[#41519]: https://github.com/rust-lang/rust/issues/41519 ------------------------ diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index cf548346b176c..a30246ae88b6c 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -1515,7 +1515,7 @@ impl Chain { /// # Ok(()) /// # } /// ``` - #[unstable(feature = "more_io_inner_methods", issue="0")] + #[unstable(feature = "more_io_inner_methods", issue="41519")] pub fn into_inner(self) -> (T, U) { (self.first, self.second) } @@ -1540,7 +1540,7 @@ impl Chain { /// # Ok(()) /// # } /// ``` - #[unstable(feature = "more_io_inner_methods", issue="0")] + #[unstable(feature = "more_io_inner_methods", issue="41519")] pub fn get_ref(&self) -> (&T, &U) { (&self.first, &self.second) } @@ -1565,7 +1565,7 @@ impl Chain { /// # Ok(()) /// # } /// ``` - #[unstable(feature = "more_io_inner_methods", issue="0")] + #[unstable(feature = "more_io_inner_methods", issue="41519")] pub fn get_mut(&mut self) -> (&mut T, &mut U) { (&mut self.first, &mut self.second) } @@ -1706,7 +1706,7 @@ impl Take { /// # Ok(()) /// # } /// ``` - #[unstable(feature = "more_io_inner_methods", issue="0")] + #[unstable(feature = "more_io_inner_methods", issue="41519")] pub fn get_ref(&self) -> &T { &self.inner } @@ -1733,7 +1733,7 @@ impl Take { /// # Ok(()) /// # } /// ``` - #[unstable(feature = "more_io_inner_methods", issue="0")] + #[unstable(feature = "more_io_inner_methods", issue="41519")] pub fn get_mut(&mut self) -> &mut T { &mut self.inner } From c168d8bb07392ca6c5e30c2cde1458c9e32bf03b Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Mon, 24 Apr 2017 16:46:21 -0700 Subject: [PATCH 08/12] Add cautions to io::get_mut method documentation. --- src/libstd/io/mod.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index a30246ae88b6c..d08ba591de018 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -1547,6 +1547,10 @@ impl Chain { /// Gets mutable references to the underlying readers in this `Chain`. /// + /// Care should be taken to avoid modifying the internal I/O state of the + /// underlying readers as doing so may corrupt the internal state of this + /// `Chain`. + /// /// # Examples /// /// ``` @@ -1713,6 +1717,10 @@ impl Take { /// Gets a mutable reference to the underlying reader. /// + /// Care should be taken to avoid modifying the internal I/O state of the + /// underlying reader as doing so may corrupt the internal limit of this + /// `Take`. + /// /// # Examples /// /// ``` From dce33e96bc2f904fbc5bfb96b5fb92433dc18ba8 Mon Sep 17 00:00:00 2001 From: steveklabnik Date: Tue, 25 Apr 2017 05:35:51 -0400 Subject: [PATCH 09/12] Clarify the doc index With regards to the unstable book, the reference, and the processes involved. Also, fix up a link by pointing to the new tracking issue rather than the older one. Fixes #41285 --- src/doc/index.md | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/doc/index.md b/src/doc/index.md index 1294c1a8c59e7..fd5b120e81fae 100644 --- a/src/doc/index.md +++ b/src/doc/index.md @@ -32,16 +32,21 @@ nicknamed 'The Rust Bookshelf.' * [The Rustonomicon][nomicon] is your guidebook to the dark arts of unsafe Rust. * [The Reference][ref] is not a formal spec, but is more detailed and comprehensive than the book. +Initially, documentation lands in the Unstable Book, and then, as part of the +stabilization process, is moved into the Book, Nomicon, or Reference. + Another few words about the reference: it is guaranteed to be accurate, but not -complete. We now have a policy that all new features must be included in the -reference before stabilization; however, we are still back-filling things that -landed before then. That work is being tracked [here][38643]. +complete. We have a policy that features must have documentation to be stabilized, +but we did not always have this policy, and so there are some stable things that +are not yet in the reference. We're working on back-filling things that landed +before this policy was put into place. That work is being tracked +[here][refchecklist]. [Rust Learning]: https://github.com/ctjhoa/rust-learning [Docs.rs]: https://docs.rs/ [api]: std/index.html [ref]: reference/index.html -[38643]: https://github.com/rust-lang/rust/issues/38643 +[refchecklist]: https://github.com/rust-lang-nursery/reference/issues/9 [err]: error-index.html [book]: book/index.html [nomicon]: nomicon/index.html From 696df71d0c442dba82f52f2b985feb0e1431bd60 Mon Sep 17 00:00:00 2001 From: steveklabnik Date: Tue, 25 Apr 2017 05:38:26 -0400 Subject: [PATCH 10/12] Clarify "side effect" in peek's docs Fixes #33269 --- src/libcore/iter/iterator.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libcore/iter/iterator.rs b/src/libcore/iter/iterator.rs index 3ad91ef15ea7b..b3f4d75c4da61 100644 --- a/src/libcore/iter/iterator.rs +++ b/src/libcore/iter/iterator.rs @@ -629,8 +629,9 @@ pub trait Iterator { /// /// Note that the underlying iterator is still advanced when [`peek`] is /// called for the first time: In order to retrieve the next element, - /// [`next`] is called on the underlying iterator, hence any side effects of - /// the [`next`] method will occur. + /// [`next`] is called on the underlying iterator, hence any side effects (i.e. + /// anything other than fetching the next value) of the [`next`] method + /// will occur. /// /// [`peek`]: struct.Peekable.html#method.peek /// [`next`]: ../../std/iter/trait.Iterator.html#tymethod.next From e70a266b3bc7b30458a7acfc3ca8c92878735ce1 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 25 Apr 2017 12:34:45 +0200 Subject: [PATCH 11/12] Implement From<&mut [T]> for Vec --- src/libcollections/vec.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 6deb87ae77204..12f53fe60fed2 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -1984,6 +1984,18 @@ impl<'a, T: Clone> From<&'a [T]> for Vec { } } +#[stable(feature = "vec_from_mut", since = "1.21.0")] +impl<'a, T: Clone> From<&'a mut [T]> for Vec { + #[cfg(not(test))] + fn from(s: &'a mut [T]) -> Vec { + s.to_vec() + } + #[cfg(test)] + fn from(s: &'a mut [T]) -> Vec { + ::slice::to_vec(s) + } +} + #[stable(feature = "vec_from_cow_slice", since = "1.14.0")] impl<'a, T> From> for Vec where [T]: ToOwned> { fn from(s: Cow<'a, [T]>) -> Vec { From 19b7272dbcd9a35acfed7c8aa5e8d3e23b2a67f9 Mon Sep 17 00:00:00 2001 From: steveklabnik Date: Tue, 25 Apr 2017 10:41:17 -0400 Subject: [PATCH 12/12] Fix up vec guarnatee around capacity Fixes #37746 --- src/libcollections/vec.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 6deb87ae77204..fcebc22bb455a 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -275,7 +275,9 @@ use Bound::{Excluded, Included, Unbounded}; /// removed data to be erased for security purposes. Even if you drop a `Vec`, its /// buffer may simply be reused by another `Vec`. Even if you zero a `Vec`'s memory /// first, that may not actually happen because the optimizer does not consider -/// this a side-effect that must be preserved. +/// this a side-effect that must be preserved. There is one case which we will +/// not break, however: using `unsafe` code to write to the excess capacity, +/// and then increasing the length to match, is always valid. /// /// `Vec` does not currently guarantee the order in which elements are dropped /// (the order has changed in the past, and may change again).