Auto merge of #41551 - frewsxcv:rollup, r=frewsxcv

Rollup of 9 pull requests

- Successful merges: #39983, #41442, #41463, #41500, #41518, #41527, #41528, #41530, #41535
- Failed merges:
This commit is contained in:
bors 2017-04-26 03:26:12 +00:00
commit 4512424391
9 changed files with 221 additions and 16 deletions

View File

@ -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");

View File

@ -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

View File

@ -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)

View File

@ -0,0 +1,11 @@
# `more_io_inner_methods`
The tracking issue for this feature is: [#41519]
[#41519]: https://github.com/rust-lang/rust/issues/41519
------------------------
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}`.

18
src/etc/rust-windbg.cmd Normal file
View File

@ -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 <LICENSE-APACHE or
REM http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
REM <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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;" %*

View File

@ -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).
@ -1147,7 +1149,8 @@ impl<T> Vec<T> {
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
///
@ -2032,6 +2035,18 @@ impl<'a, T: Clone> From<&'a [T]> for Vec<T> {
}
}
#[stable(feature = "vec_from_mut", since = "1.21.0")]
impl<'a, T: Clone> From<&'a mut [T]> for Vec<T> {
#[cfg(not(test))]
fn from(s: &'a mut [T]) -> Vec<T> {
s.to_vec()
}
#[cfg(test)]
fn from(s: &'a mut [T]) -> Vec<T> {
::slice::to_vec(s)
}
}
#[stable(feature = "vec_from_cow_slice", since = "1.14.0")]
impl<'a, T> From<Cow<'a, [T]>> for Vec<T> where [T]: ToOwned<Owned=Vec<T>> {
fn from(s: Cow<'a, [T]>) -> Vec<T> {

View File

@ -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

View File

@ -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
///
@ -1494,6 +1504,87 @@ pub struct Chain<T, U> {
done_first: bool,
}
impl<T, U> Chain<T, U> {
/// 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="41519")]
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="41519")]
pub fn get_ref(&self) -> (&T, &U) {
(&self.first, &self.second)
}
/// 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
///
/// ```
/// #![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="41519")]
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<T: fmt::Debug, U: fmt::Debug> fmt::Debug for Chain<T, U> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@ -1606,6 +1697,64 @@ impl<T> Take<T> {
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="41519")]
pub fn get_ref(&self) -> &T {
&self.inner
}
/// 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
///
/// ```
/// #![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="41519")]
pub fn get_mut(&mut self) -> &mut T {
&mut self.inner
}
}
#[stable(feature = "rust1", since = "1.0.0")]

View File

@ -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"),
}
}
}