Update extract-tests.py to use same test directives as rustdoc.

Closes #11362.
This commit is contained in:
William Ting 2014-01-11 20:25:19 -06:00
parent b3d10f4383
commit 9f60e7c306
18 changed files with 333 additions and 208 deletions

View File

@ -351,7 +351,7 @@ Vincent Belliard <vincent@famillebelliard.fr>
Vivek Galatage <vivekgalatage@gmail.com>
Volker Mische <volker.mische@gmail.com>
Wade Mealing <wmealing@gmail.com>
William Ting <william.h.ting@gmail.com>
William Ting <io@williamting.com>
Yasuhiro Fujii <y-fujii@mimosa-pudica.net>
Young-il Choi <duddlf.choi@samsung.com>
Youngmin Yoo <youngmin.yoo@samsung.com>

View File

@ -48,7 +48,7 @@ let y: i64 = x.unwrap();
Use [`File::open`](http://static.rust-lang.org/doc/master/std/io/fs/struct.File.html#method.open) to create a [`File`](http://static.rust-lang.org/doc/master/std/io/fs/struct.File.html) struct, which implements the [`Reader`](http://static.rust-lang.org/doc/master/std/io/trait.Reader.html) trait.
~~~ {.xfail-test}
~~~ {.ignore}
use std::path::Path;
use std::io::fs::File;
@ -168,7 +168,7 @@ let _ = close(Door::<Open>(~"front"));
Attempting to close a closed door is prevented statically:
~~~ {.xfail-test}
~~~ {.ignore}
let _ = close(Door::<Closed>(~"front")); // error: mismatched types: expected `main::Door<main::Open>` but found `main::Door<main::Closed>`
~~~
@ -196,7 +196,7 @@ Window* createWindow(int width, int height);
You can use a zero-element `enum` ([phantom type](#how-do-i-express-phantom-types)) to represent the opaque object handle. The FFI would look like this:
~~~ {.xfail-test}
~~~ {.ignore}
enum Window {}
extern "C" {
fn createWindow(width: c_int, height: c_int) -> *Window;

View File

@ -45,7 +45,6 @@ An example program that does this task reads like this:
~~~~
# #[allow(unused_imports)];
# extern mod extra;
use std::io::{BufferedReader, File};
# mod BufferedReader {
# use std::io::File;
@ -243,7 +242,6 @@ and trapping its exit status using `task::try`:
~~~~
# #[allow(unused_imports)];
# extern mod extra;
use std::io::{BufferedReader, File};
use std::task;
# mod BufferedReader {
@ -347,7 +345,6 @@ but similarly clear as the version that used `fail!` in the logic where the erro
~~~~
# #[allow(unused_imports)];
# extern mod extra;
use std::io::{BufferedReader, File};
# mod BufferedReader {
# use std::io::File;
@ -416,7 +413,6 @@ and replaces bad input lines with the pair `(-1,-1)`:
~~~~
# #[allow(unused_imports)];
# extern mod extra;
use std::io::{BufferedReader, File};
# mod BufferedReader {
# use std::io::File;
@ -491,7 +487,6 @@ Changing the condition's return type from `(int,int)` to `Option<(int,int)>` wil
~~~~
# #[allow(unused_imports)];
# extern mod extra;
use std::io::{BufferedReader, File};
# mod BufferedReader {
# use std::io::File;
@ -576,8 +571,7 @@ This can be encoded in the handler API by introducing a helper type: `enum Malfo
~~~~
# #[allow(unused_imports)];
# extern mod extra;
use std::io::File;
use std::io::{BufferedReader, File};
# mod BufferedReader {
# use std::io::File;
# use std::io::MemReader;
@ -700,7 +694,6 @@ a second condition and a helper function will suffice:
~~~~
# #[allow(unused_imports)];
# extern mod extra;
use std::io::{BufferedReader, File};
# mod BufferedReader {
# use std::io::File;

View File

@ -270,7 +270,7 @@ Containers can provide conversion from iterators through `collect` by
implementing the `FromIterator` trait. For example, the implementation for
vectors is as follows:
~~~ {.xfail-test}
~~~ {.ignore}
impl<A> FromIterator<A> for ~[A] {
pub fn from_iterator<T: Iterator<A>>(iterator: &mut T) -> ~[A] {
let (lower, _) = iterator.size_hint();
@ -288,7 +288,7 @@ impl<A> FromIterator<A> for ~[A] {
The `Iterator` trait provides a `size_hint` default method, returning a lower
bound and optionally on upper bound on the length of the iterator:
~~~ {.xfail-test}
~~~ {.ignore}
fn size_hint(&self) -> (uint, Option<uint>) { (0, None) }
~~~

View File

@ -11,7 +11,7 @@ snappy includes a C interface (documented in
The following is a minimal example of calling a foreign function which will
compile if snappy is installed:
~~~~ {.xfail-test}
~~~~ {.ignore}
use std::libc::size_t;
#[link(name = "snappy")]
@ -43,7 +43,7 @@ keeping the binding correct at runtime.
The `extern` block can be extended to cover the entire snappy API:
~~~~ {.xfail-test}
~~~~ {.ignore}
use std::libc::{c_int, size_t};
#[link(name = "snappy")]
@ -76,7 +76,7 @@ vectors as pointers to memory. Rust's vectors are guaranteed to be a contiguous
length is number of elements currently contained, and the capacity is the total size in elements of
the allocated memory. The length is less than or equal to the capacity.
~~~~ {.xfail-test}
~~~~ {.ignore}
pub fn validate_compressed_buffer(src: &[u8]) -> bool {
unsafe {
snappy_validate_compressed_buffer(src.as_ptr(), src.len() as size_t) == 0
@ -96,7 +96,7 @@ required capacity to hold the compressed output. The vector can then be passed t
`snappy_compress` function as an output parameter. An output parameter is also passed to retrieve
the true length after compression for setting the length.
~~~~ {.xfail-test}
~~~~ {.ignore}
pub fn compress(src: &[u8]) -> ~[u8] {
unsafe {
let srclen = src.len() as size_t;
@ -116,7 +116,7 @@ pub fn compress(src: &[u8]) -> ~[u8] {
Decompression is similar, because snappy stores the uncompressed size as part of the compression
format and `snappy_uncompressed_length` will retrieve the exact buffer size required.
~~~~ {.xfail-test}
~~~~ {.ignore}
pub fn uncompress(src: &[u8]) -> Option<~[u8]> {
unsafe {
let srclen = src.len() as size_t;
@ -263,7 +263,7 @@ to the C library and afterwards be invoked from there.
A basic example is:
Rust code:
~~~~ {.xfail-test}
~~~~ {.ignore}
extern fn callback(a:i32) {
println!("I'm called from C with value {0}", a);
}
@ -283,7 +283,7 @@ fn main() {
~~~~
C code:
~~~~ {.xfail-test}
~~~~ {.ignore}
typedef void (*rust_callback)(int32_t);
rust_callback cb;
@ -314,7 +314,7 @@ the notification. This will allow the callback to unsafely access the
referenced Rust object.
Rust code:
~~~~ {.xfail-test}
~~~~ {.ignore}
struct RustObject {
a: i32,
@ -346,7 +346,7 @@ fn main() {
~~~~
C code:
~~~~ {.xfail-test}
~~~~ {.ignore}
typedef void (*rust_callback)(int32_t);
void* cb_target;
rust_callback cb;
@ -440,7 +440,7 @@ the `link_args` attribute. This attribute is applied to `extern` blocks and
specifies raw flags which need to get passed to the linker when producing an
artifact. An example usage would be:
~~~ {.xfail-test}
~~~ {.ignore}
#[link_args = "-foo -bar -baz"]
extern {}
~~~
@ -476,7 +476,7 @@ Foreign APIs often export a global variable which could do something like track
global state. In order to access these variables, you declare them in `extern`
blocks with the `static` keyword:
~~~{.xfail-test}
~~~{.ignore}
use std::libc;
#[link(name = "readline")]
@ -494,7 +494,7 @@ Alternatively, you may need to alter global state provided by a foreign
interface. To do this, statics can be declared with `mut` so rust can mutate
them.
~~~{.xfail-test}
~~~{.ignore}
use std::libc;
use std::ptr;

View File

@ -299,7 +299,7 @@ _as soon as its owning reference changes or goes out of
scope_. Therefore, a program like this is illegal (and would be
rejected by the compiler):
~~~ {.xfail-test}
~~~ {.ignore}
fn example3() -> int {
let mut x = ~X {f: 3};
let y = &x.f;
@ -346,7 +346,7 @@ modify the previous example to introduce additional owned pointers
and structs, and the compiler will still be able to detect possible
mutations:
~~~ {.xfail-test}
~~~ {.ignore}
fn example3() -> int {
struct R { g: int }
struct S { f: ~R }
@ -524,7 +524,7 @@ the compiler accepts the function `get_x()`.
To emphasize this point, lets look at a variation on the example, this
time one that does not compile:
~~~ {.xfail-test}
~~~ {.ignore}
struct Point {x: f64, y: f64}
fn get_x_sh(p: @Point) -> &f64 {
&p.x // Error reported here

View File

@ -21,7 +21,7 @@ fn succ(x: &int) -> int { *x + 1 }
So I wrote this code to try it out:
~~~rust{.xfail-test}
~~~rust{.ignore}
fn main() {
let number = 5;
let succ_number = succ(number);
@ -261,7 +261,7 @@ program is very large and complicated.
For example, let's say you're using an owned pointer, and you want to do this:
~~~rust{.xfail-test}
~~~rust{.ignore}
struct Point {
x: int,
y: int,
@ -369,7 +369,7 @@ This theory is called 'region pointers,' and involve a concept called
'lifetimes'. Here's the simple explanation: would you expect this code to
compile?
~~~rust{.xfail-test}
~~~rust{.ignore}
fn main() {
println!("{}", x);
let x = 5;
@ -398,7 +398,7 @@ Here, we're borrowing a pointer to `x` inside of the `if`. The compiler, however
is able to determine that that pointer will go out of scope without `x` being
mutated, and therefore, lets us pass. This wouldn't work:
~~~rust{.xfail-test}
~~~rust{.ignore}
fn main() {
let mut x = ~5;
if *x < 10 {

View File

@ -190,7 +190,7 @@ senders cannot use a single `Chan`, and multiple receivers cannot use a single
`Port`. What if our example needed to compute multiple results across a number
of tasks? The following program is ill-typed:
~~~ {.xfail-test}
~~~ {.ignore}
# use std::task::{spawn};
# fn some_expensive_computation() -> int { 42 }
let (port, chan) = Chan::new();
@ -413,7 +413,7 @@ pattern-match on a result to check whether it's an `Ok` result with an `int`
field (representing a successful result) or an `Err` result (representing
termination with an error).
~~~{.xfail-test .linked-failure}
~~~{.ignore .linked-failure}
# use std::task;
# fn some_condition() -> bool { false }
# fn calculate_result() -> int { 0 }
@ -463,7 +463,7 @@ that repeatedly receives a `uint` message, converts it to a string, and sends
the string in response. The child terminates when it receives `0`.
Here is the function that implements the child task:
~~~{.xfail-test .linked-failure}
~~~{.ignore .linked-failure}
# use extra::comm::DuplexStream;
# use std::uint;
fn stringifier(channel: &DuplexStream<~str, uint>) {
@ -486,7 +486,7 @@ response itself is simply the stringified version of the received value,
Here is the code for the parent task:
~~~{.xfail-test .linked-failure}
~~~{.ignore .linked-failure}
# use std::task::spawn;
# use std::uint;
# use extra::comm::DuplexStream;

View File

@ -112,7 +112,7 @@ msgstr "## 演算子"
#: doc/complement-cheatsheet.md:54
#, fuzzy
#| msgid "~~~~ use std::task::spawn;"
msgid "~~~ {.xfail-test} use std::path::Path; use std::io::fs::File;"
msgid "~~~ {.ignore} use std::path::Path; use std::io::fs::File;"
msgstr ""
"~~~~\n"
"use std::task::spawn;"

View File

@ -34,7 +34,7 @@ msgstr "[他言語間インターフェース (foreign function inferface)][ffi]
#: doc/guide-ffi.md:16
#, fuzzy
#| msgid "~~~~ use std::task::spawn;"
msgid "~~~~ {.xfail-test} use std::libc::size_t;"
msgid "~~~~ {.ignore} use std::libc::size_t;"
msgstr ""
"~~~~\n"
"use std::task::spawn;"
@ -43,7 +43,7 @@ msgstr ""
#: doc/guide-ffi.md:48
#, fuzzy
#| msgid "~~~~ use std::task::spawn;"
msgid "~~~~ {.xfail-test} use std::libc::{c_int, size_t};"
msgid "~~~~ {.ignore} use std::libc::{c_int, size_t};"
msgstr ""
"~~~~\n"
"use std::task::spawn;"
@ -67,7 +67,7 @@ msgstr ""
#: doc/guide-ffi.md:344
#, fuzzy
#| msgid "~~~~ use std::task::spawn;"
msgid "~~~{.xfail-test} use std::libc;"
msgid "~~~{.ignore} use std::libc;"
msgstr ""
"~~~~\n"
"use std::task::spawn;"
@ -76,7 +76,7 @@ msgstr ""
#: doc/guide-ffi.md:363
#, fuzzy
#| msgid "~~~~ use std::task::spawn;"
msgid "~~~{.xfail-test} use std::libc; use std::ptr;"
msgid "~~~{.ignore} use std::libc; use std::ptr;"
msgstr ""
"~~~~\n"
"use std::task::spawn;"

View File

@ -63,7 +63,7 @@ msgstr ""
#. type: Plain text
#: doc/guide-lifetimes.md:48
#, fuzzy, no-wrap
#| msgid "~~~~ {.xfail-test} # struct Point { x: f64, y: f64 } let mut mypoint = Point { x: 1.0, y: 1.0 }; let origin = Point { x: 0.0, y: 0.0 };"
#| msgid "~~~~ {.ignore} # struct Point { x: f64, y: f64 } let mut mypoint = Point { x: 1.0, y: 1.0 }; let origin = Point { x: 0.0, y: 0.0 };"
msgid ""
"~~~\n"
"# struct Point {x: f64, y: f64}\n"
@ -72,7 +72,7 @@ msgid ""
"let owned_box : ~Point = ~Point {x: 7.0, y: 9.0};\n"
"~~~\n"
msgstr ""
"~~~~ {.xfail-test}\n"
"~~~~ {.ignore}\n"
"# struct Point { x: f64, y: f64 }\n"
"let mut mypoint = Point { x: 1.0, y: 1.0 };\n"
"let origin = Point { x: 0.0, y: 0.0 };"
@ -123,7 +123,7 @@ msgstr ""
#. type: Plain text
#: doc/guide-lifetimes.md:82
#, fuzzy, no-wrap
#| msgid "~~~~ {.xfail-test} # struct Point { x: f64, y: f64 } let mut mypoint = Point { x: 1.0, y: 1.0 }; let origin = Point { x: 0.0, y: 0.0 };"
#| msgid "~~~~ {.ignore} # struct Point { x: f64, y: f64 } let mut mypoint = Point { x: 1.0, y: 1.0 }; let origin = Point { x: 0.0, y: 0.0 };"
msgid ""
"~~~\n"
"# struct Point {x: f64, y: f64}\n"
@ -135,7 +135,7 @@ msgid ""
"compute_distance(managed_box, owned_box);\n"
"~~~\n"
msgstr ""
"~~~~ {.xfail-test}\n"
"~~~~ {.ignore}\n"
"# struct Point { x: f64, y: f64 }\n"
"let mut mypoint = Point { x: 1.0, y: 1.0 };\n"
"let origin = Point { x: 0.0, y: 0.0 };"

View File

@ -46,7 +46,7 @@ msgstr ""
#. type: Plain text
#: doc/guide-pointers.md:115
#, fuzzy, no-wrap
#| msgid "~~~~ {.xfail-test} # struct Point { x: f64, y: f64 } let mut mypoint = Point { x: 1.0, y: 1.0 }; let origin = Point { x: 0.0, y: 0.0 };"
#| msgid "~~~~ {.ignore} # struct Point { x: f64, y: f64 } let mut mypoint = Point { x: 1.0, y: 1.0 }; let origin = Point { x: 0.0, y: 0.0 };"
msgid ""
"fn main() {\n"
" let p0 = Point { x: 5, y: 10};\n"
@ -54,7 +54,7 @@ msgid ""
" println!(\"{:?}\", p1);\n"
"}\n"
msgstr ""
"~~~~ {.xfail-test}\n"
"~~~~ {.ignore}\n"
"# struct Point { x: f64, y: f64 }\n"
"let mut mypoint = Point { x: 1.0, y: 1.0 };\n"
"let origin = Point { x: 0.0, y: 0.0 };"
@ -62,7 +62,7 @@ msgstr ""
#. type: Plain text
#: doc/guide-pointers.md:129
#, fuzzy, no-wrap
#| msgid "~~~~ {.xfail-test} # struct Point { x: f64, y: f64 } let mut mypoint = Point { x: 1.0, y: 1.0 }; let origin = Point { x: 0.0, y: 0.0 };"
#| msgid "~~~~ {.ignore} # struct Point { x: f64, y: f64 } let mut mypoint = Point { x: 1.0, y: 1.0 }; let origin = Point { x: 0.0, y: 0.0 };"
msgid ""
"~~~rust\n"
"# struct Point {\n"
@ -74,7 +74,7 @@ msgid ""
" Point { x: p.x + 1, y: p.y + 1}\n"
"}\n"
msgstr ""
"~~~~ {.xfail-test}\n"
"~~~~ {.ignore}\n"
"# struct Point { x: f64, y: f64 }\n"
"let mut mypoint = Point { x: 1.0, y: 1.0 };\n"
"let origin = Point { x: 0.0, y: 0.0 };"
@ -82,13 +82,13 @@ msgstr ""
#. type: Plain text
#: doc/guide-pointers.md:145
#, fuzzy, no-wrap
#| msgid "~~~~ {.xfail-test} # struct Point { x: f64, y: f64 } let mut mypoint = Point { x: 1.0, y: 1.0 }; let origin = Point { x: 0.0, y: 0.0 };"
#| msgid "~~~~ {.ignore} # struct Point { x: f64, y: f64 } let mut mypoint = Point { x: 1.0, y: 1.0 }; let origin = Point { x: 0.0, y: 0.0 };"
msgid ""
"fn transform(p: Point) -> Point {\n"
" Point { x: p.x + 1, y: p.y + 1}\n"
"}\n"
msgstr ""
"~~~~ {.xfail-test}\n"
"~~~~ {.ignore}\n"
"# struct Point { x: f64, y: f64 }\n"
"let mut mypoint = Point { x: 1.0, y: 1.0 };\n"
"let origin = Point { x: 0.0, y: 0.0 };"
@ -96,7 +96,7 @@ msgstr ""
#. type: Plain text
#: doc/guide-pointers.md:152
#, fuzzy, no-wrap
#| msgid "~~~~ {.xfail-test} # struct Point { x: f64, y: f64 } let mut mypoint = Point { x: 1.0, y: 1.0 }; let origin = Point { x: 0.0, y: 0.0 };"
#| msgid "~~~~ {.ignore} # struct Point { x: f64, y: f64 } let mut mypoint = Point { x: 1.0, y: 1.0 }; let origin = Point { x: 0.0, y: 0.0 };"
msgid ""
"fn main() {\n"
" let p0 = Point { x: 5, y: 10};\n"
@ -105,7 +105,7 @@ msgid ""
"}\n"
"~~~\n"
msgstr ""
"~~~~ {.xfail-test}\n"
"~~~~ {.ignore}\n"
"# struct Point { x: f64, y: f64 }\n"
"let mut mypoint = Point { x: 1.0, y: 1.0 };\n"
"let origin = Point { x: 0.0, y: 0.0 };"
@ -133,7 +133,7 @@ msgstr "# データ構造"
#. type: Plain text
#: doc/guide-pointers.md:229
#, fuzzy, no-wrap
#| msgid "~~~~ {.xfail-test} # struct Point { x: f64, y: f64 } let mut mypoint = Point { x: 1.0, y: 1.0 }; let origin = Point { x: 0.0, y: 0.0 };"
#| msgid "~~~~ {.ignore} # struct Point { x: f64, y: f64 } let mut mypoint = Point { x: 1.0, y: 1.0 }; let origin = Point { x: 0.0, y: 0.0 };"
msgid ""
"fn main() {\n"
" let a = Point { x: 10, y: 20 };\n"
@ -143,7 +143,7 @@ msgid ""
"}\n"
"~~~\n"
msgstr ""
"~~~~ {.xfail-test}\n"
"~~~~ {.ignore}\n"
"# struct Point { x: f64, y: f64 }\n"
"let mut mypoint = Point { x: 1.0, y: 1.0 };\n"
"let origin = Point { x: 0.0, y: 0.0 };"
@ -151,7 +151,7 @@ msgstr ""
#. type: Plain text
#: doc/guide-pointers.md:246
#, fuzzy, no-wrap
#| msgid "~~~~ {.xfail-test} # struct Point { x: f64, y: f64 } let mut mypoint = Point { x: 1.0, y: 1.0 }; let origin = Point { x: 0.0, y: 0.0 };"
#| msgid "~~~~ {.ignore} # struct Point { x: f64, y: f64 } let mut mypoint = Point { x: 1.0, y: 1.0 }; let origin = Point { x: 0.0, y: 0.0 };"
msgid ""
"fn main() {\n"
" let a = ~Point { x: 10, y: 20 };\n"
@ -161,7 +161,7 @@ msgid ""
"}\n"
"~~~\n"
msgstr ""
"~~~~ {.xfail-test}\n"
"~~~~ {.ignore}\n"
"# struct Point { x: f64, y: f64 }\n"
"let mut mypoint = Point { x: 1.0, y: 1.0 };\n"
"let origin = Point { x: 0.0, y: 0.0 };"
@ -176,7 +176,7 @@ msgstr "## マネージドボックス"
#. type: Plain text
#: doc/guide-pointers.md:277
#, fuzzy, no-wrap
#| msgid "~~~~ {.xfail-test} # struct Point { x: f64, y: f64 } let mut mypoint = Point { x: 1.0, y: 1.0 }; let origin = Point { x: 0.0, y: 0.0 };"
#| msgid "~~~~ {.ignore} # struct Point { x: f64, y: f64 } let mut mypoint = Point { x: 1.0, y: 1.0 }; let origin = Point { x: 0.0, y: 0.0 };"
msgid ""
"fn main() {\n"
" let a = ~Point { x: 10, y: 20 };\n"
@ -186,7 +186,7 @@ msgid ""
"}\n"
"~~~\n"
msgstr ""
"~~~~ {.xfail-test}\n"
"~~~~ {.ignore}\n"
"# struct Point { x: f64, y: f64 }\n"
"let mut mypoint = Point { x: 1.0, y: 1.0 };\n"
"let origin = Point { x: 0.0, y: 0.0 };"
@ -194,7 +194,7 @@ msgstr ""
#. type: Plain text
#: doc/guide-pointers.md:308
#, fuzzy, no-wrap
#| msgid "~~~~ {.xfail-test} # struct Point { x: f64, y: f64 } let mut mypoint = Point { x: 1.0, y: 1.0 }; let origin = Point { x: 0.0, y: 0.0 };"
#| msgid "~~~~ {.ignore} # struct Point { x: f64, y: f64 } let mut mypoint = Point { x: 1.0, y: 1.0 }; let origin = Point { x: 0.0, y: 0.0 };"
msgid ""
"fn main() {\n"
" let a = @Point { x: 10, y: 20 };\n"
@ -204,7 +204,7 @@ msgid ""
"}\n"
"~~~\n"
msgstr ""
"~~~~ {.xfail-test}\n"
"~~~~ {.ignore}\n"
"# struct Point { x: f64, y: f64 }\n"
"let mut mypoint = Point { x: 1.0, y: 1.0 };\n"
"let origin = Point { x: 0.0, y: 0.0 };"
@ -227,13 +227,13 @@ msgstr ""
#. type: Plain text
#: doc/guide-pointers.md:352
#, fuzzy, no-wrap
#| msgid "~~~~ {.xfail-test} # struct Point { x: f64, y: f64 } let mut mypoint = Point { x: 1.0, y: 1.0 }; let origin = Point { x: 0.0, y: 0.0 };"
#| msgid "~~~~ {.ignore} # struct Point { x: f64, y: f64 } let mut mypoint = Point { x: 1.0, y: 1.0 }; let origin = Point { x: 0.0, y: 0.0 };"
msgid ""
"fn main() {\n"
" let origin = @Point { x: 0.0, y: 0.0 };\n"
" let p1 = ~Point { x: 5.0, y: 3.0 };\n"
msgstr ""
"~~~~ {.xfail-test}\n"
"~~~~ {.ignore}\n"
"# struct Point { x: f64, y: f64 }\n"
"let mut mypoint = Point { x: 1.0, y: 1.0 };\n"
"let origin = Point { x: 0.0, y: 0.0 };"
@ -241,16 +241,16 @@ msgstr ""
#. type: Plain text
#: doc/guide-pointers.md:378
#, fuzzy, no-wrap
#| msgid "~~~~ {.xfail-test} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"~~~rust{.xfail-test}\n"
"~~~rust{.ignore}\n"
"fn main() {\n"
" println!(\"{}\", x);\n"
" let x = 5;\n"
"}\n"
"~~~\n"
msgstr ""
"~~~~ {.xfail-test}\n"
"~~~~ {.ignore}\n"
"// main.rs\n"
"extern mod world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"

View File

@ -40,14 +40,14 @@ msgstr "## 他のクレートの利用"
#. type: Plain text
#: doc/guide-rustpkg.md:22
#, fuzzy, no-wrap
#| msgid "~~~~ {.xfail-test} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"fn main() {\n"
" hello::world();\n"
"}\n"
"~~~~\n"
msgstr ""
"~~~~ {.xfail-test}\n"
"~~~~ {.ignore}\n"
"// main.rs\n"
"extern mod world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
@ -77,14 +77,14 @@ msgstr "# イントロダクション"
#. type: Plain text
#: doc/guide-rustpkg.md:149
#, fuzzy, no-wrap
#| msgid "~~~~ {.xfail-test} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"pub fn world() {\n"
" println!(\"Hello, world.\");\n"
"}\n"
"~~~\n"
msgstr ""
"~~~~ {.xfail-test}\n"
"~~~~ {.ignore}\n"
"// main.rs\n"
"extern mod world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"

View File

@ -164,7 +164,7 @@ msgstr "## 他のクレートの利用"
#: doc/rust.md:788
#, fuzzy
#| msgid "~~~~ {.ignore} let foo = 10;"
msgid "~~~~ {.xfail-test} extern mod pcre;"
msgid "~~~~ {.ignore} extern mod pcre;"
msgstr ""
"~~~~ {.ignore}\n"
"let foo = 10;"
@ -413,19 +413,19 @@ msgstr ""
#: doc/rust.md:1395
#, fuzzy
#| msgid ""
#| "~~~ {.xfail-test} use std::f64::consts::pi; # trait Shape { fn "
#| "~~~ {.ignore} use std::f64::consts::pi; # trait Shape { fn "
#| "area(&self) -> f64; } # trait Circle : Shape { fn radius(&self) -> f64; } "
#| "# struct Point { x: f64, y: f64 } # struct CircleStruct { center: Point, "
#| "radius: f64 } # impl Circle for CircleStruct { fn radius(&self) -> f64 "
#| "{ (self.area() / pi).sqrt() } } # impl Shape for CircleStruct { fn "
#| "area(&self) -> f64 { pi * square(self.radius) } }"
msgid ""
"~~~~ {.xfail-test} # trait Shape { fn area(&self) -> f64; } # trait Circle : "
"~~~~ {.ignore} # trait Shape { fn area(&self) -> f64; } # trait Circle : "
"Shape { fn radius(&self) -> f64; } # impl Shape for int { fn area(&self) -> "
"f64 { 0.0 } } # impl Circle for int { fn radius(&self) -> f64 { 0.0 } } # "
"let mycircle = 0;"
msgstr ""
"~~~ {.xfail-test}\n"
"~~~ {.ignore}\n"
"use std::f64::consts::pi;\n"
"# trait Shape { fn area(&self) -> f64; }\n"
"# trait Circle : Shape { fn radius(&self) -> f64; }\n"
@ -613,7 +613,7 @@ msgstr "## 構文拡張"
#: doc/rust.md:2400
#, fuzzy
#| msgid "~~~~ use std::task::spawn;"
msgid "~~~~ {.xfail-test} # use std::task; # do task::spawn {"
msgid "~~~~ {.ignore} # use std::task; # do task::spawn {"
msgstr ""
"~~~~\n"
"use std::task::spawn;"
@ -928,14 +928,14 @@ msgstr "# クロージャ"
#. type: Plain text
#: doc/rust.md:3299
#, fuzzy, no-wrap
#| msgid "~~~~ {.xfail-test} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"fn main() {\n"
" print(@10 as @Printable);\n"
"}\n"
"~~~~\n"
msgstr ""
"~~~~ {.xfail-test}\n"
"~~~~ {.ignore}\n"
"// main.rs\n"
"extern mod world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"

View File

@ -422,7 +422,7 @@ msgstr ""
#. type: Plain text
#: doc/tutorial.md:136
#, fuzzy, no-wrap
#| msgid "~~~~ {.xfail-test} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"~~~~\n"
"fn main() {\n"
@ -430,7 +430,7 @@ msgid ""
"}\n"
"~~~~\n"
msgstr ""
"~~~~ {.xfail-test}\n"
"~~~~ {.ignore}\n"
"// main.rs\n"
"extern mod world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
@ -1390,10 +1390,10 @@ msgstr ""
#. type: Plain text
#: doc/tutorial.md:604
msgid ""
"~~~~ {.xfail-test} # struct Point { x: f64, y: f64 } let mut mypoint = Point "
"~~~~ {.ignore} # struct Point { x: f64, y: f64 } let mut mypoint = Point "
"{ x: 1.0, y: 1.0 }; let origin = Point { x: 0.0, y: 0.0 };"
msgstr ""
"~~~~ {.xfail-test}\n"
"~~~~ {.ignore}\n"
"# struct Point { x: f64, y: f64 }\n"
"let mut mypoint = Point { x: 1.0, y: 1.0 };\n"
"let origin = Point { x: 0.0, y: 0.0 };"
@ -2213,7 +2213,7 @@ msgstr ""
#. type: Plain text
#: doc/tutorial.md:1372
#, fuzzy, no-wrap
#| msgid "~~~~ {.xfail-test} # struct Point { x: f64, y: f64 } let mut mypoint = Point { x: 1.0, y: 1.0 }; let origin = Point { x: 0.0, y: 0.0 };"
#| msgid "~~~~ {.ignore} # struct Point { x: f64, y: f64 } let mut mypoint = Point { x: 1.0, y: 1.0 }; let origin = Point { x: 0.0, y: 0.0 };"
msgid ""
"~~~\n"
"# struct Point { x: f64, y: f64 }\n"
@ -2222,7 +2222,7 @@ msgid ""
"let owned_box : ~Point = ~Point { x: 7.0, y: 9.0 };\n"
"~~~\n"
msgstr ""
"~~~~ {.xfail-test}\n"
"~~~~ {.ignore}\n"
"# struct Point { x: f64, y: f64 }\n"
"let mut mypoint = Point { x: 1.0, y: 1.0 };\n"
"let origin = Point { x: 0.0, y: 0.0 };"
@ -2265,7 +2265,7 @@ msgstr ""
#. type: Plain text
#: doc/tutorial.md:1404
#, fuzzy, no-wrap
#| msgid "~~~~ {.xfail-test} # struct Point { x: f64, y: f64 } let mut mypoint = Point { x: 1.0, y: 1.0 }; let origin = Point { x: 0.0, y: 0.0 };"
#| msgid "~~~~ {.ignore} # struct Point { x: f64, y: f64 } let mut mypoint = Point { x: 1.0, y: 1.0 }; let origin = Point { x: 0.0, y: 0.0 };"
msgid ""
"~~~\n"
"# struct Point{ x: f64, y: f64 };\n"
@ -2277,7 +2277,7 @@ msgid ""
"compute_distance(managed_box, owned_box);\n"
"~~~\n"
msgstr ""
"~~~~ {.xfail-test}\n"
"~~~~ {.ignore}\n"
"# struct Point { x: f64, y: f64 }\n"
"let mut mypoint = Point { x: 1.0, y: 1.0 };\n"
"let origin = Point { x: 0.0, y: 0.0 };"
@ -3442,14 +3442,14 @@ msgstr ""
#: doc/tutorial.md:2067
#, no-wrap
msgid ""
"~~~~ {.xfail-test}\n"
"~~~~ {.ignore}\n"
"// This does not compile\n"
"fn head_bad<T>(v: &[T]) -> T {\n"
" v[0] // error: copying a non-copyable value\n"
"}\n"
"~~~~\n"
msgstr ""
"~~~~ {.xfail-test}\n"
"~~~~ {.ignore}\n"
"// このコードはコンパイルできない\n"
"fn head_bad<T>(v: &[T]) -> T {\n"
" v[0] // error: copying a non-copyable value\n"
@ -3622,7 +3622,7 @@ msgstr ""
#. type: Plain text
#: doc/tutorial.md:2148
#, fuzzy, no-wrap
#| msgid "~~~~ {.xfail-test} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"~~~~\n"
"trait Printable {\n"
@ -3630,7 +3630,7 @@ msgid ""
"}\n"
"~~~~\n"
msgstr ""
"~~~~ {.xfail-test}\n"
"~~~~ {.ignore}\n"
"// main.rs\n"
"extern mod world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
@ -4077,7 +4077,7 @@ msgstr "`Circle` トレイトの実装は、 `Shape` を実装した型につい
#. type: Plain text
#: doc/tutorial.md:2488
#, fuzzy, no-wrap
#| msgid "~~~ {.xfail-test} use std::f64::consts::pi; # trait Shape { fn area(&self) -> f64; } # trait Circle : Shape { fn radius(&self) -> f64; } # struct Point { x: f64, y: f64 } # struct CircleStruct { center: Point, radius: f64 } # impl Circle for CircleStruct { fn radius(&self) -> f64 { (self.area() / pi).sqrt() } } # impl Shape for CircleStruct { fn area(&self) -> f64 { pi * square(self.radius) } }"
#| msgid "~~~ {.ignore} use std::f64::consts::pi; # trait Shape { fn area(&self) -> f64; } # trait Circle : Shape { fn radius(&self) -> f64; } # struct Point { x: f64, y: f64 } # struct CircleStruct { center: Point, radius: f64 } # impl Circle for CircleStruct { fn radius(&self) -> f64 { (self.area() / pi).sqrt() } } # impl Shape for CircleStruct { fn area(&self) -> f64 { pi * square(self.radius) } }"
msgid ""
"~~~~\n"
"use std::f64::consts::PI;\n"
@ -4094,7 +4094,7 @@ msgid ""
"}\n"
"~~~~\n"
msgstr ""
"~~~ {.xfail-test}\n"
"~~~ {.ignore}\n"
"use std::f64::consts::pi;\n"
"# trait Shape { fn area(&self) -> f64; }\n"
"# trait Circle : Shape { fn radius(&self) -> f64; }\n"
@ -4153,21 +4153,21 @@ msgstr ""
#: doc/tutorial.md:2517
#, fuzzy
#| msgid ""
#| "~~~ {.xfail-test} use std::f64::consts::pi; # trait Shape { fn "
#| "~~~ {.ignore} use std::f64::consts::pi; # trait Shape { fn "
#| "area(&self) -> f64; } # trait Circle : Shape { fn radius(&self) -> f64; } "
#| "# struct Point { x: f64, y: f64 } # struct CircleStruct { center: Point, "
#| "radius: f64 } # impl Circle for CircleStruct { fn radius(&self) -> f64 "
#| "{ (self.area() / pi).sqrt() } } # impl Shape for CircleStruct { fn "
#| "area(&self) -> f64 { pi * square(self.radius) } }"
msgid ""
"~~~ {.xfail-test} use std::f64::consts::PI; # trait Shape { fn area(&self) -"
"~~~ {.ignore} use std::f64::consts::PI; # trait Shape { fn area(&self) -"
"> f64; } # trait Circle : Shape { fn radius(&self) -> f64; } # struct Point "
"{ x: f64, y: f64 } # struct CircleStruct { center: Point, radius: f64 } # "
"impl Circle for CircleStruct { fn radius(&self) -> f64 { (self.area() / PI)."
"sqrt() } } # impl Shape for CircleStruct { fn area(&self) -> f64 { PI * "
"square(self.radius) } }"
msgstr ""
"~~~ {.xfail-test}\n"
"~~~ {.ignore}\n"
"use std::f64::consts::pi;\n"
"# trait Shape { fn area(&self) -> f64; }\n"
"# trait Circle : Shape { fn radius(&self) -> f64; }\n"
@ -4265,7 +4265,7 @@ msgstr "## クレート"
#. type: Plain text
#: doc/tutorial.md:2567
#, fuzzy, no-wrap
#| msgid "~~~~ {.xfail-test} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"~~~~\n"
"// main.rs\n"
@ -4274,7 +4274,7 @@ msgid ""
"}\n"
"~~~~\n"
msgstr ""
"~~~~ {.xfail-test}\n"
"~~~~ {.ignore}\n"
"// main.rs\n"
"extern mod world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
@ -4305,14 +4305,14 @@ msgstr "## 標準ライブラリ"
#. type: Plain text
#: doc/tutorial.md:2600
#, fuzzy, no-wrap
#| msgid "~~~~ {.xfail-test} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"fn main() {\n"
" println!(\"Hello farm!\");\n"
"}\n"
"~~~~\n"
msgstr ""
"~~~~ {.xfail-test}\n"
"~~~~ {.ignore}\n"
"// main.rs\n"
"extern mod world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
@ -4328,12 +4328,12 @@ msgstr "## マネージドクロージャ"
#. type: Plain text
#: doc/tutorial.md:2620
#, fuzzy, no-wrap
#| msgid "~~~~ {.xfail-test} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"fn main() {\n"
" println!(\"Hello chicken!\");\n"
msgstr ""
"~~~~ {.xfail-test}\n"
"~~~~ {.ignore}\n"
"// main.rs\n"
"extern mod world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
@ -4374,7 +4374,7 @@ msgstr "# モジュールとクレート"
#. type: Plain text
#: doc/tutorial.md:2732
#, fuzzy, no-wrap
#| msgid "~~~~ {.xfail-test} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"fn main() {\n"
" println!(\"Hello farm!\");\n"
@ -4382,7 +4382,7 @@ msgid ""
"}\n"
"~~~~\n"
msgstr ""
"~~~~ {.xfail-test}\n"
"~~~~ {.ignore}\n"
"// main.rs\n"
"extern mod world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
@ -4400,12 +4400,12 @@ msgstr ""
#. type: Plain text
#: doc/tutorial.md:2929
#, fuzzy, no-wrap
#| msgid "~~~~ {.xfail-test} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
#| msgid "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
msgid ""
"fn main() {\n"
" println!(\"Hello farm!\");\n"
msgstr ""
"~~~~ {.xfail-test}\n"
"~~~~ {.ignore}\n"
"// main.rs\n"
"extern mod world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"
@ -4438,14 +4438,14 @@ msgstr ""
#: doc/tutorial.md:3144
#, fuzzy
#| msgid ""
#| "~~~~ {.xfail-test} extern mod farm; extern mod my_farm (name = \"farm\", "
#| "~~~~ {.ignore} extern mod farm; extern mod my_farm (name = \"farm\", "
#| "vers = \"2.5\"); extern mod my_auxiliary_farm (name = \"farm\", author = "
#| "\"mjh\"); ~~~~"
msgid ""
"~~~~ {.xfail-test} extern mod farm; extern mod farm = \"farm#2.5\"; extern "
"~~~~ {.ignore} extern mod farm; extern mod farm = \"farm#2.5\"; extern "
"mod my_farm = \"farm\"; ~~~~"
msgstr ""
"~~~~ {.xfail-test}\n"
"~~~~ {.ignore}\n"
"extern mod farm;\n"
"extern mod my_farm (name = \"farm\", vers = \"2.5\");\n"
"extern mod my_auxiliary_farm (name = \"farm\", author = \"mjh\");\n"
@ -4507,13 +4507,13 @@ msgstr ""
#: doc/tutorial.md:3185
#, fuzzy
#| msgid ""
#| "~~~~ {.xfail-test} // main.rs extern mod world; fn main() { println(~"
#| "~~~~ {.ignore} // main.rs extern mod world; fn main() { println(~"
#| "\"hello \" + world::explore()); } ~~~~"
msgid ""
"~~~~ {.xfail-test} // main.rs extern mod world; fn main() { println!(\"hello "
"~~~~ {.ignore} // main.rs extern mod world; fn main() { println!(\"hello "
"{}\", world::explore()); } ~~~~"
msgstr ""
"~~~~ {.xfail-test}\n"
"~~~~ {.ignore}\n"
"// main.rs\n"
"extern mod world;\n"
"fn main() { println(~\"hello \" + world::explore()); }\n"

View File

@ -727,7 +727,7 @@ name as the module, plus the `.rs` extension.
When a nested submodule is loaded from an external file,
it is loaded from a subdirectory path that mirrors the module hierarchy.
~~~~ {.xfail-test}
~~~~ {.ignore}
// Load the `vec` module from `vec.rs`
mod vec;
@ -740,7 +740,7 @@ mod task {
The directories and files used for loading external file modules can be influenced
with the `path` attribute.
~~~~ {.xfail-test}
~~~~ {.ignore}
#[path = "task_files"]
mod task {
// Load the `local_data` module from `task_files/tls.rs`
@ -784,7 +784,7 @@ assumed, equal to the `ident` given in the `extern_mod_decl`.
Four examples of `extern mod` declarations:
~~~~ {.xfail-test}
~~~~ {.ignore}
extern mod pcre;
extern mod extra; // equivalent to: extern mod extra = "extra";
@ -939,7 +939,7 @@ appear in its signature. Each type parameter must be explicitly
declared, in an angle-bracket-enclosed, comma-separated list following
the function name.
~~~~ {.xfail-test}
~~~~ {.ignore}
fn iter<T>(seq: &[T], f: |T|) {
for elt in seq.iter() { f(elt); }
}
@ -1389,7 +1389,7 @@ fn radius_times_area<T: Circle>(c: T) -> f64 {
Likewise, supertrait methods may also be called on trait objects.
~~~~ {.xfail-test}
~~~~ {.ignore}
# trait Shape { fn area(&self) -> f64; }
# trait Circle : Shape { fn radius(&self) -> f64; }
# impl Shape for int { fn area(&self) -> f64 { 0.0 } }
@ -1491,7 +1491,7 @@ By default external blocks assume that the library they are calling
uses the standard C "cdecl" ABI. Other ABIs may be specified using
an `abi` string, as shown here:
~~~~ {.xfail-test}
~~~~ {.ignore}
// Interface to the Windows API
extern "stdcall" { }
~~~~
@ -1500,7 +1500,7 @@ The `link` attribute allows the name of the library to be specified. When
specified the compiler will attempt to link against the native library of the
specified name.
~~~~ {.xfail-test}
~~~~ {.ignore}
#[link(name = "crypto")]
extern { }
~~~~
@ -1704,7 +1704,7 @@ within. Attributes that are not terminated by a semi-colon apply to the next ent
An example of attributes:
~~~~ {.xfail-test}
~~~~ {.ignore}
// General metadata applied to the enclosing module or crate.
#[license = "BSD"];
@ -1768,7 +1768,7 @@ For any lint check `C`:
The lint checks supported by the compiler can be found via `rustc -W help`,
along with their default settings.
~~~~ {.xfail-test}
~~~~ {.ignore}
mod m1 {
// Missing documentation is ignored here
#[allow(missing_doc)]
@ -1787,7 +1787,7 @@ mod m1 {
This example shows how one can use `allow` and `warn` to toggle
a particular check on and off.
~~~~ {.xfail-test}
~~~~ {.ignore}
#[warn(missing_doc)]
mod m2{
#[allow(missing_doc)]
@ -1809,7 +1809,7 @@ mod m2{
This example shows how one can use `forbid` to disallow uses
of `allow` for that lint check.
~~~~ {.xfail-test}
~~~~ {.ignore}
#[forbid(missing_doc)]
mod m3 {
// Attempting to toggle warning signals an error here
@ -1827,7 +1827,7 @@ The definitions of these operations have to be easy for the compiler to find.
The `lang` attribute makes it possible to declare these operations.
For example, the `str` module in the Rust standard library defines the string equality function:
~~~~ {.xfail-test}
~~~~ {.ignore}
#[lang="str_eq"]
pub fn eq_slice(a: &str, b: &str) -> bool {
// details elided
@ -2007,7 +2007,7 @@ by default. Items with not marked with a stability are considered to
be unstable for the purposes of the lint. One can give an optional
string that will be displayed when the lint flags the use of an item.
~~~~ {.xfail-test}
~~~~ {.ignore}
#[warn(unstable)];
#[deprecated="replaced by `best`"]
@ -2046,7 +2046,7 @@ considered a full-fleged language feature.
For this reason, rust recognizes a special crate-level attribute of the form:
~~~~ {.xfail-test}
~~~~ {.ignore}
#[feature(feature1, feature2, feature3)]
~~~~
@ -2403,7 +2403,7 @@ Indices are zero-based, and may be of any integral type. Vector access
is bounds-checked at run-time. When the check fails, it will put the
task in a _failing state_.
~~~~ {.xfail-test}
~~~~ {.ignore}
# use std::task;
# do task::spawn {

View File

@ -607,7 +607,7 @@ With a value (say, `mypoint`) of such a type in a mutable location, you can do
`mypoint.y += 1.0`. But in an immutable location, such an assignment to a
struct without inherited mutability would result in a type error.
~~~~ {.xfail-test}
~~~~ {.ignore}
# struct Point { x: f64, y: f64 }
let mut mypoint = Point { x: 1.0, y: 1.0 };
let origin = Point { x: 0.0, y: 0.0 };
@ -948,7 +948,7 @@ An `enum` is a natural fit for describing a linked list, because it can express
a `List` type as being *either* the end of the list (`Nil`) or another node
(`Cons`). The full definition of the `Cons` variant will require some thought.
~~~ {.xfail-test}
~~~ {.ignore}
enum List {
Cons(...), // an incomplete definition of the next element in a List
Nil // the end of a List
@ -958,7 +958,7 @@ enum List {
The obvious approach is to define `Cons` as containing an element in the list
along with the next `List` node. However, this will generate a compiler error.
~~~ {.xfail-test}
~~~ {.ignore}
// error: illegal recursive enum type; wrap the inner value in a box to make it representable
enum List {
Cons(u32, List), // an element (`u32`) and the next node in the list
@ -1092,7 +1092,7 @@ let z = x; // no new memory allocated, x can no longer be used
The `clone` method is provided by the `Clone` trait, and can be derived for
our `List` type. Traits will be explained in detail later.
~~~{.xfail-test}
~~~{.ignore}
#[deriving(Clone)]
enum List {
Cons(u32, ~List),
@ -1144,7 +1144,7 @@ ownership of a list to be passed in rather than just mutating it in-place.
The obvious signature for a `List` equality comparison is the following:
~~~{.xfail-test}
~~~{.ignore}
fn eq(xs: List, ys: List) -> bool { ... }
~~~
@ -1152,7 +1152,7 @@ However, this will cause both lists to be moved into the function. Ownership
isn't required to compare the lists, so the function should take *references*
(&T) instead.
~~~{.xfail-test}
~~~{.ignore}
fn eq(xs: &List, ys: &List) -> bool { ... }
~~~
@ -1949,7 +1949,7 @@ Implementations may also define standalone (sometimes called "static")
methods. The absence of a `self` parameter distinguishes such methods.
These methods are the preferred way to define constructor functions.
~~~~ {.xfail-test}
~~~~ {.ignore}
impl Circle {
fn area(&self) -> f64 { ... }
fn new(area: f64) -> Circle { ... }
@ -2073,7 +2073,7 @@ can we copy values of type `T` inside that function?
In Rust, we can't,
and if we try to run the following code the compiler will complain.
~~~~ {.xfail-test}
~~~~ {.ignore}
// This does not compile
fn head_bad<T>(v: &[T]) -> T {
v[0] // error: copying a non-copyable value
@ -2521,7 +2521,7 @@ fn radius_times_area<T: Circle>(c: T) -> f64 {
Likewise, supertrait methods may also be called on trait objects.
~~~ {.xfail-test}
~~~ {.ignore}
use std::f64::consts::PI;
# trait Shape { fn area(&self) -> f64; }
# trait Circle : Shape { fn radius(&self) -> f64; }
@ -2624,7 +2624,7 @@ which contains a function `hay`.
We've now defined a nice module hierarchy. But how do we access the items in it from our `main` function?
One way to do it is to simply fully qualifying it:
~~~~ {.xfail-test}
~~~~ {.ignore}
mod farm {
fn chicken() { println!("cluck cluck"); }
// ...
@ -3152,7 +3152,7 @@ You can also specify package ID information in a `extern mod` statement. For
example, these `extern mod` statements would both accept and select the
crate define above:
~~~~ {.xfail-test}
~~~~ {.ignore}
extern mod farm;
extern mod farm = "farm#2.5";
extern mod my_farm = "farm";
@ -3193,7 +3193,7 @@ pub fn explore() -> &'static str { "world" }
# fn main() {}
~~~~
~~~~ {.xfail-test}
~~~~ {.ignore}
// main.rs
extern mod world;
fn main() { println!("hello {}", world::explore()); }

View File

@ -1,77 +1,209 @@
# xfail-license
# -*- coding: utf-8 -*-
"""
Script for extracting compilable fragments from markdown documentation. See
prep.js for a description of the format recognized by this tool. Expects
a directory fragments/ to exist under the current directory, and writes the
fragments in there as individual .rs files.
"""
from __future__ import print_function
from codecs import open
from collections import deque
from itertools import imap
import os
import re
import sys
# Script for extracting compilable fragments from markdown
# documentation. See prep.js for a description of the format
# recognized by this tool. Expects a directory fragments/ to exist
# under the current directory, and writes the fragments in there as
# individual .rs files.
# regexes
CHAPTER_NAME_REGEX = re.compile(r'# (.*)')
CODE_BLOCK_DELIM_REGEX = re.compile(r'~~~')
COMMENT_REGEX = re.compile(r'^# ')
COMPILER_DIRECTIVE_REGEX = re.compile(r'\#\[(.*)\];')
ELLIPSES_REGEX = re.compile(r'\.\.\.')
EXTERN_MOD_REGEX = re.compile(r'\bextern mod extra\b')
MAIN_FUNCTION_REGEX = re.compile(r'\bfn main\b')
TAGS_REGEX = re.compile(r'\.([\w-]*)')
import sys, re
# tags to ignore
IGNORE_TAGS = \
frozenset(["abnf", "ebnf", "field", "keyword", "notrust", "precedence"])
if len(sys.argv) < 3:
print("Please provide an input filename")
sys.exit(1)
# header for code snippet files
OUTPUT_BLOCK_HEADER = '\n'.join((
"#[ deny(warnings) ];",
"#[ allow(unused_variable) ];",
"#[ allow(dead_assignment) ];",
"#[ allow(unused_mut) ];",
"#[ allow(attribute_usage) ];",
"#[ allow(dead_code) ];",
"#[ feature(macro_rules, globs, struct_variant, managed_boxes) ];\n",))
filename = sys.argv[1]
dest = sys.argv[2]
f = open(filename)
lines = f.readlines()
f.close()
cur = 0
line = ""
chapter = ""
chapter_n = 0
def add_extern_mod(block):
if not has_extern_mod(block):
# add `extern mod extra;` after compiler directives
directives = []
while len(block) and is_compiler_directive(block[0]):
directives.append(block.popleft())
while cur < len(lines):
line = lines[cur]
cur += 1
chap = re.match("# (.*)", line)
if chap:
chapter = re.sub(r"\W", "_", chap.group(1)).lower()
chapter_n = 1
elif re.match("~~~", line):
# Parse the tags that open a code block in the pandoc format:
# ~~~ {.tag1 .tag2}
tags = re.findall("\.([\w-]*)", line)
block = ""
ignore = "notrust" in tags or "ignore" in tags
# Some tags used by the language ref that indicate not rust
ignore |= "ebnf" in tags
ignore |= "abnf" in tags
ignore |= "keyword" in tags
ignore |= "field" in tags
ignore |= "precedence" in tags
xfail = "xfail-test" in tags
while cur < len(lines):
line = lines[cur]
cur += 1
if re.match("~~~", line):
break
else:
# Lines beginning with '# ' are turned into valid code
line = re.sub("^# ", "", line)
# Allow ellipses in code snippets
line = re.sub("\.\.\.", "", line)
block += line
if not ignore:
if not re.search(r"\bfn main\b", block):
block = "fn main() {\n" + block + "\n}\n"
if not re.search(r"\bextern mod extra\b", block):
block = "extern mod extra;\n" + block
block = """#[ deny(warnings) ];
#[ allow(unused_variable) ];\n
#[ allow(dead_assignment) ];\n
#[ allow(unused_mut) ];\n
#[ allow(attribute_usage) ];\n
#[ allow(dead_code) ];\n
#[ feature(macro_rules, globs, struct_variant, managed_boxes) ];\n
""" + block
if xfail:
block = "// xfail-test\n" + block
filename = (dest + "/" + str(chapter)
+ "_" + str(chapter_n) + ".rs")
chapter_n += 1
f = open(filename, 'w')
f.write(block)
f.close()
block.appendleft("\nextern mod extra;\n\n")
block.extendleft(reversed(directives))
return block
def add_main_function(block):
if not has_main_function(block):
prepend_spaces = lambda x: ' ' + x
block = deque(imap(prepend_spaces, block))
block.appendleft("\nfn main() {\n")
block.append("\n}\n")
return block
def extract_code_fragments(dest_dir, lines):
"""
Extracts all the code fragments from a file that do not have ignored tags
writing them to the following file:
[dest dir]/[chapter name]_[chapter_index].rs
"""
chapter_name = None
chapter_index = 0
for line in lines:
if is_chapter_title(line):
chapter_name = get_chapter_name(line)
chapter_index = 1
continue
if not is_code_block_delim(line):
continue
assert chapter_name, "Chapter name missing for code block."
tags = get_tags(line)
block = get_code_block(lines)
if tags & IGNORE_TAGS:
continue
block = add_extern_mod(add_main_function(block))
block.appendleft(OUTPUT_BLOCK_HEADER)
if "ignore" in tags:
block.appendleft("//xfail-test\n")
elif "should_fail" in tags:
block.appendleft("//should-fail\n")
output_filename = os.path.join(
dest_dir,
chapter_name + '_' + str(chapter_index) + '.rs')
write_file(output_filename, block)
chapter_index += 1
def has_extern_mod(block):
"""Checks if a code block has the line `extern mod extra`."""
find_extern_mod = lambda x: re.search(EXTERN_MOD_REGEX, x)
return any(imap(find_extern_mod, block))
def has_main_function(block):
"""Checks if a code block has a main function."""
find_main_fn = lambda x: re.search(MAIN_FUNCTION_REGEX, x)
return any(imap(find_main_fn, block))
def is_chapter_title(line):
return re.match(CHAPTER_NAME_REGEX, line)
def is_code_block_delim(line):
return re.match(CODE_BLOCK_DELIM_REGEX, line)
def is_compiler_directive(line):
return re.match(COMPILER_DIRECTIVE_REGEX, line)
def get_chapter_name(line):
"""Get the chapter name from a `# Containers` line."""
return re.sub(
r'\W',
'_',
re.match(CHAPTER_NAME_REGEX, line).group(1)).lower()
def get_code_block(lines):
"""
Get a code block surrounded by ~~~, for example:
1: ~~~ { .tag }
2: let u: ~[u32] = ~[0, 1, 2];
3: let v: &[u32] = &[0, 1, 2, 3];
4: let w: [u32, .. 5] = [0, 1, 2, 3, 4];
5:
6: println!("u: {}, v: {}, w: {}", u.len(), v.len(), w.len());
7: ~~~
Returns lines 2-6. Assumes line 1 has been consumed by the caller.
"""
strip_comments = lambda x: re.sub(COMMENT_REGEX, '', x)
strip_ellipses = lambda x: re.sub(ELLIPSES_REGEX, '', x)
result = deque()
for line in lines:
if is_code_block_delim(line):
break
result.append(strip_comments(strip_ellipses(line)))
return result
def get_lines(filename):
with open(filename) as f:
for line in f:
yield line
def get_tags(line):
"""
Retrieves all tags from the line format:
~~~ { .tag1 .tag2 .tag3 }
"""
return set(re.findall(TAGS_REGEX, line))
def write_file(filename, lines):
with open(filename, 'w', encoding='utf-8') as f:
for line in lines:
f.write(unicode(line, encoding='utf-8', errors='replace'))
def main(argv=None):
if not argv:
argv = sys.argv
if len(sys.argv) < 2:
sys.stderr.write("Please provide an input filename.")
sys.exit(1)
elif len(sys.argv) < 3:
sys.stderr.write("Please provide a destination directory.")
sys.exit(1)
input_file = sys.argv[1]
dest_dir = sys.argv[2]
if not os.path.exists(input_file):
sys.stderr.write("Input file does not exist.")
sys.exit(1)
if not os.path.exists(dest_dir):
os.mkdir(dest_dir)
extract_code_fragments(dest_dir, get_lines(input_file))
if __name__ == "__main__":
sys.exit(main())