Skip to content

Commit 353b80a

Browse files
committed
---
yaml --- r: 205800 b: refs/heads/beta c: fbd3261 h: refs/heads/master v: v3
1 parent 2f10310 commit 353b80a

File tree

238 files changed

+673
-1056
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

238 files changed

+673
-1056
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
2929
refs/heads/automation-fail: 1bf06495443584539b958873e04cc2f864ab10e4
3030
refs/heads/batch: b7fd822592a4fb577552d93010c4a4e14f314346
3131
refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
32-
refs/heads/beta: 77fee7db49ea9795da53c2196bc725242888b876
32+
refs/heads/beta: fbd3261e376ca9bbaf9cb5e50ad9fa71901aeb74
3333
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3434
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
3535
refs/heads/tmp: 579e31929feff51dcaf8d444648eff8de735f91a

branches/beta/src/doc/reference.md

Lines changed: 115 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,8 @@ Use declarations support a number of convenient shortcuts:
973973

974974
An example of `use` declarations:
975975

976-
```rust
976+
```
977+
# #![feature(core)]
977978
use std::option::Option::{Some, None};
978979
use std::collections::hash_map::{self, HashMap};
979980
@@ -1030,17 +1031,16 @@ declarations.
10301031
An example of what will and will not work for `use` items:
10311032

10321033
```
1034+
# #![feature(core)]
10331035
# #![allow(unused_imports)]
1036+
use foo::core::iter; // good: foo is at the root of the crate
10341037
use foo::baz::foobaz; // good: foo is at the root of the crate
10351038
10361039
mod foo {
1040+
extern crate core;
10371041
1038-
mod example {
1039-
pub mod iter {}
1040-
}
1041-
1042-
use foo::example::iter; // good: foo is at crate root
1043-
// use example::iter; // bad: core is not at the crate root
1042+
use foo::core::iter; // good: foo is at crate root
1043+
// use core::iter; // bad: core is not at the crate root
10441044
use self::baz::foobaz; // good: self refers to module 'foo'
10451045
use foo::bar::foobar; // good: foo is at crate root
10461046
@@ -1368,14 +1368,17 @@ a = Animal::Cat;
13681368

13691369
Enumeration constructors can have either named or unnamed fields:
13701370

1371-
```rust
1371+
```
1372+
# #![feature(struct_variant)]
1373+
# fn main() {
13721374
enum Animal {
13731375
Dog (String, f64),
13741376
Cat { name: String, weight: f64 }
13751377
}
13761378
13771379
let mut a: Animal = Animal::Dog("Cocoa".to_string(), 37.2);
13781380
a = Animal::Cat { name: "Spotty".to_string(), weight: 2.7 };
1381+
# }
13791382
```
13801383

13811384
In this example, `Cat` is a _struct-like enum variant_,
@@ -1715,6 +1718,17 @@ Functions within external blocks are declared in the same way as other Rust
17151718
functions, with the exception that they may not have a body and are instead
17161719
terminated by a semicolon.
17171720

1721+
```
1722+
# #![feature(libc)]
1723+
extern crate libc;
1724+
use libc::{c_char, FILE};
1725+
1726+
extern {
1727+
fn fopen(filename: *const c_char, mode: *const c_char) -> *mut FILE;
1728+
}
1729+
# fn main() {}
1730+
```
1731+
17181732
Functions within external blocks may be called by Rust code, just like
17191733
functions defined in Rust. The Rust compiler automatically translates between
17201734
the Rust ABI and the foreign ABI.
@@ -1725,7 +1739,7 @@ By default external blocks assume that the library they are calling uses the
17251739
standard C "cdecl" ABI. Other ABIs may be specified using an `abi` string, as
17261740
shown here:
17271741

1728-
```ignore
1742+
```{.ignore}
17291743
// Interface to the Windows API
17301744
extern "stdcall" { }
17311745
```
@@ -3217,7 +3231,55 @@ expression.
32173231

32183232
In a pattern whose head expression has an `enum` type, a placeholder (`_`)
32193233
stands for a *single* data field, whereas a wildcard `..` stands for *all* the
3220-
fields of a particular variant.
3234+
fields of a particular variant. For example:
3235+
3236+
```
3237+
#![feature(box_patterns)]
3238+
#![feature(box_syntax)]
3239+
enum List<X> { Nil, Cons(X, Box<List<X>>) }
3240+
3241+
fn main() {
3242+
let x: List<i32> = List::Cons(10, box List::Cons(11, box List::Nil));
3243+
3244+
match x {
3245+
List::Cons(_, box List::Nil) => panic!("singleton list"),
3246+
List::Cons(..) => return,
3247+
List::Nil => panic!("empty list")
3248+
}
3249+
}
3250+
```
3251+
3252+
The first pattern matches lists constructed by applying `Cons` to any head
3253+
value, and a tail value of `box Nil`. The second pattern matches _any_ list
3254+
constructed with `Cons`, ignoring the values of its arguments. The difference
3255+
between `_` and `..` is that the pattern `C(_)` is only type-correct if `C` has
3256+
exactly one argument, while the pattern `C(..)` is type-correct for any enum
3257+
variant `C`, regardless of how many arguments `C` has.
3258+
3259+
Used inside an array pattern, `..` stands for any number of elements, when the
3260+
`advanced_slice_patterns` feature gate is turned on. This wildcard can be used
3261+
at most once for a given array, which implies that it cannot be used to
3262+
specifically match elements that are at an unknown distance from both ends of a
3263+
array, like `[.., 42, ..]`. If preceded by a variable name, it will bind the
3264+
corresponding slice to the variable. Example:
3265+
3266+
```
3267+
# #![feature(advanced_slice_patterns, slice_patterns)]
3268+
fn is_symmetric(list: &[u32]) -> bool {
3269+
match list {
3270+
[] | [_] => true,
3271+
[x, inside.., y] if x == y => is_symmetric(inside),
3272+
_ => false
3273+
}
3274+
}
3275+
3276+
fn main() {
3277+
let sym = &[0, 1, 4, 2, 4, 1, 0];
3278+
let not_sym = &[0, 1, 7, 2, 4, 1, 0];
3279+
assert!(is_symmetric(sym));
3280+
assert!(!is_symmetric(not_sym));
3281+
}
3282+
```
32213283

32223284
A `match` behaves differently depending on whether or not the head expression
32233285
is an [lvalue or an rvalue](#lvalues,-rvalues-and-temporaries). If the head
@@ -3236,15 +3298,30 @@ the inside of the match.
32363298
An example of a `match` expression:
32373299

32383300
```
3239-
let x = 1;
3301+
#![feature(box_patterns)]
3302+
#![feature(box_syntax)]
3303+
# fn process_pair(a: i32, b: i32) { }
3304+
# fn process_ten() { }
3305+
3306+
enum List<X> { Nil, Cons(X, Box<List<X>>) }
3307+
3308+
fn main() {
3309+
let x: List<i32> = List::Cons(10, box List::Cons(11, box List::Nil));
32403310
3241-
match x {
3242-
1 => println!("one"),
3243-
2 => println!("two"),
3244-
3 => println!("three"),
3245-
4 => println!("four"),
3246-
5 => println!("five"),
3247-
_ => println!("something else"),
3311+
match x {
3312+
List::Cons(a, box List::Cons(b, _)) => {
3313+
process_pair(a, b);
3314+
}
3315+
List::Cons(10, _) => {
3316+
process_ten();
3317+
}
3318+
List::Nil => {
3319+
return;
3320+
}
3321+
_ => {
3322+
panic!();
3323+
}
3324+
}
32483325
}
32493326
```
32503327

@@ -3257,12 +3334,28 @@ Subpatterns can also be bound to variables by the use of the syntax `variable @
32573334
subpattern`. For example:
32583335

32593336
```
3260-
let x = 1;
3337+
#![feature(box_patterns)]
3338+
#![feature(box_syntax)]
3339+
3340+
enum List { Nil, Cons(u32, Box<List>) }
32613341
3262-
match x {
3263-
e @ 1 ... 5 => println!("got a range element {}", e),
3264-
_ => println!("anything"),
3342+
fn is_sorted(list: &List) -> bool {
3343+
match *list {
3344+
List::Nil | List::Cons(_, box List::Nil) => true,
3345+
List::Cons(x, ref r @ box List::Cons(_, _)) => {
3346+
match *r {
3347+
box List::Cons(y, _) => (x <= y) && is_sorted(&**r),
3348+
_ => panic!()
3349+
}
3350+
}
3351+
}
3352+
}
3353+
3354+
fn main() {
3355+
let a = List::Cons(6, box List::Cons(7, box List::Cons(42, box List::Nil)));
3356+
assert!(is_sorted(&a));
32653357
}
3358+
32663359
```
32673360

32683361
Patterns can also dereference pointers by using the `&`, `&mut` and `box`

branches/beta/src/doc/trpl/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ fn main() {
165165

166166
Rust has [move semantics][move] by default, so if we want to make a copy of some
167167
data, we call the `clone()` method. In this example, `y` is no longer a reference
168-
to the vector stored in `x`, but a copy of its first element, `"hello"`. Now
168+
to the vector stored in `x`, but a copy of its first element, `"Hello"`. Now
169169
that we don’t have a reference, our `push()` works just fine.
170170

171171
[move]: move-semantics.html

branches/beta/src/doc/trpl/SUMMARY.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* [Concurrency](concurrency.md)
1515
* [Error Handling](error-handling.md)
1616
* [FFI](ffi.md)
17+
* [Deref coercions](deref-coercions.md)
1718
* [Syntax and Semantics](syntax-and-semantics.md)
1819
* [Variable Bindings](variable-bindings.md)
1920
* [Functions](functions.md)
@@ -29,15 +30,15 @@
2930
* [Move semantics](move-semantics.md)
3031
* [Enums](enums.md)
3132
* [Match](match.md)
32-
* [Structs](structs.md)
3333
* [Patterns](patterns.md)
34+
* [Structs](structs.md)
3435
* [Method Syntax](method-syntax.md)
36+
* [Drop](drop.md)
3537
* [Vectors](vectors.md)
3638
* [Strings](strings.md)
37-
* [Generics](generics.md)
3839
* [Traits](traits.md)
3940
* [Operators and Overloading](operators-and-overloading.md)
40-
* [Drop](drop.md)
41+
* [Generics](generics.md)
4142
* [if let](if-let.md)
4243
* [Trait Objects](trait-objects.md)
4344
* [Closures](closures.md)
@@ -52,7 +53,6 @@
5253
* [Casting between types](casting-between-types.md)
5354
* [Associated Types](associated-types.md)
5455
* [Unsized Types](unsized-types.md)
55-
* [Deref coercions](deref-coercions.md)
5656
* [Macros](macros.md)
5757
* [`unsafe` Code](unsafe-code.md)
5858
* [Nightly Rust](nightly-rust.md)

0 commit comments

Comments
 (0)