From 49e466f1e1b908e4e97d772d2676e91fe3486113 Mon Sep 17 00:00:00 2001 From: Chris Peterson Date: Sun, 20 Jan 2013 22:39:09 -0800 Subject: [PATCH 1/4] doc: Fix manual's link attributes example code --- doc/rust.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/rust.md b/doc/rust.md index b5f045bc13a..ab9981bcabe 100644 --- a/doc/rust.md +++ b/doc/rust.md @@ -594,16 +594,16 @@ and may optionally begin with any number of `attributes` that apply to the conta Atributes on the anonymous crate module define important metadata that influences the behavior of the compiler. -~~~~~~~~{.xfail-test} +~~~~~~~~ // Linkage attributes -#[ link(name = "projx" +#[ link(name = "projx", vers = "2.5", uuid = "9cccc5d5-aceb-4af5-8285-811211826b82") ]; // Additional metadata attributes -#[ desc = "Project X", - license = "BSD" ]; - author = "Jane Doe" ]; +#[ desc = "Project X" ]; +#[ license = "BSD" ]; +#[ author = "Jane Doe" ]; // Specify the output type #[ crate_type = "lib" ]; From 0b6487cf2c51945c7107f4ebf2b49e4c4e873043 Mon Sep 17 00:00:00 2001 From: Chris Peterson Date: Sun, 20 Jan 2013 22:48:47 -0800 Subject: [PATCH 2/4] doc: Fix tutorial typo and remove unnecessary xfail-test --- doc/tutorial-tasks.md | 2 +- doc/tutorial.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/tutorial-tasks.md b/doc/tutorial-tasks.md index d29eb8a98fd..26541eca7d3 100644 --- a/doc/tutorial-tasks.md +++ b/doc/tutorial-tasks.md @@ -220,7 +220,7 @@ let result = port.recv(); The `Port` and `Chan` pair created by `stream` enables efficient communication between a single sender and a single receiver, but multiple senders cannot use a single `Chan`, and multiple receivers cannot use a single `Port`. What if our -example needed to computer multiple results across a number of tasks? The +example needed to compute multiple results across a number of tasks? The following program is ill-typed: ~~~ {.xfail-test} diff --git a/doc/tutorial.md b/doc/tutorial.md index e26651508ef..a8839ad1630 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -2393,7 +2393,7 @@ override the name used to search for the crate. Our example crate declared this set of `link` attributes: -~~~~ {.xfail-test} +~~~~ #[link(name = "farm", vers = "2.5", author = "mjh")]; ~~~~ From 50c8cbb25aeb9d8132ac06914e9978d3cddb7f42 Mon Sep 17 00:00:00 2001 From: Chris Peterson Date: Sun, 20 Jan 2013 22:50:00 -0800 Subject: [PATCH 3/4] doc: Fix tutorial-ffi xfail-tests and update SHA1() to use size_t --- doc/tutorial-ffi.md | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/doc/tutorial-ffi.md b/doc/tutorial-ffi.md index 8324f752c1d..7b39dc2f198 100644 --- a/doc/tutorial-ffi.md +++ b/doc/tutorial-ffi.md @@ -12,12 +12,12 @@ argument, which it then converts to a hexadecimal string and prints to standard output. If you have the OpenSSL libraries installed, it should compile and run without any extra effort. -~~~~ {.xfail-test} +~~~~ extern mod std; -use libc::c_uint; +use libc::size_t; extern mod crypto { - fn SHA1(src: *u8, sz: c_uint, out: *u8) -> *u8; + fn SHA1(src: *u8, sz: size_t, out: *u8) -> *u8; } fn as_hex(data: ~[u8]) -> ~str { @@ -29,7 +29,7 @@ fn as_hex(data: ~[u8]) -> ~str { fn sha1(data: ~str) -> ~str unsafe { let bytes = str::to_bytes(data); let hash = crypto::SHA1(vec::raw::to_ptr(bytes), - vec::len(bytes) as c_uint, ptr::null()); + vec::len(bytes) as size_t, ptr::null()); return as_hex(vec::from_buf(hash, 20)); } @@ -43,9 +43,11 @@ fn main() { Before we can call the `SHA1` function defined in the OpenSSL library, we have to declare it. That is what this part of the program does: -~~~~ {.xfail-test} +~~~~ +# use libc::size_t; extern mod crypto { - fn SHA1(src: *u8, sz: uint, out: *u8) -> *u8; } + fn SHA1(src: *u8, sz: size_t, out: *u8) -> *u8; +} ~~~~ An `extern` module declaration containing function signatures introduces the @@ -62,10 +64,11 @@ searches for the shared library with that name, and links the library into the program. If you want the module to have a different name from the actual library, you can use the `"link_name"` attribute, like: -~~~~ {.xfail-test} +~~~~ +# use libc::size_t; #[link_name = "crypto"] extern mod something { - fn SHA1(src: *u8, sz: uint, out: *u8) -> *u8; + fn SHA1(src: *u8, sz: size_t, out: *u8) -> *u8; } ~~~~ @@ -94,9 +97,10 @@ calling conventions. The foreign `SHA1` function takes three arguments, and returns a pointer. -~~~~ {.xfail-test} +~~~~ +# use libc::size_t; # extern mod crypto { -fn SHA1(src: *u8, sz: libc::c_uint, out: *u8) -> *u8; +fn SHA1(src: *u8, sz: size_t, out: *u8) -> *u8; # } ~~~~ @@ -108,8 +112,8 @@ probably even worse, your code will work on one platform, but break on another. In this case, we declare that `SHA1` takes two `unsigned char*` -arguments and one `unsigned long`. The Rust equivalents are `*u8` -unsafe pointers and an `uint` (which, like `unsigned long`, is a +arguments and one `size_t`. The Rust equivalents are `*u8` +unsafe pointers and an `libc::size_t` (which, like `unsigned long`, is a machine-word-sized type). The standard library provides various functions to create unsafe pointers, @@ -124,14 +128,16 @@ The `sha1` function is the most obscure part of the program. ~~~~ # pub mod crypto { -# pub fn SHA1(src: *u8, sz: uint, out: *u8) -> *u8 { out } +# use libc::size_t; +# pub fn SHA1(src: *u8, sz: size_t, out: *u8) -> *u8 { out } # } +# use libc::size_t; # fn as_hex(data: ~[u8]) -> ~str { ~"hi" } fn sha1(data: ~str) -> ~str { unsafe { let bytes = str::to_bytes(data); let hash = crypto::SHA1(vec::raw::to_ptr(bytes), - vec::len(bytes), ptr::null()); + vec::len(bytes) as size_t, ptr::null()); return as_hex(vec::from_buf(hash, 20)); } } @@ -169,14 +175,16 @@ Let's look at our `sha1` function again. ~~~~ # pub mod crypto { -# pub fn SHA1(src: *u8, sz: uint, out: *u8) -> *u8 { out } +# use libc::size_t; +# pub fn SHA1(src: *u8, sz: size_t, out: *u8) -> *u8 { out } # } +# use libc::size_t; # fn as_hex(data: ~[u8]) -> ~str { ~"hi" } # fn x(data: ~str) -> ~str { # unsafe { let bytes = str::to_bytes(data); let hash = crypto::SHA1(vec::raw::to_ptr(bytes), - vec::len(bytes), ptr::null()); + vec::len(bytes) as size_t, ptr::null()); return as_hex(vec::from_buf(hash, 20)); # } # } From b3cbe9e3c1115239997e806498fa5bc7eea7bc98 Mon Sep 17 00:00:00 2001 From: Chris Peterson Date: Sun, 20 Jan 2013 22:52:42 -0800 Subject: [PATCH 4/4] Enable lint warnings for doc tests --- src/etc/extract-tests.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/etc/extract-tests.py b/src/etc/extract-tests.py index 9d9b7817f4b..5754d234afb 100644 --- a/src/etc/extract-tests.py +++ b/src/etc/extract-tests.py @@ -2,11 +2,11 @@ # Script for extracting compilable fragments from markdown # documentation. See prep.js for a description of the format -# recognized by this tool. Expects a directory fragements/ to exist +# recognized by this tool. Expects a directory fragments/ to exist # under the current directory, and writes the fragments in there as # individual .rs files. -import sys, re; +import sys, re if len(sys.argv) < 3: print("Please provide an input filename") @@ -26,7 +26,7 @@ chapter_n = 0 while cur < len(lines): line = lines[cur] cur += 1 - chap = re.match("# (.*)", line); + chap = re.match("# (.*)", line) if chap: chapter = re.sub(r"\W", "_", chap.group(1)).lower() chapter_n = 1 @@ -51,14 +51,30 @@ while cur < len(lines): else: # Lines beginning with '# ' are turned into valid code line = re.sub("^# ", "", line) - # Allow elipses in code snippets + # 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 std\b", block): - block = "extern mod std;\n" + block; + block = "extern mod std;\n" + block + block = """#[ forbid(ctypes) ]; +#[ forbid(deprecated_mode) ]; +#[ forbid(deprecated_pattern) ]; +#[ forbid(implicit_copies) ]; +#[ forbid(non_implicitly_copyable_typarams) ]; +#[ forbid(path_statement) ]; +#[ forbid(type_limits) ]; +#[ forbid(unrecognized_lint) ]; +#[ forbid(unused_imports) ]; +#[ forbid(vecs_implicitly_copyable) ]; +#[ forbid(while_true) ]; + +#[ warn(deprecated_self) ]; +#[ warn(non_camel_case_types) ]; +#[ warn(structural_records) ];\n +""" + block if xfail: block = "// xfail-test\n" + block filename = (dest + "/" + str(chapter)