Skip to content

Commit 3cb1304

Browse files
committed
---
yaml --- r: 97902 b: refs/heads/master c: 983f307 h: refs/heads/master v: v3
1 parent 714dca7 commit 3cb1304

File tree

131 files changed

+3350
-1984
lines changed

Some content is hidden

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

131 files changed

+3350
-1984
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: 6b2a6cb3fe241d6e27fc685a72dd05c3a55d1ea8
2+
refs/heads/master: 983f307e123f1da3d351ed2032163bf93ea8f638
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: b6400f998497c3958f40997a71756ead344a776d
55
refs/heads/try: c274a6888410ce3e357e014568b43310ed787d36

trunk/AUTHORS.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ Lindsey Kuper <[email protected]>
225225
Luca Bruno <[email protected]>
226226
Luis de Bethencourt <[email protected]>
227227
Luqman Aden <[email protected]>
228+
228229
Magnus Auvinen <[email protected]>
229230
Mahmut Bulut <[email protected]>
230231
maikklein <[email protected]>
@@ -240,6 +241,7 @@ Martin DeMello <[email protected]>
240241
Marvin Löbel <[email protected]>
241242
Matt Brubeck <[email protected]>
242243
Matt Carberry <[email protected]>
244+
Matthew Auld <[email protected]>
243245
Matthew Iselin <[email protected]>
244246
Matthew McPherrin <[email protected]>
245247
Matthew O'Connor <[email protected]>

trunk/Makefile.in

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
# stageN - this is the system root, corresponding to, e.g. /usr
3434
# bin - binaries compiled for the host
3535
# lib - libraries used by the host compiler
36-
# rustc - rustc's own place to organize libraries
36+
# rustlib - rustc's own place to organize libraries
3737
# $(target) - target-specific artifacts
3838
# bin - binaries for target architectures
3939
# lib - libraries for target architectures
@@ -415,6 +415,7 @@ export CFG_LLVM_ROOT
415415
export CFG_ENABLE_MINGW_CROSS
416416
export CFG_PREFIX
417417
export CFG_LIBDIR
418+
export CFG_RUSTLIBDIR
418419

419420
######################################################################
420421
# Subprograms
@@ -435,7 +436,7 @@ HBIN$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/bin
435436
HLIB$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/$$(CFG_LIBDIR)
436437

437438
# Destinations of artifacts for target architectures
438-
TROOT$(1)_T_$(2)_H_$(3) = $$(HLIB$(1)_H_$(3))/rustc/$(2)
439+
TROOT$(1)_T_$(2)_H_$(3) = $$(HLIB$(1)_H_$(3))/$$(CFG_RUSTLIBDIR)/$(2)
439440
TBIN$(1)_T_$(2)_H_$(3) = $$(TROOT$(1)_T_$(2)_H_$(3))/bin
440441
TLIB$(1)_T_$(2)_H_$(3) = $$(TROOT$(1)_T_$(2)_H_$(3))/$$(CFG_LIBDIR)
441442

trunk/RELEASES.txt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Version 0.9 (January 2014)
22
--------------------------
33

4-
* ~1600 changes, numerous bugfixes
4+
* ~1800 changes, numerous bugfixes
55

66
* Language
77
* The `float` type has been removed. Use `f32` or `f64` instead.
@@ -22,6 +22,9 @@ Version 0.9 (January 2014)
2222
* `@fn`s have been removed.
2323
* `do` only works with procs in order to make it obvious what the cost
2424
of `do` is.
25+
* Single-element tuple-like structs can no longer be dereferenced to
26+
obtain the inner value. A more comprehensive solution for overloading
27+
the dereference operator will be provided in the future.
2528
* The `#[link(...)]` attribute has been replaced with
2629
`#[crate_id = "name#vers"]`.
2730
* Empty `impl`s must be terminated with empty braces and may not be
@@ -32,6 +35,8 @@ Version 0.9 (January 2014)
3235
* `printf!` and `printfln!` (old-style formatting) removed in favor of
3336
`print!` and `println!`.
3437
* `mut` works in patterns now, as in `let (mut x, y) = (1, 2);`.
38+
* The `extern mod foo (name = "bar")` syntax has been removed. Use
39+
`extern mod foo = "bar"` instead.
3540
* New reserved keywords: `alignof`, `offsetof`, `sizeof`.
3641
* Macros can have attributes.
3742
* Macros can expand to items with attributes.
@@ -76,6 +81,7 @@ Version 0.9 (January 2014)
7681
variables. Currently behind the `thread_local` feature gate.
7782
* The `return` keyword may be used in closures.
7883
* Types that can be copied via a memcpy implement the `Pod` kind.
84+
* The `cfg` attribute can now be used on struct fields and enum variants.
7985

8086
* Libraries
8187
* std: The `option` and `result` API's have been overhauled to make them
@@ -90,9 +96,14 @@ Version 0.9 (January 2014)
9096
* std: The reference counted pointer type `extra::rc` moved into std.
9197
* std: The `Gc` type in the `gc` module will replace `@` (it is currently
9298
just a wrapper around it).
99+
* std: The `Either` type has been removed.
93100
* std: `fmt::Default` can be implemented for any type to provide default
94101
formatting to the `format!` macro, as in `format!("{}", myfoo)`.
95102
* std: The `rand` API continues to be tweaked.
103+
* std: The `rust_begin_unwind` function, useful for insterting breakpoints
104+
on failure in gdb, is now named `rust_fail`.
105+
* std: The `each_key` and `each_value` methods on `HashMap` have been
106+
replaced by the `keys` and `values` iterators.
96107
* std: Functions dealing with type size and alignment have moved from the
97108
`sys` module to the `mem` module.
98109
* std: The `path` module was written and API changed.

trunk/configure

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ 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"
400400
valopt libdir "${CFG_PREFIX}/lib" "install libraries"
401+
valopt rustlibdir "rustlib" "subdirectory name for rustc's libraries"
401402

402403
# Validate Options
403404
step_msg "validating $CFG_SELF args"
@@ -775,11 +776,16 @@ do
775776
make_dir $h/stage$i/test
776777

777778
# target bin dir
778-
make_dir $h/stage$i/$CFG_LIBDIR/rustc/$t/bin
779+
make_dir $h/stage$i/$CFG_LIBDIR/$CFG_RUSTLIBDIR/$t/bin
779780

780781
# target lib dir
781-
make_dir $h/stage$i/$CFG_LIBDIR/rustc/$t/$CFG_LIBDIR
782+
make_dir $h/stage$i/$CFG_LIBDIR/$CFG_RUSTLIBDIR/$t/$CFG_LIBDIR
782783
done
784+
785+
# Fix stage0:
786+
make_dir $h/stage0/$CFG_LIBDIR/rustc/$t/bin
787+
make_dir $h/stage0/$CFG_LIBDIR/rustc/$t/$CFG_LIBDIR
788+
783789
done
784790

785791
make_dir $h/test/run-pass
@@ -1031,6 +1037,7 @@ putvar CFG_HOST
10311037
putvar CFG_TARGET
10321038
putvar CFG_C_COMPILER
10331039
putvar CFG_LIBDIR
1040+
putvar CFG_RUSTLIBDIR
10341041
putvar CFG_DISABLE_MANAGE_SUBMODULES
10351042
putvar CFG_ANDROID_CROSS_PATH
10361043
putvar CFG_MINGW32_CROSS_PATH

trunk/doc/complement-bugreport.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
% HOWTO submit a RUST bug report
2+
3+
# I think I found a bug in the compiler!
4+
5+
If you see this message: ''error: internal compiler error: unexpected failure'',
6+
then you have definitely found a bug in the compiler. It's also possible that
7+
your code is not well-typed, but if you saw this message, it's still a bug in
8+
error reporting.
9+
10+
If you see a message about an LLVM assertion failure, then you have also
11+
definitely found a bug in the compiler. In both of these cases, it's not your
12+
fault and you should report a bug!
13+
14+
If you see a compiler error message that you think is meant for users to see,
15+
but it confuses you, *that's a bug too*. If it wasn't clear to you, then it's
16+
an error message we want to improve, so please report it so that we can try
17+
to make it better.
18+
19+
# I don't want to waste the Rust devs' time! How do I know the bug I found isn't a bug that already exists in the issue tracker?
20+
21+
If you don't have much time, then don't worry about that. Just submit the bug.
22+
If it's a duplicate, somebody will notice that and close it. No one will laugh
23+
at you, we promise (and if someone did, they would be violating the Rust
24+
[code of conduct](https://github.com/mozilla/rust/wiki/Note-development-policy code of conduct)).
25+
26+
If you have more time, it's very helpful if you can type the text of the error
27+
message you got [into the issue tracker search box](https://github.com/mozilla/rust/issues)
28+
to see if there's an existing bug that resembles your problem. If there is,
29+
and it's an open bug, you can comment on that issue and say you ran into it too.
30+
This will encourage devs to fix it. But again, don't let this stop you from
31+
submitting a bug. We'd rather have to do the work of closing duplicates than
32+
miss out on valid bug reports.
33+
34+
# What information should I include in a bug report?
35+
36+
It's helpful to include your specific OS (for example: Mac OS X 10.8.3,
37+
Windows 7, Ubuntu 12.0.4) and your hardware architecture (for example: i686, x86_64).
38+
It's also helpful to copy/paste the output of re-running the erroneous rustc
39+
commmand with the `-v` flag. Finally, if you can run the offending command under gdb,
40+
pasting a stack trace can be useful; to do so, you will need to set a breakpoint on `rust_begin_unwind`.
41+
42+
# I submitted a bug, but nobody has commented on it! I'm sad.
43+
44+
This is sad, but does happen sometimes, since we're short-staffed. If you
45+
submit a bug and you haven't received a comment on it within 3 business days,
46+
it's entirely reasonable to either ask on the #rust IRC channel,
47+
or post on the [rust-dev mailing list](https://mail.mozilla.org/listinfo/rust-dev)
48+
to ask what the status of the bug is.

trunk/doc/complement-cheatsheet.md

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
% Rust Cheatsheet
2+
3+
# How do I convert *X* to *Y*?
4+
5+
**Int to string**
6+
7+
Use [`ToStr`](http://static.rust-lang.org/doc/master/std/to_str/trait.ToStr.html).
8+
9+
```rust
10+
let x: int = 42;
11+
let y: ~str = x.to_str();
12+
```
13+
14+
**String to int**
15+
16+
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).
17+
18+
```rust
19+
let x: Option<int> = from_str("42");
20+
let y: int = x.unwrap();
21+
```
22+
23+
**Int to string, in non-base-10**
24+
25+
Use [`ToStrRadix`](http://static.rust-lang.org/doc/master/std/num/trait.ToStrRadix.html).
26+
27+
```rust
28+
use std::num::ToStrRadix;
29+
30+
let x: int = 42;
31+
let y: ~str = x.to_str_radix(16);
32+
```
33+
34+
**String to int, in non-base-10**
35+
36+
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).
37+
38+
```rust
39+
use std::num::from_str_radix;
40+
41+
let x: Option<int> = from_str_radix("deadbeef", 16);
42+
let y: int = x.unwrap();
43+
```
44+
45+
# File operations
46+
47+
## How do I read from a file?
48+
49+
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.
50+
51+
```rust
52+
use std::path::Path;
53+
use std::io::fs::File;
54+
55+
let path : Path = Path::new("Doc-FAQ-Cheatsheet.md");
56+
let on_error = || fail!("open of {:?} failed", path);
57+
let reader : File = File::open(&path).unwrap_or_else(on_error);
58+
```
59+
60+
## How do I iterate over the lines in a file?
61+
62+
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).
63+
64+
```rust
65+
use std::io::buffered::BufferedReader;
66+
67+
let mut reader = BufferedReader::new(reader);
68+
for line in reader.lines() {
69+
print!("line: {}", line);
70+
}
71+
```
72+
73+
# String operations
74+
75+
## How do I search for a substring?
76+
77+
Use the [`find_str`](http://static.rust-lang.org/doc/master/std/str/trait.StrSlice.html#tymethod.find_str) method.
78+
79+
```rust
80+
let str = "Hello, this is some random string";
81+
let index: Option<uint> = str.find_str("rand");
82+
```
83+
84+
# Containers
85+
86+
## How do I get the length of a vector?
87+
88+
The [`Container`](http://static.rust-lang.org/doc/master/std/container/trait.Container.html) trait provides the `len` method.
89+
90+
```rust
91+
let u: ~[u32] = ~[0, 1, 2];
92+
let v: &[u32] = &[0, 1, 2, 3];
93+
let w: [u32, .. 5] = [0, 1, 2, 3, 4];
94+
95+
println!("u: {}, v: {}, w: {}", u.len(), v.len(), w.len()); // 3, 4, 5
96+
```
97+
98+
## How do I iterate over a vector?
99+
100+
Use the [`iter`](http://static.rust-lang.org/doc/master/std/vec/trait.ImmutableVector.html#tymethod.iter) method.
101+
102+
```rust
103+
let values: ~[int] = ~[1, 2, 3, 4, 5];
104+
for value in values.iter() { // value: &int
105+
println!("{}", *value);
106+
}
107+
```
108+
109+
(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.)
110+
111+
# Type system
112+
113+
## How do I store a function in a struct?
114+
115+
```rust
116+
struct Foo {
117+
myfunc: fn(int, uint) -> i32
118+
}
119+
120+
struct FooClosure<'a> {
121+
myfunc: 'a |int, uint| -> i32
122+
}
123+
124+
fn a(a: int, b: uint) -> i32 {
125+
(a as uint + b) as i32
126+
}
127+
128+
fn main() {
129+
let f = Foo { myfunc: a };
130+
let g = FooClosure { myfunc: |a, b| { (a - b as int) as i32 } };
131+
println!("{}", (f.myfunc)(1, 2));
132+
println!("{}", (g.myfunc)(3, 4));
133+
}
134+
```
135+
136+
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.
137+
138+
## How do I express phantom types?
139+
140+
[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:
141+
142+
```rust
143+
enum Open {}
144+
enum Closed {}
145+
```
146+
147+
Phantom types are useful for enforcing state at compile time. For example:
148+
149+
```rust
150+
struct Door<State>(~str);
151+
152+
fn close(Door(name): Door<Open>) -> Door<Closed> {
153+
Door::<Closed>(name)
154+
}
155+
156+
fn open(Door(name): Door<Closed>) -> Door<Open> {
157+
Door::<Open>(name)
158+
}
159+
160+
let _ = close(Door::<Open>(~"front")); // ok
161+
let _ = close(Door::<Closed>(~"front")); // error: mismatched types: expected `main::Door<main::Open>` but found `main::Door<main::Closed>`
162+
```
163+
164+
# FFI (Foreign Function Interface)
165+
166+
## C function signature conversions
167+
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);`
174+
175+
Note: The Rust signatures should be wrapped in an `extern "ABI" { ... }` block.
176+
177+
### Representing opaque handles
178+
179+
You might see things like this in C APIs:
180+
181+
```c
182+
typedef struct Window Window;
183+
Window* createWindow(int width, int height);
184+
```
185+
186+
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:
187+
188+
```rust
189+
enum Window {}
190+
extern "C" {
191+
fn createWindow(width: c_int, height: c_int) -> *Window;
192+
}
193+
```
194+
195+
Using a phantom type ensures that the handles cannot be (safely) constructed in client code.
196+
197+
# Contributing to this page
198+
199+
For small examples, have full type annotations, as much as is reasonable, to keep it clear what, exactly, everything is doing. Try to link to the API docs, as well.
200+
201+
Similar documents for other programming languages:
202+
203+
* [http://pleac.sourceforge.net/](http://pleac.sourceforge.net)

0 commit comments

Comments
 (0)