Skip to content

Commit

Permalink
Auto merge of #35240 - sanxiyn:rollup, r=sanxiyn
Browse files Browse the repository at this point in the history
Rollup of 7 pull requests

- Successful merges: #34319, #35041, #35042, #35175, #35181, #35182, #35189
- Failed merges:
  • Loading branch information
bors committed Aug 3, 2016
2 parents 9cf1897 + 870b71b commit 07f1bac
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/doc/book/the-stack-and-the-heap.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ The stack is very fast, and is where memory is allocated in Rust by default.
But the allocation is local to a function call, and is limited in size. The
heap, on the other hand, is slower, and is explicitly allocated by your
program. But it’s effectively unlimited in size, and is globally accessible.
Note this meaning of heap, which allocates arbitrary-sized blocks of memory in arbitrary
order, is quite different from the heap data structure.

# The Stack

Expand Down
32 changes: 32 additions & 0 deletions src/libcollections/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,45 @@ pub trait RangeArgument<T> {
/// Start index (inclusive)
///
/// Return start value if present, else `None`.
///
/// # Examples
///
/// ```
/// #![feature(collections)]
/// #![feature(collections_range)]
///
/// extern crate collections;
///
/// # fn main() {
/// use collections::range::RangeArgument;
///
/// assert_eq!((..10).start(), None);
/// assert_eq!((3..10).start(), Some(&3));
/// # }
/// ```
fn start(&self) -> Option<&T> {
None
}

/// End index (exclusive)
///
/// Return end value if present, else `None`.
///
/// # Examples
///
/// ```
/// #![feature(collections)]
/// #![feature(collections_range)]
///
/// extern crate collections;
///
/// # fn main() {
/// use collections::range::RangeArgument;
///
/// assert_eq!((3..).end(), None);
/// assert_eq!((3..10).end(), Some(&10));
/// # }
/// ```
fn end(&self) -> Option<&T> {
None
}
Expand Down
19 changes: 19 additions & 0 deletions src/libcollections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,25 @@ impl<T> Vec<T> {
/// Note that this will drop any excess capacity. Calling this and
/// converting back to a vector with `into_vec()` is equivalent to calling
/// `shrink_to_fit()`.
///
/// # Examples
///
/// ```
/// let v = vec![1, 2, 3];
///
/// let slice = v.into_boxed_slice();
/// ```
///
/// Any excess capacity is removed:
///
/// ```
/// let mut vec = Vec::with_capacity(10);
/// vec.extend([1, 2, 3].iter().cloned());
///
/// assert_eq!(vec.capacity(), 10);
/// let slice = vec.into_boxed_slice();
/// assert_eq!(slice.into_vec().capacity(), 3);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn into_boxed_slice(mut self) -> Box<[T]> {
unsafe {
Expand Down
6 changes: 6 additions & 0 deletions src/libcore/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ pub trait Unsize<T: ?Sized> {
/// Generalizing the latter case, any type implementing `Drop` can't be `Copy`, because it's
/// managing some resource besides its own `size_of::<T>()` bytes.
///
/// ## What if I derive `Copy` on a type that can't?
///
/// If you try to derive `Copy` on a struct or enum, you will get a compile-time error.
/// Specifically, with structs you'll get [E0204](https://doc.rust-lang.org/error-index.html#E0204)
/// and with enums you'll get [E0205](https://doc.rust-lang.org/error-index.html#E0205).
///
/// ## When should my type be `Copy`?
///
/// Generally speaking, if your type _can_ implement `Copy`, it should. There's one important thing
Expand Down
101 changes: 98 additions & 3 deletions src/librustc_typeck/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3897,6 +3897,104 @@ impl SpaceLlama for i32 {
```
"##,

E0527: r##"
The number of elements in an array or slice pattern differed from the number of
elements in the array being matched.
Example of erroneous code:
```compile_fail,E0527
#![feature(slice_patterns)]
let r = &[1, 2, 3, 4];
match r {
&[a, b] => { // error: pattern requires 2 elements but array
// has 4
println!("a={}, b={}", a, b);
}
}
```
Ensure that the pattern is consistent with the size of the matched
array. Additional elements can be matched with `..`:
```
#![feature(slice_patterns)]
let r = &[1, 2, 3, 4];
match r {
&[a, b, ..] => { // ok!
println!("a={}, b={}", a, b);
}
}
```
"##,

E0528: r##"
An array or slice pattern required more elements than were present in the
matched array.
Example of erroneous code:
```compile_fail,E0528
#![feature(slice_patterns)]
let r = &[1, 2];
match r {
&[a, b, c, rest..] => { // error: pattern requires at least 3
// elements but array has 2
println!("a={}, b={}, c={} rest={:?}", a, b, c, rest);
}
}
```
Ensure that the matched array has at least as many elements as the pattern
requires. You can match an arbitrary number of remaining elements with `..`:
```
#![feature(slice_patterns)]
let r = &[1, 2, 3, 4, 5];
match r {
&[a, b, c, rest..] => { // ok!
// prints `a=1, b=2, c=3 rest=[4, 5]`
println!("a={}, b={}, c={} rest={:?}", a, b, c, rest);
}
}
```
"##,

E0529: r##"
An array or slice pattern was matched against some other type.
Example of erroneous code:
```compile_fail,E0529
#![feature(slice_patterns)]
let r: f32 = 1.0;
match r {
[a, b] => { // error: expected an array or slice, found `f32`
println!("a={}, b={}", a, b);
}
}
```
Ensure that the pattern and the expression being matched on are of consistent
types:
```
#![feature(slice_patterns)]
let r = [1.0, 2.0];
match r {
[a, b] => { // ok!
println!("a={}, b={}", a, b);
}
}
```
"##,

E0559: r##"
An unknown field was specified into an enum's structure variant.
Expand Down Expand Up @@ -4018,8 +4116,5 @@ register_diagnostics! {
E0436, // functional record update requires a struct
E0513, // no type for local variable ..
E0521, // redundant default implementations of trait
E0527, // expected {} elements, found {}
E0528, // expected at least {} elements, found {}
E0529, // slice pattern expects array or slice, not `{}`
E0533, // `{}` does not name a unit variant, unit struct or a constant
}
12 changes: 12 additions & 0 deletions src/libstd/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,18 @@ impl Borrow<CStr> for CString {
impl NulError {
/// Returns the position of the nul byte in the slice that was provided to
/// `CString::new`.
///
/// # Examples
///
/// ```
/// use std::ffi::CString;
///
/// let nul_error = CString::new("foo\0bar").unwrap_err();
/// assert_eq!(nul_error.nul_position(), 3);
///
/// let nul_error = CString::new("foo bar\0").unwrap_err();
/// assert_eq!(nul_error.nul_position(), 7);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn nul_position(&self) -> usize { self.0 }

Expand Down
6 changes: 5 additions & 1 deletion src/libstd/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ mod udp;
mod parser;
#[cfg(test)] mod test;

/// Possible values which can be passed to the `shutdown` method of `TcpStream`.
/// Possible values which can be passed to the [`shutdown`] method of
/// [`TcpStream`].
///
/// [`shutdown`]: struct.TcpStream.html#method.shutdown
/// [`TcpStream`]: struct.TcpStream.html
#[derive(Copy, Clone, PartialEq, Debug)]
#[stable(feature = "rust1", since = "1.0.0")]
pub enum Shutdown {
Expand Down
5 changes: 5 additions & 0 deletions src/libstd/net/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ pub struct TcpListener(net_imp::TcpListener);
///
/// This iterator will infinitely yield `Some` of the accepted connections. It
/// is equivalent to calling `accept` in a loop.
///
/// This `struct` is created by the [`incoming`] method on [`TcpListener`].
///
/// [`incoming`]: struct.TcpListener.html#method.incoming
/// [`TcpListener`]: struct.TcpListener.html
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Incoming<'a> { listener: &'a TcpListener }

Expand Down

0 comments on commit 07f1bac

Please sign in to comment.