Skip to content

Commit 645dd3b

Browse files
committed
---
yaml --- r: 97958 b: refs/heads/master c: ebc079c h: refs/heads/master v: v3
1 parent 0491f70 commit 645dd3b

File tree

187 files changed

+2831
-1449
lines changed

Some content is hidden

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

187 files changed

+2831
-1449
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: 1812a7b540e929bb1688880541fb4c8e3b80bf6d
2+
refs/heads/master: ebc079c787aead54b23c81cfc1d7522fe513b1b5
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: b6400f998497c3958f40997a71756ead344a776d
55
refs/heads/try: c274a6888410ce3e357e014568b43310ed787d36

trunk/COPYRIGHT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ terms.
66

77
Longer version:
88

9-
The Rust Project is copyright 2013, The Rust Project
9+
The Rust Project is copyright 2014, The Rust Project
1010
Developers (given in the file AUTHORS.txt).
1111

1212
Licensed under the Apache License, Version 2.0

trunk/LICENSE-MIT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Copyright (c) 2006-2009 Graydon Hoare
2-
Copyright (c) 2009-2013 Mozilla Foundation
2+
Copyright (c) 2009-2014 Mozilla Foundation
33

44
Permission is hereby granted, free of charge, to any
55
person obtaining a copy of this software and associated

trunk/Makefile.in

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,12 +410,14 @@ export CFG_SRC_DIR
410410
export CFG_BUILD_DIR
411411
export CFG_VERSION
412412
export CFG_VERSION_WIN
413+
export CFG_RELEASE
413414
export CFG_BUILD
414415
export CFG_LLVM_ROOT
415416
export CFG_ENABLE_MINGW_CROSS
416417
export CFG_PREFIX
417418
export CFG_LIBDIR
418419
export CFG_RUSTLIBDIR
420+
export LIBDIR_RELATIVE
419421

420422
######################################################################
421423
# Subprograms
@@ -433,12 +435,12 @@ define SREQ
433435
# Destinations of artifacts for the host compiler
434436
HROOT$(1)_H_$(3) = $(3)/stage$(1)
435437
HBIN$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/bin
436-
HLIB$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/$$(CFG_LIBDIR)
438+
HLIB$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/$$(LIBDIR_RELATIVE)
437439

438440
# Destinations of artifacts for target architectures
439441
TROOT$(1)_T_$(2)_H_$(3) = $$(HLIB$(1)_H_$(3))/$$(CFG_RUSTLIBDIR)/$(2)
440442
TBIN$(1)_T_$(2)_H_$(3) = $$(TROOT$(1)_T_$(2)_H_$(3))/bin
441-
TLIB$(1)_T_$(2)_H_$(3) = $$(TROOT$(1)_T_$(2)_H_$(3))/$$(CFG_LIBDIR)
443+
TLIB$(1)_T_$(2)_H_$(3) = $$(TROOT$(1)_T_$(2)_H_$(3))/lib
442444

443445
# The name of the standard and extra libraries used by rustc
444446
HSTDLIB_DEFAULT$(1)_H_$(3) = \

trunk/configure

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,17 @@ valopt sysconfdir "/etc" "install system configuration files"
397397
valopt datadir "${CFG_PREFIX}/share" "install data"
398398
valopt infodir "${CFG_PREFIX}/share/info" "install additional info"
399399
valopt mandir "${CFG_PREFIX}/share/man" "install man pages in PATH"
400-
valopt libdir "${CFG_PREFIX}/lib" "install libraries"
400+
401+
# On windows we just store the libraries in the bin directory because
402+
# there's no rpath
403+
# FIXME: Thise needs to parameterized over target triples. Do it in platform.mk
404+
LIBDIR_RELATIVE=lib
405+
if [ "$CFG_OSTYPE" = "pc-mingw32" ]
406+
then
407+
LIBDIR_RELATIVE=bin
408+
fi
409+
410+
valopt libdir "${CFG_PREFIX}/${LIBDIR_RELATIVE}" "install libraries"
401411
valopt rustlibdir "rustlib" "subdirectory name for rustc's libraries"
402412

403413
# Validate Options
@@ -560,10 +570,10 @@ then
560570
step_msg "on OS X 10.9, forcing use of clang"
561571
CFG_ENABLE_CLANG=1
562572
putvar CFG_ENABLE_CLANG
563-
else
564-
# on OS X, with xcode 5 and newer, certain developers may have
573+
else
574+
# on OS X, with xcode 5 and newer, certain developers may have
565575
# cc, gcc and g++ point to a mixture of clang and gcc
566-
# if so, this will create very strange build errors
576+
# if so, this will create very strange build errors
567577
# this last stanza is to detect some such problems and save the future rust
568578
# contributor some time solving that issue.
569579
# this detection could be generalized to other OSes aside from OS X
@@ -576,8 +586,8 @@ then
576586
# note that for xcode 5, g++ points to clang, not clang++
577587
if !((chk_cc gcc clang && chk_cc g++ clang) ||
578588
(chk_cc gcc gcc &&( chk_cc g++ g++ || chk g++ gcc))) then
579-
err "the gcc and g++ in your path point to different compilers.
580-
Check which versions are in your path with cc --version and g++ --version.
589+
err "the gcc and g++ in your path point to different compilers.
590+
Check which versions are in your path with cc --version and g++ --version.
581591
To resolve this problem, either fix your PATH or run configure with --enable-clang"
582592
fi
583593

@@ -751,15 +761,6 @@ do
751761
done
752762
done
753763

754-
# On windows we just store the libraries in the bin directory because
755-
# there's no rpath
756-
# FIXME: Thise needs to parameterized over target triples. Do it in platform.mk
757-
CFG_LIBDIR=lib
758-
if [ "$CFG_OSTYPE" = "pc-mingw32" ]
759-
then
760-
CFG_LIBDIR=bin
761-
fi
762-
763764
for h in $CFG_HOST
764765
do
765766
for t in $CFG_TARGET
@@ -770,21 +771,21 @@ do
770771
make_dir $h/stage$i/bin
771772

772773
# host lib dir
773-
make_dir $h/stage$i/$CFG_LIBDIR
774+
make_dir $h/stage$i/$LIBDIR_RELATIVE
774775

775776
# host test dir
776777
make_dir $h/stage$i/test
777778

778779
# target bin dir
779-
make_dir $h/stage$i/$CFG_LIBDIR/$CFG_RUSTLIBDIR/$t/bin
780+
make_dir $h/stage$i/$LIBDIR_RELATIVE/$CFG_RUSTLIBDIR/$t/bin
780781

781782
# target lib dir
782-
make_dir $h/stage$i/$CFG_LIBDIR/$CFG_RUSTLIBDIR/$t/$CFG_LIBDIR
783+
make_dir $h/stage$i/$LIBDIR_RELATIVE/$CFG_RUSTLIBDIR/$t/lib
783784
done
784785

785786
# Fix stage0:
786-
make_dir $h/stage0/$CFG_LIBDIR/rustc/$t/bin
787-
make_dir $h/stage0/$CFG_LIBDIR/rustc/$t/$CFG_LIBDIR
787+
make_dir $h/stage0/$LIBDIR_RELATIVE/rustc/$t/bin
788+
make_dir $h/stage0/$LIBDIR_RELATIVE/rustc/$t/$LIBDIR_RELATIVE
788789

789790
done
790791

@@ -800,10 +801,12 @@ do
800801
make_dir $h/test/doc-tutorial
801802
make_dir $h/test/doc-guide-ffi
802803
make_dir $h/test/doc-guide-macros
803-
make_dir $h/test/doc-guide-borrowed-ptr
804+
make_dir $h/test/doc-guide-lifetimes
805+
make_dir $h/test/doc-guide-pointers
804806
make_dir $h/test/doc-guide-container
805807
make_dir $h/test/doc-guide-tasks
806808
make_dir $h/test/doc-guide-conditions
809+
make_dir $h/test/doc-complement-cheatsheet
807810
make_dir $h/test/doc-rust
808811
done
809812

@@ -1038,6 +1041,7 @@ putvar CFG_TARGET
10381041
putvar CFG_C_COMPILER
10391042
putvar CFG_LIBDIR
10401043
putvar CFG_RUSTLIBDIR
1044+
putvar LIBDIR_RELATIVE
10411045
putvar CFG_DISABLE_MANAGE_SUBMODULES
10421046
putvar CFG_ANDROID_CROSS_PATH
10431047
putvar CFG_MINGW32_CROSS_PATH

trunk/doc/complement-cheatsheet.md

Lines changed: 49 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,113 +6,116 @@
66

77
Use [`ToStr`](http://static.rust-lang.org/doc/master/std/to_str/trait.ToStr.html).
88

9-
```rust
9+
~~~
1010
let x: int = 42;
1111
let y: ~str = x.to_str();
12-
```
12+
~~~
1313

1414
**String to int**
1515

1616
Use [`FromStr`](http://static.rust-lang.org/doc/master/std/from_str/trait.FromStr.html), and its helper function, [`from_str`](http://static.rust-lang.org/doc/master/std/from_str/fn.from_str.html).
1717

18-
```rust
18+
~~~
1919
let x: Option<int> = from_str("42");
2020
let y: int = x.unwrap();
21-
```
21+
~~~
2222

2323
**Int to string, in non-base-10**
2424

2525
Use [`ToStrRadix`](http://static.rust-lang.org/doc/master/std/num/trait.ToStrRadix.html).
2626

27-
```rust
27+
~~~
2828
use std::num::ToStrRadix;
2929
3030
let x: int = 42;
3131
let y: ~str = x.to_str_radix(16);
32-
```
32+
~~~
3333

3434
**String to int, in non-base-10**
3535

3636
Use [`FromStrRadix`](http://static.rust-lang.org/doc/master/std/num/trait.FromStrRadix.html), and its helper function, [`from_str_radix`](http://static.rust-lang.org/doc/master/std/num/fn.from_str_radix.html).
3737

38-
```rust
38+
~~~
3939
use std::num::from_str_radix;
4040
41-
let x: Option<int> = from_str_radix("deadbeef", 16);
42-
let y: int = x.unwrap();
43-
```
41+
let x: Option<i64> = from_str_radix("deadbeef", 16);
42+
let y: i64 = x.unwrap();
43+
~~~
4444

4545
# File operations
4646

4747
## How do I read from a file?
4848

4949
Use [`File::open`](http://static.rust-lang.org/doc/master/std/io/fs/struct.File.html#method.open) to create a [`File`](http://static.rust-lang.org/doc/master/std/io/fs/struct.File.html) struct, which implements the [`Reader`](http://static.rust-lang.org/doc/master/std/io/trait.Reader.html) trait.
5050

51-
```rust
51+
~~~ {.xfail-test}
5252
use std::path::Path;
5353
use std::io::fs::File;
5454
5555
let path : Path = Path::new("Doc-FAQ-Cheatsheet.md");
5656
let on_error = || fail!("open of {:?} failed", path);
5757
let reader : File = File::open(&path).unwrap_or_else(on_error);
58-
```
58+
~~~
5959

6060
## How do I iterate over the lines in a file?
6161

6262
Use the [`lines`](http://static.rust-lang.org/doc/master/std/io/trait.Buffer.html#method.lines) method on a [`BufferedReader`](http://static.rust-lang.org/doc/master/std/io/buffered/struct.BufferedReader.html).
6363

64-
```rust
64+
~~~
6565
use std::io::buffered::BufferedReader;
66+
# use std::io::mem::MemReader;
67+
68+
# let reader = MemReader::new(~[]);
6669
6770
let mut reader = BufferedReader::new(reader);
6871
for line in reader.lines() {
6972
print!("line: {}", line);
7073
}
71-
```
74+
~~~
7275

7376
# String operations
7477

7578
## How do I search for a substring?
7679

7780
Use the [`find_str`](http://static.rust-lang.org/doc/master/std/str/trait.StrSlice.html#tymethod.find_str) method.
7881

79-
```rust
82+
~~~
8083
let str = "Hello, this is some random string";
8184
let index: Option<uint> = str.find_str("rand");
82-
```
85+
~~~
8386

8487
# Containers
8588

8689
## How do I get the length of a vector?
8790

8891
The [`Container`](http://static.rust-lang.org/doc/master/std/container/trait.Container.html) trait provides the `len` method.
8992

90-
```rust
93+
~~~
9194
let u: ~[u32] = ~[0, 1, 2];
9295
let v: &[u32] = &[0, 1, 2, 3];
9396
let w: [u32, .. 5] = [0, 1, 2, 3, 4];
9497
9598
println!("u: {}, v: {}, w: {}", u.len(), v.len(), w.len()); // 3, 4, 5
96-
```
99+
~~~
97100

98101
## How do I iterate over a vector?
99102

100103
Use the [`iter`](http://static.rust-lang.org/doc/master/std/vec/trait.ImmutableVector.html#tymethod.iter) method.
101104

102-
```rust
105+
~~~
103106
let values: ~[int] = ~[1, 2, 3, 4, 5];
104107
for value in values.iter() { // value: &int
105108
println!("{}", *value);
106109
}
107-
```
110+
~~~
108111

109112
(See also [`mut_iter`](http://static.rust-lang.org/doc/master/std/vec/trait.MutableVector.html#tymethod.mut_iter) which yields `&mut int` and [`move_iter`](http://static.rust-lang.org/doc/master/std/vec/trait.OwnedVector.html#tymethod.move_iter) which yields `int` while consuming the `values` vector.)
110113

111114
# Type system
112115

113116
## How do I store a function in a struct?
114117

115-
```rust
118+
~~~
116119
struct Foo {
117120
myfunc: fn(int, uint) -> i32
118121
}
@@ -131,24 +134,27 @@ fn main() {
131134
println!("{}", (f.myfunc)(1, 2));
132135
println!("{}", (g.myfunc)(3, 4));
133136
}
134-
```
137+
~~~
135138

136139
Note that the parenthesis surrounding `f.myfunc` are necessary: they are how Rust disambiguates field lookup and method call. The `'a` on `FooClosure` is the lifetime of the closure's environment pointer.
137140

138141
## How do I express phantom types?
139142

140143
[Phantom types](http://www.haskell.org/haskellwiki/Phantom_type) are those that cannot be constructed at compile time. To express these in Rust, zero-variant `enum`s can be used:
141144

142-
```rust
145+
~~~
143146
enum Open {}
144147
enum Closed {}
145-
```
148+
~~~
146149

147150
Phantom types are useful for enforcing state at compile time. For example:
148151

149-
```rust
152+
~~~
150153
struct Door<State>(~str);
151154
155+
struct Open;
156+
struct Closed;
157+
152158
fn close(Door(name): Door<Open>) -> Door<Closed> {
153159
Door::<Closed>(name)
154160
}
@@ -157,40 +163,45 @@ fn open(Door(name): Door<Closed>) -> Door<Open> {
157163
Door::<Open>(name)
158164
}
159165
160-
let _ = close(Door::<Open>(~"front")); // ok
166+
let _ = close(Door::<Open>(~"front"));
167+
~~~
168+
169+
Attempting to close a closed door is prevented statically:
170+
171+
~~~ {.xfail-test}
161172
let _ = close(Door::<Closed>(~"front")); // error: mismatched types: expected `main::Door<main::Open>` but found `main::Door<main::Closed>`
162-
```
173+
~~~
163174

164175
# FFI (Foreign Function Interface)
165176

166177
## C function signature conversions
167178

168-
Description | C signature | Equivalent Rust signature
169-
----------------------|----------------------------------------------|------------------------------------------
170-
no parameters | `void foo(void);` | `fn foo();`
171-
return value | `int foo(void);` | `fn foo() -> c_int;`
172-
function parameters | `void foo(int x, int y);` | `fn foo(x: int, y: int);`
173-
in-out pointers | `void foo(const int* in_ptr, int* out_ptr);` | `fn foo(in_ptr: *c_int, out_ptr: *mut c_int);`
179+
Description C signature Equivalent Rust signature
180+
---------------------- ---------------------------------------------- ------------------------------------------
181+
no parameters `void foo(void);` `fn foo();`
182+
return value `int foo(void);` `fn foo() -> c_int;`
183+
function parameters `void foo(int x, int y);` `fn foo(x: int, y: int);`
184+
in-out pointers `void foo(const int* in_ptr, int* out_ptr);` `fn foo(in_ptr: *c_int, out_ptr: *mut c_int);`
174185

175186
Note: The Rust signatures should be wrapped in an `extern "ABI" { ... }` block.
176187

177188
### Representing opaque handles
178189

179190
You might see things like this in C APIs:
180191

181-
```c
192+
~~~ {.notrust}
182193
typedef struct Window Window;
183194
Window* createWindow(int width, int height);
184-
```
195+
~~~
185196

186197
You can use a zero-element `enum` ([phantom type](#how-do-i-express-phantom-types)) to represent the opaque object handle. The FFI would look like this:
187198

188-
```rust
199+
~~~ {.xfail-test}
189200
enum Window {}
190201
extern "C" {
191202
fn createWindow(width: c_int, height: c_int) -> *Window;
192203
}
193-
```
204+
~~~
194205

195206
Using a phantom type ensures that the handles cannot be (safely) constructed in client code.
196207

@@ -200,4 +211,4 @@ For small examples, have full type annotations, as much as is reasonable, to kee
200211

201212
Similar documents for other programming languages:
202213

203-
* [http://pleac.sourceforge.net/](http://pleac.sourceforge.net)
214+
* [http://pleac.sourceforge.net/](http://pleac.sourceforge.net)

0 commit comments

Comments
 (0)