Skip to content

Commit 637de10

Browse files
committed
Auto merge of #23200 - Manishearth:rollup, r=Manishearth
2 parents b775541 + 9f851a7 commit 637de10

14 files changed

+137
-48
lines changed

src/doc/grammar.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ field_expr : expr '.' ident ;
514514
### Array expressions
515515

516516
```antlr
517-
array_expr : '[' "mut" ? vec_elems? ']' ;
517+
array_expr : '[' "mut" ? array_elems? ']' ;
518518
519519
array_elems : [expr [',' expr]*] | [expr ',' ".." expr] ;
520520
```

src/doc/reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2847,7 +2847,7 @@ automatically dereferenced to make the field access possible.
28472847
### Array expressions
28482848

28492849
```{.ebnf .gram}
2850-
array_expr : '[' "mut" ? vec_elems? ']' ;
2850+
array_expr : '[' "mut" ? array_elems? ']' ;
28512851
28522852
array_elems : [expr [',' expr]*] | [expr ';' expr] ;
28532853
```

src/doc/trpl/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
* [Standard Input](standard-input.md)
1717
* [Guessing Game](guessing-game.md)
1818
* [II: Intermediate Rust](intermediate.md)
19-
* [More Strings](more-strings.md)
2019
* [Crates and Modules](crates-and-modules.md)
2120
* [Testing](testing.md)
2221
* [Pointers](pointers.md)
2322
* [Ownership](ownership.md)
23+
* [More Strings](more-strings.md)
2424
* [Patterns](patterns.md)
2525
* [Method Syntax](method-syntax.md)
2626
* [Closures](closures.md)

src/doc/trpl/concurrency.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -223,15 +223,8 @@ method which has this signature:
223223
fn lock(&self) -> LockResult<MutexGuard<T>>
224224
```
225225

226-
If we [look at the code for MutexGuard](https://github.com/rust-lang/rust/blob/ca4b9674c26c1de07a2042cb68e6a062d7184cef/src/libstd/sync/mutex.rs#L172), we'll see
227-
this:
228-
229-
```ignore
230-
__marker: marker::NoSend,
231-
```
232-
233-
Because our guard is `NoSend`, it's not `Send`. Which means we can't actually
234-
transfer the guard across thread boundaries, which gives us our error.
226+
Because `Send` is not implemented for `MutexGuard<T>`, we can't transfer the
227+
guard across thread boundaries, which gives us our error.
235228

236229
We can use `Arc<T>` to fix this. Here's the working version:
237230

src/doc/trpl/method-syntax.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,28 @@ You can think of this first parameter as being the `x` in `x.foo()`. The three
5050
variants correspond to the three kinds of thing `x` could be: `self` if it's
5151
just a value on the stack, `&self` if it's a reference, and `&mut self` if it's
5252
a mutable reference. We should default to using `&self`, as it's the most
53-
common.
53+
common. Here's an example of all three variants:
54+
55+
```rust
56+
struct Circle {
57+
x: f64,
58+
y: f64,
59+
radius: f64,
60+
}
61+
62+
impl Circle {
63+
fn reference(&self) {
64+
println!("taking self by reference!");
65+
}
66+
67+
fn mutable_reference(&mut self) {
68+
println!("taking self by mutable reference!");
69+
}
70+
71+
fn takes_ownership(self) {
72+
println!("taking ownership of self!");
73+
}
74+
```
5475

5576
Finally, as you may remember, the value of the area of a circle is `π*r²`.
5677
Because we took the `&self` parameter to `area`, we can use it just like any

src/doc/trpl/more-strings.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,18 @@ This will print:
278278

279279
Many more bytes than graphemes!
280280

281-
# Other Documentation
281+
# `Deref` coercions
282282

283-
* [the `&str` API documentation](../std/str/index.html)
284-
* [the `String` API documentation](../std/string/index.html)
283+
References to `String`s will automatically coerce into `&str`s. Like this:
284+
285+
```
286+
fn hello(s: &str) {
287+
println!("Hello, {}!", s);
288+
}
289+
290+
let slice = "Steve";
291+
let string = "Steve".to_string();
292+
293+
hello(slice);
294+
hello(&string);
295+
```

src/doc/trpl/traits.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,3 +435,46 @@ println!("the inverse of {} is {:?}", 2.0f64, inverse(2.0f64));
435435
println!("the inverse of {} is {:?}", 0.0f32, inverse(0.0f32));
436436
println!("the inverse of {} is {:?}", 0.0f64, inverse(0.0f64));
437437
```
438+
439+
## Default methods
440+
441+
There's one last feature of traits we should cover: default methods. It's
442+
easiest just to show an example:
443+
444+
```rust
445+
trait Foo {
446+
fn bar(&self);
447+
448+
fn baz(&self) { println!("We called baz."); }
449+
}
450+
```
451+
452+
Implementors of the `Foo` trait need to implement `bar()`, but they don't
453+
need to implement `baz()`. They'll get this default behavior. They can
454+
override the default if they so choose:
455+
456+
```rust
457+
# trait Foo {
458+
# fn bar(&self);
459+
# fn baz(&self) { println!("We called baz."); }
460+
# }
461+
struct UseDefault;
462+
463+
impl Foo for UseDefault {
464+
fn bar(&self) { println!("We called bar."); }
465+
}
466+
467+
struct OverrideDefault;
468+
469+
impl Foo for OverrideDefault {
470+
fn bar(&self) { println!("We called bar."); }
471+
472+
fn baz(&self) { println!("Override baz!"); }
473+
}
474+
475+
let default = UseDefault;
476+
default.baz(); // prints "We called bar."
477+
478+
let over = OverrideDefault;
479+
over.baz(); // prints "Override baz!"
480+
```

src/libcore/intrinsics.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -545,11 +545,7 @@ extern "rust-intrinsic" {
545545
pub fn u32_mul_with_overflow(x: u32, y: u32) -> (u32, bool);
546546
/// Performs checked `u64` multiplication.
547547
pub fn u64_mul_with_overflow(x: u64, y: u64) -> (u64, bool);
548-
}
549548

550-
// SNAP 880fb89
551-
#[cfg(not(stage0))]
552-
extern "rust-intrinsic" {
553549
/// Returns (a + b) mod 2^N, where N is the width of N in bits.
554550
pub fn overflowing_add<T>(a: T, b: T) -> T;
555551
/// Returns (a - b) mod 2^N, where N is the width of N in bits.

src/libcore/iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ pub trait IteratorExt: Iterator + Sized {
611611
///
612612
/// ```
613613
/// let a = [1, 2, 3, 4, 5];
614-
/// assert!(a.iter().fold(0, |a, &b| a + b) == 15);
614+
/// assert!(a.iter().fold(0, |acc, &item| acc + item) == 15);
615615
/// ```
616616
#[inline]
617617
#[stable(feature = "rust1", since = "1.0.0")]

src/libcore/marker.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,45 @@ pub trait PhantomFn<A:?Sized,R:?Sized=()> { }
351351
/// instance, it will behave *as if* an instance of the type `T` were
352352
/// present for the purpose of various automatic analyses.
353353
///
354-
/// For example, embedding a `PhantomData<T>` will inform the compiler
354+
/// # Examples
355+
///
356+
/// When handling external resources over a foreign function interface, `PhantomData<T>` can
357+
/// prevent mismatches by enforcing types in the method implementations, although the struct
358+
/// doesn't actually contain values of the resource type.
359+
///
360+
/// ```
361+
/// # trait ResType { fn foo(&self); };
362+
/// # struct ParamType;
363+
/// # mod foreign_lib {
364+
/// # pub fn new(_: usize) -> *mut () { 42 as *mut () }
365+
/// # pub fn do_stuff(_: *mut (), _: usize) {}
366+
/// # }
367+
/// # fn convert_params(_: ParamType) -> usize { 42 }
368+
/// use std::marker::PhantomData;
369+
/// use std::mem;
370+
///
371+
/// struct ExternalResource<R> {
372+
/// resource_handle: *mut (),
373+
/// resource_type: PhantomData<R>,
374+
/// }
375+
///
376+
/// impl<R: ResType> ExternalResource<R> {
377+
/// fn new() -> ExternalResource<R> {
378+
/// let size_of_res = mem::size_of::<R>();
379+
/// ExternalResource {
380+
/// resource_handle: foreign_lib::new(size_of_res),
381+
/// resource_type: PhantomData,
382+
/// }
383+
/// }
384+
///
385+
/// fn do_stuff(&self, param: ParamType) {
386+
/// let foreign_params = convert_params(param);
387+
/// foreign_lib::do_stuff(self.resource_handle, foreign_params);
388+
/// }
389+
/// }
390+
/// ```
391+
///
392+
/// Another example: embedding a `PhantomData<T>` will inform the compiler
355393
/// that one or more instances of the type `T` could be dropped when
356394
/// instances of the type itself is dropped, though that may not be
357395
/// apparent from the other structure of the type itself. This is

src/libcore/num/wrapping.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
use ops::*;
1313

14-
#[cfg(not(stage0))]
1514
use intrinsics::{overflowing_add, overflowing_sub, overflowing_mul};
1615

1716
use intrinsics::{i8_add_with_overflow, u8_add_with_overflow};
@@ -40,7 +39,6 @@ pub trait OverflowingOps {
4039
fn overflowing_mul(self, rhs: Self) -> (Self, bool);
4140
}
4241

43-
#[cfg(not(stage0))]
4442
macro_rules! wrapping_impl {
4543
($($t:ty)*) => ($(
4644
impl WrappingOps for $t {
@@ -66,26 +64,6 @@ macro_rules! wrapping_impl {
6664
)*)
6765
}
6866

69-
#[cfg(stage0)]
70-
macro_rules! wrapping_impl {
71-
($($t:ty)*) => ($(
72-
impl WrappingOps for $t {
73-
#[inline(always)]
74-
fn wrapping_add(self, rhs: $t) -> $t {
75-
self + rhs
76-
}
77-
#[inline(always)]
78-
fn wrapping_sub(self, rhs: $t) -> $t {
79-
self - rhs
80-
}
81-
#[inline(always)]
82-
fn wrapping_mul(self, rhs: $t) -> $t {
83-
self * rhs
84-
}
85-
}
86-
)*)
87-
}
88-
8967
wrapping_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 }
9068

9169
#[unstable(feature = "core", reason = "may be removed, renamed, or relocated")]

src/libstd/process.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ impl Command {
264264
/// By default, stdin, stdout and stderr are captured (and used to
265265
/// provide the resulting output).
266266
///
267-
/// # Example
267+
/// # Examples
268268
///
269269
/// ```
270270
/// # #![feature(process)]
@@ -275,8 +275,8 @@ impl Command {
275275
/// });
276276
///
277277
/// println!("status: {}", output.status);
278-
/// println!("stdout: {}", String::from_utf8_lossy(output.stdout.as_slice()));
279-
/// println!("stderr: {}", String::from_utf8_lossy(output.stderr.as_slice()));
278+
/// println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
279+
/// println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
280280
/// ```
281281
#[stable(feature = "process", since = "1.0.0")]
282282
pub fn output(&mut self) -> io::Result<Output> {

src/libsyntax/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1264,7 +1264,7 @@ pub struct BareFnTy {
12641264
/// The different kinds of types recognized by the compiler
12651265
pub enum Ty_ {
12661266
TyVec(P<Ty>),
1267-
/// A fixed length array (`[T, ..n]`)
1267+
/// A fixed length array (`[T; n]`)
12681268
TyFixedLengthVec(P<Ty>, P<Expr>),
12691269
/// A raw pointer (`*const T` or `*mut T`)
12701270
TyPtr(MutTy),

src/snapshots.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
S 2015-03-07 270a677
2+
freebsd-x86_64 3c147d8e4cfdcb02c2569f5aca689a1d8920d17b
3+
linux-i386 50a47ef247610fb089d2c4f24e4b641eb0ba4afb
4+
linux-x86_64 ccb20709b3c984f960ddde996451be8ce2268d7c
5+
macos-i386 ad263bdeadcf9bf1889426e0c1391a7cf277364e
6+
macos-x86_64 01c8275828042264206b7acd8e86dc719a2f27aa
7+
winnt-i386 cb73ac7a9bf408e8b5cdb92d595082a537a90794
8+
winnt-x86_64 b9b47e80101f726ae4f5919373ea20b92d827f3c
9+
110
S 2015-02-25 880fb89
211
bitrig-x86_64 8cdc4ca0a80103100f46cbf8caa9fe497df048c5
312
freebsd-x86_64 f4cbe4227739de986444211f8ee8d74745ab8f7f

0 commit comments

Comments
 (0)