Skip to content

Commit ba3f9aa

Browse files
committed
---
yaml --- r: 189367 b: refs/heads/master c: b515b4e h: refs/heads/master i: 189365: b393157 189363: 99820f4 189359: 6384467 v: v3
1 parent c9ec2d8 commit ba3f9aa

File tree

15 files changed

+1041
-393
lines changed

15 files changed

+1041
-393
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: d65064da349f1f7182180549628fb0ee650771b7
2+
refs/heads/master: b515b4e28a47338b4c63e9ef2c393abe58dc9aaf
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 270a677d4d698916f5ad103f0afc3c070b8dbeb4
55
refs/heads/try: 649d35e4d830b27806705dc5352c86ab6d6fd1a1

trunk/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
```

trunk/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
```

trunk/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

trunk/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+
```

trunk/src/doc/trpl/plugins.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ that implements Roman numeral integer literals.
6363

6464
```ignore
6565
#![crate_type="dylib"]
66-
#![feature(plugin_registrar)]
66+
#![feature(plugin_registrar, rustc_private)]
6767
6868
extern crate syntax;
6969
extern crate rustc;
@@ -92,13 +92,13 @@ fn expand_rn(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
9292
}
9393
};
9494
95-
let mut text = &text;
95+
let mut text = &*text;
9696
let mut total = 0;
9797
while !text.is_empty() {
9898
match NUMERALS.iter().find(|&&(rn, _)| text.starts_with(rn)) {
9999
Some(&(rn, val)) => {
100100
total += val;
101-
text = text.slice_from(rn.len());
101+
text = &text[rn.len()..];
102102
}
103103
None => {
104104
cx.span_err(sp, "invalid Roman numeral");
@@ -107,7 +107,7 @@ fn expand_rn(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
107107
}
108108
}
109109
110-
MacEager::expr(cx.expr_usize(sp, total))
110+
MacEager::expr(cx.expr_u32(sp, total))
111111
}
112112
113113
#[plugin_registrar]

trunk/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+
```

trunk/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.

trunk/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")]

trunk/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

trunk/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")]

0 commit comments

Comments
 (0)