1
Fork 0

docs: Stop using notrust

Now that rustdoc understands proper language tags
as the code not being Rust, we can tag everything
properly.

This change tags examples in other languages by
their language. Plain notations are marked as `text`.
Console examples are marked as `console`.

Also fix markdown.rs to not highlight non-rust code.
This commit is contained in:
Florian Gilcher 2014-06-02 12:37:54 +02:00
parent b981add9ee
commit 20fb7c62d4
19 changed files with 165 additions and 156 deletions

View file

@ -255,7 +255,7 @@ Note: The Rust signatures should be wrapped in an `extern "ABI" { ... }` block.
You might see things like this in C APIs: You might see things like this in C APIs:
~~~ {.notrust} ~~~c
typedef struct Window Window; typedef struct Window Window;
Window* createWindow(int width, int height); Window* createWindow(int width, int height);
~~~ ~~~

View file

@ -135,7 +135,7 @@ For simplicity, we do not plan to do so. Implementing automatic semicolon insert
**Short answer** set the RUST_LOG environment variable to the name of your source file, sans extension. **Short answer** set the RUST_LOG environment variable to the name of your source file, sans extension.
```notrust,sh ```sh
rustc hello.rs rustc hello.rs
export RUST_LOG=hello export RUST_LOG=hello
./hello ./hello

View file

@ -229,7 +229,7 @@ fn main() {
C code: C code:
~~~~ {.notrust} ~~~~c
typedef void (*rust_callback)(int32_t); typedef void (*rust_callback)(int32_t);
rust_callback cb; rust_callback cb;
@ -296,7 +296,7 @@ fn main() {
C code: C code:
~~~~ {.notrust} ~~~~c
typedef void (*rust_callback)(int32_t); typedef void (*rust_callback)(int32_t);
void* cb_target; void* cb_target;
rust_callback cb; rust_callback cb;

View file

@ -218,7 +218,7 @@ fn example3() -> int {
To make this clearer, consider this diagram showing the state of To make this clearer, consider this diagram showing the state of
memory immediately before the re-assignment of `x`: memory immediately before the re-assignment of `x`:
~~~ {.notrust} ~~~ {.text}
Stack Exchange Heap Stack Exchange Heap
x +-------------+ x +-------------+
@ -232,7 +232,7 @@ memory immediately before the re-assignment of `x`:
Once the reassignment occurs, the memory will look like this: Once the reassignment occurs, the memory will look like this:
~~~ {.notrust} ~~~ {.text}
Stack Exchange Heap Stack Exchange Heap
x +-------------+ +---------+ x +-------------+ +---------+
@ -329,7 +329,7 @@ to a pointer of type `&size` into the _interior of the enum_.
To make this more clear, let's look at a diagram of memory layout in To make this more clear, let's look at a diagram of memory layout in
the case where `shape` points at a rectangle: the case where `shape` points at a rectangle:
~~~ {.notrust} ~~~ {.text}
Stack Memory Stack Memory
+-------+ +---------------+ +-------+ +---------------+
@ -354,7 +354,7 @@ to store that shape value would still be valid, _it would have a
different type_! The following diagram shows what memory would look different type_! The following diagram shows what memory would look
like if code overwrote `shape` with a circle: like if code overwrote `shape` with a circle:
~~~ {.notrust} ~~~ {.text}
Stack Memory Stack Memory
+-------+ +---------------+ +-------+ +---------------+

View file

@ -31,7 +31,7 @@ fn main() {
And now I get an error: And now I get an error:
~~~ {.notrust} ~~~text
error: mismatched types: expected `&int` but found `<generic integer #0>` (expected &-ptr but found integral variable) error: mismatched types: expected `&int` but found `<generic integer #0>` (expected &-ptr but found integral variable)
~~~ ~~~
@ -201,7 +201,7 @@ fn main() {
This prints: This prints:
~~~ {.notrust} ~~~text
Cons(1, box Cons(2, box Cons(3, box Nil))) Cons(1, box Cons(2, box Cons(3, box Nil)))
~~~ ~~~
@ -347,7 +347,7 @@ fn main() {
It gives this error: It gives this error:
~~~ {.notrust} ~~~text
test.rs:5:8: 5:10 error: cannot assign to `*x` because it is borrowed test.rs:5:8: 5:10 error: cannot assign to `*x` because it is borrowed
test.rs:5 *x -= 1; test.rs:5 *x -= 1;
^~ ^~

View file

@ -19,7 +19,7 @@ fn return_two_test() {
To run these tests, compile with `rustc --test` and run the resulting To run these tests, compile with `rustc --test` and run the resulting
binary: binary:
~~~ {.notrust} ~~~console
$ rustc --test foo.rs $ rustc --test foo.rs
$ ./foo $ ./foo
running 1 test running 1 test
@ -111,7 +111,7 @@ sequentially.
### Typical test run ### Typical test run
~~~ {.notrust} ~~~console
$ mytests $ mytests
running 30 tests running 30 tests
@ -125,7 +125,7 @@ result: ok. 28 passed; 0 failed; 2 ignored
### Test run with failures ### Test run with failures
~~~ {.notrust} ~~~console
$ mytests $ mytests
running 30 tests running 30 tests
@ -139,7 +139,7 @@ result: FAILED. 27 passed; 1 failed; 2 ignored
### Running ignored tests ### Running ignored tests
~~~ {.notrust} ~~~console
$ mytests --ignored $ mytests --ignored
running 2 tests running 2 tests
@ -153,7 +153,7 @@ result: FAILED. 1 passed; 1 failed; 0 ignored
Using a plain string: Using a plain string:
~~~ {.notrust} ~~~console
$ mytests mytest23 $ mytests mytest23
running 1 tests running 1 tests
@ -164,7 +164,7 @@ result: ok. 1 passed; 0 failed; 0 ignored
Using some regular expression features: Using some regular expression features:
~~~ {.notrust} ~~~console
$ mytests 'mytest[145]' $ mytests 'mytest[145]'
running 13 tests running 13 tests
@ -247,7 +247,7 @@ Advice on writing benchmarks:
To run benchmarks, pass the `--bench` flag to the compiled To run benchmarks, pass the `--bench` flag to the compiled
test-runner. Benchmarks are compiled-in but not executed by default. test-runner. Benchmarks are compiled-in but not executed by default.
~~~ {.notrust} ~~~console
$ rustc mytests.rs -O --test $ rustc mytests.rs -O --test
$ mytests --bench $ mytests --bench
@ -283,7 +283,7 @@ fn bench_xor_1000_ints(b: &mut Bencher) {
gives the following results gives the following results
~~~ {.notrust} ~~~console
running 1 test running 1 test
test bench_xor_1000_ints ... bench: 0 ns/iter (+/- 0) test bench_xor_1000_ints ... bench: 0 ns/iter (+/- 0)
@ -323,7 +323,7 @@ overhead (e.g. `black_box(&huge_struct)`).
Performing either of the above changes gives the following Performing either of the above changes gives the following
benchmarking results benchmarking results
~~~ {.notrust} ~~~console
running 1 test running 1 test
test bench_xor_1000_ints ... bench: 375 ns/iter (+/- 148) test bench_xor_1000_ints ... bench: 375 ns/iter (+/- 148)

View file

@ -22,7 +22,7 @@ and is the feature from which many of Rust's powerful capabilities are derived.
write, and ultimately release, memory. write, and ultimately release, memory.
Let's start by looking at some C++ code: Let's start by looking at some C++ code:
```notrust ```cpp
int* dangling(void) int* dangling(void)
{ {
int i = 1234; int i = 1234;
@ -74,7 +74,7 @@ fn main() {
Save this program as `dangling.rs`. When you try to compile this program with `rustc dangling.rs`, you'll get an interesting (and long) error message: Save this program as `dangling.rs`. When you try to compile this program with `rustc dangling.rs`, you'll get an interesting (and long) error message:
```notrust ```text
dangling.rs:3:12: 3:14 error: `i` does not live long enough dangling.rs:3:12: 3:14 error: `i` does not live long enough
dangling.rs:3 return &i; dangling.rs:3 return &i;
^~ ^~
@ -155,7 +155,7 @@ You can roughly compare these two lines:
let i = box 1234; let i = box 1234;
``` ```
```notrust ```cpp
// C++ // C++
int *i = new int; int *i = new int;
*i = 1234; *i = 1234;
@ -254,7 +254,7 @@ fn main() {
This will result an error indicating that the value is no longer in scope: This will result an error indicating that the value is no longer in scope:
```notrust ```text
concurrency.rs:12:20: 12:27 error: use of moved value: 'numbers' concurrency.rs:12:20: 12:27 error: use of moved value: 'numbers'
concurrency.rs:12 println!("{}", numbers.get(0)); concurrency.rs:12 println!("{}", numbers.get(0));
^~~~~~~ ^~~~~~~

View file

@ -356,15 +356,15 @@ msgstr "上記条件を満たしていれば、以下のような手順でビル
#: src/doc/tutorial.md:112 #: src/doc/tutorial.md:112
#, fuzzy #, fuzzy
#| msgid "" #| msgid ""
#| "~~~~ {.notrust} $ curl -O http://static.rust-lang.org/dist/rust-nightly.tar." #| "~~~~console $ curl -O http://static.rust-lang.org/dist/rust-nightly.tar."
#| "gz $ tar -xzf rust-nightly.tar.gz $ cd rust-nightly $ ./configure $ make && make " #| "gz $ tar -xzf rust-nightly.tar.gz $ cd rust-nightly $ ./configure $ make && make "
#| "install ~~~~" #| "install ~~~~"
msgid "" msgid ""
"~~~~ {.notrust} $ curl -O http://static.rust-lang.org/dist/rust-nightly.tar.gz $ " "~~~~console $ curl -O http://static.rust-lang.org/dist/rust-nightly.tar.gz $ "
"tar -xzf rust-nightly.tar.gz $ cd rust-nightly $ ./configure $ make && make install " "tar -xzf rust-nightly.tar.gz $ cd rust-nightly $ ./configure $ make && make install "
"~~~~" "~~~~"
msgstr "" msgstr ""
"~~~~ {.notrust}\n" "~~~~console\n"
"$ curl -O http://static.rust-lang.org/dist/rust-nightly.tar.gz\n" "$ curl -O http://static.rust-lang.org/dist/rust-nightly.tar.gz\n"
"$ tar -xzf rust-nightly.tar.gz $ cd rust-nightly $ ./configure\n" "$ tar -xzf rust-nightly.tar.gz $ cd rust-nightly $ ./configure\n"
"$ make && make install\n" "$ make && make install\n"
@ -4610,7 +4610,7 @@ msgstr ""
#: src/doc/tutorial.md:2761 src/doc/tutorial.md:2793 #: src/doc/tutorial.md:2761 src/doc/tutorial.md:2793
#, fuzzy #, fuzzy
#| msgid "~~~~ {.ignore} let foo = 10;" #| msgid "~~~~ {.ignore} let foo = 10;"
msgid "~~~ {.notrust} src/plants.rs src/plants/mod.rs" msgid "~~~text src/plants.rs src/plants/mod.rs"
msgstr "" msgstr ""
"~~~~ {.ignore}\n" "~~~~ {.ignore}\n"
"let foo = 10;" "let foo = 10;"
@ -4927,24 +4927,24 @@ msgstr ""
#: src/doc/tutorial.md:3168 #: src/doc/tutorial.md:3168
#, fuzzy, no-wrap #, fuzzy, no-wrap
#| msgid "" #| msgid ""
#| "~~~~ {.notrust}\n" #| "~~~~console\n"
#| "> rustc --lib world.rs # compiles libworld-94839cbfe144198-1.0.so\n" #| "$ rustc --lib world.rs # compiles libworld-94839cbfe144198-1.0.so\n"
#| "> rustc main.rs -L . # compiles main\n" #| "$ rustc main.rs -L . # compiles main\n"
#| "> ./main\n" #| "$ ./main\n"
#| "\"hello world\"\n" #| "\"hello world\"\n"
#| "~~~~\n" #| "~~~~\n"
msgid "" msgid ""
"~~~~ {.notrust}\n" "~~~~console\n"
"> rustc --lib world.rs # compiles libworld-<HASH>-0.42.so\n" "$ rustc --crate-type=lib world.rs # compiles libworld-<HASH>-0.42.so\n"
"> rustc main.rs -L . # compiles main\n" "$ rustc main.rs -L . # compiles main\n"
"> ./main\n" "$ ./main\n"
"\"hello world\"\n" "\"hello world\"\n"
"~~~~\n" "~~~~\n"
msgstr "" msgstr ""
"~~~~ {.notrust}\n" "~~~~console\n"
"> rustc --lib world.rs # libworld-94839cbfe144198-1.0.so が生成される\n" "$ rustc --lib world.rs # libworld-94839cbfe144198-1.0.so が生成される\n"
"> rustc main.rs -L . # main が生成される\n" "$ rustc main.rs -L . # main が生成される\n"
"> ./main\n" "$ ./main\n"
"\"hello world\"\n" "\"hello world\"\n"
"~~~~\n" "~~~~\n"

View file

@ -59,7 +59,7 @@ dialect of EBNF supported by common automated LL(k) parsing tools such as
`llgen`, rather than the dialect given in ISO 14977. The dialect can be `llgen`, rather than the dialect given in ISO 14977. The dialect can be
defined self-referentially as follows: defined self-referentially as follows:
~~~~ {.notrust .ebnf .notation} ~~~~ {.ebnf .notation}
grammar : rule + ; grammar : rule + ;
rule : nonterminal ':' productionrule ';' ; rule : nonterminal ':' productionrule ';' ;
productionrule : production [ '|' production ] * ; productionrule : production [ '|' production ] * ;
@ -153,7 +153,7 @@ Some productions are defined by exclusion of particular Unicode characters:
## Comments ## Comments
~~~~ {.notrust .ebnf .gram} ~~~~ {.ebnf .gram}
comment : block_comment | line_comment ; comment : block_comment | line_comment ;
block_comment : "/*" block_comment_body * '*' + '/' ; block_comment : "/*" block_comment_body * '*' + '/' ;
block_comment_body : [block_comment | character] * ; block_comment_body : [block_comment | character] * ;
@ -174,7 +174,7 @@ Non-doc comments are interpreted as a form of whitespace.
## Whitespace ## Whitespace
~~~~ {.notrust .ebnf .gram} ~~~~ {.ebnf .gram}
whitespace_char : '\x20' | '\x09' | '\x0a' | '\x0d' ; whitespace_char : '\x20' | '\x09' | '\x0a' | '\x0d' ;
whitespace : [ whitespace_char | comment ] + ; whitespace : [ whitespace_char | comment ] + ;
~~~~ ~~~~
@ -191,7 +191,7 @@ with any other legal whitespace element, such as a single space character.
## Tokens ## Tokens
~~~~ {.notrust .ebnf .gram} ~~~~ {.ebnf .gram}
simple_token : keyword | unop | binop ; simple_token : keyword | unop | binop ;
token : simple_token | ident | literal | symbol | whitespace token ; token : simple_token | ident | literal | symbol | whitespace token ;
~~~~ ~~~~
@ -205,7 +205,7 @@ grammar as double-quoted strings. Other tokens have exact rules given.
The keywords are the following strings: The keywords are the following strings:
~~~~ {.notrust .keyword} ~~~~ {.text .keyword}
as as
box break box break
continue crate continue crate
@ -233,13 +233,13 @@ evaluates to, rather than referring to it by name or some other evaluation
rule. A literal is a form of constant expression, so is evaluated (primarily) rule. A literal is a form of constant expression, so is evaluated (primarily)
at compile time. at compile time.
~~~~ {.notrust .ebnf .gram} ~~~~ {.ebnf .gram}
literal : string_lit | char_lit | num_lit ; literal : string_lit | char_lit | num_lit ;
~~~~ ~~~~
#### Character and string literals #### Character and string literals
~~~~ {.notrust .ebnf .gram} ~~~~ {.ebnf .gram}
char_lit : '\x27' char_body '\x27' ; char_lit : '\x27' char_body '\x27' ;
string_lit : '"' string_body * '"' | 'r' raw_string ; string_lit : '"' string_body * '"' | 'r' raw_string ;
@ -321,7 +321,7 @@ r##"foo #"# bar"##; // foo #"# bar
#### Number literals #### Number literals
~~~~ {.notrust .ebnf .gram} ~~~~ {.ebnf .gram}
num_lit : nonzero_dec [ dec_digit | '_' ] * num_suffix ? num_lit : nonzero_dec [ dec_digit | '_' ] * num_suffix ?
| '0' [ [ dec_digit | '_' ] * num_suffix ? | '0' [ [ dec_digit | '_' ] * num_suffix ?
| 'b' [ '1' | '0' | '_' ] + int_suffix ? | 'b' [ '1' | '0' | '_' ] + int_suffix ?
@ -419,7 +419,7 @@ The two values of the boolean type are written `true` and `false`.
### Symbols ### Symbols
~~~~ {.notrust .ebnf .gram} ~~~~ {.ebnf .gram}
symbol : "::" "->" symbol : "::" "->"
| '#' | '[' | ']' | '(' | ')' | '{' | '}' | '#' | '[' | ']' | '(' | ')' | '{' | '}'
| ',' | ';' ; | ',' | ';' ;
@ -434,7 +434,7 @@ operators](#binary-operator-expressions), or [keywords](#keywords).
## Paths ## Paths
~~~~ {.notrust .ebnf .gram} ~~~~ {.ebnf .gram}
expr_path : [ "::" ] ident [ "::" expr_path_tail ] + ; expr_path : [ "::" ] ident [ "::" expr_path_tail ] + ;
expr_path_tail : '<' type_expr [ ',' type_expr ] + '>' expr_path_tail : '<' type_expr [ ',' type_expr ] + '>'
| expr_path ; | expr_path ;
@ -543,7 +543,7 @@ All of the above extensions are expressions with values.
## Macros ## Macros
~~~~ {.notrust .ebnf .gram} ~~~~ {.ebnf .gram}
expr_macro_rules : "macro_rules" '!' ident '(' macro_rule * ')' ; expr_macro_rules : "macro_rules" '!' ident '(' macro_rule * ')' ;
macro_rule : '(' matcher * ')' "=>" '(' transcriber * ')' ';' ; macro_rule : '(' matcher * ')' "=>" '(' transcriber * ')' ';' ;
matcher : '(' matcher * ')' | '[' matcher * ']' matcher : '(' matcher * ')' | '[' matcher * ']'
@ -687,7 +687,7 @@ each of which may have some number of [attributes](#attributes) attached to it.
## Items ## Items
~~~~ {.notrust .ebnf .gram} ~~~~ {.ebnf .gram}
item : mod_item | fn_item | type_item | struct_item | enum_item item : mod_item | fn_item | type_item | struct_item | enum_item
| static_item | trait_item | impl_item | extern_block ; | static_item | trait_item | impl_item | extern_block ;
~~~~ ~~~~
@ -735,7 +735,7 @@ That is, Rust has no notion of type abstraction: there are no first-class "foral
### Modules ### Modules
~~~~ {.notrust .ebnf .gram} ~~~~ {.ebnf .gram}
mod_item : "mod" ident ( ';' | '{' mod '}' ); mod_item : "mod" ident ( ';' | '{' mod '}' );
mod : [ view_item | item ] * ; mod : [ view_item | item ] * ;
~~~~ ~~~~
@ -803,7 +803,7 @@ mod task {
#### View items #### View items
~~~~ {.notrust .ebnf .gram} ~~~~ {.ebnf .gram}
view_item : extern_crate_decl | use_decl ; view_item : extern_crate_decl | use_decl ;
~~~~ ~~~~
@ -816,7 +816,7 @@ There are several kinds of view item:
##### Extern crate declarations ##### Extern crate declarations
~~~~ {.notrust .ebnf .gram} ~~~~ {.ebnf .gram}
extern_crate_decl : "extern" "crate" ident [ '(' link_attrs ')' ] ? [ '=' string_lit ] ? ; extern_crate_decl : "extern" "crate" ident [ '(' link_attrs ')' ] ? [ '=' string_lit ] ? ;
link_attrs : link_attr [ ',' link_attrs ] + ; link_attrs : link_attr [ ',' link_attrs ] + ;
link_attr : ident '=' literal ; link_attr : ident '=' literal ;
@ -848,7 +848,7 @@ extern crate foo = "some/where/rust-foo#foo:1.0"; // a full crate ID for externa
##### Use declarations ##### Use declarations
~~~~ {.notrust .ebnf .gram} ~~~~ {.ebnf .gram}
use_decl : "pub" ? "use" [ ident '=' path use_decl : "pub" ? "use" [ ident '=' path
| path_glob ] ; | path_glob ] ;
@ -1274,7 +1274,7 @@ whereas `Dog` is simply called an enum variant.
### Static items ### Static items
~~~~ {.notrust .ebnf .gram} ~~~~ {.ebnf .gram}
static_item : "static" ident ':' type '=' expr ';' ; static_item : "static" ident ':' type '=' expr ';' ;
~~~~ ~~~~
@ -1519,7 +1519,7 @@ impl Seq<bool> for u32 {
### External blocks ### External blocks
~~~~ {.notrust .ebnf .gram} ~~~~ {.ebnf .gram}
extern_block_item : "extern" '{' extern_block '}' ; extern_block_item : "extern" '{' extern_block '}' ;
extern_block : [ foreign_fn ] * ; extern_block : [ foreign_fn ] * ;
~~~~ ~~~~
@ -1741,7 +1741,7 @@ import public items from their destination, not private items.
## Attributes ## Attributes
~~~~ {.notrust .ebnf .gram} ~~~~ {.ebnf .gram}
attribute : '#' '!' ? '[' meta_item ']' ; attribute : '#' '!' ? '[' meta_item ']' ;
meta_item : ident [ '=' literal meta_item : ident [ '=' literal
| '(' meta_seq ')' ] ? ; | '(' meta_seq ')' ] ? ;
@ -2383,7 +2383,7 @@ declaring a function-local item.
#### Slot declarations #### Slot declarations
~~~~ {.notrust .ebnf .gram} ~~~~ {.ebnf .gram}
let_decl : "let" pat [':' type ] ? [ init ] ? ';' ; let_decl : "let" pat [':' type ] ? [ init ] ? ';' ;
init : [ '=' ] expr ; init : [ '=' ] expr ;
~~~~ ~~~~
@ -2483,7 +2483,7 @@ values.
### Structure expressions ### Structure expressions
~~~~ {.notrust .ebnf .gram} ~~~~ {.ebnf .gram}
struct_expr : expr_path '{' ident ':' expr struct_expr : expr_path '{' ident ':' expr
[ ',' ident ':' expr ] * [ ',' ident ':' expr ] *
[ ".." expr ] '}' | [ ".." expr ] '}' |
@ -2537,7 +2537,7 @@ Point3d {y: 0, z: 10, .. base};
### Block expressions ### Block expressions
~~~~ {.notrust .ebnf .gram} ~~~~ {.ebnf .gram}
block_expr : '{' [ view_item ] * block_expr : '{' [ view_item ] *
[ stmt ';' | item ] * [ stmt ';' | item ] *
[ expr ] '}' ; [ expr ] '}' ;
@ -2555,7 +2555,7 @@ of the block are that of the expression itself.
### Method-call expressions ### Method-call expressions
~~~~ {.notrust .ebnf .gram} ~~~~ {.ebnf .gram}
method_call_expr : expr '.' ident paren_expr_list ; method_call_expr : expr '.' ident paren_expr_list ;
~~~~ ~~~~
@ -2566,7 +2566,7 @@ or dynamically dispatching if the left-hand-side expression is an indirect [obje
### Field expressions ### Field expressions
~~~~ {.notrust .ebnf .gram} ~~~~ {.ebnf .gram}
field_expr : expr '.' ident ; field_expr : expr '.' ident ;
~~~~ ~~~~
@ -2588,7 +2588,7 @@ it is automatically dereferenced to make the field access possible.
### Vector expressions ### Vector expressions
~~~~ {.notrust .ebnf .gram} ~~~~ {.ebnf .gram}
vec_expr : '[' "mut" ? vec_elems? ']' ; vec_expr : '[' "mut" ? vec_elems? ']' ;
vec_elems : [expr [',' expr]*] | [expr ',' ".." expr] ; vec_elems : [expr [',' expr]*] | [expr ',' ".." expr] ;
@ -2610,7 +2610,7 @@ as a [literal](#literals) or a [static item](#static-items).
### Index expressions ### Index expressions
~~~~ {.notrust .ebnf .gram} ~~~~ {.ebnf .gram}
idx_expr : expr '[' expr ']' ; idx_expr : expr '[' expr ']' ;
~~~~ ~~~~
@ -2662,7 +2662,7 @@ before the expression they apply to.
### Binary operator expressions ### Binary operator expressions
~~~~ {.notrust .ebnf .gram} ~~~~ {.ebnf .gram}
binop_expr : expr binop expr ; binop_expr : expr binop expr ;
~~~~ ~~~~
@ -2803,7 +2803,7 @@ Any such expression always has the [`unit`](#primitive-types) type.
The precedence of Rust binary operators is ordered as follows, going The precedence of Rust binary operators is ordered as follows, going
from strong to weak: from strong to weak:
~~~~ {.notrust .precedence} ~~~~ {.text .precedence}
* / % * / %
as as
+ - + -
@ -2827,7 +2827,7 @@ An expression enclosed in parentheses evaluates to the result of the enclosed
expression. Parentheses can be used to explicitly specify evaluation order expression. Parentheses can be used to explicitly specify evaluation order
within an expression. within an expression.
~~~~ {.notrust .ebnf .gram} ~~~~ {.ebnf .gram}
paren_expr : '(' expr ')' ; paren_expr : '(' expr ')' ;
~~~~ ~~~~
@ -2840,7 +2840,7 @@ let x = (2 + 3) * 4;
### Call expressions ### Call expressions
~~~~ {.notrust .ebnf .gram} ~~~~ {.ebnf .gram}
expr_list : [ expr [ ',' expr ]* ] ? ; expr_list : [ expr [ ',' expr ]* ] ? ;
paren_expr_list : '(' expr_list ')' ; paren_expr_list : '(' expr_list ')' ;
call_expr : expr paren_expr_list ; call_expr : expr paren_expr_list ;
@ -2863,7 +2863,7 @@ let pi: Option<f32> = FromStr::from_str("3.14");
### Lambda expressions ### Lambda expressions
~~~~ {.notrust .ebnf .gram} ~~~~ {.ebnf .gram}
ident_list : [ ident [ ',' ident ]* ] ? ; ident_list : [ ident [ ',' ident ]* ] ? ;
lambda_expr : '|' ident_list '|' expr ; lambda_expr : '|' ident_list '|' expr ;
~~~~ ~~~~
@ -2906,7 +2906,7 @@ ten_times(|j| println!("hello, {}", j));
### While loops ### While loops
~~~~ {.notrust .ebnf .gram} ~~~~ {.ebnf .gram}
while_expr : "while" expr '{' block '}' ; while_expr : "while" expr '{' block '}' ;
~~~~ ~~~~
@ -2930,7 +2930,7 @@ while i < 10 {
A `loop` expression denotes an infinite loop. A `loop` expression denotes an infinite loop.
~~~~ {.notrust .ebnf .gram} ~~~~ {.ebnf .gram}
loop_expr : [ lifetime ':' ] "loop" '{' block '}'; loop_expr : [ lifetime ':' ] "loop" '{' block '}';
~~~~ ~~~~
@ -2941,7 +2941,7 @@ See [Break expressions](#break-expressions) and [Continue expressions](#continue
### Break expressions ### Break expressions
~~~~ {.notrust .ebnf .gram} ~~~~ {.ebnf .gram}
break_expr : "break" [ lifetime ]; break_expr : "break" [ lifetime ];
~~~~ ~~~~
@ -2954,7 +2954,7 @@ but must enclose it.
### Continue expressions ### Continue expressions
~~~~ {.notrust .ebnf .gram} ~~~~ {.ebnf .gram}
continue_expr : "continue" [ lifetime ]; continue_expr : "continue" [ lifetime ];
~~~~ ~~~~
@ -2973,7 +2973,7 @@ A `continue` expression is only permitted in the body of a loop.
### For expressions ### For expressions
~~~~ {.notrust .ebnf .gram} ~~~~ {.ebnf .gram}
for_expr : "for" pat "in" expr '{' block '}' ; for_expr : "for" pat "in" expr '{' block '}' ;
~~~~ ~~~~
@ -3007,7 +3007,7 @@ for i in range(0u, 256) {
### If expressions ### If expressions
~~~~ {.notrust .ebnf .gram} ~~~~ {.ebnf .gram}
if_expr : "if" expr '{' block '}' if_expr : "if" expr '{' block '}'
else_tail ? ; else_tail ? ;
@ -3028,7 +3028,7 @@ then any `else` block is executed.
### Match expressions ### Match expressions
~~~~ {.notrust .ebnf .gram} ~~~~ {.ebnf .gram}
match_expr : "match" expr '{' match_arm * '}' ; match_expr : "match" expr '{' match_arm * '}' ;
match_arm : attribute * match_pat "=>" [ expr "," | '{' block '}' ] ; match_arm : attribute * match_pat "=>" [ expr "," | '{' block '}' ] ;
@ -3219,7 +3219,7 @@ let message = match maybe_digit {
### Return expressions ### Return expressions
~~~~ {.notrust .ebnf .gram} ~~~~ {.ebnf .gram}
return_expr : "return" expr ? ; return_expr : "return" expr ? ;
~~~~ ~~~~
@ -3496,7 +3496,7 @@ x = bo(5,7);
### Closure types ### Closure types
~~~~ {.notrust .ebnf .notation} ~~~~ {.ebnf .notation}
closure_type := [ 'unsafe' ] [ '<' lifetime-list '>' ] '|' arg-list '|' closure_type := [ 'unsafe' ] [ '<' lifetime-list '>' ] '|' arg-list '|'
[ ':' bound-list ] [ '->' type ] [ ':' bound-list ] [ '->' type ]
procedure_type := 'proc' [ '<' lifetime-list '>' ] '(' arg-list ')' procedure_type := 'proc' [ '<' lifetime-list '>' ] '(' arg-list ')'
@ -4107,7 +4107,7 @@ fn main() {
These four log levels correspond to levels 1-4, as controlled by `RUST_LOG`: These four log levels correspond to levels 1-4, as controlled by `RUST_LOG`:
```notrust,bash ```sh
$ RUST_LOG=rust=3 ./rust $ RUST_LOG=rust=3 ./rust
This is an error log This is an error log
This is a warn log This is a warn log

View file

@ -122,33 +122,41 @@ source code.
To test documentation, the `--test` argument is passed to rustdoc: To test documentation, the `--test` argument is passed to rustdoc:
~~~ {.notrust} ~~~ {.sh}
rustdoc --test crate.rs rustdoc --test crate.rs
~~~ ~~~
## Defining tests ## Defining tests
Rust documentation currently uses the markdown format, and rustdoc treats all Rust documentation currently uses the markdown format, and rustdoc treats all
code blocks as testable-by-default. In order to not run a test over a block of code blocks as testable-by-default unless they carry a language tag of another
code, the `ignore` string can be added to the three-backtick form of markdown language. In order to not run a test over a block of code, the `ignore` string
code block. can be added to the three-backtick form of markdown code block.
~~~notrust ~~~md
``` ```
// This is a testable code block // This is a testable code block
``` ```
```rust{.example}
// This is rust and also testable
```
```ignore ```ignore
// This is not a testable code block // This is not a testable code block
``` ```
// This is a testable code block (4-space indent) // This is a testable code block (4-space indent)
```sh
# this is shell code and not tested
```
~~~ ~~~
You can specify that the test's execution should fail with the `should_fail` You can specify that the test's execution should fail with the `should_fail`
directive. directive.
~~~notrust ~~~md
```should_fail ```should_fail
// This code block is expected to generate a failure when run // This code block is expected to generate a failure when run
``` ```
@ -157,7 +165,7 @@ directive.
You can specify that the code block should be compiled but not run with the You can specify that the code block should be compiled but not run with the
`no_run` directive. `no_run` directive.
~~~notrust ~~~md
```no_run ```no_run
// This code will be compiled but not executed // This code will be compiled but not executed
``` ```
@ -169,7 +177,7 @@ will not show up in the HTML documentation, but it will be used when
testing the code block (NB. the space after the `#` is required, so testing the code block (NB. the space after the `#` is required, so
that one can still write things like `#[deriving(Eq)]`). that one can still write things like `#[deriving(Eq)]`).
~~~notrust ~~~md
``` ```
# /!\ The three following lines are comments, which are usually stripped off by # /!\ The three following lines are comments, which are usually stripped off by
# the doc-generating tool. In order to display them anyway in this particular # the doc-generating tool. In order to display them anyway in this particular
@ -194,7 +202,7 @@ uses is build on crate `test`, which is also used when you compile crates with
rustc's `--test` flag. Extra arguments can be passed to rustdoc's test harness rustc's `--test` flag. Extra arguments can be passed to rustdoc's test harness
with the `--test-args` flag. with the `--test-args` flag.
~~~ {.notrust} ~~~console
# Only run tests containing 'foo' in their name # Only run tests containing 'foo' in their name
$ rustdoc --test lib.rs --test-args 'foo' $ rustdoc --test lib.rs --test-args 'foo'

View file

@ -106,7 +106,7 @@ packages:
If you've fulfilled those prerequisites, something along these lines If you've fulfilled those prerequisites, something along these lines
should work. should work.
~~~~ {.notrust} ~~~~console
$ curl -O http://static.rust-lang.org/dist/rust-nightly.tar.gz $ curl -O http://static.rust-lang.org/dist/rust-nightly.tar.gz
$ tar -xzf rust-nightly.tar.gz $ tar -xzf rust-nightly.tar.gz
$ cd rust-nightly $ cd rust-nightly
@ -151,7 +151,7 @@ error. If you introduce an error into the program (for example, by changing
`println!` to some nonexistent macro), and then compile it, you'll see `println!` to some nonexistent macro), and then compile it, you'll see
an error message like this: an error message like this:
~~~~ {.notrust} ~~~~text
hello.rs:2:5: 2:24 error: macro undefined: 'print_with_unicorns' hello.rs:2:5: 2:24 error: macro undefined: 'print_with_unicorns'
hello.rs:2 print_with_unicorns!("hello?"); hello.rs:2 print_with_unicorns!("hello?");
^~~~~~~~~~~~~~~~~~~ ^~~~~~~~~~~~~~~~~~~
@ -1066,7 +1066,7 @@ being destroyed along with the owner. Since the `list` variable above is
immutable, the whole list is immutable. The memory allocation itself is the immutable, the whole list is immutable. The memory allocation itself is the
box, while the owner holds onto a pointer to it: box, while the owner holds onto a pointer to it:
~~~ {.notrust} ~~~text
List box List box List box List box List box List box List box List box
+--------------+ +--------------+ +--------------+ +----------+ +--------------+ +--------------+ +--------------+ +----------+
list -> | Cons | 1 | | -> | Cons | 2 | | -> | Cons | 3 | | -> | Nil | list -> | Cons | 1 | | -> | Cons | 2 | | -> | Cons | 3 | | -> | Nil |
@ -2841,7 +2841,7 @@ mod animals {
The compiler will look for these files, in this order: The compiler will look for these files, in this order:
~~~ {.notrust} ~~~text
src/plants.rs src/plants.rs
src/plants/mod.rs src/plants/mod.rs
@ -2872,7 +2872,7 @@ mod mammals {
...then the source files of `mod animals`'s submodules can either be in the same directory as the animals source file or in a subdirectory of its directory. If the animals file is `src/animals.rs`, `rustc` will look for: ...then the source files of `mod animals`'s submodules can either be in the same directory as the animals source file or in a subdirectory of its directory. If the animals file is `src/animals.rs`, `rustc` will look for:
~~~ {.notrust} ~~~text
src/animals.rs src/animals.rs
src/fish.rs src/fish.rs
src/fish/mod.rs src/fish/mod.rs
@ -2883,7 +2883,7 @@ src/animals.rs
If the animals file is `src/animals/mod.rs`, `rustc` will look for: If the animals file is `src/animals/mod.rs`, `rustc` will look for:
~~~ {.notrust} ~~~text
src/animals/mod.rs src/animals/mod.rs
src/animals/fish.rs src/animals/fish.rs
src/animals/fish/mod.rs src/animals/fish/mod.rs
@ -3244,10 +3244,10 @@ fn main() { println!("hello {}", world::explore()); }
Now compile and run like this (adjust to your platform if necessary): Now compile and run like this (adjust to your platform if necessary):
~~~~ {.notrust} ~~~~console
> rustc --crate-type=lib world.rs # compiles libworld-<HASH>-0.42.so $ rustc --crate-type=lib world.rs # compiles libworld-<HASH>-0.42.so
> rustc main.rs -L . # compiles main $ rustc main.rs -L . # compiles main
> ./main $ ./main
"hello world" "hello world"
~~~~ ~~~~

View file

@ -59,7 +59,7 @@ pub trait Zero: Add<Self, Self> {
/// ///
/// # Laws /// # Laws
/// ///
/// ~~~notrust /// ~~~text
/// a + 0 = a ∀ a ∈ Self /// a + 0 = a ∀ a ∈ Self
/// 0 + a = a ∀ a ∈ Self /// 0 + a = a ∀ a ∈ Self
/// ~~~ /// ~~~
@ -123,7 +123,7 @@ pub trait One: Mul<Self, Self> {
/// ///
/// # Laws /// # Laws
/// ///
/// ~~~notrust /// ~~~text
/// a * 1 = a ∀ a ∈ Self /// a * 1 = a ∀ a ∈ Self
/// 1 * a = a ∀ a ∈ Self /// 1 * a = a ∀ a ∈ Self
/// ~~~ /// ~~~

View file

@ -57,7 +57,7 @@ disabled except for `error!` (a log level of 1). Logging is controlled via the
`RUST_LOG` environment variable. The value of this environment variable is a `RUST_LOG` environment variable. The value of this environment variable is a
comma-separated list of logging directives. A logging directive is of the form: comma-separated list of logging directives. A logging directive is of the form:
```notrust ```text
path::to::module=log_level path::to::module=log_level
``` ```
@ -80,7 +80,7 @@ all modules is set to this value.
Some examples of valid values of `RUST_LOG` are: Some examples of valid values of `RUST_LOG` are:
```notrust ```text
hello // turns on all logging for the 'hello' module hello // turns on all logging for the 'hello' module
info // turns on all info logging info // turns on all info logging
hello=debug // turns on debug logging for 'hello' hello=debug // turns on debug logging for 'hello'

View file

@ -20,7 +20,7 @@ use super::{IndependentSample, Sample, Exp};
/// ///
/// The density function of this distribution is /// The density function of this distribution is
/// ///
/// ```notrust /// ```text
/// f(x) = x^(k - 1) * exp(-x / θ) / (Γ(k) * θ^k) /// f(x) = x^(k - 1) * exp(-x / θ) / (Γ(k) * θ^k)
/// ``` /// ```
/// ///

View file

@ -56,7 +56,7 @@ it is safe with respect to the in-scope loans.
Throughout the docs we'll consider a simple subset of Rust in which Throughout the docs we'll consider a simple subset of Rust in which
you can only borrow from lvalues, defined like so: you can only borrow from lvalues, defined like so:
```notrust ```text
LV = x | LV.f | *LV LV = x | LV.f | *LV
``` ```
@ -64,7 +64,7 @@ Here `x` represents some variable, `LV.f` is a field reference,
and `*LV` is a pointer dereference. There is no auto-deref or other and `*LV` is a pointer dereference. There is no auto-deref or other
niceties. This means that if you have a type like: niceties. This means that if you have a type like:
```notrust ```text
struct S { f: uint } struct S { f: uint }
``` ```
@ -73,7 +73,7 @@ to an `LV` of `(*a).f`.
Here is the formal grammar for the types we'll consider: Here is the formal grammar for the types we'll consider:
```notrust ```text
TY = () | S<'LT...> | Box<TY> | & 'LT MQ TY | @ MQ TY TY = () | S<'LT...> | Box<TY> | & 'LT MQ TY | @ MQ TY
MQ = mut | imm | const MQ = mut | imm | const
``` ```
@ -81,7 +81,7 @@ MQ = mut | imm | const
Most of these types should be pretty self explanatory. Here `S` is a Most of these types should be pretty self explanatory. Here `S` is a
struct name and we assume structs are declared like so: struct name and we assume structs are declared like so:
```notrust ```text
SD = struct S<'LT...> { (f: TY)... } SD = struct S<'LT...> { (f: TY)... }
``` ```
@ -93,7 +93,7 @@ SD = struct S<'LT...> { (f: TY)... }
Now, imagine we had a program like this: Now, imagine we had a program like this:
```notrust ```text
struct Foo { f: uint, g: uint } struct Foo { f: uint, g: uint }
... ...
'a: { 'a: {
@ -118,7 +118,7 @@ the borrow, and (3) a set of restrictions. In the code, `Loan` is a
struct defined in `middle::borrowck`. Formally, we define `LOAN` as struct defined in `middle::borrowck`. Formally, we define `LOAN` as
follows: follows:
```notrust ```text
LOAN = (LV, LT, MQ, RESTRICTION*) LOAN = (LV, LT, MQ, RESTRICTION*)
RESTRICTION = (LV, ACTION*) RESTRICTION = (LV, ACTION*)
ACTION = MUTATE | CLAIM | FREEZE ACTION = MUTATE | CLAIM | FREEZE
@ -151,7 +151,7 @@ To give you a better feeling for what kind of restrictions derived
from a loan, let's look at the loan `L` that would be issued as a from a loan, let's look at the loan `L` that would be issued as a
result of the borrow `&mut (*x).f` in the example above: result of the borrow `&mut (*x).f` in the example above:
```notrust ```text
L = ((*x).f, 'a, mut, RS) where L = ((*x).f, 'a, mut, RS) where
RS = [((*x).f, [MUTATE, CLAIM, FREEZE]), RS = [((*x).f, [MUTATE, CLAIM, FREEZE]),
(*x, [MUTATE, CLAIM, FREEZE]), (*x, [MUTATE, CLAIM, FREEZE]),
@ -214,7 +214,7 @@ conditions that it uses. For simplicity I will ignore const loans.
I will present the rules in a modified form of standard inference I will present the rules in a modified form of standard inference
rules, which looks as follows: rules, which looks as follows:
```notrust ```text
PREDICATE(X, Y, Z) // Rule-Name PREDICATE(X, Y, Z) // Rule-Name
Condition 1 Condition 1
Condition 2 Condition 2
@ -290,7 +290,7 @@ Let's begin with the rules for variables, which state that if a
variable is declared as mutable, it may be borrowed any which way, but variable is declared as mutable, it may be borrowed any which way, but
otherwise the variable must be borrowed as immutable or const: otherwise the variable must be borrowed as immutable or const:
```notrust ```text
MUTABILITY(X, MQ) // M-Var-Mut MUTABILITY(X, MQ) // M-Var-Mut
DECL(X) = mut DECL(X) = mut
@ -305,7 +305,7 @@ Fields and owned pointers inherit their mutability from
their base expressions, so both of their rules basically their base expressions, so both of their rules basically
delegate the check to the base expression `LV`: delegate the check to the base expression `LV`:
```notrust ```text
MUTABILITY(LV.f, MQ) // M-Field MUTABILITY(LV.f, MQ) // M-Field
MUTABILITY(LV, MQ) MUTABILITY(LV, MQ)
@ -319,7 +319,7 @@ MUTABILITY(*LV, MQ) // M-Deref-Unique
Immutable pointer types like `&T` and `@T` can only Immutable pointer types like `&T` and `@T` can only
be borrowed if MQ is immutable or const: be borrowed if MQ is immutable or const:
```notrust ```text
MUTABILITY(*LV, MQ) // M-Deref-Borrowed-Imm MUTABILITY(*LV, MQ) // M-Deref-Borrowed-Imm
TYPE(LV) = &Ty TYPE(LV) = &Ty
MQ == imm | const MQ == imm | const
@ -333,7 +333,7 @@ MUTABILITY(*LV, MQ) // M-Deref-Managed-Imm
`&mut T` can be frozen, so it is acceptable to borrow it as either imm or mut: `&mut T` can be frozen, so it is acceptable to borrow it as either imm or mut:
```notrust ```text
MUTABILITY(*LV, MQ) // M-Deref-Borrowed-Mut MUTABILITY(*LV, MQ) // M-Deref-Borrowed-Mut
TYPE(LV) = &mut Ty TYPE(LV) = &mut Ty
``` ```
@ -352,7 +352,7 @@ Rust code corresponding to this predicate is the function
Local variables are never aliasable as they are accessible only within Local variables are never aliasable as they are accessible only within
the stack frame. the stack frame.
```notrust ```text
ALIASABLE(X, MQ) // M-Var-Mut ALIASABLE(X, MQ) // M-Var-Mut
``` ```
@ -360,7 +360,7 @@ the stack frame.
Owned content is aliasable if it is found in an aliasable location: Owned content is aliasable if it is found in an aliasable location:
```notrust ```text
ALIASABLE(LV.f, MQ) // M-Field ALIASABLE(LV.f, MQ) // M-Field
ALIASABLE(LV, MQ) ALIASABLE(LV, MQ)
@ -373,7 +373,7 @@ ALIASABLE(*LV, MQ) // M-Deref-Unique
Immutable pointer types like `&T` are aliasable, and hence can only be Immutable pointer types like `&T` are aliasable, and hence can only be
borrowed immutably: borrowed immutably:
```notrust ```text
ALIASABLE(*LV, imm) // M-Deref-Borrowed-Imm ALIASABLE(*LV, imm) // M-Deref-Borrowed-Imm
TYPE(LV) = &Ty TYPE(LV) = &Ty
``` ```
@ -382,7 +382,7 @@ ALIASABLE(*LV, imm) // M-Deref-Borrowed-Imm
`&mut T` can be frozen, so it is acceptable to borrow it as either imm or mut: `&mut T` can be frozen, so it is acceptable to borrow it as either imm or mut:
```notrust ```text
ALIASABLE(*LV, MQ) // M-Deref-Borrowed-Mut ALIASABLE(*LV, MQ) // M-Deref-Borrowed-Mut
TYPE(LV) = &mut Ty TYPE(LV) = &mut Ty
``` ```
@ -405,13 +405,13 @@ guaranteed to exist, presuming that no mutations occur.
The scope of a local variable is the block where it is declared: The scope of a local variable is the block where it is declared:
```notrust ```text
SCOPE(X) = block where X is declared SCOPE(X) = block where X is declared
``` ```
The scope of a field is the scope of the struct: The scope of a field is the scope of the struct:
```notrust ```text
SCOPE(LV.f) = SCOPE(LV) SCOPE(LV.f) = SCOPE(LV)
``` ```
@ -419,7 +419,7 @@ The scope of a unique referent is the scope of the pointer, since
(barring mutation or moves) the pointer will not be freed until (barring mutation or moves) the pointer will not be freed until
the pointer itself `LV` goes out of scope: the pointer itself `LV` goes out of scope:
```notrust ```text
SCOPE(*LV) = SCOPE(LV) if LV has type Box<T> SCOPE(*LV) = SCOPE(LV) if LV has type Box<T>
``` ```
@ -427,7 +427,7 @@ The scope of a managed referent is also the scope of the pointer. This
is a conservative approximation, since there may be other aliases for is a conservative approximation, since there may be other aliases for
that same managed box that would cause it to live longer: that same managed box that would cause it to live longer:
```notrust ```text
SCOPE(*LV) = SCOPE(LV) if LV has type @T SCOPE(*LV) = SCOPE(LV) if LV has type @T
``` ```
@ -435,7 +435,7 @@ The scope of a borrowed referent is the scope associated with the
pointer. This is a conservative approximation, since the data that pointer. This is a conservative approximation, since the data that
the pointer points at may actually live longer: the pointer points at may actually live longer:
```notrust ```text
SCOPE(*LV) = LT if LV has type &'LT T or &'LT mut T SCOPE(*LV) = LT if LV has type &'LT T or &'LT mut T
``` ```
@ -444,7 +444,7 @@ the pointer points at may actually live longer:
The rule for variables states that a variable can only be borrowed a The rule for variables states that a variable can only be borrowed a
lifetime `LT` that is a subregion of the variable's scope: lifetime `LT` that is a subregion of the variable's scope:
```notrust ```text
LIFETIME(X, LT, MQ) // L-Local LIFETIME(X, LT, MQ) // L-Local
LT <= SCOPE(X) LT <= SCOPE(X)
``` ```
@ -454,7 +454,7 @@ LIFETIME(X, LT, MQ) // L-Local
The lifetime of a field or owned pointer is the same as the lifetime The lifetime of a field or owned pointer is the same as the lifetime
of its owner: of its owner:
```notrust ```text
LIFETIME(LV.f, LT, MQ) // L-Field LIFETIME(LV.f, LT, MQ) // L-Field
LIFETIME(LV, LT, MQ) LIFETIME(LV, LT, MQ)
@ -471,7 +471,7 @@ lifetime. Therefore, the borrow is valid so long as the lifetime `LT`
of the borrow is shorter than the lifetime `LT'` of the pointer of the borrow is shorter than the lifetime `LT'` of the pointer
itself: itself:
```notrust ```text
LIFETIME(*LV, LT, MQ) // L-Deref-Borrowed LIFETIME(*LV, LT, MQ) // L-Deref-Borrowed
TYPE(LV) = &LT' Ty OR &LT' mut Ty TYPE(LV) = &LT' Ty OR &LT' mut Ty
LT <= LT' LT <= LT'
@ -484,7 +484,7 @@ Managed pointers are valid so long as the data within them is
when the user guarantees such a root will exist. For this to be true, when the user guarantees such a root will exist. For this to be true,
three conditions must be met: three conditions must be met:
```notrust ```text
LIFETIME(*LV, LT, MQ) // L-Deref-Managed-Imm-User-Root LIFETIME(*LV, LT, MQ) // L-Deref-Managed-Imm-User-Root
TYPE(LV) = @Ty TYPE(LV) = @Ty
LT <= SCOPE(LV) // (1) LT <= SCOPE(LV) // (1)
@ -518,7 +518,7 @@ borrow without crossing the exit from the scope `LT`.
The rule for compiler rooting is as follows: The rule for compiler rooting is as follows:
```notrust ```text
LIFETIME(*LV, LT, MQ) // L-Deref-Managed-Imm-Compiler-Root LIFETIME(*LV, LT, MQ) // L-Deref-Managed-Imm-Compiler-Root
TYPE(LV) = @Ty TYPE(LV) = @Ty
LT <= innermost enclosing loop/func LT <= innermost enclosing loop/func
@ -542,7 +542,7 @@ for the lifetime of the loan".
Note that there is an initial set of restrictions: these restrictions Note that there is an initial set of restrictions: these restrictions
are computed based on the kind of borrow: are computed based on the kind of borrow:
```notrust ```text
&mut LV => RESTRICTIONS(LV, LT, MUTATE|CLAIM|FREEZE) &mut LV => RESTRICTIONS(LV, LT, MUTATE|CLAIM|FREEZE)
&LV => RESTRICTIONS(LV, LT, MUTATE|CLAIM) &LV => RESTRICTIONS(LV, LT, MUTATE|CLAIM)
&const LV => RESTRICTIONS(LV, LT, []) &const LV => RESTRICTIONS(LV, LT, [])
@ -559,7 +559,7 @@ moved out from under it, so no actions are forbidden.
The simplest case is a borrow of a local variable `X`: The simplest case is a borrow of a local variable `X`:
```notrust ```text
RESTRICTIONS(X, LT, ACTIONS) = (X, ACTIONS) // R-Variable RESTRICTIONS(X, LT, ACTIONS) = (X, ACTIONS) // R-Variable
``` ```
@ -570,7 +570,7 @@ In such cases we just record the actions that are not permitted.
Restricting a field is the same as restricting the owner of that Restricting a field is the same as restricting the owner of that
field: field:
```notrust ```text
RESTRICTIONS(LV.f, LT, ACTIONS) = RS, (LV.f, ACTIONS) // R-Field RESTRICTIONS(LV.f, LT, ACTIONS) = RS, (LV.f, ACTIONS) // R-Field
RESTRICTIONS(LV, LT, ACTIONS) = RS RESTRICTIONS(LV, LT, ACTIONS) = RS
``` ```
@ -593,7 +593,7 @@ must prevent the owned pointer `LV` from being mutated, which means
that we always add `MUTATE` and `CLAIM` to the restriction set imposed that we always add `MUTATE` and `CLAIM` to the restriction set imposed
on `LV`: on `LV`:
```notrust ```text
RESTRICTIONS(*LV, LT, ACTIONS) = RS, (*LV, ACTIONS) // R-Deref-Send-Pointer RESTRICTIONS(*LV, LT, ACTIONS) = RS, (*LV, ACTIONS) // R-Deref-Send-Pointer
TYPE(LV) = Box<Ty> TYPE(LV) = Box<Ty>
RESTRICTIONS(LV, LT, ACTIONS|MUTATE|CLAIM) = RS RESTRICTIONS(LV, LT, ACTIONS|MUTATE|CLAIM) = RS
@ -610,7 +610,7 @@ restricting that path. Therefore, the rule for `&Ty` and `@Ty`
pointers always returns an empty set of restrictions, and it only pointers always returns an empty set of restrictions, and it only
permits restricting `MUTATE` and `CLAIM` actions: permits restricting `MUTATE` and `CLAIM` actions:
```notrust ```text
RESTRICTIONS(*LV, LT, ACTIONS) = [] // R-Deref-Imm-Managed RESTRICTIONS(*LV, LT, ACTIONS) = [] // R-Deref-Imm-Managed
TYPE(LV) = @Ty TYPE(LV) = @Ty
ACTIONS subset of [MUTATE, CLAIM] ACTIONS subset of [MUTATE, CLAIM]
@ -733,7 +733,7 @@ Because moves from a `&const` or `@const` lvalue are never legal, it
is not necessary to add any restrictions at all to the final is not necessary to add any restrictions at all to the final
result. result.
```notrust ```text
RESTRICTIONS(*LV, LT, []) = [] // R-Deref-Freeze-Borrowed RESTRICTIONS(*LV, LT, []) = [] // R-Deref-Freeze-Borrowed
TYPE(LV) = &const Ty or @const Ty TYPE(LV) = &const Ty or @const Ty
``` ```
@ -749,7 +749,7 @@ while the new claimant is live.
The rule for mutable borrowed pointers is as follows: The rule for mutable borrowed pointers is as follows:
```notrust ```text
RESTRICTIONS(*LV, LT, ACTIONS) = RS, (*LV, ACTIONS) // R-Deref-Mut-Borrowed RESTRICTIONS(*LV, LT, ACTIONS) = RS, (*LV, ACTIONS) // R-Deref-Mut-Borrowed
TYPE(LV) = &LT' mut Ty TYPE(LV) = &LT' mut Ty
LT <= LT' // (1) LT <= LT' // (1)

View file

@ -45,7 +45,7 @@ There are several critical invariants which we maintain:
> types lie in between. The bottom type is then the Null type. > types lie in between. The bottom type is then the Null type.
> So the tree looks like: > So the tree looks like:
> >
> ```notrust > ```text
> Object > Object
> / \ > / \
> String Other > String Other
@ -106,7 +106,7 @@ Pictorally, what this does is to take two distinct variables with
(hopefully not completely) distinct type ranges and produce one with (hopefully not completely) distinct type ranges and produce one with
the intersection. the intersection.
```notrust ```text
B.ub B.ub B.ub B.ub
/\ / /\ /
A.ub / \ A.ub / A.ub / \ A.ub /
@ -129,7 +129,7 @@ bounds in such a way that, whatever happens, we know that A <: B will hold.
This can be achieved by ensuring that A.ub <: B.lb. In practice there This can be achieved by ensuring that A.ub <: B.lb. In practice there
are two ways to do that, depicted pictorally here: are two ways to do that, depicted pictorally here:
```notrust ```text
Before Option #1 Option #2 Before Option #1 Option #2
B.ub B.ub B.ub B.ub B.ub B.ub
@ -164,7 +164,7 @@ course, it depends on the program.
The main case which fails today that I would like to support is: The main case which fails today that I would like to support is:
```notrust ```text
fn foo<T>(x: T, y: T) { ... } fn foo<T>(x: T, y: T) { ... }
fn bar() { fn bar() {

View file

@ -168,7 +168,8 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result {
slice::raw::buf_as_slice((*lang).data, slice::raw::buf_as_slice((*lang).data,
(*lang).size as uint, |rlang| { (*lang).size as uint, |rlang| {
let rlang = str::from_utf8(rlang).unwrap(); let rlang = str::from_utf8(rlang).unwrap();
if rlang.contains("notrust") { let (_,_,_,notrust) = parse_lang_string(rlang);
if notrust {
(my_opaque.dfltblk)(ob, &buf, lang, (my_opaque.dfltblk)(ob, &buf, lang,
opaque as *mut libc::c_void); opaque as *mut libc::c_void);
true true

View file

@ -85,7 +85,7 @@ function, but the `format!` macro is a syntax extension which allows it to
leverage named parameters. Named parameters are listed at the end of the leverage named parameters. Named parameters are listed at the end of the
argument list and have the syntax: argument list and have the syntax:
```notrust ```text
identifier '=' expression identifier '=' expression
``` ```
@ -110,7 +110,7 @@ Each argument's type is dictated by the format string. It is a requirement that
every argument is only ever referred to by one type. For example, this is an every argument is only ever referred to by one type. For example, this is an
invalid format string: invalid format string:
```notrust ```text
{0:d} {0:s} {0:d} {0:s}
``` ```
@ -126,7 +126,7 @@ must have the type `uint`. Although a `uint` can be printed with `{:u}`, it is
illegal to reference an argument as such. For example, this is another invalid illegal to reference an argument as such. For example, this is another invalid
format string: format string:
```notrust ```text
{:.*s} {0:u} {:.*s} {0:u}
``` ```
@ -347,7 +347,7 @@ This example is the equivalent of `{0:s}` essentially.
The select method is a switch over a `&str` parameter, and the parameter *must* The select method is a switch over a `&str` parameter, and the parameter *must*
be of the type `&str`. An example of the syntax is: be of the type `&str`. An example of the syntax is:
```notrust ```text
{0, select, male{...} female{...} other{...}} {0, select, male{...} female{...} other{...}}
``` ```
@ -366,7 +366,7 @@ The plural method is a switch statement over a `uint` parameter, and the
parameter *must* be a `uint`. A plural method in its full glory can be specified parameter *must* be a `uint`. A plural method in its full glory can be specified
as: as:
```notrust ```text
{0, plural, offset=1 =1{...} two{...} many{...} other{...}} {0, plural, offset=1 =1{...} two{...} many{...} other{...}}
``` ```
@ -394,7 +394,7 @@ should not be too alien. Arguments are formatted with python-like syntax,
meaning that arguments are surrounded by `{}` instead of the C-like `%`. The meaning that arguments are surrounded by `{}` instead of the C-like `%`. The
actual grammar for the formatting syntax is: actual grammar for the formatting syntax is:
```notrust ```text
format_string := <text> [ format <text> ] * format_string := <text> [ format <text> ] *
format := '{' [ argument ] [ ':' format_spec ] [ ',' function_spec ] '}' format := '{' [ argument ] [ ':' format_spec ] [ ',' function_spec ] '}'
argument := integer | identifier argument := integer | identifier

View file

@ -102,7 +102,7 @@ above `PartialEq`, `A`, `B` and `C`.
When generating the `expr` for the `A` impl, the `SubstructureFields` is When generating the `expr` for the `A` impl, the `SubstructureFields` is
~~~notrust ~~~text
Struct(~[FieldInfo { Struct(~[FieldInfo {
span: <span of x> span: <span of x>
name: Some(<ident of x>), name: Some(<ident of x>),
@ -113,7 +113,7 @@ Struct(~[FieldInfo {
For the `B` impl, called with `B(a)` and `B(b)`, For the `B` impl, called with `B(a)` and `B(b)`,
~~~notrust ~~~text
Struct(~[FieldInfo { Struct(~[FieldInfo {
span: <span of `int`>, span: <span of `int`>,
name: None, name: None,
@ -127,7 +127,7 @@ Struct(~[FieldInfo {
When generating the `expr` for a call with `self == C0(a)` and `other When generating the `expr` for a call with `self == C0(a)` and `other
== C0(b)`, the SubstructureFields is == C0(b)`, the SubstructureFields is
~~~notrust ~~~text
EnumMatching(0, <ast::Variant for C0>, EnumMatching(0, <ast::Variant for C0>,
~[FieldInfo { ~[FieldInfo {
span: <span of int> span: <span of int>
@ -139,7 +139,7 @@ EnumMatching(0, <ast::Variant for C0>,
For `C1 {x}` and `C1 {x}`, For `C1 {x}` and `C1 {x}`,
~~~notrust ~~~text
EnumMatching(1, <ast::Variant for C1>, EnumMatching(1, <ast::Variant for C1>,
~[FieldInfo { ~[FieldInfo {
span: <span of x> span: <span of x>
@ -151,7 +151,7 @@ EnumMatching(1, <ast::Variant for C1>,
For `C0(a)` and `C1 {x}` , For `C0(a)` and `C1 {x}` ,
~~~notrust ~~~text
EnumNonMatching(~[(0, <ast::Variant for B0>, EnumNonMatching(~[(0, <ast::Variant for B0>,
~[(<span of int>, None, <expr for &a>)]), ~[(<span of int>, None, <expr for &a>)]),
(1, <ast::Variant for B1>, (1, <ast::Variant for B1>,
@ -165,7 +165,7 @@ EnumNonMatching(~[(0, <ast::Variant for B0>,
A static method on the above would result in, A static method on the above would result in,
~~~~notrust ~~~text
StaticStruct(<ast::StructDef of A>, Named(~[(<ident of x>, <span of x>)])) StaticStruct(<ast::StructDef of A>, Named(~[(<ident of x>, <span of x>)]))
StaticStruct(<ast::StructDef of B>, Unnamed(~[<span of x>])) StaticStruct(<ast::StructDef of B>, Unnamed(~[<span of x>]))
@ -792,7 +792,7 @@ impl<'a> MethodDef<'a> {
/** /**
Creates the nested matches for an enum definition recursively, i.e. Creates the nested matches for an enum definition recursively, i.e.
~~~notrust ~~~text
match self { match self {
Variant1 => match other { Variant1 => matching, Variant2 => nonmatching, ... }, Variant1 => match other { Variant1 => matching, Variant2 => nonmatching, ... },
Variant2 => match other { Variant1 => nonmatching, Variant2 => matching, ... }, Variant2 => match other { Variant1 => nonmatching, Variant2 => matching, ... },