auto merge of #19785 : brson/rust/rollup, r=brson

This commit is contained in:
bors 2014-12-15 15:33:11 +00:00
commit 1b97cd338b
43 changed files with 209 additions and 151 deletions

3
configure vendored
View file

@ -988,8 +988,7 @@ do
make_dir $t/rt/jemalloc
for i in \
isaac sync test \
arch/i386 arch/x86_64 arch/arm arch/mips \
sundown/src sundown/html
arch/i386 arch/x86_64 arch/arm arch/mips
do
make_dir $t/rt/stage$s/$i
done

View file

@ -16,7 +16,7 @@
.PHONY: TAGS.emacs TAGS.vi
# This is using a blacklist approach, probably more durable than a whitelist.
# We exclude: external dependencies (llvm, rt/{msvc,sundown,vg}),
# We exclude: external dependencies (llvm, rt/{msvc,vg}),
# tests (compiletest, test) and a couple of other things (rt/arch, etc)
CTAGS_LOCATIONS=$(patsubst ${CFG_SRC_DIR}src/llvm,, \
$(patsubst ${CFG_SRC_DIR}src/compiletest,, \
@ -25,7 +25,6 @@ CTAGS_LOCATIONS=$(patsubst ${CFG_SRC_DIR}src/llvm,, \
$(patsubst ${CFG_SRC_DIR}src/rt,, \
$(patsubst ${CFG_SRC_DIR}src/rt/arch,, \
$(patsubst ${CFG_SRC_DIR}src/rt/msvc,, \
$(patsubst ${CFG_SRC_DIR}src/rt/sundown,, \
$(patsubst ${CFG_SRC_DIR}src/rt/vg,, \
$(wildcard ${CFG_SRC_DIR}src/*) $(wildcard ${CFG_SRC_DIR}src/rt/*) \
)))))))))

View file

@ -37,7 +37,7 @@ It's also helpful to provide the exact version and host by copying the output of
re-running the erroneous rustc command with the `--version=verbose` flag, which will
produce something like this:
```{ignore}
```text
rustc 0.12.0 (ba4081a5a 2014-10-07 13:44:41 -0700)
binary: rustc
commit-hash: ba4081a5a8573875fed17545846f6f6902c8ba8d
@ -46,8 +46,13 @@ host: i686-apple-darwin
release: 0.12.0
```
Finally, if you can run the offending command under gdb, pasting a stack trace can be
useful; to do so, you will need to set a breakpoint on `rust_panic`.
Finally, if you can also provide a backtrace, that'd be great. You can get a
backtrace by setting the `RUST_BACKTRACE` environment variable to `1`, like
this:
```bash
$ RUST_BACKTRACE=1 rustc ...
```
# I submitted a bug, but nobody has commented on it!

View file

@ -452,7 +452,7 @@ fn main() {
Rust will give us a compile-time error:
```{notrust}
```text
Compiling phrases v0.0.1 (file:///home/you/projects/phrases)
/home/you/projects/phrases/src/main.rs:4:5: 4:40 error: a value named `hello` has already been imported in this module
/home/you/projects/phrases/src/main.rs:4 use phrases::japanese::greetings::hello;

View file

@ -76,7 +76,7 @@ fn main() {
This will give us an error:
```{notrust}
```text
error: non-exhaustive patterns: `_` not covered [E0004]
```
@ -189,7 +189,7 @@ panic!("boom");
gives
```{notrust}
```text
task '<main>' panicked at 'boom', hello.rs:2
```

View file

@ -130,7 +130,7 @@ fn add_one(mut num: Box<int>) {
This does not compile, and gives us an error:
```{notrust}
```text
error: use of moved value: `x`
println!("{}", x);
^
@ -208,7 +208,7 @@ the function is over, and `num` goes out of scope, the borrow is over.
Lending out a reference to a resource that someone else owns can be
complicated, however. For example, imagine this set of operations:
1. I aquire a handle to some kind of resource.
1. I acquire a handle to some kind of resource.
2. I lend you a reference to the resource.
3. I decide I'm done with the resource, and deallocate it, while you still have
your reference.
@ -406,7 +406,7 @@ fn main() {
We try to make four `Wheel`s, each with a `Car` that it's attached to. But the
compiler knows that on the second iteration of the loop, there's a problem:
```{notrust}
```text
error: use of moved value: `car`
Wheel { size: 360, owner: car };
^~~

View file

@ -84,7 +84,7 @@ println!("{}", x + z);
This gives us an error:
```{notrust}
```text
hello.rs:6:24: 6:25 error: mismatched types: expected `int` but found `&int` (expected int but found &-ptr)
hello.rs:6 println!("{}", x + z);
^
@ -132,7 +132,7 @@ Pointers are useful in languages that are pass-by-value, rather than
pass-by-reference. Basically, languages can make two choices (this is made
up syntax, it's not Rust):
```{ignore}
```text
func foo(x) {
x = 5
}
@ -152,7 +152,7 @@ and therefore, can change its value. At the comment, `i` will be `5`.
So what do pointers have to do with this? Well, since pointers point to a
location in memory...
```{ignore}
```text
func foo(&int x) {
*x = 5
}
@ -191,7 +191,7 @@ knows. This might be harmless, and it might be catastrophic.
When you combine pointers and functions, it's easy to accidentally invalidate
the memory the pointer is pointing to. For example:
```{ignore}
```text
func make_pointer(): &int {
x = 5;
@ -213,7 +213,7 @@ As one last example of a big problem with pointers, **aliasing** can be an
issue. Two pointers are said to alias when they point at the same location
in memory. Like this:
```{ignore}
```text
func mutate(&int i, int j) {
*i = j;
}
@ -398,7 +398,7 @@ fn main() {
It gives this error:
```{notrust}
```text
test.rs:5:8: 5:10 error: cannot assign to `*x` because it is borrowed
test.rs:5 *x -= 1;
^~
@ -522,7 +522,7 @@ boxes, though. As a rough approximation, you can treat this Rust code:
As being similar to this C code:
```{ignore}
```c
{
int *x;
x = (int *)malloc(sizeof(int));
@ -626,7 +626,7 @@ fn main() {
This prints:
```{ignore}
```text
Cons(1, box Cons(2, box Cons(3, box Nil)))
```

View file

@ -22,7 +22,7 @@ install Rust, but the easiest is to use the `rustup` script. If you're on
Linux or a Mac, all you need to do is this (note that you don't need to type
in the `$`s, they just indicate the start of each command):
```{ignore}
```bash
$ curl -s https://static.rust-lang.org/rustup.sh | sudo sh
```
@ -39,7 +39,7 @@ If you decide you don't want Rust anymore, we'll be a bit sad, but that's okay.
Not every programming language is great for everyone. Just pass an argument to
the script:
```{ignore}
```bash
$ curl -s https://static.rust-lang.org/rustup.sh | sudo sh -s -- --uninstall
```
@ -78,13 +78,13 @@ commit is tested against Windows just like any other platform.
If you've got Rust installed, you can open up a shell, and type this:
```{ignore}
```bash
$ rustc --version
```
You should see some output that looks something like this:
```{ignore}
```bash
rustc 0.12.0-nightly (b7aa03a3c 2014-09-28 11:38:01 +0000)
```
@ -310,7 +310,7 @@ Make sure to get this name right: you need the capital `C`!
Put this inside:
```{ignore}
```toml
[package]
name = "hello_world"
@ -355,7 +355,7 @@ just `cargo build` and it'll work the right way.
You'll also notice that Cargo has created a new file: `Cargo.lock`.
```{ignore}
```toml
[root]
name = "hello_world"
version = "0.0.1"
@ -426,7 +426,7 @@ x = 10i;
It will give you this error:
```{notrust}
```text
error: re-assignment of immutable variable `x`
x = 10i;
^~~~~~~
@ -461,7 +461,7 @@ let x;
...we'll get an error:
```{ignore}
```text
src/main.rs:2:9: 2:10 error: cannot determine a type for this local variable: unconstrained type
src/main.rs:2 let x;
^
@ -486,7 +486,7 @@ fn main() {
You can use `cargo build` on the command line to build it. You'll get a warning,
but it will still print "Hello, world!":
```{notrust}
```text
Compiling hello_world v0.0.1 (file:///home/you/projects/hello_world)
src/main.rs:2:9: 2:10 warning: unused variable: `x`, #[warn(unused_variable)] on by default
src/main.rs:2 let x: int;
@ -664,7 +664,7 @@ let y: int = if x == 5i { 10i; } else { 15i; };
Note the semicolons after the 10 and 15. Rust will give us the following error:
```{notrust}
```text
error: mismatched types: expected `int` but found `()` (expected int but found ())
```
@ -747,7 +747,7 @@ fn print_number(x, y) {
You get this error:
```{notrust}
```text
hello.rs:5:18: 5:19 error: expected `:` but found `,`
hello.rs:5 fn print_number(x, y) {
```
@ -779,7 +779,7 @@ fn add_one(x: int) -> int {
We would get an error:
```{ignore}
```text
error: not all control paths return a value
fn add_one(x: int) -> int {
x + 1;
@ -1246,7 +1246,7 @@ So what's the big advantage here? Well, there are a few. First of all, `match`
enforces 'exhaustiveness checking.' Do you see that last arm, the one with the
underscore (`_`)? If we remove that arm, Rust will give us an error:
```{notrust}
```text
error: non-exhaustive patterns: `_` not covered
```
@ -1864,7 +1864,7 @@ since we're making a binary, rather than a library.
Check out the generated `Cargo.toml`:
```{ignore}
```toml
[package]
name = "guessing_game"
@ -1898,7 +1898,7 @@ Before we move on, let me show you one more Cargo command: `run`. `cargo run`
is kind of like `cargo build`, but it also then runs the produced executable.
Try it out:
```{notrust}
```bash
$ cargo run
Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
Running `target/guessing_game`
@ -1996,7 +1996,7 @@ for this example, it is not important.
Let's try to compile this using `cargo build`:
```{notrust}
```bash
$ cargo build
Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
src/main.rs:7:26: 7:34 error: the type of this value must be known in this context
@ -2044,7 +2044,7 @@ fn main() {
Try running our new program a few times:
```{notrust}
```bash
$ cargo run
Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
Running `target/guessing_game`
@ -2097,7 +2097,7 @@ fn main() {
And trying it out:
```{notrust}
```bash
$ cargo run
Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
Running `target/guessing_game`
@ -2152,7 +2152,7 @@ fn cmp(a: int, b: int) -> Ordering {
If we try to compile, we'll get some errors:
```{notrust}
```bash
$ cargo build
Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
src/main.rs:20:15: 20:20 error: mismatched types: expected `int` but found `collections::string::String` (expected int but found struct collections::string::String)
@ -2206,7 +2206,7 @@ fn cmp(a: uint, b: uint) -> Ordering {
And try compiling again:
```{notrust}
```bash
$ cargo build
Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
src/main.rs:20:15: 20:20 error: mismatched types: expected `uint` but found `collections::string::String` (expected uint but found struct collections::string::String)
@ -2219,7 +2219,7 @@ This error is similar to the last one: we expected to get a `uint`, but we got
a `String` instead! That's because our `input` variable is coming from the
standard input, and you can guess anything. Try it:
```{notrust}
```bash
$ ./target/guessing_game
Guess the number!
The secret number is: 73
@ -2303,7 +2303,7 @@ fn cmp(a: uint, b: uint) -> Ordering {
Let's try it out!
```{notrust}
```bash
$ cargo build
Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
src/main.rs:22:15: 22:24 error: mismatched types: expected `uint` but found `core::option::Option<uint>` (expected uint but found enum core::option::Option)
@ -2362,7 +2362,7 @@ fn cmp(a: uint, b: uint) -> Ordering {
We use a `match` to either give us the `uint` inside of the `Option`, or we
print an error message and return. Let's give this a shot:
```{notrust}
```bash
$ cargo run
Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
Running `target/guessing_game`
@ -2427,7 +2427,7 @@ fn cmp(a: uint, b: uint) -> Ordering {
Let's try it!
```{notrust}
```bash
$ cargo run
Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
Running `target/guessing_game`
@ -2504,7 +2504,7 @@ fn cmp(a: uint, b: uint) -> Ordering {
And try it out. But wait, didn't we just add an infinite loop? Yup. Remember
that `return`? If we give a non-number answer, we'll `return` and quit. Observe:
```{notrust}
```bash
$ cargo run
Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
Running `target/guessing_game`
@ -2636,7 +2636,7 @@ fn cmp(a: uint, b: uint) -> Ordering {
Now we should be good! Let's try:
```{notrust}
```bash
$ cargo run
Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
Running `target/guessing_game`
@ -2814,7 +2814,7 @@ mod hello {
It gives an error:
```{notrust}
```bash
Compiling modules v0.0.1 (file:///home/you/projects/modules)
src/main.rs:2:5: 2:23 error: function `print_hello` is private
src/main.rs:2 hello::print_hello();
@ -2838,7 +2838,7 @@ mod hello {
Usage of the `pub` keyword is sometimes called 'exporting', because
we're making the function available for other modules. This will work:
```{notrust}
```bash
$ cargo run
Compiling modules v0.0.1 (file:///home/you/projects/modules)
Running `target/modules`
@ -2972,7 +2972,7 @@ $ cd testing
And try it out:
```{notrust}
```bash
$ cargo run
Compiling testing v0.0.1 (file:///home/you/projects/testing)
Running `target/testing`
@ -3004,7 +3004,7 @@ you give them descriptive names. You'll see why in a moment. We then use a
macro, `assert!`, to assert that something is true. In this case, we're giving
it `false`, so this test should fail. Let's try it!
```{notrust}
```bash
$ cargo test
Compiling testing v0.0.1 (file:///home/you/projects/testing)
/home/you/projects/testing/src/main.rs:1:1: 3:2 warning: function is never used: `main`, #[warn(dead_code)] on by default
@ -3033,7 +3033,7 @@ task '<main>' failed at 'Some tests failed', /home/you/src/rust/src/libtest/lib.
Lots of output! Let's break this down:
```{ignore}
```bash
$ cargo test
Compiling testing v0.0.1 (file:///home/you/projects/testing)
```
@ -3041,7 +3041,7 @@ $ cargo test
You can run all of your tests with `cargo test`. This runs both your tests in
`tests`, as well as the tests you put inside of your crate.
```{notrust}
```text
/home/you/projects/testing/src/main.rs:1:1: 3:2 warning: function is never used: `main`, #[warn(dead_code)] on by default
/home/you/projects/testing/src/main.rs:1 fn main() {
/home/you/projects/testing/src/main.rs:2 println!("Hello, world!")
@ -3055,7 +3055,7 @@ case, Rust is warning us that we've written some code that's never used: our
We'll turn this lint off for just this function soon. For now, just ignore this
output.
```{ignore}
```text
Running target/lib-654ce120f310a3a5
running 1 test
@ -3067,7 +3067,7 @@ with good names? This is why. Here, it says 'test foo' because we called our
test 'foo.' If we had given it a good name, it'd be more clear which test
failed, especially as we accumulate more tests.
```{notrust}
```text
failures:
---- foo stdout ----
@ -3098,7 +3098,7 @@ fn foo() {
And then try to run our tests again:
```{ignore}
```bash
$ cargo test
Compiling testing v0.0.1 (file:///home/you/projects/testing)
Running target/lib-654ce120f310a3a5
@ -3138,7 +3138,7 @@ include `main` when it's _not_ true. So we use `not` to negate things:
With this attribute we won't get the warning (even
though `src/main.rs` gets recompiled this time):
```{ignore}
```bash
$ cargo test
Compiling testing v0.0.1 (file:///home/you/projects/testing)
Running target/lib-654ce120f310a3a5
@ -3169,7 +3169,7 @@ fn math_checks_out() {
And try to run the test:
```{notrust}
```bash
$ cargo test
Compiling testing v0.0.1 (file:///home/you/projects/testing)
/home/you/projects/testing/tests/lib.rs:3:18: 3:38 error: unresolved name `add_three_times_four`.
@ -3229,7 +3229,7 @@ fn math_checks_out() {
Let's give it a run:
```{ignore}
```bash
$ cargo test
Compiling testing v0.0.1 (file:///home/you/projects/testing)
Running target/lib-654ce120f310a3a5
@ -3278,7 +3278,7 @@ fn times_four(x: int) -> int { x * 4 }
If you run `cargo test`, you should get the same output:
```{ignore}
```bash
$ cargo test
Compiling testing v0.0.1 (file:///home/you/projects/testing)
Running target/lib-654ce120f310a3a5
@ -3332,7 +3332,7 @@ fn test_add_three() {
We'd get this error:
```{notrust}
```text
Compiling testing v0.0.1 (file:///home/you/projects/testing)
/home/you/projects/testing/tests/lib.rs:3:5: 3:24 error: function `add_three` is private
/home/you/projects/testing/tests/lib.rs:3 use testing::add_three;
@ -3374,7 +3374,7 @@ mod test {
Let's give it a shot:
```{ignore}
```bash
$ cargo test
Compiling testing v0.0.1 (file:///home/you/projects/testing)
Running target/lib-654ce120f310a3a5
@ -3504,7 +3504,7 @@ let y = &mut x;
Rust will complain:
```{notrust}
```text
error: cannot borrow immutable local variable `x` as mutable
let y = &mut x;
^
@ -3531,7 +3531,7 @@ let z = &mut x;
It gives us this error:
```{notrust}
```text
error: cannot borrow `x` as mutable more than once at a time
let z = &mut x;
^
@ -3677,7 +3677,7 @@ let z = &mut x;
The error:
```{notrust}
```text
error: cannot borrow `x` as mutable more than once at a time
let z = &mut x;
^
@ -3695,7 +3695,7 @@ note: previous borrow ends here
This error comes in three parts. Let's go over each in turn.
```{notrust}
```text
error: cannot borrow `x` as mutable more than once at a time
let z = &mut x;
^
@ -3704,7 +3704,7 @@ error: cannot borrow `x` as mutable more than once at a time
This error states the restriction: you cannot lend out something mutable more
than once at the same time. The borrow checker knows the rules!
```{notrust}
```text
note: previous borrow of `x` occurs here; the mutable borrow prevents subsequent moves, borrows, or modification of `x` until the borrow ends
let y = &mut x;
^
@ -3716,7 +3716,7 @@ the first mutable borrow occurred. The error showed us the second. So now we
see both parts of the problem. It also alludes to rule #3, by reminding us that
we can't change `x` until the borrow is over.
```{ignore}
```text
note: previous borrow ends here
fn main() {
let mut x = 5i;
@ -3819,7 +3819,7 @@ let y = &mut x;
This gives us this error:
```{notrust}
```text
error: cannot use `*x` because it was mutably borrowed
*x;
^~
@ -4624,7 +4624,7 @@ element reference has the closure it's been given as an argument called on it.
So this would give us the numbers from `2-100`. Well, almost! If you
compile the example, you'll get a warning:
```{ignore}
```text
warning: unused result which must be used: iterator adaptors are lazy and
do nothing unless consumed, #[warn(unused_must_use)] on by default
range(1i, 100i).map(|x| x + 1i);
@ -4654,7 +4654,7 @@ for i in std::iter::count(1i, 5i).take(5) {
This will print
```{ignore}
```text
1
6
11
@ -4867,7 +4867,7 @@ We can then use `T` inside the rest of the signature: `x` has type `T`, and half
of the `Result` has type `T`. However, if we try to compile that example, we'll get
an error:
```{notrust}
```text
error: binary operation `==` cannot be applied to type `T`
```
@ -4923,7 +4923,7 @@ we use `impl Trait for Item`, rather than just `impl Item`.
So what's the big deal? Remember the error we were getting with our generic
`inverse` function?
```{notrust}
```text
error: binary operation `==` cannot be applied to type `T`
```
@ -4938,7 +4938,7 @@ fn print_area<T>(shape: T) {
Rust complains:
```{notrust}
```text
error: type `T` does not implement any method in scope named `area`
```
@ -5014,7 +5014,7 @@ fn main() {
This program outputs:
```{ignore}
```text
This shape has an area of 3.141593
This shape has an area of 1
```
@ -5028,7 +5028,7 @@ print_area(5i);
We get a compile-time error:
```{ignore}
```text
error: failed to find an implementation of trait main::HasArea for int
```
@ -5095,7 +5095,7 @@ fn main() {
Now that we've moved the structs and traits into their own module, we get an
error:
```{notrust}
```text
error: type `shapes::Circle` does not implement any method in scope named `area`
```

View file

@ -155,13 +155,13 @@ when you have unrestricted access to memory. As an example, here's some Ruby
code:
```{ruby}
v = [];
v = []
v.push("Hello");
v.push("Hello")
x = v[0];
x = v[0]
v.push("world");
v.push("world")
puts x
```
@ -313,7 +313,7 @@ print `"Hello"`, or does Rust crash?
Neither. It refuses to compile:
```{notrust}
```bash
$ cargo run
Compiling hello_world v0.0.1 (file:///Users/you/src/hello_world)
main.rs:8:5: 8:6 error: cannot borrow `v` as mutable because it is also borrowed as immutable
@ -431,7 +431,7 @@ fn main() {
It gives us this error:
```{notrust}
```text
6:71 error: capture of moved value: `numbers`
for j in range(0, 3) { numbers[j] += 1 }
^~~~~~~

View file

@ -26,4 +26,3 @@
[type: text] src/doc/intro.md $lang:doc/l10n/$lang/intro.md
[type: text] src/doc/rust.md $lang:doc/l10n/$lang/rust.md
[type: text] src/doc/rustdoc.md $lang:doc/l10n/$lang/rustdoc.md
[type: text] src/doc/guide.md $lang:doc/l10n/$lang/guide.md

View file

@ -1317,10 +1317,10 @@ let fptr: extern "C" fn() -> int = new_int;
Extern functions may be called directly from Rust code as Rust uses large,
contiguous stack segments like C.
### Type definitions
### Type aliases
A _type definition_ defines a new name for an existing [type](#types). Type
definitions are declared with the keyword `type`. Every value has a single,
A _type alias_ defines a new name for an existing [type](#types). Type
aliases are declared with the keyword `type`. Every value has a single,
specific type; the type-specified aspects of a value include:
* Whether the value is composed of sub-values or is indivisible.
@ -2548,10 +2548,6 @@ The currently implemented features of the reference compiler are:
* `default_type_params` - Allows use of default type parameters. The future of
this feature is uncertain.
* `if_let` - Allows use of the `if let` syntax.
* `while_let` - Allows use of the `while let` syntax.
* `intrinsics` - Allows use of the "rust-intrinsics" ABI. Compiler intrinsics
are inherently unstable and no promise about them is made.
@ -2638,8 +2634,6 @@ The currently implemented features of the reference compiler are:
which is considered wildly unsafe and will be
obsoleted by language improvements.
* `tuple_indexing` - Allows use of tuple indexing (expressions like `expr.0`)
* `associated_types` - Allows type aliases in traits. Experimental.
If a feature is promoted to a language feature, then all existing programs will

View file

@ -270,6 +270,7 @@
'|"|
\\|n|r|t|0|
x\%{hex_digit}{2}|
u{\%{hex_digit}{1,6}}|
u\%{hex_digit}{4}|
U\%{hex_digit}{8}
</define-regex>

View file

@ -90,7 +90,7 @@ syn keyword rustTrait Clone
syn keyword rustTrait PartialEq PartialOrd Eq Ord
syn keyword rustEnum Ordering Equiv
syn keyword rustEnumVariant Less Equal Greater
syn keyword rustTrait FromIterator Extend ExactSize
syn keyword rustTrait FromIterator Extend ExactSizeIterator
syn keyword rustTrait Iterator DoubleEndedIterator
syn keyword rustTrait RandomAccessIterator CloneableIterator
syn keyword rustTrait OrdIterator MutableDoubleEndedIterator
@ -151,6 +151,7 @@ syn match rustMacro '#\w\(\w\)*' contains=rustAssert,rustPanic
syn match rustEscapeError display contained /\\./
syn match rustEscape display contained /\\\([nrt0\\'"]\|x\x\{2}\)/
syn match rustEscapeUnicode display contained /\\\(u\x\{4}\|U\x\{8}\)/
syn match rustEscapeUnicode display contained /\\u{\x\{1,6}}/
syn match rustStringContinuation display contained /\\\n\s*/
syn region rustString start=+b"+ skip=+\\\\\|\\"+ end=+"+ contains=rustEscape,rustEscapeError,rustStringContinuation
syn region rustString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=rustEscape,rustEscapeUnicode,rustEscapeError,rustStringContinuation,@Spell
@ -187,7 +188,7 @@ syn match rustCharacterInvalid display contained /b\?'\zs[\n\r\t']\ze'/
" The groups negated here add up to 0-255 but nothing else (they do not seem to go beyond ASCII).
syn match rustCharacterInvalidUnicode display contained /b'\zs[^[:cntrl:][:graph:][:alnum:][:space:]]\ze'/
syn match rustCharacter /b'\([^\\]\|\\\(.\|x\x\{2}\)\)'/ contains=rustEscape,rustEscapeError,rustCharacterInvalid,rustCharacterInvalidUnicode
syn match rustCharacter /'\([^\\]\|\\\(.\|x\x\{2}\|u\x\{4}\|U\x\{8}\)\)'/ contains=rustEscape,rustEscapeUnicode,rustEscapeError,rustCharacterInvalid
syn match rustCharacter /'\([^\\]\|\\\(.\|x\x\{2}\|u\x\{4}\|U\x\{8}\|u{\x\{1,6}}\)\)'/ contains=rustEscape,rustEscapeUnicode,rustEscapeError,rustCharacterInvalid
syn region rustCommentLine start="//" end="$" contains=rustTodo,@Spell
syn region rustCommentLineDoc start="//\%(//\@!\|!\)" end="$" contains=rustTodo,@Spell

View file

@ -65,6 +65,14 @@ pub struct UnionItems<'a, T:'a> {
impl<T: Ord> BTreeSet<T> {
/// Makes a new BTreeSet with a reasonable choice of B.
///
/// # Examples
///
/// ```
/// use std::collections::BTreeSet;
///
/// let mut set: BTreeSet<int> = BTreeSet::new();
/// ```
#[unstable = "matches collection reform specification, waiting for dust to settle"]
pub fn new() -> BTreeSet<T> {
BTreeSet { map: BTreeMap::new() }
@ -80,12 +88,38 @@ impl<T: Ord> BTreeSet<T> {
impl<T> BTreeSet<T> {
/// Gets an iterator over the BTreeSet's contents.
///
/// # Examples
///
/// ```
/// use std::collections::BTreeSet;
///
/// let set: BTreeSet<uint> = [1u, 2, 3, 4].iter().map(|&x| x).collect();
///
/// for x in set.iter() {
/// println!("{}", x);
/// }
///
/// let v: Vec<uint> = set.iter().map(|&x| x).collect();
/// assert_eq!(v, vec![1u,2,3,4]);
/// ```
#[unstable = "matches collection reform specification, waiting for dust to settle"]
pub fn iter<'a>(&'a self) -> Items<'a, T> {
self.map.keys()
}
/// Gets an iterator for moving out the BtreeSet's contents.
///
/// # Examples
///
/// ```
/// use std::collections::BTreeSet;
///
/// let set: BTreeSet<uint> = [1u, 2, 3, 4].iter().map(|&x| x).collect();
///
/// let v: Vec<uint> = set.into_iter().collect();
/// assert_eq!(v, vec![1u,2,3,4]);
/// ```
#[unstable = "matches collection reform specification, waiting for dust to settle"]
pub fn into_iter(self) -> MoveItems<T> {
fn first<A, B>((a, _): (A, B)) -> A { a }

View file

@ -15,7 +15,7 @@
//!
//! `TreeMap`s are ordered.
//!
//! ## Example
//! # Examples
//!
//! ```{rust}
//! use std::collections::TreeSet;

View file

@ -27,7 +27,7 @@ use tree_map::{TreeMap, Entries, RevEntries, MoveEntries};
/// requirement is that the type of the elements contained ascribes to the
/// `Ord` trait.
///
/// ## Examples
/// # Examples
///
/// ```{rust}
/// use std::collections::TreeSet;

View file

@ -93,7 +93,7 @@ use intrinsics;
use option::Option;
use option::Option::{Some, None};
use cmp::{PartialEq, Eq, PartialOrd, Equiv};
use cmp::{PartialEq, Eq, Ord, PartialOrd, Equiv};
use cmp::Ordering;
use cmp::Ordering::{Less, Equal, Greater};
@ -388,16 +388,23 @@ mod externfnpointers {
}
// Comparison for pointers
impl<T> Ord for *const T {
#[inline]
fn cmp(&self, other: &*const T) -> Ordering {
if self < other {
Less
} else if self == other {
Equal
} else {
Greater
}
}
}
impl<T> PartialOrd for *const T {
#[inline]
fn partial_cmp(&self, other: &*const T) -> Option<Ordering> {
if self < other {
Some(Less)
} else if self == other {
Some(Equal)
} else {
Some(Greater)
}
Some(self.cmp(other))
}
#[inline]
@ -413,16 +420,23 @@ impl<T> PartialOrd for *const T {
fn ge(&self, other: &*const T) -> bool { *self >= *other }
}
impl<T> Ord for *mut T {
#[inline]
fn cmp(&self, other: &*mut T) -> Ordering {
if self < other {
Less
} else if self == other {
Equal
} else {
Greater
}
}
}
impl<T> PartialOrd for *mut T {
#[inline]
fn partial_cmp(&self, other: &*mut T) -> Option<Ordering> {
if self < other {
Some(Less)
} else if self == other {
Some(Equal)
} else {
Some(Greater)
}
Some(self.cmp(other))
}
#[inline]

View file

@ -29,7 +29,7 @@
//! }
//! ```
//!
//! ## Stability Note
//! # Stability Note
//!
//! These are all experimental. The interface may change entirely, without
//! warning.

View file

@ -1757,9 +1757,9 @@ pub trait StrPrelude for Sized? {
/// }
/// ```
///
/// ## Output
/// This outputs:
///
/// ```ignore
/// ```text
/// 0: 中
/// 3: 华
/// 6: V

View file

@ -10,7 +10,7 @@
//! Utilities for program-wide and customizable logging
//!
//! ## Example
//! # Examples
//!
//! ```
//! #![feature(phase)]
@ -64,8 +64,7 @@
//! INFO:main: the answer was: 12
//! ```
//!
//!
//! ## Logging Macros
//! # Logging Macros
//!
//! There are five macros that the logging subsystem uses:
//!
@ -86,7 +85,7 @@
//!
//! * `log_enabled!(level)` - returns true if logging of the given level is enabled
//!
//! ## Enabling logging
//! # Enabling logging
//!
//! Log levels are controlled on a per-module basis, and by default all logging is
//! disabled except for `error!` (a log level of 1). Logging is controlled via the
@ -123,7 +122,7 @@
//! * `hello,std::option` turns on hello, and std's option logging
//! * `error,hello=warn` turn on global error logging and also warn for hello
//!
//! ## Filtering results
//! # Filtering results
//!
//! A RUST_LOG directive may include a regex filter. The syntax is to append `/`
//! followed by a regex. Each message is checked against the regex, and is only
@ -143,7 +142,7 @@
//! hello. In both cases the log message must include a single digit number
//! followed by 'scopes'
//!
//! ## Performance and Side Effects
//! # Performance and Side Effects
//!
//! Each of these macros will expand to code similar to:
//!

View file

@ -1056,6 +1056,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_bounds_and_type(rbml_w, ecx, &lookup_item_type(tcx, def_id));
encode_name(rbml_w, item.ident.name);
encode_path(rbml_w, path);
encode_attributes(rbml_w, item.attrs.as_slice());
encode_inlined_item(ecx, rbml_w, IIItemRef(item));
encode_visibility(rbml_w, vis);
encode_stability(rbml_w, stab);

View file

@ -140,7 +140,7 @@ pub fn run(sess: &session::Session, llmod: ModuleRef,
// Internalize everything but the reachable symbols of the current module
let cstrs: Vec<::std::c_str::CString> =
reachable.iter().map(|s| s.to_c_str()).collect();
let arr: Vec<*const i8> = cstrs.iter().map(|c| c.as_ptr()).collect();
let arr: Vec<*const libc::c_char> = cstrs.iter().map(|c| c.as_ptr()).collect();
let ptr = arr.as_ptr();
unsafe {
llvm::LLVMRustRunRestrictionPass(llmod,

View file

@ -104,6 +104,10 @@ fn try_inline_def(cx: &DocContext, tcx: &ty::ctxt,
record_extern_fqn(cx, did, clean::TypeStatic);
clean::StaticItem(build_static(cx, tcx, did, mtbl))
}
def::DefConst(did) => {
record_extern_fqn(cx, did, clean::TypeConst);
clean::ConstantItem(build_const(cx, tcx, did))
}
_ => return None,
};
let fqn = csearch::get_item_path(tcx, did);
@ -388,6 +392,24 @@ fn build_module(cx: &DocContext, tcx: &ty::ctxt,
}
}
fn build_const(cx: &DocContext, tcx: &ty::ctxt,
did: ast::DefId) -> clean::Constant {
use rustc::middle::const_eval;
use syntax::print::pprust;
let expr = const_eval::lookup_const_by_id(tcx, did).unwrap_or_else(|| {
panic!("expected lookup_const_by_id to succeed for {}", did);
});
debug!("converting constant expr {} to snippet", expr);
let sn = pprust::expr_to_string(expr);
debug!("got snippet {}", sn);
clean::Constant {
type_: ty::lookup_item_type(tcx, did).ty.clean(cx),
expr: sn
}
}
fn build_static(cx: &DocContext, tcx: &ty::ctxt,
did: ast::DefId,
mutable: bool) -> clean::Static {

View file

@ -1201,6 +1201,7 @@ pub enum TypeKind {
TypeEnum,
TypeFunction,
TypeModule,
TypeConst,
TypeStatic,
TypeStruct,
TypeTrait,
@ -1841,7 +1842,7 @@ impl Clean<Item> for doctree::Static {
}
}
#[deriving(Clone, Encodable, Decodable)]
#[deriving(Clone, Encodable, Decodable, Show)]
pub struct Constant {
pub type_: Type,
pub expr: String,

View file

@ -76,6 +76,7 @@ impl ItemType {
clean::TypeTrait => ItemType::Trait,
clean::TypeModule => ItemType::Module,
clean::TypeStatic => ItemType::Static,
clean::TypeConst => ItemType::Constant,
clean::TypeVariant => ItemType::Variant,
clean::TypeTypedef => ItemType::Typedef,
}

View file

@ -24,9 +24,11 @@ pub struct Toc {
/// both of which end up in the same `Toc` as they have the same
/// parent (Main).
///
/// ```text
/// # Main
/// ### A
/// ## B
/// ```
entries: Vec<TocEntry>
}
@ -78,6 +80,7 @@ impl TocBuilder {
///
/// Example:
///
/// ```text
/// ## A
/// # B
/// # C
@ -86,6 +89,7 @@ impl TocBuilder {
/// ### F
/// #### G
/// ### H
/// ```
///
/// If we are considering H (i.e. level 3), then A and B are in
/// self.top_level, D is in C.children, and C, E, F, G are in

View file

@ -603,7 +603,7 @@ mod tests {
assert_eq!(*buf.offset(0), 'f' as libc::c_char);
assert_eq!(*buf.offset(1), 'o' as libc::c_char);
assert_eq!(*buf.offset(2), 'o' as libc::c_char);
assert_eq!(*buf.offset(3), 0xffu8 as i8);
assert_eq!(*buf.offset(3), 0xffu8 as libc::c_char);
assert_eq!(*buf.offset(4), 0);
}
}

View file

@ -80,7 +80,7 @@ impl<R: Reader> BufferedReader<R> {
/// Gets a mutable reference to the underlying reader.
///
/// ## Warning
/// # Warning
///
/// It is inadvisable to directly read from the underlying reader.
pub fn get_mut(&mut self) -> &mut R { &mut self.inner }
@ -185,7 +185,7 @@ impl<W: Writer> BufferedWriter<W> {
/// Gets a mutable reference to the underlying write.
///
/// ## Warning
/// # Warning
///
/// It is inadvisable to directly read from the underlying writer.
pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() }
@ -357,7 +357,7 @@ impl<S: Stream> BufferedStream<S> {
/// Gets a mutable reference to the underlying stream.
///
/// ## Warning
/// # Warning
///
/// It is inadvisable to read directly from or write directly to the
/// underlying stream.

View file

@ -127,7 +127,7 @@ impl StdinReader {
///
/// This provides access to methods like `chars` and `lines`.
///
/// ## Example
/// # Examples
///
/// ```rust
/// use std::io;

View file

@ -378,7 +378,7 @@ pub fn getenv_as_bytes(n: &str) -> Option<Vec<u8>> {
if s.is_null() {
None
} else {
Some(CString::new(s as *const i8, false).as_bytes_no_nul().to_vec())
Some(CString::new(s as *const libc::c_char, false).as_bytes_no_nul().to_vec())
}
})
}
@ -1237,7 +1237,7 @@ impl Copy for MapOption {}
/// Possible errors when creating a map.
pub enum MapError {
/// ## The following are POSIX-specific
/// # The following are POSIX-specific
///
/// fd was not open for reading or, if using `MapWritable`, was not open for
/// writing.
@ -1259,7 +1259,7 @@ pub enum MapError {
ErrZeroLength,
/// Unrecognized error. The inner value is the unrecognized errno.
ErrUnknown(int),
/// ## The following are Windows-specific
/// # The following are Windows-specific
///
/// Unsupported combination of protection flags
/// (`MapReadable`/`MapWritable`/`MapExecutable`).

View file

@ -32,7 +32,7 @@
//! the main task panics the application will exit with a non-zero
//! exit code.
//!
//! ## Example
//! # Examples
//!
//! ```rust
//! spawn(move|| {

View file

@ -66,6 +66,7 @@ pub fn cs_cmp(cx: &mut ExtCtxt, span: Span,
let equals_path = cx.path_global(span,
vec!(cx.ident_of("std"),
cx.ident_of("cmp"),
cx.ident_of("Ordering"),
cx.ident_of("Equal")));
let cmp_path = vec![

View file

@ -16,7 +16,7 @@
//! [terminfo][ti] database, and `WinConsole`, which uses the [Win32 Console
//! API][win].
//!
//! ## Example
//! # Examples
//!
//! ```no_run
//! extern crate term;

View file

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(tuple_indexing)]
fn main() {
let t = (42i, 42i);
t.0::<int>; //~ ERROR expected one of `.`, `;`, `}`, or an operator, found `::`

View file

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(tuple_indexing)]
struct Foo(int, int);
fn main() {

View file

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(if_let)]
pub fn main() {
let x = Some(3i);
if let Some(y) = x {

View file

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(tuple_indexing)]
// Test that non-static methods can be assigned to local variables as
// function pointers.

View file

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(tuple_indexing)]
struct MyStruct { field: uint }
const STRUCT: MyStruct = MyStruct { field: 42 };
const TUP: (uint,) = (43,);

View file

@ -8,7 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(tuple_indexing)]
struct S {
o: Option<String>
}

View file

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(tuple_indexing)]
struct Foo<'a>(&'a [int]);
fn main() {

View file

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(tuple_indexing)]
struct Point(int, int);
fn main() {

View file

@ -19,7 +19,7 @@ extern {
}
unsafe fn check<T>(expected: &str, f: |*mut c_char| -> T) {
let mut x = [0i8, ..50];
let mut x = [0 as c_char, ..50];
f(&mut x[0] as *mut c_char);
let res = CString::new(&x[0], false);
assert_eq!(expected, res.as_str().unwrap());

View file

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(while_let)]
use std::collections::BinaryHeap;
fn make_pq() -> BinaryHeap<int> {