Skip to content

Commit 1b31c93

Browse files
committed
---
yaml --- r: 190422 b: refs/heads/snap-stage3 c: 777f5d9 h: refs/heads/master v: v3
1 parent 31c2f25 commit 1b31c93

File tree

16 files changed

+141
-51
lines changed

16 files changed

+141
-51
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 857ac28867722111249b5c3ef68e32499bd11ea0
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 646830076a289d6040ba8e29518266d34ef1c5dd
4+
refs/heads/snap-stage3: 777f5d959930711acc321a50c493b984b780f156
55
refs/heads/try: 1c28ab65017d74fc13d003f7c7a73d1a48e5406f
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d

branches/snap-stage3/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
```

branches/snap-stage3/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
```

branches/snap-stage3/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)

branches/snap-stage3/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

branches/snap-stage3/src/doc/trpl/method-syntax.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,29 @@ 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+
}
75+
```
5476

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

branches/snap-stage3/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+
```

branches/snap-stage3/src/doc/trpl/pointers.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,8 +634,8 @@ use-case for boxes.
634634
### Returning data
635635

636636
This is important enough to have its own section entirely. The TL;DR is this:
637-
you don't generally want to return pointers, even when you might in a language
638-
like C or C++.
637+
you don't want to return pointers, even when you might in a language like C or
638+
C++.
639639

640640
See [Returning Pointers](#returning-pointers) below for more.
641641

branches/snap-stage3/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+
```

branches/snap-stage3/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.

branches/snap-stage3/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")]

branches/snap-stage3/src/libcore/marker.rs

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

branches/snap-stage3/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")]

branches/snap-stage3/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> {

branches/snap-stage3/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),

branches/snap-stage3/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)