Skip to content

Commit 39039ab

Browse files
authored
Auto merge of #35240 - sanxiyn:rollup, r=sanxiyn
Rollup of 7 pull requests - Successful merges: #34319, #35041, #35042, #35175, #35181, #35182, #35189 - Failed merges:
2 parents a0b4e67 + 870b71b commit 39039ab

File tree

8 files changed

+179
-4
lines changed

8 files changed

+179
-4
lines changed

src/doc/book/the-stack-and-the-heap.md

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ The stack is very fast, and is where memory is allocated in Rust by default.
2626
But the allocation is local to a function call, and is limited in size. The
2727
heap, on the other hand, is slower, and is explicitly allocated by your
2828
program. But it’s effectively unlimited in size, and is globally accessible.
29+
Note this meaning of heap, which allocates arbitrary-sized blocks of memory in arbitrary
30+
order, is quite different from the heap data structure.
2931

3032
# The Stack
3133

src/libcollections/range.rs

+32
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,45 @@ pub trait RangeArgument<T> {
2323
/// Start index (inclusive)
2424
///
2525
/// Return start value if present, else `None`.
26+
///
27+
/// # Examples
28+
///
29+
/// ```
30+
/// #![feature(collections)]
31+
/// #![feature(collections_range)]
32+
///
33+
/// extern crate collections;
34+
///
35+
/// # fn main() {
36+
/// use collections::range::RangeArgument;
37+
///
38+
/// assert_eq!((..10).start(), None);
39+
/// assert_eq!((3..10).start(), Some(&3));
40+
/// # }
41+
/// ```
2642
fn start(&self) -> Option<&T> {
2743
None
2844
}
2945

3046
/// End index (exclusive)
3147
///
3248
/// Return end value if present, else `None`.
49+
///
50+
/// # Examples
51+
///
52+
/// ```
53+
/// #![feature(collections)]
54+
/// #![feature(collections_range)]
55+
///
56+
/// extern crate collections;
57+
///
58+
/// # fn main() {
59+
/// use collections::range::RangeArgument;
60+
///
61+
/// assert_eq!((3..).end(), None);
62+
/// assert_eq!((3..10).end(), Some(&10));
63+
/// # }
64+
/// ```
3365
fn end(&self) -> Option<&T> {
3466
None
3567
}

src/libcollections/vec.rs

+19
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,25 @@ impl<T> Vec<T> {
476476
/// Note that this will drop any excess capacity. Calling this and
477477
/// converting back to a vector with `into_vec()` is equivalent to calling
478478
/// `shrink_to_fit()`.
479+
///
480+
/// # Examples
481+
///
482+
/// ```
483+
/// let v = vec![1, 2, 3];
484+
///
485+
/// let slice = v.into_boxed_slice();
486+
/// ```
487+
///
488+
/// Any excess capacity is removed:
489+
///
490+
/// ```
491+
/// let mut vec = Vec::with_capacity(10);
492+
/// vec.extend([1, 2, 3].iter().cloned());
493+
///
494+
/// assert_eq!(vec.capacity(), 10);
495+
/// let slice = vec.into_boxed_slice();
496+
/// assert_eq!(slice.into_vec().capacity(), 3);
497+
/// ```
479498
#[stable(feature = "rust1", since = "1.0.0")]
480499
pub fn into_boxed_slice(mut self) -> Box<[T]> {
481500
unsafe {

src/libcore/marker.rs

+6
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ pub trait Unsize<T: ?Sized> {
144144
/// Generalizing the latter case, any type implementing `Drop` can't be `Copy`, because it's
145145
/// managing some resource besides its own `size_of::<T>()` bytes.
146146
///
147+
/// ## What if I derive `Copy` on a type that can't?
148+
///
149+
/// If you try to derive `Copy` on a struct or enum, you will get a compile-time error.
150+
/// Specifically, with structs you'll get [E0204](https://doc.rust-lang.org/error-index.html#E0204)
151+
/// and with enums you'll get [E0205](https://doc.rust-lang.org/error-index.html#E0205).
152+
///
147153
/// ## When should my type be `Copy`?
148154
///
149155
/// Generally speaking, if your type _can_ implement `Copy`, it should. There's one important thing

src/librustc_typeck/diagnostics.rs

+98-3
Original file line numberDiff line numberDiff line change
@@ -3897,6 +3897,104 @@ impl SpaceLlama for i32 {
38973897
```
38983898
"##,
38993899

3900+
E0527: r##"
3901+
The number of elements in an array or slice pattern differed from the number of
3902+
elements in the array being matched.
3903+
3904+
Example of erroneous code:
3905+
3906+
```compile_fail,E0527
3907+
#![feature(slice_patterns)]
3908+
3909+
let r = &[1, 2, 3, 4];
3910+
match r {
3911+
&[a, b] => { // error: pattern requires 2 elements but array
3912+
// has 4
3913+
println!("a={}, b={}", a, b);
3914+
}
3915+
}
3916+
```
3917+
3918+
Ensure that the pattern is consistent with the size of the matched
3919+
array. Additional elements can be matched with `..`:
3920+
3921+
```
3922+
#![feature(slice_patterns)]
3923+
3924+
let r = &[1, 2, 3, 4];
3925+
match r {
3926+
&[a, b, ..] => { // ok!
3927+
println!("a={}, b={}", a, b);
3928+
}
3929+
}
3930+
```
3931+
"##,
3932+
3933+
E0528: r##"
3934+
An array or slice pattern required more elements than were present in the
3935+
matched array.
3936+
3937+
Example of erroneous code:
3938+
3939+
```compile_fail,E0528
3940+
#![feature(slice_patterns)]
3941+
3942+
let r = &[1, 2];
3943+
match r {
3944+
&[a, b, c, rest..] => { // error: pattern requires at least 3
3945+
// elements but array has 2
3946+
println!("a={}, b={}, c={} rest={:?}", a, b, c, rest);
3947+
}
3948+
}
3949+
```
3950+
3951+
Ensure that the matched array has at least as many elements as the pattern
3952+
requires. You can match an arbitrary number of remaining elements with `..`:
3953+
3954+
```
3955+
#![feature(slice_patterns)]
3956+
3957+
let r = &[1, 2, 3, 4, 5];
3958+
match r {
3959+
&[a, b, c, rest..] => { // ok!
3960+
// prints `a=1, b=2, c=3 rest=[4, 5]`
3961+
println!("a={}, b={}, c={} rest={:?}", a, b, c, rest);
3962+
}
3963+
}
3964+
```
3965+
"##,
3966+
3967+
E0529: r##"
3968+
An array or slice pattern was matched against some other type.
3969+
3970+
Example of erroneous code:
3971+
3972+
```compile_fail,E0529
3973+
#![feature(slice_patterns)]
3974+
3975+
let r: f32 = 1.0;
3976+
match r {
3977+
[a, b] => { // error: expected an array or slice, found `f32`
3978+
println!("a={}, b={}", a, b);
3979+
}
3980+
}
3981+
```
3982+
3983+
Ensure that the pattern and the expression being matched on are of consistent
3984+
types:
3985+
3986+
```
3987+
#![feature(slice_patterns)]
3988+
3989+
let r = [1.0, 2.0];
3990+
match r {
3991+
[a, b] => { // ok!
3992+
println!("a={}, b={}", a, b);
3993+
}
3994+
}
3995+
```
3996+
"##,
3997+
39003998
E0559: r##"
39013999
An unknown field was specified into an enum's structure variant.
39024000
@@ -4018,8 +4116,5 @@ register_diagnostics! {
40184116
E0436, // functional record update requires a struct
40194117
E0513, // no type for local variable ..
40204118
E0521, // redundant default implementations of trait
4021-
E0527, // expected {} elements, found {}
4022-
E0528, // expected at least {} elements, found {}
4023-
E0529, // slice pattern expects array or slice, not `{}`
40244119
E0533, // `{}` does not name a unit variant, unit struct or a constant
40254120
}

src/libstd/ffi/c_str.rs

+12
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,18 @@ impl Borrow<CStr> for CString {
356356
impl NulError {
357357
/// Returns the position of the nul byte in the slice that was provided to
358358
/// `CString::new`.
359+
///
360+
/// # Examples
361+
///
362+
/// ```
363+
/// use std::ffi::CString;
364+
///
365+
/// let nul_error = CString::new("foo\0bar").unwrap_err();
366+
/// assert_eq!(nul_error.nul_position(), 3);
367+
///
368+
/// let nul_error = CString::new("foo bar\0").unwrap_err();
369+
/// assert_eq!(nul_error.nul_position(), 7);
370+
/// ```
359371
#[stable(feature = "rust1", since = "1.0.0")]
360372
pub fn nul_position(&self) -> usize { self.0 }
361373

src/libstd/net/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ mod udp;
3535
mod parser;
3636
#[cfg(test)] mod test;
3737

38-
/// Possible values which can be passed to the `shutdown` method of `TcpStream`.
38+
/// Possible values which can be passed to the [`shutdown`] method of
39+
/// [`TcpStream`].
40+
///
41+
/// [`shutdown`]: struct.TcpStream.html#method.shutdown
42+
/// [`TcpStream`]: struct.TcpStream.html
3943
#[derive(Copy, Clone, PartialEq, Debug)]
4044
#[stable(feature = "rust1", since = "1.0.0")]
4145
pub enum Shutdown {

src/libstd/net/tcp.rs

+5
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ pub struct TcpListener(net_imp::TcpListener);
7777
///
7878
/// This iterator will infinitely yield `Some` of the accepted connections. It
7979
/// is equivalent to calling `accept` in a loop.
80+
///
81+
/// This `struct` is created by the [`incoming`] method on [`TcpListener`].
82+
///
83+
/// [`incoming`]: struct.TcpListener.html#method.incoming
84+
/// [`TcpListener`]: struct.TcpListener.html
8085
#[stable(feature = "rust1", since = "1.0.0")]
8186
pub struct Incoming<'a> { listener: &'a TcpListener }
8287

0 commit comments

Comments
 (0)