Skip to content

Commit 669ecd7

Browse files
committed
---
yaml --- r: 187893 b: refs/heads/tmp c: 8519e78 h: refs/heads/master i: 187891: 790db5e v: v3
1 parent acf3b36 commit 669ecd7

File tree

317 files changed

+8584
-6497
lines changed

Some content is hidden

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

317 files changed

+8584
-6497
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
3434
refs/heads/beta: 522d09dfecbeca1595f25ac58c6d0178bbd21d7d
3535
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3636
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
37-
refs/heads/tmp: ff678ea3f4f0e0ec2fd552db57d57889470ee7f5
37+
refs/heads/tmp: 8519e7833daa1dd14ff8f88e09929193bd13b6b1
3838
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/tmp/mk/crates.mk

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ TARGET_CRATES := libc std flate arena term \
5454
log graphviz core rbml alloc \
5555
unicode rustc_bitflags
5656
RUSTC_CRATES := rustc rustc_typeck rustc_borrowck rustc_resolve rustc_driver \
57-
rustc_trans rustc_back rustc_llvm rustc_privacy
57+
rustc_trans rustc_back rustc_llvm rustc_privacy rustc_lint
5858
HOST_CRATES := syntax $(RUSTC_CRATES) rustdoc fmt_macros
5959
CRATES := $(TARGET_CRATES) $(HOST_CRATES)
6060
TOOLS := compiletest rustdoc rustc rustbook
@@ -70,20 +70,21 @@ DEPS_graphviz := std
7070
DEPS_syntax := std term serialize log fmt_macros arena libc
7171
DEPS_rustc_driver := arena flate getopts graphviz libc rustc rustc_back rustc_borrowck \
7272
rustc_typeck rustc_resolve log syntax serialize rustc_llvm \
73-
rustc_trans rustc_privacy
73+
rustc_trans rustc_privacy rustc_lint
7474

7575
DEPS_rustc_trans := arena flate getopts graphviz libc rustc rustc_back \
7676
log syntax serialize rustc_llvm
7777
DEPS_rustc_typeck := rustc syntax
7878
DEPS_rustc_borrowck := rustc log graphviz syntax
7979
DEPS_rustc_resolve := rustc log syntax
8080
DEPS_rustc_privacy := rustc log syntax
81+
DEPS_rustc_lint := rustc log syntax
8182
DEPS_rustc := syntax flate arena serialize getopts rbml \
8283
log graphviz rustc_llvm rustc_back
8384
DEPS_rustc_llvm := native:rustllvm libc std
8485
DEPS_rustc_back := std syntax rustc_llvm flate log libc
8586
DEPS_rustdoc := rustc rustc_driver native:hoedown serialize getopts \
86-
test
87+
test rustc_lint
8788
DEPS_rustc_bitflags := core
8889
DEPS_flate := std native:miniz
8990
DEPS_arena := std
@@ -128,11 +129,13 @@ DOC_CRATES := $(filter-out rustc, \
128129
$(filter-out rustc_resolve, \
129130
$(filter-out rustc_driver, \
130131
$(filter-out rustc_privacy, \
132+
$(filter-out rustc_lint, \
131133
$(filter-out log, \
132134
$(filter-out getopts, \
133-
$(filter-out syntax, $(CRATES)))))))))))
135+
$(filter-out syntax, $(CRATES))))))))))))
134136
COMPILER_DOC_CRATES := rustc rustc_trans rustc_borrowck rustc_resolve \
135-
rustc_typeck rustc_driver syntax rustc_privacy
137+
rustc_typeck rustc_driver syntax rustc_privacy \
138+
rustc_lint
136139

137140
# This macro creates some simple definitions for each crate being built, just
138141
# some munging of all of the parameters above.

branches/tmp/mk/tests.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ $(eval $(call RUST_CRATE,coretest))
2121

2222
TEST_TARGET_CRATES = $(filter-out core unicode,$(TARGET_CRATES)) coretest
2323
TEST_DOC_CRATES = $(DOC_CRATES)
24-
TEST_HOST_CRATES = $(filter-out rustc_typeck rustc_borrowck rustc_resolve rustc_trans,\
24+
TEST_HOST_CRATES = $(filter-out rustc_typeck rustc_borrowck rustc_resolve rustc_trans rustc_lint,\
2525
$(HOST_CRATES))
2626
TEST_CRATES = $(TEST_TARGET_CRATES) $(TEST_HOST_CRATES)
2727

branches/tmp/src/doc/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ There are questions that are asked quite often, and so we've made FAQs for them:
6868
* [Language Design FAQ](complement-design-faq.html)
6969
* [Language FAQ](complement-lang-faq.html)
7070
* [Project FAQ](complement-project-faq.html)
71-
* [How to submit a bug report](complement-bugreport.html)
71+
* [How to submit a bug report](https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports)
7272

7373
# The standard library
7474

branches/tmp/src/doc/reference.md

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ nonzero_dec: '1' | '2' | '3' | '4'
302302

303303
A _character literal_ is a single Unicode character enclosed within two
304304
`U+0027` (single-quote) characters, with the exception of `U+0027` itself,
305-
which must be _escaped_ by a preceding U+005C character (`\`).
305+
which must be _escaped_ by a preceding `U+005C` character (`\`).
306306

307307
##### String literals
308308

@@ -311,6 +311,19 @@ A _string literal_ is a sequence of any Unicode characters enclosed within two
311311
which must be _escaped_ by a preceding `U+005C` character (`\`), or a _raw
312312
string literal_.
313313

314+
A multi-line string literal may be defined by terminating each line with a
315+
`U+005C` character (`\`) immediately before the newline. This causes the
316+
`U+005C` character, the newline, and all whitespace at the beginning of the
317+
next line to be ignored.
318+
319+
```rust
320+
let a = "foobar";
321+
let b = "foo\
322+
bar";
323+
324+
assert_eq!(a,b);
325+
```
326+
314327
##### Character escapes
315328

316329
Some additional _escapes_ are available in either character or non-raw string
@@ -731,15 +744,20 @@ Rust syntax is restricted in two ways:
731744
pairs when they occur at the beginning of, or immediately after, a `$(...)*`;
732745
requiring a distinctive token in front can solve the problem.
733746

734-
## Syntax extensions useful for the macro author
747+
## Syntax extensions useful in macros
735748

736-
* `log_syntax!` : print out the arguments at compile time
737-
* `trace_macros!` : supply `true` or `false` to enable or disable macro expansion logging
738749
* `stringify!` : turn the identifier argument into a string literal
739750
* `concat!` : concatenates a comma-separated list of literals
740-
* `concat_idents!` : create a new identifier by concatenating the arguments
741751

742-
The following attributes are used for quasiquoting in procedural macros:
752+
## Syntax extensions for macro debugging
753+
754+
* `log_syntax!` : print out the arguments at compile time
755+
* `trace_macros!` : supply `true` or `false` to enable or disable macro expansion logging
756+
757+
## Quasiquoting
758+
759+
The following syntax extensions are used for quasiquoting Rust syntax trees,
760+
usually in [procedural macros](book/plugins.html#syntax-extensions):
743761

744762
* `quote_expr!`
745763
* `quote_item!`
@@ -748,6 +766,8 @@ The following attributes are used for quasiquoting in procedural macros:
748766
* `quote_tokens!`
749767
* `quote_ty!`
750768

769+
Documentation is very limited at the moment.
770+
751771
# Crates and source files
752772

753773
Rust is a *compiled* language. Its semantics obey a *phase distinction*

branches/tmp/src/doc/trpl/advanced-macros.md

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -192,19 +192,58 @@ To keep this system simple and correct, `#[macro_use] extern crate ...` may
192192
only appear at the root of your crate, not inside `mod`. This ensures that
193193
`$crate` is a single identifier.
194194

195-
# A final note
195+
# The deep end
196196

197-
Macros, as currently implemented, are not for the faint of heart. Even
198-
ordinary syntax errors can be more difficult to debug when they occur inside a
199-
macro, and errors caused by parse problems in generated code can be very
200-
tricky. Invoking the `log_syntax!` macro can help elucidate intermediate
201-
states, invoking `trace_macros!(true)` will automatically print those
202-
intermediate states out, and passing the flag `--pretty expanded` as a
203-
command-line argument to the compiler will show the result of expansion.
197+
The introductory chapter mentioned recursive macros, but it did not give the
198+
full story. Recursive macros are useful for another reason: Each recursive
199+
invocation gives you another opportunity to pattern-match the macro's
200+
arguments.
201+
202+
As an extreme example, it is possible, though hardly advisable, to implement
203+
the [Bitwise Cyclic Tag](http://esolangs.org/wiki/Bitwise_Cyclic_Tag) automaton
204+
within Rust's macro system.
205+
206+
```rust
207+
#![feature(trace_macros)]
208+
209+
macro_rules! bct {
210+
// cmd 0: d ... => ...
211+
(0, $($ps:tt),* ; $_d:tt)
212+
=> (bct!($($ps),*, 0 ; ));
213+
(0, $($ps:tt),* ; $_d:tt, $($ds:tt),*)
214+
=> (bct!($($ps),*, 0 ; $($ds),*));
215+
216+
// cmd 1p: 1 ... => 1 ... p
217+
(1, $p:tt, $($ps:tt),* ; 1)
218+
=> (bct!($($ps),*, 1, $p ; 1, $p));
219+
(1, $p:tt, $($ps:tt),* ; 1, $($ds:tt),*)
220+
=> (bct!($($ps),*, 1, $p ; 1, $($ds),*, $p));
221+
222+
// cmd 1p: 0 ... => 0 ...
223+
(1, $p:tt, $($ps:tt),* ; $($ds:tt),*)
224+
=> (bct!($($ps),*, 1, $p ; $($ds),*));
225+
226+
// halt on empty data string
227+
( $($ps:tt),* ; )
228+
=> (());
229+
}
230+
231+
fn main() {
232+
trace_macros!(true);
233+
# /* just check the definition
234+
bct!(0, 0, 1, 1, 1 ; 1, 0, 1);
235+
# */
236+
}
237+
```
238+
239+
Exercise: use macros to reduce duplication in the above definition of the
240+
`bct!` macro.
241+
242+
# Procedural macros
204243

205244
If Rust's macro system can't do what you need, you may want to write a
206245
[compiler plugin](plugins.html) instead. Compared to `macro_rules!`
207246
macros, this is significantly more work, the interfaces are much less stable,
208-
and the warnings about debugging apply ten-fold. In exchange you get the
247+
and bugs can be much harder to track down. In exchange you get the
209248
flexibility of running arbitrary Rust code within the compiler. Syntax
210249
extension plugins are sometimes called *procedural macros* for this reason.

branches/tmp/src/doc/trpl/error-handling.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,78 @@ let input = io::stdin().read_line()
223223
.ok()
224224
.expect("Failed to read line");
225225
```
226+
226227
`ok()` converts the `IoResult` into an `Option`, and `expect()` does the same
227228
thing as `unwrap()`, but takes a message. This message is passed along to the
228229
underlying `panic!`, providing a better error message if the code errors.
230+
231+
# Using `try!`
232+
233+
When writing code that calls many functions that return the `Result` type, the
234+
error handling can be tedious. The `try!` macro hides some of the boilerplate
235+
of propagating errors up the call stack.
236+
237+
It replaces this:
238+
239+
```rust
240+
use std::fs::File;
241+
use std::io;
242+
use std::io::prelude::*;
243+
244+
struct Info {
245+
name: String,
246+
age: i32,
247+
rating: i32,
248+
}
249+
250+
fn write_info(info: &Info) -> io::Result<()> {
251+
let mut file = File::open("my_best_friends.txt").unwrap();
252+
253+
if let Err(e) = writeln!(&mut file, "name: {}", info.name) {
254+
return Err(e)
255+
}
256+
if let Err(e) = writeln!(&mut file, "age: {}", info.age) {
257+
return Err(e)
258+
}
259+
if let Err(e) = writeln!(&mut file, "rating: {}", info.rating) {
260+
return Err(e)
261+
}
262+
263+
return Ok(());
264+
}
265+
```
266+
267+
With this:
268+
269+
```rust
270+
use std::fs::File;
271+
use std::io;
272+
use std::io::prelude::*;
273+
274+
struct Info {
275+
name: String,
276+
age: i32,
277+
rating: i32,
278+
}
279+
280+
fn write_info(info: &Info) -> io::Result<()> {
281+
let mut file = try!(File::open("my_best_friends.txt"));
282+
283+
try!(writeln!(&mut file, "name: {}", info.name));
284+
try!(writeln!(&mut file, "age: {}", info.age));
285+
try!(writeln!(&mut file, "rating: {}", info.rating));
286+
287+
return Ok(());
288+
}
289+
```
290+
291+
Wrapping an expression in `try!` will result in the unwrapped success (`Ok`)
292+
value, unless the result is `Err`, in which case `Err` is returned early from
293+
the enclosing function.
294+
295+
It's worth noting that you can only use `try!` from a function that returns a
296+
`Result`, which means that you cannot use `try!` inside of `main()`, because
297+
`main()` doesn't return anything.
298+
299+
`try!` makes use of [`FromError`](../std/error/#the-fromerror-trait) to determine
300+
what to return in the error case.

branches/tmp/src/doc/trpl/hello-cargo.md

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ the Cargo
1818
README](https://github.com/rust-lang/cargo#installing-cargo-from-nightlies)
1919
for specific instructions about installing it.
2020

21+
## Converting to Cargo
22+
2123
Let's convert Hello World to Cargo.
2224

2325
To Cargo-ify our project, we need to do two things: Make a `Cargo.toml`
2426
configuration file, and put our source file in the right place. Let's
2527
do that part first:
2628

27-
```{bash}
29+
```bash
2830
$ mkdir src
2931
$ mv main.rs src/main.rs
3032
```
@@ -36,7 +38,7 @@ place for everything, and everything in its place.
3638

3739
Next, our configuration file:
3840

39-
```{bash}
41+
```bash
4042
$ editor Cargo.toml
4143
```
4244

@@ -73,7 +75,7 @@ well as what it is named.
7375

7476
Once you have this file in place, we should be ready to build! Try this:
7577

76-
```{bash}
78+
```bash
7779
$ cargo build
7880
Compiling hello_world v0.0.1 (file:///home/yourname/projects/hello_world)
7981
$ ./target/hello_world
@@ -103,6 +105,62 @@ That's it! We've successfully built `hello_world` with Cargo. Even though our
103105
program is simple, it's using much of the real tooling that you'll use for the
104106
rest of your Rust career.
105107

108+
## A New Project
109+
110+
You don't have to go through this whole process every time you want to start a new
111+
project! Cargo has the ability to make a bare-bones project directory in which you
112+
can start developing right away.
113+
114+
To start a new project with Cargo, use `cargo new`:
115+
116+
```bash
117+
$ cargo new hello_world --bin
118+
```
119+
120+
We're passing `--bin` because we're making a binary program: if we
121+
were making a library, we'd leave it off.
122+
123+
Let's check out what Cargo has generated for us:
124+
125+
```bash
126+
$ cd hello_world
127+
$ tree .
128+
.
129+
├── Cargo.toml
130+
└── src
131+
└── main.rs
132+
133+
1 directory, 2 files
134+
```
135+
136+
If you don't have the `tree` command, you can probably get it from your distro's package
137+
manager. It's not necessary, but it's certainly useful.
138+
139+
This is all we need to get started. First, let's check out `Cargo.toml`:
140+
141+
```toml
142+
[package]
143+
144+
name = "hello_world"
145+
version = "0.0.1"
146+
authors = ["Your Name <[email protected]>"]
147+
```
148+
149+
Cargo has populated this file with reasonable defaults based off the arguments you gave
150+
it and your `git` global configuration. You may notice that Cargo has also initialized
151+
the `hello_world` directory as a `git` repository.
152+
153+
Here's what's in `src/main.rs`:
154+
155+
```rust
156+
fn main() {
157+
println!("Hello, world!");
158+
}
159+
```
160+
161+
Cargo has generated a "Hello World!" for us, and you're ready to start coding! A
162+
much more in-depth guide to Cargo can be found [here](http://doc.crates.io/guide.html).
163+
106164
Now that you've got the tools down, let's actually learn more about the Rust
107165
language itself. These are the basics that will serve you well through the rest
108-
of your time with Rust.
166+
of your time with Rust.

0 commit comments

Comments
 (0)