From b2949ae543e5a7a1e2b5543aff8e4252f1aab41c Mon Sep 17 00:00:00 2001 From: "NODA, Kai" Date: Sun, 12 Oct 2014 16:16:43 +0800 Subject: [PATCH 01/19] Fix HTML version of the keyword table. This should really fix rust-lang/rust#17528. --- src/doc/reference.md | 18 +----------------- src/doc/rust.css | 7 ++++++- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/src/doc/reference.md b/src/doc/reference.md index c34a136a68e8..9426105b5b31 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -185,40 +185,24 @@ grammar as double-quoted strings. Other tokens have exact rules given. ### Keywords -The keywords are the following strings, organized by first letter: +

The keywords are the following strings, organized by first letter:

-
| | | | | |----------|--------|--------|-------| | as | | | | -|----------|--------|--------|-------| | box | break | | | -|----------|--------|--------|-------| | continue | crate | | | -|----------|--------|--------|-------| | else | enum | extern | | -|----------|--------|--------|-------| | false | fn | for | | -|----------|--------|--------|-------| | if | impl | in | | -|----------|--------|--------|-------| | let | loop | | | -|----------|--------|--------|-------| | match | mod | mut | | -|----------|--------|--------|-------| | priv | proc | pub | | -|----------|--------|--------|-------| | ref | return | | | -|----------|--------|--------|-------| | self | static | struct | super | -|----------|--------|--------|-------| | trait | true | type | | -|----------|--------|--------|-------| | unsafe | use | | | -|----------|--------|--------|-------| | while | | | | -|----------|--------|--------|-------| -
Each of these keywords has special meaning in its grammar, and all of them are excluded from the `ident` rule. diff --git a/src/doc/rust.css b/src/doc/rust.css index b615c392bd5e..4bbb80984021 100644 --- a/src/doc/rust.css +++ b/src/doc/rust.css @@ -393,4 +393,9 @@ pre.rust { position: relative; } } } -#keywords table td { border: none; } +#keyword-table-marker + table thead { display: none; } +#keyword-table-marker + table td { border: none; } +#keyword-table-marker + table { + margin-left: 2em; + margin-bottom: 1em; +} From e2fed746c2b0d40707900fe9091868cc7d9ed94b Mon Sep 17 00:00:00 2001 From: "NODA, Kai" Date: Thu, 25 Sep 2014 22:11:18 +0800 Subject: [PATCH 02/19] src/doc/README.md: fix a dead link. Also make some typographical changes. --- src/doc/README.md | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/doc/README.md b/src/doc/README.md index cf1557e66049..50222973509a 100644 --- a/src/doc/README.md +++ b/src/doc/README.md @@ -1,4 +1,6 @@ -# Dependencies +# Rust documentations + +## Dependencies [Pandoc](http://johnmacfarlane.net/pandoc/installing.html), a universal document converter, is required to generate docs as HTML from Rust's @@ -10,7 +12,7 @@ docs from the master (English) docs. [GNU gettext](http://www.gnu.org/software/gettext/) is required for managing the translation data. -# Building +## Building To generate all the docs, just run `make docs` from the root of the repository. This will convert the distributed Markdown docs to HTML and generate HTML doc @@ -24,7 +26,7 @@ rustdoc --output html-doc/ --output-format html ../src/libstd/path.rs (This, of course, requires a working build of the `rustdoc` tool.) -# Additional notes +## Additional notes To generate an HTML version of a doc from Markdown manually, you can do something like: @@ -33,37 +35,39 @@ something like: pandoc --from=markdown --to=html5 --number-sections -o reference.html reference.md ~~~~ -(reference.md being the Rust Reference Manual.) +(`reference.md` being the Rust Reference Manual.) The syntax for pandoc flavored markdown can be found at: -http://johnmacfarlane.net/pandoc/README.html#pandocs-markdown + +- http://johnmacfarlane.net/pandoc/README.html#pandocs-markdown A nice quick reference (for non-pandoc markdown) is at: -http://kramdown.rubyforge.org/quickref.html -# Notes for translators +- http://kramdown.gettalong.org/quickref.html + +## Notes for translators Notice: The procedure described below is a work in progress. We are working on translation system but the procedure contains some manual operations for now. -To start the translation for a new language, see po4a.conf at first. +To start the translation for a new language, see `po4a.conf` at first. -To generate .pot and .po files, do something like: +To generate `.pot` and `.po` files, do something like: ~~~~ po4a --copyright-holder="The Rust Project Developers" \ --package-name="Rust" \ - --package-version="0.11.0" \ + --package-version="0.13.0" \ -M UTF-8 -L UTF-8 \ src/doc/po4a.conf ~~~~ -(the version number must be changed if it is not 0.11.0 now.) +(the version number must be changed if it is not `0.13.0` now.) -Now you can translate documents with .po files, commonly used with gettext. If +Now you can translate documents with `.po` files, commonly used with gettext. If you are not familiar with gettext-based translation, please read the online manual linked from http://www.gnu.org/software/gettext/ . We use UTF-8 as the -file encoding of .po files. +file encoding of `.po` files. When you want to make a commit, do the command below before staging your change: @@ -79,4 +83,4 @@ for f in src/doc/po/**/*.po; do done ~~~~ -This removes untranslated entries from .po files to save disk space. +This removes untranslated entries from `.po` files to save disk space. From 785ae90f104252492accb15dcbba3a094915504a Mon Sep 17 00:00:00 2001 From: Michael Gehring Date: Sat, 11 Oct 2014 16:16:38 +0200 Subject: [PATCH 03/19] Fix run-pass/lang-item-public test on FreeBSD --- src/test/run-pass/lang-item-public.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/test/run-pass/lang-item-public.rs b/src/test/run-pass/lang-item-public.rs index abd5f8326b07..982d4f6a0b56 100644 --- a/src/test/run-pass/lang-item-public.rs +++ b/src/test/run-pass/lang-item-public.rs @@ -28,6 +28,10 @@ extern {} #[link(name = "execinfo")] extern {} +#[cfg(target_os = "freebsd")] +#[link(name = "c")] +extern {} + #[cfg(target_os = "dragonfly")] #[link(name = "c")] extern {} From d7dc97e38405eabccf2a863c888666df2ea8a535 Mon Sep 17 00:00:00 2001 From: Erwan Date: Sun, 12 Oct 2014 18:51:11 +0200 Subject: [PATCH 04/19] fix broken link in guide-strings.md --- src/doc/guide-strings.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/guide-strings.md b/src/doc/guide-strings.md index a49132ec8be9..afca75a76d44 100644 --- a/src/doc/guide-strings.md +++ b/src/doc/guide-strings.md @@ -206,5 +206,5 @@ Many more bytes than graphemes! # Other Documentation -* [the `&str` API documentation](/std/str/index.html) +* [the `&str` API documentation](std/str/index.html) * [the `String` API documentation](std/string/index.html) From 18e41299f9368c593be688792962a6d0c299c9bc Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 10 Oct 2014 08:31:13 -0700 Subject: [PATCH 05/19] rustc: Warn about dead constants A few catch-all blocks ended up not having this case for constants. Closes #17925 --- src/librustc/middle/dead.rs | 1 + src/libsyntax/ast.rs | 4 +++- src/test/compile-fail/lint-dead-code-1.rs | 7 +++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index ff3720381009..61b013d795ea 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -441,6 +441,7 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> { fn should_warn_about_item(&mut self, item: &ast::Item) -> bool { let should_warn = match item.node { ast::ItemStatic(..) + | ast::ItemConst(..) | ast::ItemFn(..) | ast::ItemEnum(..) | ast::ItemStruct(..) => true, diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 274bb2e39e01..be79b18bfe9a 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1334,6 +1334,7 @@ impl Item_ { pub fn descriptive_variant(&self) -> &str { match *self { ItemStatic(..) => "static item", + ItemConst(..) => "constant item", ItemFn(..) => "function", ItemMod(..) => "module", ItemForeignMod(..) => "foreign module", @@ -1341,7 +1342,8 @@ impl Item_ { ItemEnum(..) => "enum", ItemStruct(..) => "struct", ItemTrait(..) => "trait", - _ => "item" + ItemMac(..) | + ItemImpl(..) => "item" } } } diff --git a/src/test/compile-fail/lint-dead-code-1.rs b/src/test/compile-fail/lint-dead-code-1.rs index a4320b8dc775..998e7c017923 100644 --- a/src/test/compile-fail/lint-dead-code-1.rs +++ b/src/test/compile-fail/lint-dead-code-1.rs @@ -35,6 +35,13 @@ pub static used_static2: int = used_static; const USED_STATIC: int = 0; const STATIC_USED_IN_ENUM_DISCRIMINANT: int = 10; +pub const pub_const: int = 0; +const priv_const: int = 0; //~ ERROR: constant item is never used +const used_const: int = 0; +pub const used_const2: int = used_const; +const USED_CONST: int = 0; +const CONST_USED_IN_ENUM_DISCRIMINANT: int = 10; + pub type typ = *const UsedStruct4; pub struct PubStruct; struct PrivStruct; //~ ERROR: struct is never used From 67418f55098750fe196d9d465de671d2e1f659c1 Mon Sep 17 00:00:00 2001 From: John Kleint Date: Sun, 12 Oct 2014 15:24:39 -0400 Subject: [PATCH 06/19] Guide: remove promise of a counter in the guessing game. Issue #17964. --- src/doc/guide.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/doc/guide.md b/src/doc/guide.md index 4e9966cb3db2..9f7e51155c6f 100644 --- a/src/doc/guide.md +++ b/src/doc/guide.md @@ -1746,8 +1746,7 @@ For our first project, we'll implement a classic beginner programming problem: the guessing game. Here's how it works: Our program will generate a random integer between one and a hundred. It will then prompt us to enter a guess. Upon entering our guess, it will tell us if we're too low or too high. Once we -guess correctly, it will congratulate us, and print the number of guesses we've -taken to the screen. Sound good? +guess correctly, it will congratulate us. Sound good? ## Set up From 5b043d712b18e0477e578a47767b35a643acedfd Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sun, 12 Oct 2014 12:36:32 -0700 Subject: [PATCH 07/19] Fix `find` check for executables Apparently the fix in d08441b9 didn't catch a recent executable (#17965), but I've verified that this does indeed catch the executable --- mk/tests.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mk/tests.mk b/mk/tests.mk index 04be295c2713..894c5901228c 100644 --- a/mk/tests.mk +++ b/mk/tests.mk @@ -284,7 +284,7 @@ tidy: | xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py $(Q)echo $(ALL_HS) \ | xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py - $(Q)find $(S)src -type f -perm a+x \ + $(Q)find $(S)src -type f -perm +a+x \ -not -name '*.rs' -and -not -name '*.py' \ -and -not -name '*.sh' \ | grep '^$(S)src/jemalloc' -v \ From 04608413ba1e814e70353369ebde9fc849215157 Mon Sep 17 00:00:00 2001 From: Brian Koropoff Date: Sun, 12 Oct 2014 14:43:32 -0700 Subject: [PATCH 08/19] Properly visit nested functions and closures in check_rvalues This correctly catches moves of unsized values in nested functions and closures. Closes issue #17651 --- src/librustc/middle/check_rvalues.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/librustc/middle/check_rvalues.rs b/src/librustc/middle/check_rvalues.rs index 21023986e1c2..2a2655cc49c6 100644 --- a/src/librustc/middle/check_rvalues.rs +++ b/src/librustc/middle/check_rvalues.rs @@ -32,13 +32,16 @@ struct RvalueContext<'a, 'tcx: 'a> { impl<'a, 'tcx, 'v> visit::Visitor<'v> for RvalueContext<'a, 'tcx> { fn visit_fn(&mut self, - _: visit::FnKind<'v>, + fk: visit::FnKind<'v>, fd: &'v ast::FnDecl, b: &'v ast::Block, - _: Span, + s: Span, _: ast::NodeId) { - let mut euv = euv::ExprUseVisitor::new(self, self.tcx); - euv.walk_fn(fd, b); + { + let mut euv = euv::ExprUseVisitor::new(self, self.tcx); + euv.walk_fn(fd, b); + } + visit::walk_fn(self, fk, fd, b, s) } } From 1cbce309fe2a2fb91577eb8010a378f4ae32daa8 Mon Sep 17 00:00:00 2001 From: Felix Raimundo Date: Mon, 13 Oct 2014 00:13:41 +0200 Subject: [PATCH 09/19] Fixes small error on the doc (task part) --- src/doc/guide.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/guide.md b/src/doc/guide.md index 4e9966cb3db2..ece6af0af018 100644 --- a/src/doc/guide.md +++ b/src/doc/guide.md @@ -5062,8 +5062,8 @@ println!("The value of x[0] is: {}", x[0]); // error: use of moved value: `x` ``` `x` is now owned by the proc, and so we can't use it anymore. Many other -languages would let us do this, but it's not safe to do so. Rust's type system -catches the error. +languages would let us do this, but it's not safe to do so. Rust's borrow +checker catches the error. If tasks were only able to capture these values, they wouldn't be very useful. Luckily, tasks can communicate with each other through **channel**s. Channels From 3caecffe0155e40ec888c16a3987a8582a8b80b1 Mon Sep 17 00:00:00 2001 From: Brian Koropoff Date: Sun, 12 Oct 2014 15:14:36 -0700 Subject: [PATCH 10/19] Add regression test for issue #17651 --- src/test/compile-fail/issue-17651.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/test/compile-fail/issue-17651.rs diff --git a/src/test/compile-fail/issue-17651.rs b/src/test/compile-fail/issue-17651.rs new file mode 100644 index 000000000000..ef8174a26aa8 --- /dev/null +++ b/src/test/compile-fail/issue-17651.rs @@ -0,0 +1,17 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that moves of unsized values within closures are caught +// and rejected. + +fn main() { + (|| box *[0u].as_slice())(); + //~^ ERROR cannot move a value of type [uint] +} From ed7d1be12f61e8a863c8c1cb645ca12f9ce38721 Mon Sep 17 00:00:00 2001 From: John Kleint Date: Sun, 12 Oct 2014 23:50:22 -0400 Subject: [PATCH 11/19] Guide: specify that both shared and mutable borrows can be re-lent. --- src/doc/guide.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/doc/guide.md b/src/doc/guide.md index 4e9966cb3db2..d507812478e9 100644 --- a/src/doc/guide.md +++ b/src/doc/guide.md @@ -3538,9 +3538,8 @@ restriction: 1. If the borrow is immutable, you may read the data the pointer points to. 2. If the borrow is mutable, you may read and write the data the pointer points to. -3. You may lend the pointer to someone else in an immutable fashion, **BUT** -4. When you do so, they must return it to you before you must give your own - borrow back. +3. You may lend the pointer to someone else, **BUT** +4. When you do so, they must return it before you can give your own borrow back. This last requirement can seem odd, but it also makes sense. If you have to return something, and you've lent it to someone, they need to give it back to From c6f9b8ff17e9ca45b12e50af2de8815bd63c7cab Mon Sep 17 00:00:00 2001 From: Gil Cottle Date: Mon, 13 Oct 2014 01:36:10 -0400 Subject: [PATCH 12/19] Doc: Fix C-Code Example in FFI Docs Add missing void* for passed RustObject. --- src/doc/guide-ffi.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/guide-ffi.md b/src/doc/guide-ffi.md index 14e60b5ba088..ee398334e2ad 100644 --- a/src/doc/guide-ffi.md +++ b/src/doc/guide-ffi.md @@ -298,7 +298,7 @@ fn main() { C code: ~~~~c -typedef void (*rust_callback)(int32_t); +typedef void (*rust_callback)(void*, int32_t); void* cb_target; rust_callback cb; From f27ad3d3e99ce679f782607971a9f6f18befa503 Mon Sep 17 00:00:00 2001 From: "NODA, Kai" Date: Sun, 5 Oct 2014 18:11:17 +0800 Subject: [PATCH 13/19] Clean up rustc warnings. compiletest: compact "linux" "macos" etc.as "unix". liballoc: remove a superfluous "use". libcollections: remove invocations of deprecated methods in favor of their suggested replacements and use "_" for a loop counter. libcoretest: remove invocations of deprecated methods; also add "allow(deprecated)" for testing a deprecated method itself. libglob: use "cfg_attr". libgraphviz: add a test for one of data constructors. libgreen: remove a superfluous "use". libnum: "allow(type_overflow)" for type cast into u8 in a test code. librustc: names of static variables should be in upper case. libserialize: v[i] instead of get(). libstd/ascii: to_lowercase() instead of to_lower(). libstd/bitflags: modify AnotherSetOfFlags to use i8 as its backend. It will serve better for testing various aspects of bitflags!. libstd/collections: "allow(deprecated)" for testing a deprecated method itself. libstd/io: remove invocations of deprecated methods and superfluous "use". Also add #[test] where it was missing. libstd/num: introduce a helper function to effectively remove invocations of a deprecated method. libstd/path and rand: remove invocations of deprecated methods and superfluous "use". libstd/task and libsync/comm: "allow(deprecated)" for testing a deprecated method itself. libsync/deque: remove superfluous "unsafe". libsync/mutex and once: names of static variables should be in upper case. libterm: introduce a helper function to effectively remove invocations of a deprecated method. We still see a few warnings about using obsoleted native::task::spawn() in the test modules for libsync. I'm not sure how I should replace them with std::task::TaksBuilder and native::task::NativeTaskBuilder (dependency to libstd?) Signed-off-by: NODA, Kai --- src/compiletest/runtest.rs | 28 +++++++---------- src/liballoc/arc.rs | 1 - src/libcollections/bitv.rs | 2 +- src/libcollections/dlist.rs | 8 ++--- src/libcollections/ringbuf.rs | 12 ++++---- src/libcollections/str.rs | 3 +- src/libcollections/string.rs | 25 ++++++++------- src/libcollections/vec.rs | 44 +++++++++++++-------------- src/libcoretest/char.rs | 4 +-- src/libcoretest/iter.rs | 2 +- src/libcoretest/mem.rs | 2 +- src/libcoretest/result.rs | 1 + src/libglob/lib.rs | 2 +- src/libgraphviz/lib.rs | 14 +++++++++ src/libgreen/sched.rs | 1 - src/libnum/integer.rs | 1 + src/librustrt/mutex.rs | 30 +++++++++--------- src/libserialize/json.rs | 4 +-- src/libstd/ascii.rs | 16 +++++----- src/libstd/bitflags.rs | 31 +++++++++++++++++-- src/libstd/collections/hashmap/map.rs | 1 + src/libstd/io/buffered.rs | 6 ++-- src/libstd/io/fs.rs | 10 +++--- src/libstd/io/mem.rs | 2 +- src/libstd/io/mod.rs | 42 ++++++++++++------------- src/libstd/io/net/addrinfo.rs | 2 -- src/libstd/io/net/tcp.rs | 2 -- src/libstd/io/pipe.rs | 1 - src/libstd/io/process.rs | 8 ++--- src/libstd/io/stdio.rs | 5 ++- src/libstd/io/timer.rs | 1 - src/libstd/num/strconv.rs | 34 +++++++++++++-------- src/libstd/path/posix.rs | 4 +-- src/libstd/rand/reader.rs | 15 +++++---- src/libstd/task.rs | 1 + src/libsync/comm/duplex.rs | 3 +- src/libsync/deque.rs | 34 +++++++++------------ src/libsync/mutex.rs | 26 ++++++++-------- src/libsync/one.rs | 12 ++++---- src/libterm/terminfo/parm.rs | 43 +++++++++++++------------- 40 files changed, 263 insertions(+), 220 deletions(-) diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index ab8d924a4426..ff6b1b153332 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -947,15 +947,12 @@ fn check_expected_errors(expected_errors: Vec , String::from_chars(c.as_slice()) } - #[cfg(target_os = "windows")] + #[cfg(windows)] fn prefix_matches( line : &str, prefix : &str ) -> bool { to_lower(line).as_slice().starts_with(to_lower(prefix).as_slice()) } - #[cfg(any(target_os = "linux", - target_os = "macos", - target_os = "freebsd", - target_os = "dragonfly"))] + #[cfg(unix)] fn prefix_matches( line : &str, prefix : &str ) -> bool { line.starts_with( prefix ) } @@ -1356,24 +1353,21 @@ fn program_output(config: &Config, testfile: &Path, lib_path: &str, prog: String } // Linux and mac don't require adjusting the library search path -#[cfg(any(target_os = "linux", - target_os = "macos", - target_os = "freebsd", - target_os = "dragonfly"))] +#[cfg(unix)] fn make_cmdline(_libpath: &str, prog: &str, args: &[String]) -> String { format!("{} {}", prog, args.connect(" ")) } -#[cfg(target_os = "windows")] +#[cfg(windows)] fn make_cmdline(libpath: &str, prog: &str, args: &[String]) -> String { - format!("{} {} {}", lib_path_cmd_prefix(libpath), prog, args.connect(" ")) -} -// Build the LD_LIBRARY_PATH variable as it would be seen on the command line -// for diagnostic purposes -#[cfg(target_os = "windows")] -fn lib_path_cmd_prefix(path: &str) -> String { - format!("{}=\"{}\"", util::lib_path_env_var(), util::make_new_path(path)) + // Build the LD_LIBRARY_PATH variable as it would be seen on the command line + // for diagnostic purposes + fn lib_path_cmd_prefix(path: &str) -> String { + format!("{}=\"{}\"", util::lib_path_env_var(), util::make_new_path(path)) + } + + format!("{} {} {}", lib_path_cmd_prefix(libpath), prog, args.connect(" ")) } fn dump_output(config: &Config, testfile: &Path, out: &str, err: &str) { diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index 39524ed547d5..a2483f23534e 100644 --- a/src/liballoc/arc.rs +++ b/src/liballoc/arc.rs @@ -276,7 +276,6 @@ impl Drop for Weak { #[allow(experimental)] mod tests { use std::clone::Clone; - use std::collections::MutableSeq; use std::comm::channel; use std::mem::drop; use std::ops::Drop; diff --git a/src/libcollections/bitv.rs b/src/libcollections/bitv.rs index 8f9873d77d17..bfa5e237f55e 100644 --- a/src/libcollections/bitv.rs +++ b/src/libcollections/bitv.rs @@ -2659,7 +2659,7 @@ mod tests { let mut r = rng(); let mut bitv = Bitv::with_capacity(BENCH_BITS, false); b.iter(|| { - for i in range(0u, 100) { + for _ in range(0u, 100) { bitv.set((r.next_u32() as uint) % BENCH_BITS, r.gen()); } &bitv diff --git a/src/libcollections/dlist.rs b/src/libcollections/dlist.rs index 87e07b7b1b66..088784070e71 100644 --- a/src/libcollections/dlist.rs +++ b/src/libcollections/dlist.rs @@ -890,13 +890,13 @@ mod tests { } let v = vec![1i,2,3,4,5]; - let u = vec![9i,8,1,2,3,4,5]; + let mut u = vec![9i,8,1,2,3,4,5]; let mut m = list_from(v.as_slice()); m.prepend(list_from(u.as_slice())); check_links(&m); - let sum = u.append(v.as_slice()); - assert_eq!(sum.len(), m.len()); - for elt in sum.into_iter() { + u.extend(v.as_slice().iter().map(|&b| b)); + assert_eq!(u.len(), m.len()); + for elt in u.into_iter() { assert_eq!(m.pop_front(), Some(elt)) } } diff --git a/src/libcollections/ringbuf.rs b/src/libcollections/ringbuf.rs index c9c824ac9ceb..4d8e67f6ac8f 100644 --- a/src/libcollections/ringbuf.rs +++ b/src/libcollections/ringbuf.rs @@ -611,10 +611,10 @@ mod tests { assert_eq!(deq.len(), 3); deq.push_front(a.clone()); assert_eq!(deq.len(), 4); - assert_eq!((*deq.get(0)).clone(), a.clone()); - assert_eq!((*deq.get(1)).clone(), b.clone()); - assert_eq!((*deq.get(2)).clone(), c.clone()); - assert_eq!((*deq.get(3)).clone(), d.clone()); + assert_eq!(deq[0].clone(), a.clone()); + assert_eq!(deq[1].clone(), b.clone()); + assert_eq!(deq[2].clone(), c.clone()); + assert_eq!(deq[3].clone(), d.clone()); } #[test] @@ -626,7 +626,7 @@ mod tests { assert_eq!(deq.len(), 66); for i in range(0u, 66) { - assert_eq!(*deq.get(i), 65 - i); + assert_eq!(deq[i], 65 - i); } let mut deq = RingBuf::new(); @@ -635,7 +635,7 @@ mod tests { } for i in range(0u, 66) { - assert_eq!(*deq.get(i), i); + assert_eq!(deq[i], i); } } diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index f3d3506de837..f49371b8e886 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -883,6 +883,7 @@ mod tests { use std::slice::{AsSlice, ImmutableSlice}; use string::String; use vec::Vec; + use slice::CloneableVector; use unicode::char::UnicodeChar; @@ -1504,7 +1505,7 @@ mod tests { fn vec_str_conversions() { let s1: String = String::from_str("All mimsy were the borogoves"); - let v: Vec = Vec::from_slice(s1.as_bytes()); + let v: Vec = s1.as_bytes().to_vec(); let s2: String = String::from_str(from_utf8(v.as_slice()).unwrap()); let mut i: uint = 0u; let n1: uint = s1.len(); diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 848068f20c2d..061064ff803d 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -1036,6 +1036,7 @@ mod tests { use str::{Str, StrSlice, Owned}; use super::{as_string, String}; use vec::Vec; + use slice::CloneableVector; #[test] fn test_as_string() { @@ -1051,15 +1052,15 @@ mod tests { #[test] fn test_from_utf8() { - let xs = Vec::from_slice(b"hello"); + let xs = b"hello".to_vec(); assert_eq!(String::from_utf8(xs), Ok(String::from_str("hello"))); - let xs = Vec::from_slice("ศไทย中华Việt Nam".as_bytes()); + let xs = "ศไทย中华Việt Nam".as_bytes().to_vec(); assert_eq!(String::from_utf8(xs), Ok(String::from_str("ศไทย中华Việt Nam"))); - let xs = Vec::from_slice(b"hello\xFF"); + let xs = b"hello\xFF".to_vec(); assert_eq!(String::from_utf8(xs), - Err(Vec::from_slice(b"hello\xFF"))); + Err(b"hello\xFF".to_vec())); } #[test] @@ -1211,7 +1212,8 @@ mod tests { fn test_push_bytes() { let mut s = String::from_str("ABC"); unsafe { - s.push_bytes([b'D']); + let mv = s.as_mut_vec(); + mv.push_all([b'D']); } assert_eq!(s.as_slice(), "ABCD"); } @@ -1239,17 +1241,18 @@ mod tests { } #[test] - fn test_pop_char() { + fn test_pop() { let mut data = String::from_str("ประเทศไทย中华b¢€𤭢"); - assert_eq!(data.pop_char().unwrap(), '𤭢'); // 4 bytes - assert_eq!(data.pop_char().unwrap(), '€'); // 3 bytes - assert_eq!(data.pop_char().unwrap(), '¢'); // 2 bytes - assert_eq!(data.pop_char().unwrap(), 'b'); // 1 bytes - assert_eq!(data.pop_char().unwrap(), '华'); + assert_eq!(data.pop().unwrap(), '𤭢'); // 4 bytes + assert_eq!(data.pop().unwrap(), '€'); // 3 bytes + assert_eq!(data.pop().unwrap(), '¢'); // 2 bytes + assert_eq!(data.pop().unwrap(), 'b'); // 1 bytes + assert_eq!(data.pop().unwrap(), '华'); assert_eq!(data.as_slice(), "ประเทศไทย中"); } #[test] + #[allow(deprecated)] // use remove(0) instead fn test_shift_char() { let mut data = String::from_str("𤭢€¢b华ประเทศไทย中"); assert_eq!(data.shift_char().unwrap(), '𤭢'); // 4 bytes diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index f922c189fefa..c714e3935706 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -2266,8 +2266,8 @@ mod tests { } #[test] - fn test_mut_slice_from() { - let mut values = Vec::from_slice([1u8,2,3,4,5]); + fn test_slice_from_mut() { + let mut values = vec![1u8,2,3,4,5]; { let slice = values.slice_from_mut(2); assert!(slice == [3, 4, 5]); @@ -2280,8 +2280,8 @@ mod tests { } #[test] - fn test_mut_slice_to() { - let mut values = Vec::from_slice([1u8,2,3,4,5]); + fn test_slice_to_mut() { + let mut values = vec![1u8,2,3,4,5]; { let slice = values.slice_to_mut(2); assert!(slice == [1, 2]); @@ -2294,8 +2294,8 @@ mod tests { } #[test] - fn test_mut_split_at() { - let mut values = Vec::from_slice([1u8,2,3,4,5]); + fn test_split_at_mut() { + let mut values = vec![1u8,2,3,4,5]; { let (left, right) = values.split_at_mut(2); { @@ -2315,7 +2315,7 @@ mod tests { } } - assert!(values == Vec::from_slice([2u8, 3, 5, 6, 7])); + assert!(values == vec![2u8, 3, 5, 6, 7]); } #[test] @@ -2355,16 +2355,16 @@ mod tests { #[test] fn test_grow_fn() { - let mut v = Vec::from_slice([0u, 1]); + let mut v = vec![0u, 1]; v.grow_fn(3, |i| i); - assert!(v == Vec::from_slice([0u, 1, 0, 1, 2])); + assert!(v == vec![0u, 1, 0, 1, 2]); } #[test] fn test_retain() { - let mut vec = Vec::from_slice([1u, 2, 3, 4]); + let mut vec = vec![1u, 2, 3, 4]; vec.retain(|x| x%2 == 0); - assert!(vec == Vec::from_slice([2u, 4])); + assert!(vec == vec![2u, 4]); } #[test] @@ -2567,32 +2567,32 @@ mod tests { #[test] fn test_move_items() { - let mut vec = vec!(1i, 2, 3); - let mut vec2 : Vec = vec!(); + let vec = vec![1, 2, 3]; + let mut vec2 : Vec = vec![]; for i in vec.into_iter() { vec2.push(i); } - assert!(vec2 == vec!(1i, 2, 3)); + assert!(vec2 == vec![1, 2, 3]); } #[test] fn test_move_items_reverse() { - let mut vec = vec!(1i, 2, 3); - let mut vec2 : Vec = vec!(); + let vec = vec![1, 2, 3]; + let mut vec2 : Vec = vec![]; for i in vec.into_iter().rev() { vec2.push(i); } - assert!(vec2 == vec!(3i, 2, 1)); + assert!(vec2 == vec![3, 2, 1]); } #[test] fn test_move_items_zero_sized() { - let mut vec = vec!((), (), ()); - let mut vec2 : Vec<()> = vec!(); + let vec = vec![(), (), ()]; + let mut vec2 : Vec<()> = vec![]; for i in vec.into_iter() { vec2.push(i); } - assert!(vec2 == vec!((), (), ())); + assert!(vec2 == vec![(), (), ()]); } #[test] @@ -2707,7 +2707,7 @@ mod tests { b.bytes = src_len as u64; b.iter(|| { - let dst = Vec::from_slice(src.clone().as_slice()); + let dst = src.clone().as_slice().to_vec(); assert_eq!(dst.len(), src_len); assert!(dst.iter().enumerate().all(|(i, x)| i == *x)); }); @@ -2871,7 +2871,7 @@ mod tests { b.iter(|| { let mut dst = dst.clone(); - dst.push_all_move(src.clone()); + dst.extend(src.clone().into_iter()); assert_eq!(dst.len(), dst_len + src_len); assert!(dst.iter().enumerate().all(|(i, x)| i == *x)); }); diff --git a/src/libcoretest/char.rs b/src/libcoretest/char.rs index 9628d7950b5c..8807756d01b7 100644 --- a/src/libcoretest/char.rs +++ b/src/libcoretest/char.rs @@ -117,7 +117,7 @@ fn test_is_digit() { fn test_escape_default() { fn string(c: char) -> String { let mut result = String::new(); - escape_default(c, |c| { result.push_char(c); }); + escape_default(c, |c| { result.push(c); }); return result; } let s = string('\n'); @@ -152,7 +152,7 @@ fn test_escape_default() { fn test_escape_unicode() { fn string(c: char) -> String { let mut result = String::new(); - escape_unicode(c, |c| { result.push_char(c); }); + escape_unicode(c, |c| { result.push(c); }); return result; } let s = string('\x00'); diff --git a/src/libcoretest/iter.rs b/src/libcoretest/iter.rs index 4135a02cc618..476a2b50fcc8 100644 --- a/src/libcoretest/iter.rs +++ b/src/libcoretest/iter.rs @@ -868,7 +868,7 @@ fn bench_multiple_take(b: &mut Bencher) { let mut it = range(0u, 42).cycle(); b.iter(|| { let n = it.next().unwrap(); - for m in range(0u, n) { + for _ in range(0u, n) { it.take(it.next().unwrap()).all(|_| true); } }); diff --git a/src/libcoretest/mem.rs b/src/libcoretest/mem.rs index 76409c8612f3..e4dde7c641e1 100644 --- a/src/libcoretest/mem.rs +++ b/src/libcoretest/mem.rs @@ -109,7 +109,7 @@ fn test_transmute() { } unsafe { - assert!(Vec::from_slice([76u8]) == transmute("L".to_string())); + assert!(vec![76u8] == transmute("L".to_string())); } } diff --git a/src/libcoretest/result.rs b/src/libcoretest/result.rs index b45ac6a993ef..b023833f3947 100644 --- a/src/libcoretest/result.rs +++ b/src/libcoretest/result.rs @@ -89,6 +89,7 @@ fn test_collect() { } #[test] +#[allow(deprecated)] // we know fold_ is deprecated fn test_fold() { assert_eq!(fold_(range(0i, 0) .map(|_| Ok::<(), ()>(()))), diff --git a/src/libglob/lib.rs b/src/libglob/lib.rs index d9584c2db4eb..0313c22933cf 100644 --- a/src/libglob/lib.rs +++ b/src/libglob/lib.rs @@ -682,7 +682,7 @@ mod test { } #[test] - #[ignore(cfg(windows))] // FIXME (#9406) + #[cfg_attr(windows, ignore)] // FIXME (#9406) fn test_lots_of_files() { // this is a good test because it touches lots of differently named files glob("/*/*/*/*").skip(10000).next(); diff --git a/src/libgraphviz/lib.rs b/src/libgraphviz/lib.rs index f7908b76ab51..e21186a5fc87 100644 --- a/src/libgraphviz/lib.rs +++ b/src/libgraphviz/lib.rs @@ -735,6 +735,20 @@ r#"digraph single_edge { "#); } + #[test] + fn test_some_labelled() { + let labels : Trivial = SomeNodesLabelled(vec![Some("A"), None]); + let result = test_input(LabelledGraph::new("test_some_labelled", labels, + vec![edge(0, 1, "A-1")])); + assert_eq!(result.unwrap().as_slice(), +r#"digraph test_some_labelled { + N0[label="A"]; + N1[label="N1"]; + N0 -> N1[label="A-1"]; +} +"#); + } + #[test] fn single_cyclic_node() { let labels : Trivial = UnlabelledNodes(1); diff --git a/src/libgreen/sched.rs b/src/libgreen/sched.rs index f36a43c3c291..f46d96ffe4a3 100644 --- a/src/libgreen/sched.rs +++ b/src/libgreen/sched.rs @@ -1027,7 +1027,6 @@ mod test { use std::rt::task::TaskOpts; use std::rt::task::Task; use std::rt::local::Local; - use std::time::Duration; use {TaskState, PoolConfig, SchedPool}; use basic; diff --git a/src/libnum/integer.rs b/src/libnum/integer.rs index 7c7869766994..c5d076a70b58 100644 --- a/src/libnum/integer.rs +++ b/src/libnum/integer.rs @@ -462,6 +462,7 @@ macro_rules! impl_integer_for_uint { } #[test] + #[allow(type_overflow)] fn test_lcm() { assert_eq!((1 as $T).lcm(&0), 0 as $T); assert_eq!((0 as $T).lcm(&1), 0 as $T); diff --git a/src/librustrt/mutex.rs b/src/librustrt/mutex.rs index 7d4fb2f5c529..b328df1949e0 100644 --- a/src/librustrt/mutex.rs +++ b/src/librustrt/mutex.rs @@ -655,19 +655,19 @@ mod test { #[test] fn smoke_lock() { - static lock: StaticNativeMutex = NATIVE_MUTEX_INIT; + static LK: StaticNativeMutex = NATIVE_MUTEX_INIT; unsafe { - let _guard = lock.lock(); + let _guard = LK.lock(); } } #[test] fn smoke_cond() { - static lock: StaticNativeMutex = NATIVE_MUTEX_INIT; + static LK: StaticNativeMutex = NATIVE_MUTEX_INIT; unsafe { - let guard = lock.lock(); + let guard = LK.lock(); let t = Thread::start(proc() { - let guard = lock.lock(); + let guard = LK.lock(); guard.signal(); }); guard.wait(); @@ -679,25 +679,25 @@ mod test { #[test] fn smoke_lock_noguard() { - static lock: StaticNativeMutex = NATIVE_MUTEX_INIT; + static LK: StaticNativeMutex = NATIVE_MUTEX_INIT; unsafe { - lock.lock_noguard(); - lock.unlock_noguard(); + LK.lock_noguard(); + LK.unlock_noguard(); } } #[test] fn smoke_cond_noguard() { - static lock: StaticNativeMutex = NATIVE_MUTEX_INIT; + static LK: StaticNativeMutex = NATIVE_MUTEX_INIT; unsafe { - lock.lock_noguard(); + LK.lock_noguard(); let t = Thread::start(proc() { - lock.lock_noguard(); - lock.signal_noguard(); - lock.unlock_noguard(); + LK.lock_noguard(); + LK.signal_noguard(); + LK.unlock_noguard(); }); - lock.wait_noguard(); - lock.unlock_noguard(); + LK.wait_noguard(); + LK.unlock_noguard(); t.join(); } diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index 5d9211caac1b..eda38e96cbb1 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -2964,8 +2964,8 @@ mod tests { let s = "{\"f\":null,\"a\":[null,123]}"; let obj: FloatStruct = super::decode(s).unwrap(); assert!(obj.f.is_nan()); - assert!(obj.a.get(0).is_nan()); - assert_eq!(obj.a.get(1), &123f64); + assert!(obj.a[0].is_nan()); + assert_eq!(obj.a[1], 123f64); } #[test] diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index 7a36680b3a62..71d38ac66597 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -582,15 +582,15 @@ mod tests { assert_eq!('A'.to_ascii().to_char(), 'A'); assert_eq!('A'.to_ascii().to_byte(), 65u8); - assert_eq!('A'.to_ascii().to_lower().to_char(), 'a'); - assert_eq!('Z'.to_ascii().to_lower().to_char(), 'z'); - assert_eq!('a'.to_ascii().to_upper().to_char(), 'A'); - assert_eq!('z'.to_ascii().to_upper().to_char(), 'Z'); + assert_eq!('A'.to_ascii().to_lowercase().to_char(), 'a'); + assert_eq!('Z'.to_ascii().to_lowercase().to_char(), 'z'); + assert_eq!('a'.to_ascii().to_uppercase().to_char(), 'A'); + assert_eq!('z'.to_ascii().to_uppercase().to_char(), 'Z'); - assert_eq!('@'.to_ascii().to_lower().to_char(), '@'); - assert_eq!('['.to_ascii().to_lower().to_char(), '['); - assert_eq!('`'.to_ascii().to_upper().to_char(), '`'); - assert_eq!('{'.to_ascii().to_upper().to_char(), '{'); + assert_eq!('@'.to_ascii().to_lowercase().to_char(), '@'); + assert_eq!('['.to_ascii().to_lowercase().to_char(), '['); + assert_eq!('`'.to_ascii().to_uppercase().to_char(), '`'); + assert_eq!('{'.to_ascii().to_uppercase().to_char(), '{'); assert!('0'.to_ascii().is_digit()); assert!('9'.to_ascii().is_digit()); diff --git a/src/libstd/bitflags.rs b/src/libstd/bitflags.rs index adb55f2cc8cf..42e3a823ff4f 100644 --- a/src/libstd/bitflags.rs +++ b/src/libstd/bitflags.rs @@ -273,8 +273,8 @@ mod tests { } bitflags! { - flags AnotherSetOfFlags: uint { - const AnotherFlag = 1u, + flags AnotherSetOfFlags: i8 { + const AnotherFlag = -1_i8, } } @@ -283,6 +283,9 @@ mod tests { assert_eq!(Flags::empty().bits(), 0x00000000); assert_eq!(FlagA.bits(), 0x00000001); assert_eq!(FlagABC.bits(), 0x00000111); + + assert_eq!(AnotherSetOfFlags::empty().bits(), 0x00); + assert_eq!(AnotherFlag.bits(), !0_i8); } #[test] @@ -292,6 +295,8 @@ mod tests { assert!(Flags::from_bits(0x10) == Some(FlagB)); assert!(Flags::from_bits(0x11) == Some(FlagA | FlagB)); assert!(Flags::from_bits(0x1000) == None); + + assert!(AnotherSetOfFlags::from_bits(!0_i8) == Some(AnotherFlag)); } #[test] @@ -302,6 +307,8 @@ mod tests { assert!(Flags::from_bits_truncate(0x11) == (FlagA | FlagB)); assert!(Flags::from_bits_truncate(0x1000) == Flags::empty()); assert!(Flags::from_bits_truncate(0x1001) == FlagA); + + assert!(AnotherSetOfFlags::from_bits_truncate(0_i8) == AnotherSetOfFlags::empty()); } #[test] @@ -309,6 +316,8 @@ mod tests { assert!(Flags::empty().is_empty()); assert!(!FlagA.is_empty()); assert!(!FlagABC.is_empty()); + + assert!(!AnotherFlag.is_empty()); } #[test] @@ -316,6 +325,8 @@ mod tests { assert!(Flags::all().is_all()); assert!(!FlagA.is_all()); assert!(FlagABC.is_all()); + + assert!(AnotherFlag.is_all()); } #[test] @@ -323,6 +334,8 @@ mod tests { let e1 = Flags::empty(); let e2 = Flags::empty(); assert!(!e1.intersects(e2)); + + assert!(AnotherFlag.intersects(AnotherFlag)); } #[test] @@ -353,6 +366,8 @@ mod tests { assert!(!e1.contains(e2)); assert!(e2.contains(e1)); assert!(FlagABC.contains(e2)); + + assert!(AnotherFlag.contains(AnotherFlag)); } #[test] @@ -361,6 +376,10 @@ mod tests { let e2 = FlagA | FlagB; e1.insert(e2); assert!(e1 == e2); + + let mut e3 = AnotherSetOfFlags::empty(); + e3.insert(AnotherFlag); + assert!(e3 == AnotherFlag); } #[test] @@ -369,6 +388,10 @@ mod tests { let e2 = FlagA | FlagC; e1.remove(e2); assert!(e1 == FlagB); + + let mut e3 = AnotherFlag; + e3.remove(AnotherFlag); + assert!(e3 == AnotherSetOfFlags::empty()); } #[test] @@ -383,6 +406,10 @@ mod tests { let mut e3 = e1; e3.toggle(e2); assert!(e3 == FlagA | FlagB); + + let mut m4 = AnotherSetOfFlags::empty(); + m4.toggle(AnotherSetOfFlags::empty()); + assert!(m4 == AnotherSetOfFlags::empty()); } #[test] diff --git a/src/libstd/collections/hashmap/map.rs b/src/libstd/collections/hashmap/map.rs index ef40402105b5..bdd9d8d9d1f5 100644 --- a/src/libstd/collections/hashmap/map.rs +++ b/src/libstd/collections/hashmap/map.rs @@ -1930,6 +1930,7 @@ mod test_map { } #[test] + #[allow(deprecated)] // insert_or_update_with fn test_update_with() { let mut m = HashMap::with_capacity(4); assert!(m.insert(1i, 2i)); diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index 754b440b0de8..8ab0d3a55040 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -400,7 +400,7 @@ mod test { impl Reader for ShortReader { fn read(&mut self, _: &mut [u8]) -> io::IoResult { - match self.lengths.shift() { + match self.lengths.remove(0) { Some(i) => Ok(i), None => Err(io::standard_error(io::EndOfFile)) } @@ -551,7 +551,7 @@ mod test { #[test] fn test_read_line() { - let in_buf = MemReader::new(Vec::from_slice(b"a\nb\nc")); + let in_buf = MemReader::new(b"a\nb\nc".to_vec()); let mut reader = BufferedReader::with_capacity(2, in_buf); assert_eq!(reader.read_line(), Ok("a\n".to_string())); assert_eq!(reader.read_line(), Ok("b\n".to_string())); @@ -561,7 +561,7 @@ mod test { #[test] fn test_lines() { - let in_buf = MemReader::new(Vec::from_slice(b"a\nb\nc")); + let in_buf = MemReader::new(b"a\nb\nc".to_vec()); let mut reader = BufferedReader::with_capacity(2, in_buf); let mut it = reader.lines(); assert_eq!(it.next(), Some(Ok("a\n".to_string()))); diff --git a/src/libstd/io/fs.rs b/src/libstd/io/fs.rs index 82494d41aa3f..e8fed67fffed 100644 --- a/src/libstd/io/fs.rs +++ b/src/libstd/io/fs.rs @@ -1415,7 +1415,7 @@ mod test { check!(copy(&input, &output)); assert_eq!(check!(File::open(&output).read_to_end()), - (Vec::from_slice(b"foo"))); + b"foo".to_vec()); } #[test] @@ -1459,7 +1459,7 @@ mod test { } assert_eq!(check!(stat(&out)).size, check!(stat(&input)).size); assert_eq!(check!(File::open(&out).read_to_end()), - (Vec::from_slice(b"foobar"))); + b"foobar".to_vec()); } #[cfg(not(windows))] // apparently windows doesn't like symlinks @@ -1497,7 +1497,7 @@ mod test { assert_eq!(check!(stat(&out)).size, check!(stat(&input)).size); assert_eq!(check!(stat(&out)).size, check!(input.stat()).size); assert_eq!(check!(File::open(&out).read_to_end()), - (Vec::from_slice(b"foobar"))); + b"foobar".to_vec()); // can't link to yourself match link(&input, &input) { @@ -1560,7 +1560,7 @@ mod test { check!(file.fsync()); assert_eq!(check!(file.stat()).size, 10); assert_eq!(check!(File::open(&path).read_to_end()), - (Vec::from_slice(b"foobar\0\0\0\0"))); + b"foobar\0\0\0\0".to_vec()); // Truncate to a smaller length, don't seek, and then write something. // Ensure that the intermediate zeroes are all filled in (we're seeked @@ -1571,7 +1571,7 @@ mod test { check!(file.fsync()); assert_eq!(check!(file.stat()).size, 9); assert_eq!(check!(File::open(&path).read_to_end()), - (Vec::from_slice(b"fo\0\0\0\0wut"))); + b"fo\0\0\0\0wut".to_vec()); drop(file); } diff --git a/src/libstd/io/mem.rs b/src/libstd/io/mem.rs index 0f8e0ed52f8b..f86ae05d623c 100644 --- a/src/libstd/io/mem.rs +++ b/src/libstd/io/mem.rs @@ -617,7 +617,7 @@ mod test { #[bench] fn bench_mem_reader(b: &mut Bencher) { b.iter(|| { - let buf = Vec::from_slice([5 as u8, ..100]); + let buf = [5 as u8, ..100].to_vec(); { let mut rdr = MemReader::new(buf); for _i in range(0u, 10) { diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index d18b3cdf2e75..8592d48974a2 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -1949,62 +1949,62 @@ mod tests { return Ok(0); } }; - behavior.shift(); + behavior.remove(0); } } } #[test] fn test_read_at_least() { - let mut r = BadReader::new(MemReader::new(Vec::from_slice(b"hello, world!")), - Vec::from_slice([GoodBehavior(uint::MAX)])); + let mut r = BadReader::new(MemReader::new(b"hello, world!".to_vec()), + vec![GoodBehavior(uint::MAX)]); let mut buf = [0u8, ..5]; assert!(r.read_at_least(1, buf).unwrap() >= 1); assert!(r.read_exact(5).unwrap().len() == 5); // read_exact uses read_at_least assert!(r.read_at_least(0, buf).is_ok()); - let mut r = BadReader::new(MemReader::new(Vec::from_slice(b"hello, world!")), - Vec::from_slice([BadBehavior(50), GoodBehavior(uint::MAX)])); + let mut r = BadReader::new(MemReader::new(b"hello, world!".to_vec()), + vec![BadBehavior(50), GoodBehavior(uint::MAX)]); assert!(r.read_at_least(1, buf).unwrap() >= 1); - let mut r = BadReader::new(MemReader::new(Vec::from_slice(b"hello, world!")), - Vec::from_slice([BadBehavior(1), GoodBehavior(1), - BadBehavior(50), GoodBehavior(uint::MAX)])); + let mut r = BadReader::new(MemReader::new(b"hello, world!".to_vec()), + vec![BadBehavior(1), GoodBehavior(1), + BadBehavior(50), GoodBehavior(uint::MAX)]); assert!(r.read_at_least(1, buf).unwrap() >= 1); assert!(r.read_at_least(1, buf).unwrap() >= 1); - let mut r = BadReader::new(MemReader::new(Vec::from_slice(b"hello, world!")), - Vec::from_slice([BadBehavior(uint::MAX)])); + let mut r = BadReader::new(MemReader::new(b"hello, world!".to_vec()), + vec![BadBehavior(uint::MAX)]); assert_eq!(r.read_at_least(1, buf).unwrap_err().kind, NoProgress); - let mut r = MemReader::new(Vec::from_slice(b"hello, world!")); + let mut r = MemReader::new(b"hello, world!".to_vec()); assert_eq!(r.read_at_least(5, buf).unwrap(), 5); assert_eq!(r.read_at_least(6, buf).unwrap_err().kind, InvalidInput); } #[test] fn test_push_at_least() { - let mut r = BadReader::new(MemReader::new(Vec::from_slice(b"hello, world!")), - Vec::from_slice([GoodBehavior(uint::MAX)])); + let mut r = BadReader::new(MemReader::new(b"hello, world!".to_vec()), + vec![GoodBehavior(uint::MAX)]); let mut buf = Vec::new(); assert!(r.push_at_least(1, 5, &mut buf).unwrap() >= 1); assert!(r.push_at_least(0, 5, &mut buf).is_ok()); - let mut r = BadReader::new(MemReader::new(Vec::from_slice(b"hello, world!")), - Vec::from_slice([BadBehavior(50), GoodBehavior(uint::MAX)])); + let mut r = BadReader::new(MemReader::new(b"hello, world!".to_vec()), + vec![BadBehavior(50), GoodBehavior(uint::MAX)]); assert!(r.push_at_least(1, 5, &mut buf).unwrap() >= 1); - let mut r = BadReader::new(MemReader::new(Vec::from_slice(b"hello, world!")), - Vec::from_slice([BadBehavior(1), GoodBehavior(1), - BadBehavior(50), GoodBehavior(uint::MAX)])); + let mut r = BadReader::new(MemReader::new(b"hello, world!".to_vec()), + vec![BadBehavior(1), GoodBehavior(1), + BadBehavior(50), GoodBehavior(uint::MAX)]); assert!(r.push_at_least(1, 5, &mut buf).unwrap() >= 1); assert!(r.push_at_least(1, 5, &mut buf).unwrap() >= 1); - let mut r = BadReader::new(MemReader::new(Vec::from_slice(b"hello, world!")), - Vec::from_slice([BadBehavior(uint::MAX)])); + let mut r = BadReader::new(MemReader::new(b"hello, world!".to_vec()), + vec![BadBehavior(uint::MAX)]); assert_eq!(r.push_at_least(1, 5, &mut buf).unwrap_err().kind, NoProgress); - let mut r = MemReader::new(Vec::from_slice(b"hello, world!")); + let mut r = MemReader::new(b"hello, world!".to_vec()); assert_eq!(r.push_at_least(5, 1, &mut buf).unwrap_err().kind, InvalidInput); } diff --git a/src/libstd/io/net/addrinfo.rs b/src/libstd/io/net/addrinfo.rs index 27241f9bfa55..9d85701eb298 100644 --- a/src/libstd/io/net/addrinfo.rs +++ b/src/libstd/io/net/addrinfo.rs @@ -126,9 +126,7 @@ fn lookup(hostname: Option<&str>, servname: Option<&str>, hint: Option) #[cfg(all(test, not(target_os = "android")))] mod test { use super::*; - use io::net::tcp::*; use io::net::ip::*; - use io::net::udp::*; #[test] fn dns_smoke_test() { diff --git a/src/libstd/io/net/tcp.rs b/src/libstd/io/net/tcp.rs index e2a850c58e44..d6528ce977e9 100644 --- a/src/libstd/io/net/tcp.rs +++ b/src/libstd/io/net/tcp.rs @@ -521,10 +521,8 @@ impl Clone for TcpAcceptor { #[cfg(test)] #[allow(experimental)] mod test { - use super::*; use io::net::tcp::*; use io::net::ip::*; - use io::net::udp::*; use io::*; use io::test::*; use prelude::*; diff --git a/src/libstd/io/pipe.rs b/src/libstd/io/pipe.rs index d7d478bd458c..9362a48a6f00 100644 --- a/src/libstd/io/pipe.rs +++ b/src/libstd/io/pipe.rs @@ -118,7 +118,6 @@ impl Writer for PipeStream { #[cfg(test)] mod test { - use super::*; use prelude::*; #[test] diff --git a/src/libstd/io/process.rs b/src/libstd/io/process.rs index 5de4bc10e1ae..88f8434b9576 100644 --- a/src/libstd/io/process.rs +++ b/src/libstd/io/process.rs @@ -727,7 +727,7 @@ mod tests { assert!(p.is_ok()); let mut p = p.unwrap(); assert!(p.stdout.is_some()); - let ret = read_all(p.stdout.get_mut_ref() as &mut Reader); + let ret = read_all(p.stdout.as_mut().unwrap() as &mut Reader); assert!(p.wait().unwrap().success()); return ret; } @@ -758,9 +758,9 @@ mod tests { .stdin(CreatePipe(true, false)) .stdout(CreatePipe(false, true)) .spawn().unwrap(); - p.stdin.get_mut_ref().write("foobar".as_bytes()).unwrap(); + p.stdin.as_mut().unwrap().write("foobar".as_bytes()).unwrap(); drop(p.stdin.take()); - let out = read_all(p.stdout.get_mut_ref() as &mut Reader); + let out = read_all(p.stdout.as_mut().unwrap() as &mut Reader); assert!(p.wait().unwrap().success()); assert_eq!(out, "foobar\n".to_string()); } @@ -1019,7 +1019,7 @@ mod tests { fn test_add_to_env() { let prog = env_cmd().env("RUN_TEST_NEW_ENV", "123").spawn().unwrap(); let result = prog.wait_with_output().unwrap(); - let output = str::from_utf8_lossy(result.output.as_slice()).into_string(); + let output = String::from_utf8_lossy(result.output.as_slice()).into_string(); assert!(output.as_slice().contains("RUN_TEST_NEW_ENV=123"), "didn't find RUN_TEST_NEW_ENV inside of:\n\n{}", output); diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index b174f19f1982..93037f765d63 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -385,6 +385,7 @@ mod tests { use super::*; use prelude::*; + #[test] fn smoke() { // Just make sure we can acquire handles stdin(); @@ -392,6 +393,7 @@ mod tests { stderr(); } + #[test] fn capture_stdout() { use io::{ChanReader, ChanWriter}; @@ -404,9 +406,10 @@ mod tests { assert_eq!(r.read_to_string().unwrap(), "hello!\n".to_string()); } + #[test] fn capture_stderr() { use realstd::comm::channel; - use realstd::io::{Writer, ChanReader, ChanWriter, Reader}; + use realstd::io::{ChanReader, ChanWriter, Reader}; let (tx, rx) = channel(); let (mut r, w) = (ChanReader::new(rx), ChanWriter::new(tx)); diff --git a/src/libstd/io/timer.rs b/src/libstd/io/timer.rs index e7df02855406..a657989fe124 100644 --- a/src/libstd/io/timer.rs +++ b/src/libstd/io/timer.rs @@ -235,7 +235,6 @@ mod test { use super::*; use time::Duration; use task::spawn; - use io::*; use prelude::*; #[test] diff --git a/src/libstd/num/strconv.rs b/src/libstd/num/strconv.rs index f97bbe0dc8ea..48ee7664c16a 100644 --- a/src/libstd/num/strconv.rs +++ b/src/libstd/num/strconv.rs @@ -819,72 +819,82 @@ mod bench { mod uint { use super::test::Bencher; use rand::{weak_rng, Rng}; - use num::ToStrRadix; + use std::fmt; + + #[inline] + fn to_string(x: uint, base: u8) { + format!("{}", fmt::radix(x, base)); + } #[bench] fn to_str_bin(b: &mut Bencher) { let mut rng = weak_rng(); - b.iter(|| { rng.gen::().to_str_radix(2); }) + b.iter(|| { to_string(rng.gen::(), 2); }) } #[bench] fn to_str_oct(b: &mut Bencher) { let mut rng = weak_rng(); - b.iter(|| { rng.gen::().to_str_radix(8); }) + b.iter(|| { to_string(rng.gen::(), 8); }) } #[bench] fn to_str_dec(b: &mut Bencher) { let mut rng = weak_rng(); - b.iter(|| { rng.gen::().to_str_radix(10); }) + b.iter(|| { to_string(rng.gen::(), 10); }) } #[bench] fn to_str_hex(b: &mut Bencher) { let mut rng = weak_rng(); - b.iter(|| { rng.gen::().to_str_radix(16); }) + b.iter(|| { to_string(rng.gen::(), 16); }) } #[bench] fn to_str_base_36(b: &mut Bencher) { let mut rng = weak_rng(); - b.iter(|| { rng.gen::().to_str_radix(36); }) + b.iter(|| { to_string(rng.gen::(), 36); }) } } mod int { use super::test::Bencher; use rand::{weak_rng, Rng}; - use num::ToStrRadix; + use std::fmt; + + #[inline] + fn to_string(x: int, base: u8) { + format!("{}", fmt::radix(x, base)); + } #[bench] fn to_str_bin(b: &mut Bencher) { let mut rng = weak_rng(); - b.iter(|| { rng.gen::().to_str_radix(2); }) + b.iter(|| { to_string(rng.gen::(), 2); }) } #[bench] fn to_str_oct(b: &mut Bencher) { let mut rng = weak_rng(); - b.iter(|| { rng.gen::().to_str_radix(8); }) + b.iter(|| { to_string(rng.gen::(), 8); }) } #[bench] fn to_str_dec(b: &mut Bencher) { let mut rng = weak_rng(); - b.iter(|| { rng.gen::().to_str_radix(10); }) + b.iter(|| { to_string(rng.gen::(), 10); }) } #[bench] fn to_str_hex(b: &mut Bencher) { let mut rng = weak_rng(); - b.iter(|| { rng.gen::().to_str_radix(16); }) + b.iter(|| { to_string(rng.gen::(), 16); }) } #[bench] fn to_str_base_36(b: &mut Bencher) { let mut rng = weak_rng(); - b.iter(|| { rng.gen::().to_str_radix(36); }) + b.iter(|| { to_string(rng.gen::(), 36); }) } } diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index f7fb9adb1fb6..27eafdab642a 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -775,7 +775,7 @@ mod tests { t!(s: "a/b/c", ["d".to_string(), "e".to_string()], "a/b/c/d/e"); t!(v: b"a/b/c", [b"d", b"e"], b"a/b/c/d/e"); t!(v: b"a/b/c", [b"d", b"/e", b"f"], b"/e/f"); - t!(v: b"a/b/c", [Vec::from_slice(b"d"), Vec::from_slice(b"e")], b"a/b/c/d/e"); + t!(v: b"a/b/c", [b"d".to_vec(), b"e".to_vec()], b"a/b/c/d/e"); } #[test] @@ -879,7 +879,7 @@ mod tests { t!(s: "a/b/c", ["d", "/e", "f"], "/e/f"); t!(s: "a/b/c", ["d".to_string(), "e".to_string()], "a/b/c/d/e"); t!(v: b"a/b/c", [b"d", b"e"], b"a/b/c/d/e"); - t!(v: b"a/b/c", [Vec::from_slice(b"d"), Vec::from_slice(b"e")], b"a/b/c/d/e"); + t!(v: b"a/b/c", [b"d".to_vec(), b"e".to_vec()], b"a/b/c/d/e"); } #[test] diff --git a/src/libstd/rand/reader.rs b/src/libstd/rand/reader.rs index fe5d8fc068c9..8ca1cec3e0ae 100644 --- a/src/libstd/rand/reader.rs +++ b/src/libstd/rand/reader.rs @@ -76,7 +76,6 @@ mod test { use super::ReaderRng; use io::MemReader; - use mem; use rand::Rng; #[test] @@ -87,25 +86,25 @@ mod test { 0, 0, 0, 0, 0, 0, 0, 3]; let mut rng = ReaderRng::new(MemReader::new(v)); - assert_eq!(rng.next_u64(), mem::to_be64(1)); - assert_eq!(rng.next_u64(), mem::to_be64(2)); - assert_eq!(rng.next_u64(), mem::to_be64(3)); + assert_eq!(rng.next_u64(), 1_u64.to_be()); + assert_eq!(rng.next_u64(), 2_u64.to_be()); + assert_eq!(rng.next_u64(), 3_u64.to_be()); } #[test] fn test_reader_rng_u32() { let v = vec![0u8, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3]; let mut rng = ReaderRng::new(MemReader::new(v)); - assert_eq!(rng.next_u32(), mem::to_be32(1)); - assert_eq!(rng.next_u32(), mem::to_be32(2)); - assert_eq!(rng.next_u32(), mem::to_be32(3)); + assert_eq!(rng.next_u32(), 1_u32.to_be()); + assert_eq!(rng.next_u32(), 2_u32.to_be()); + assert_eq!(rng.next_u32(), 3_u32.to_be()); } #[test] fn test_reader_rng_fill_bytes() { let v = [1u8, 2, 3, 4, 5, 6, 7, 8]; let mut w = [0u8, .. 8]; - let mut rng = ReaderRng::new(MemReader::new(Vec::from_slice(v))); + let mut rng = ReaderRng::new(MemReader::new(v.as_slice().to_vec())); rng.fill_bytes(w); assert!(v == w); diff --git a/src/libstd/task.rs b/src/libstd/task.rs index 977b3018fa74..04d3bb8b3a7e 100644 --- a/src/libstd/task.rs +++ b/src/libstd/task.rs @@ -447,6 +447,7 @@ mod test { } #[test] + #[allow(deprecated)] fn test_with_wrapper() { let (tx, rx) = channel(); TaskBuilder::new().with_wrapper(proc(body) { diff --git a/src/libsync/comm/duplex.rs b/src/libsync/comm/duplex.rs index 587827d2bc57..1dc1f4b87f27 100644 --- a/src/libsync/comm/duplex.rs +++ b/src/libsync/comm/duplex.rs @@ -59,10 +59,11 @@ impl DuplexStream { } } +#[allow(deprecated)] #[cfg(test)] mod test { use std::prelude::*; - use comm::{duplex}; + use comm::duplex; #[test] pub fn duplex_stream_1() { diff --git a/src/libsync/deque.rs b/src/libsync/deque.rs index 338816293298..09fa8920a07d 100644 --- a/src/libsync/deque.rs +++ b/src/libsync/deque.rs @@ -553,14 +553,12 @@ mod tests { let threads = range(0, NTHREADS).map(|_| { let s = s.clone(); Thread::start(proc() { - unsafe { - loop { - match s.steal() { - Data(2) => { HITS.fetch_add(1, SeqCst); } - Data(..) => fail!(), - _ if DONE.load(SeqCst) => break, - _ => {} - } + loop { + match s.steal() { + Data(2) => { HITS.fetch_add(1, SeqCst); } + Data(..) => fail!(), + _ if DONE.load(SeqCst) => break, + _ => {} } } }) @@ -572,7 +570,7 @@ mod tests { if rng.gen_range(0i, 3) == 2 { match w.pop() { None => {} - Some(2) => unsafe { HITS.fetch_add(1, SeqCst); }, + Some(2) => { HITS.fetch_add(1, SeqCst); }, Some(_) => fail!(), } } else { @@ -581,22 +579,20 @@ mod tests { } } - unsafe { - while HITS.load(SeqCst) < AMT as uint { - match w.pop() { - None => {} - Some(2) => { HITS.fetch_add(1, SeqCst); }, - Some(_) => fail!(), - } + while HITS.load(SeqCst) < AMT as uint { + match w.pop() { + None => {} + Some(2) => { HITS.fetch_add(1, SeqCst); }, + Some(_) => fail!(), } - DONE.store(true, SeqCst); } + DONE.store(true, SeqCst); for thread in threads.into_iter() { thread.join(); } - assert_eq!(unsafe { HITS.load(SeqCst) }, expected as uint); + assert_eq!(HITS.load(SeqCst), expected as uint); } #[test] @@ -655,7 +651,7 @@ mod tests { } } - unsafe { DONE.store(true, SeqCst); } + DONE.store(true, SeqCst); for thread in threads.into_iter() { thread.join(); diff --git a/src/libsync/mutex.rs b/src/libsync/mutex.rs index 9861d27c8cdf..796c62354c31 100644 --- a/src/libsync/mutex.rs +++ b/src/libsync/mutex.rs @@ -536,32 +536,32 @@ mod test { #[test] fn smoke_static() { - static m: StaticMutex = MUTEX_INIT; + static M: StaticMutex = MUTEX_INIT; unsafe { - drop(m.lock()); - drop(m.lock()); - m.destroy(); + drop(M.lock()); + drop(M.lock()); + M.destroy(); } } #[test] fn lots_and_lots() { - static m: StaticMutex = MUTEX_INIT; + static M: StaticMutex = MUTEX_INIT; static mut CNT: uint = 0; - static M: uint = 1000; - static N: uint = 3; + static J: uint = 1000; + static K: uint = 3; fn inc() { - for _ in range(0, M) { + for _ in range(0, J) { unsafe { - let _g = m.lock(); + let _g = M.lock(); CNT += 1; } } } let (tx, rx) = channel(); - for _ in range(0, N) { + for _ in range(0, K) { let tx2 = tx.clone(); native::task::spawn(proc() { inc(); tx2.send(()); }); let tx2 = tx.clone(); @@ -569,12 +569,12 @@ mod test { } drop(tx); - for _ in range(0, 2 * N) { + for _ in range(0, 2 * K) { rx.recv(); } - assert_eq!(unsafe {CNT}, M * N * 2); + assert_eq!(unsafe {CNT}, J * K * 2); unsafe { - m.destroy(); + M.destroy(); } } diff --git a/src/libsync/one.rs b/src/libsync/one.rs index f0c72780be10..62b376609122 100644 --- a/src/libsync/one.rs +++ b/src/libsync/one.rs @@ -126,17 +126,17 @@ mod test { #[test] fn smoke_once() { - static o: Once = ONCE_INIT; + static O: Once = ONCE_INIT; let mut a = 0i; - o.doit(|| a += 1); + O.doit(|| a += 1); assert_eq!(a, 1); - o.doit(|| a += 1); + O.doit(|| a += 1); assert_eq!(a, 1); } #[test] fn stampede_once() { - static o: Once = ONCE_INIT; + static O: Once = ONCE_INIT; static mut run: bool = false; let (tx, rx) = channel(); @@ -145,7 +145,7 @@ mod test { spawn(proc() { for _ in range(0u, 4) { task::deschedule() } unsafe { - o.doit(|| { + O.doit(|| { assert!(!run); run = true; }); @@ -156,7 +156,7 @@ mod test { } unsafe { - o.doit(|| { + O.doit(|| { assert!(!run); run = true; }); diff --git a/src/libterm/terminfo/parm.rs b/src/libterm/terminfo/parm.rs index 736cacbdeb78..a1bce6e8e8b0 100644 --- a/src/libterm/terminfo/parm.rs +++ b/src/libterm/terminfo/parm.rs @@ -575,7 +575,7 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result ,String> { #[cfg(test)] mod test { - use super::{expand,Words,Variables,Number}; + use super::{expand,Param,Words,Variables,Number}; use std::result::Ok; #[test] @@ -605,40 +605,39 @@ mod test { fn test_param_stack_failure_conditions() { let mut varstruct = Variables::new(); let vars = &mut varstruct; + fn get_res(fmt: &str, cap: &str, params: &[Param], vars: &mut Variables) -> + Result, String> + { + let mut u8v: Vec<_> = fmt.bytes().collect(); + u8v.extend(cap.as_bytes().iter().map(|&b| b)); + expand(u8v.as_slice(), params, vars) + } + let caps = ["%d", "%c", "%s", "%Pa", "%l", "%!", "%~"]; - for cap in caps.iter() { - let res = expand(cap.as_bytes(), [], vars); + for &cap in caps.iter() { + let res = get_res("", cap, [], vars); assert!(res.is_err(), - "Op {} succeeded incorrectly with 0 stack entries", *cap); - let p = if *cap == "%s" || *cap == "%l" { + "Op {} succeeded incorrectly with 0 stack entries", cap); + let p = if cap == "%s" || cap == "%l" { Words("foo".to_string()) } else { Number(97) }; - let res = expand("%p1".bytes().collect::>() - .append(cap.as_bytes()).as_slice(), - [p], - vars); + let res = get_res("%p1", cap, [p], vars); assert!(res.is_ok(), - "Op {} failed with 1 stack entry: {}", *cap, res.unwrap_err()); + "Op {} failed with 1 stack entry: {}", cap, res.unwrap_err()); } let caps = ["%+", "%-", "%*", "%/", "%m", "%&", "%|", "%A", "%O"]; - for cap in caps.iter() { + for &cap in caps.iter() { let res = expand(cap.as_bytes(), [], vars); assert!(res.is_err(), - "Binop {} succeeded incorrectly with 0 stack entries", *cap); - let res = expand("%{1}".bytes().collect::>() - .append(cap.as_bytes()).as_slice(), - [], - vars); + "Binop {} succeeded incorrectly with 0 stack entries", cap); + let res = get_res("%{1}", cap, [], vars); assert!(res.is_err(), - "Binop {} succeeded incorrectly with 1 stack entry", *cap); - let res = expand("%{1}%{2}".bytes().collect::>() - .append(cap.as_bytes()).as_slice(), - [], - vars); + "Binop {} succeeded incorrectly with 1 stack entry", cap); + let res = get_res("%{1}%{2}", cap, [], vars); assert!(res.is_ok(), - "Binop {} failed with 2 stack entries: {}", *cap, res.unwrap_err()); + "Binop {} failed with 2 stack entries: {}", cap, res.unwrap_err()); } } From 61a8a28f9ff10aed41b1ee5c58df827db6b87d7c Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Mon, 13 Oct 2014 13:51:43 +0100 Subject: [PATCH 14/19] Include the Unicode version used to generate `src/libunicode/tables.rs`. --- src/etc/unicode.py | 9 +++++++++ src/libunicode/lib.rs | 1 + src/libunicode/tables.rs | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/src/etc/unicode.py b/src/etc/unicode.py index 0b128686690f..d3de1d2b64e0 100755 --- a/src/etc/unicode.py +++ b/src/etc/unicode.py @@ -604,6 +604,15 @@ if __name__ == "__main__": rf.write(preamble) # download and parse all the data + fetch("ReadMe.txt") + with open("ReadMe.txt") as readme: + pattern = "for Version (\d+)\.(\d+)\.(\d+) of the Unicode" + unicode_version = re.search(pattern, readme.read()).groups() + rf.write(""" +/// The version of [Unicode](http://www.unicode.org/) +/// that the `UnicodeChar` and `UnicodeStrSlice` traits are based on. +pub const UNICODE_VERSION: (uint, uint, uint) = (%s, %s, %s); +""" % unicode_version) (canon_decomp, compat_decomp, gencats, combines, lowerupper, upperlower) = load_unicode_data("UnicodeData.txt") want_derived = ["XID_Start", "XID_Continue", "Alphabetic", "Lowercase", "Uppercase"] diff --git a/src/libunicode/lib.rs b/src/libunicode/lib.rs index 2918bad03df2..b84aec77a09c 100644 --- a/src/libunicode/lib.rs +++ b/src/libunicode/lib.rs @@ -64,6 +64,7 @@ pub mod char { pub use normalize::{decompose_canonical, decompose_compatible, compose}; pub use tables::normalization::canonical_combining_class; + pub use tables::UNICODE_VERSION; pub use u_char::{is_alphabetic, is_XID_start, is_XID_continue}; pub use u_char::{is_lowercase, is_uppercase, is_whitespace}; diff --git a/src/libunicode/tables.rs b/src/libunicode/tables.rs index e359883295f4..3f15abcad6dc 100644 --- a/src/libunicode/tables.rs +++ b/src/libunicode/tables.rs @@ -12,6 +12,10 @@ #![allow(missing_doc, non_uppercase_statics, non_snake_case)] +/// The version of [Unicode](http://www.unicode.org/) +/// that the `UnicodeChar` and `UnicodeStrSlice` traits are based on. +pub const UNICODE_VERSION: (uint, uint, uint) = (7, 0, 0); + fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool { use core::cmp::{Equal, Less, Greater}; use core::slice::ImmutableSlice; From fafe136c2d3bf62d5449b024516bd5439bbd0da1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Steinbrink?= Date: Mon, 13 Oct 2014 16:12:38 +0200 Subject: [PATCH 15/19] Emit lifetime end markers for function arguments Function arguments are (hopefully!) the last places where allocas don't get proper markers for the end of their lifetimes. This means that this code using 64 bytes of stack for the function arguments: ````rust std::io::println("1"); std::io::println("2"); std::io::println("3"); std::io::println("4"); ```` But with the proper lifetime markers, the slots can be reused, and the arguments only need 16 bytes of stack. --- src/librustc/middle/trans/callee.rs | 7 +++++-- src/librustc/middle/trans/cleanup.rs | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/librustc/middle/trans/callee.rs b/src/librustc/middle/trans/callee.rs index bc562b39c98f..1b23841c913c 100644 --- a/src/librustc/middle/trans/callee.rs +++ b/src/librustc/middle/trans/callee.rs @@ -788,7 +788,7 @@ pub fn trans_call_inner<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, llself.is_some(), abi); - fcx.pop_custom_cleanup_scope(arg_cleanup_scope); + fcx.scopes.borrow_mut().last_mut().unwrap().drop_non_lifetime_clean(); // Invoke the actual rust fn and update bcx/llresult. let (llret, b) = base::invoke(bcx, @@ -829,12 +829,15 @@ pub fn trans_call_inner<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, cleanup::CustomScope(arg_cleanup_scope), false, abi); - fcx.pop_custom_cleanup_scope(arg_cleanup_scope); + fcx.scopes.borrow_mut().last_mut().unwrap().drop_non_lifetime_clean(); + bcx = foreign::trans_native_call(bcx, callee_ty, llfn, opt_llretslot.unwrap(), llargs.as_slice(), arg_tys); } + fcx.pop_and_trans_custom_cleanup_scope(bcx, arg_cleanup_scope); + // If the caller doesn't care about the result of this fn call, // drop the temporary slot we made. match (dest, opt_llretslot) { diff --git a/src/librustc/middle/trans/cleanup.rs b/src/librustc/middle/trans/cleanup.rs index 392436d3a806..f3844a956fad 100644 --- a/src/librustc/middle/trans/cleanup.rs +++ b/src/librustc/middle/trans/cleanup.rs @@ -74,6 +74,7 @@ pub struct CachedEarlyExit { pub trait Cleanup { fn must_unwind(&self) -> bool; fn clean_on_unwind(&self) -> bool; + fn is_lifetime_end(&self) -> bool; fn trans<'blk, 'tcx>(&self, bcx: Block<'blk, 'tcx>, debug_loc: Option) @@ -875,6 +876,10 @@ impl<'blk, 'tcx> CleanupScope<'blk, 'tcx> { LoopScopeKind(id, _) => format!("{}_loop_{}_", prefix, id), } } + + pub fn drop_non_lifetime_clean(&mut self) { + self.cleanups.retain(|c| c.is_lifetime_end()); + } } impl<'blk, 'tcx> CleanupScopeKind<'blk, 'tcx> { @@ -943,6 +948,10 @@ impl Cleanup for DropValue { self.must_unwind } + fn is_lifetime_end(&self) -> bool { + false + } + fn trans<'blk, 'tcx>(&self, bcx: Block<'blk, 'tcx>, debug_loc: Option) @@ -978,6 +987,10 @@ impl Cleanup for FreeValue { true } + fn is_lifetime_end(&self) -> bool { + false + } + fn trans<'blk, 'tcx>(&self, bcx: Block<'blk, 'tcx>, debug_loc: Option) @@ -1008,6 +1021,10 @@ impl Cleanup for FreeSlice { true } + fn is_lifetime_end(&self) -> bool { + false + } + fn trans<'blk, 'tcx>(&self, bcx: Block<'blk, 'tcx>, debug_loc: Option) @@ -1035,6 +1052,10 @@ impl Cleanup for LifetimeEnd { true } + fn is_lifetime_end(&self) -> bool { + true + } + fn trans<'blk, 'tcx>(&self, bcx: Block<'blk, 'tcx>, debug_loc: Option) From 84d1cbfd25f26e32e8f1bae9d380cc585afe0668 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sun, 12 Oct 2014 20:38:04 -0700 Subject: [PATCH 16/19] Don't ICE on bad extern paths Closes #17990 --- src/librustc/metadata/loader.rs | 75 +++++++++++++---------- src/test/compile-fail/empty-extern-arg.rs | 14 +++++ 2 files changed, 56 insertions(+), 33 deletions(-) create mode 100644 src/test/compile-fail/empty-extern-arg.rs diff --git a/src/librustc/metadata/loader.rs b/src/librustc/metadata/loader.rs index 62c179f598c9..d6b02a1d0639 100644 --- a/src/librustc/metadata/loader.rs +++ b/src/librustc/metadata/loader.rs @@ -1,4 +1,4 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -641,41 +641,50 @@ impl<'a> Context<'a> { // rlibs/dylibs. let sess = self.sess; let dylibname = self.dylibname(); - let mut locs = locs.iter().map(|l| Path::new(l.as_slice())).filter(|loc| { - if !loc.exists() { - sess.err(format!("extern location does not exist: {}", - loc.display()).as_slice()); - return false; - } - let file = loc.filename_str().unwrap(); - if file.starts_with("lib") && file.ends_with(".rlib") { - return true - } else { - match dylibname { - Some((prefix, suffix)) => { - if file.starts_with(prefix) && file.ends_with(suffix) { - return true - } - } - None => {} - } - } - sess.err(format!("extern location is of an unknown type: {}", - loc.display()).as_slice()); - false - }); - - // Now that we have an iterator of good candidates, make sure there's at - // most one rlib and at most one dylib. let mut rlibs = HashSet::new(); let mut dylibs = HashSet::new(); - for loc in locs { - if loc.filename_str().unwrap().ends_with(".rlib") { - rlibs.insert(fs::realpath(&loc).unwrap()); - } else { - dylibs.insert(fs::realpath(&loc).unwrap()); + { + let mut locs = locs.iter().map(|l| Path::new(l.as_slice())).filter(|loc| { + if !loc.exists() { + sess.err(format!("extern location for {} does not exist: {}", + self.crate_name, loc.display()).as_slice()); + return false; + } + let file = match loc.filename_str() { + Some(file) => file, + None => { + sess.err(format!("extern location for {} is not a file: {}", + self.crate_name, loc.display()).as_slice()); + return false; + } + }; + if file.starts_with("lib") && file.ends_with(".rlib") { + return true + } else { + match dylibname { + Some((prefix, suffix)) => { + if file.starts_with(prefix) && file.ends_with(suffix) { + return true + } + } + None => {} + } + } + sess.err(format!("extern location for {} is of an unknown type: {}", + self.crate_name, loc.display()).as_slice()); + false + }); + + // Now that we have an iterator of good candidates, make sure there's at + // most one rlib and at most one dylib. + for loc in locs { + if loc.filename_str().unwrap().ends_with(".rlib") { + rlibs.insert(fs::realpath(&loc).unwrap()); + } else { + dylibs.insert(fs::realpath(&loc).unwrap()); + } } - } + }; // Extract the rlib/dylib pair. let mut metadata = None; diff --git a/src/test/compile-fail/empty-extern-arg.rs b/src/test/compile-fail/empty-extern-arg.rs new file mode 100644 index 000000000000..9b7df81a5dcb --- /dev/null +++ b/src/test/compile-fail/empty-extern-arg.rs @@ -0,0 +1,14 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// compile-flags: --extern std= +// error-pattern: is not a file + +fn main() {} From c56c9fcf08603ab88ec36a7e0757d29129339097 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 10 Oct 2014 08:49:12 -0700 Subject: [PATCH 17/19] rustc: Remove the dummy hack from check_match Turns out you can create &'static T quite easily in a constant, I just forgot about this! --- src/librustc/middle/check_match.rs | 34 ++++++++----------- src/librustc/middle/trans/_match.rs | 22 ++---------- .../compile-fail/issue-17718-const-naming.rs | 1 + src/test/compile-fail/lint-dead-code-1.rs | 10 ++++-- 4 files changed, 25 insertions(+), 42 deletions(-) diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index 297640707687..1c06bc1cebaa 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -32,7 +32,7 @@ use syntax::ptr::P; use syntax::visit::{mod, Visitor, FnKind}; use util::ppaux::ty_to_string; -pub const DUMMY_WILD_PAT: Pat = Pat { +pub const DUMMY_WILD_PAT: &'static Pat = &Pat { id: DUMMY_NODE_ID, node: PatWild(PatWildSingle), span: DUMMY_SP @@ -297,12 +297,11 @@ fn raw_pat<'a>(p: &'a Pat) -> &'a Pat { } fn check_exhaustive(cx: &MatchCheckCtxt, sp: Span, matrix: &Matrix) { - match is_useful(cx, matrix, &[&DUMMY_WILD_PAT], ConstructWitness) { + match is_useful(cx, matrix, &[DUMMY_WILD_PAT], ConstructWitness) { UsefulWithWitness(pats) => { - let dummy = DUMMY_WILD_PAT.clone(); let witness = match pats.as_slice() { [ref witness] => &**witness, - [] => &dummy, + [] => DUMMY_WILD_PAT, _ => unreachable!() }; span_err!(cx.tcx.sess, sp, E0004, @@ -556,9 +555,8 @@ fn is_useful(cx: &MatchCheckCtxt, let arity = constructor_arity(cx, &c, left_ty); let mut result = { let pat_slice = pats.as_slice(); - let dummy = DUMMY_WILD_PAT.clone(); let subpats = Vec::from_fn(arity, |i| { - pat_slice.get(i).map_or(&dummy, |p| &**p) + pat_slice.get(i).map_or(DUMMY_WILD_PAT, |p| &**p) }); vec![construct_witness(cx, &c, subpats, left_ty)] }; @@ -580,9 +578,8 @@ fn is_useful(cx: &MatchCheckCtxt, }).collect(); match is_useful(cx, &matrix, v.tail(), witness) { UsefulWithWitness(pats) => { - let dummy = DUMMY_WILD_PAT.clone(); let arity = constructor_arity(cx, &constructor, left_ty); - let wild_pats = Vec::from_elem(arity, &dummy); + let wild_pats = Vec::from_elem(arity, DUMMY_WILD_PAT); let enum_pat = construct_witness(cx, &constructor, wild_pats, left_ty); let mut new_pats = vec![enum_pat]; new_pats.extend(pats.into_iter()); @@ -603,11 +600,10 @@ fn is_useful_specialized(cx: &MatchCheckCtxt, &Matrix(ref m): &Matrix, v: &[&Pat], ctor: Constructor, lty: ty::t, witness: WitnessPreference) -> Usefulness { let arity = constructor_arity(cx, &ctor, lty); - let dummy = DUMMY_WILD_PAT.clone(); let matrix = Matrix(m.iter().filter_map(|r| { - specialize(cx, r.as_slice(), &dummy, &ctor, 0u, arity) + specialize(cx, r.as_slice(), &ctor, 0u, arity) }).collect()); - match specialize(cx, v, &dummy, &ctor, 0u, arity) { + match specialize(cx, v, &ctor, 0u, arity) { Some(v) => is_useful(cx, &matrix, v.as_slice(), witness), None => NotUseful } @@ -729,7 +725,7 @@ fn range_covered_by_constructor(ctor: &Constructor, /// different patterns. /// Structure patterns with a partial wild pattern (Foo { a: 42, .. }) have their missing /// fields filled with wild patterns. -pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat], dummy: &'a Pat, +pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat], constructor: &Constructor, col: uint, arity: uint) -> Option> { let &Pat { id: pat_id, node: ref node, span: pat_span @@ -737,7 +733,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat], dummy: &'a Pat, let head: Option> = match node { &PatWild(_) => - Some(Vec::from_elem(arity, dummy)), + Some(Vec::from_elem(arity, DUMMY_WILD_PAT)), &PatIdent(_, _, _) => { let opt_def = cx.tcx.def_map.borrow().find_copy(&pat_id); @@ -750,7 +746,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat], dummy: &'a Pat, } else { None }, - _ => Some(Vec::from_elem(arity, dummy)) + _ => Some(Vec::from_elem(arity, DUMMY_WILD_PAT)) } } @@ -764,7 +760,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat], dummy: &'a Pat, DefVariant(..) | DefStruct(..) => { Some(match args { &Some(ref args) => args.iter().map(|p| &**p).collect(), - &None => Vec::from_elem(arity, dummy) + &None => Vec::from_elem(arity, DUMMY_WILD_PAT) }) } _ => None @@ -800,7 +796,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat], dummy: &'a Pat, let args = struct_fields.iter().map(|sf| { match pattern_fields.iter().find(|f| f.ident.name == sf.name) { Some(ref f) => &*f.pat, - _ => dummy + _ => DUMMY_WILD_PAT } }).collect(); args @@ -843,13 +839,13 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat], dummy: &'a Pat, // Fixed-length vectors. Single => { let mut pats: Vec<&Pat> = before.iter().map(|p| &**p).collect(); - pats.grow_fn(arity - before.len() - after.len(), |_| dummy); + pats.grow_fn(arity - before.len() - after.len(), |_| DUMMY_WILD_PAT); pats.extend(after.iter().map(|p| &**p)); Some(pats) }, Slice(length) if before.len() + after.len() <= length && slice.is_some() => { let mut pats: Vec<&Pat> = before.iter().map(|p| &**p).collect(); - pats.grow_fn(arity - before.len() - after.len(), |_| dummy); + pats.grow_fn(arity - before.len() - after.len(), |_| DUMMY_WILD_PAT); pats.extend(after.iter().map(|p| &**p)); Some(pats) }, @@ -919,7 +915,7 @@ fn check_fn(cx: &mut MatchCheckCtxt, fn is_refutable(cx: &MatchCheckCtxt, pat: &Pat, refutable: |&Pat| -> A) -> Option { let pats = Matrix(vec!(vec!(pat))); - match is_useful(cx, &pats, [&DUMMY_WILD_PAT], ConstructWitness) { + match is_useful(cx, &pats, [DUMMY_WILD_PAT], ConstructWitness) { UsefulWithWitness(pats) => { assert_eq!(pats.len(), 1); Some(refutable(&*pats[0])) diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index 9eb02717f04a..4f7d165d1594 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -351,19 +351,6 @@ struct Match<'a, 'p: 'a, 'blk: 'a, 'tcx: 'blk> { pats: Vec<&'p ast::Pat>, data: &'a ArmData<'p, 'blk, 'tcx>, bound_ptrs: Vec<(Ident, ValueRef)>, - - // This is a pointer to an instance of check_match::DUMMY_WILD_PAT. The - // check_match code requires that we pass this in (with the same lifetime as - // the patterns passed in). Unfortunately this is required to be propagated - // into this structure in order to get the lifetimes to work. - // - // Lots of the `check_match` code will deal with &DUMMY_WILD_PAT when - // returning references, which used to have the `'static` lifetime before - // const was added to the language. The DUMMY_WILD_PAT does not implement - // Sync, however, so it must be a const, which longer has a static lifetime, - // hence we're passing it in here. This certainly isn't crucial, and if it - // can be removed, please do! - dummy: &'p ast::Pat, } impl<'a, 'p, 'blk, 'tcx> Repr for Match<'a, 'p, 'blk, 'tcx> { @@ -416,7 +403,6 @@ fn expand_nested_bindings<'a, 'p, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>, *pats.get_mut(col) = pat; Match { pats: pats, - dummy: br.dummy, data: &*br.data, bound_ptrs: bound_ptrs } @@ -464,7 +450,6 @@ fn enter_match<'a, 'b, 'p, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>, } Match { pats: pats, - dummy: br.dummy, data: br.data, bound_ptrs: bound_ptrs } @@ -559,8 +544,7 @@ fn enter_opt<'a, 'p, 'blk, 'tcx>( let mcx = check_match::MatchCheckCtxt { tcx: bcx.tcx() }; enter_match(bcx, dm, m, col, val, |pats| - check_match::specialize(&mcx, pats.as_slice(), m[0].dummy, &ctor, col, - variant_size) + check_match::specialize(&mcx, pats.as_slice(), &ctor, col, variant_size) ) } @@ -1041,7 +1025,7 @@ fn compile_submatch_continue<'a, 'p, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, match adt_vals { Some(field_vals) => { let pats = enter_match(bcx, dm, m, col, val, |pats| - check_match::specialize(&mcx, pats, m[0].dummy, + check_match::specialize(&mcx, pats, &check_match::Single, col, field_vals.len()) ); @@ -1365,7 +1349,6 @@ fn trans_match_inner<'blk, 'tcx>(scope_cx: Block<'blk, 'tcx>, bindings_map: create_bindings_map(bcx, &**arm.pats.get(0), discr_expr, &*arm.body) }).collect(); - let dummy = check_match::DUMMY_WILD_PAT.clone(); let mut static_inliner = StaticInliner::new(scope_cx.tcx()); let arm_pats: Vec>> = arm_datas.iter().map(|arm_data| { arm_data.arm.pats.iter().map(|p| static_inliner.fold_pat((*p).clone())).collect() @@ -1374,7 +1357,6 @@ fn trans_match_inner<'blk, 'tcx>(scope_cx: Block<'blk, 'tcx>, for (arm_data, pats) in arm_datas.iter().zip(arm_pats.iter()) { matches.extend(pats.iter().map(|p| Match { pats: vec![&**p], - dummy: &dummy, data: arm_data, bound_ptrs: Vec::new(), })); diff --git a/src/test/compile-fail/issue-17718-const-naming.rs b/src/test/compile-fail/issue-17718-const-naming.rs index 046f038847b7..0cfee6daf3f1 100644 --- a/src/test/compile-fail/issue-17718-const-naming.rs +++ b/src/test/compile-fail/issue-17718-const-naming.rs @@ -12,5 +12,6 @@ const foo: int = 3; //~^ ERROR: should have an uppercase name such as +//~^^ ERROR: constant item is never used fn main() {} diff --git a/src/test/compile-fail/lint-dead-code-1.rs b/src/test/compile-fail/lint-dead-code-1.rs index 998e7c017923..96d40c52657f 100644 --- a/src/test/compile-fail/lint-dead-code-1.rs +++ b/src/test/compile-fail/lint-dead-code-1.rs @@ -39,8 +39,8 @@ pub const pub_const: int = 0; const priv_const: int = 0; //~ ERROR: constant item is never used const used_const: int = 0; pub const used_const2: int = used_const; -const USED_CONST: int = 0; -const CONST_USED_IN_ENUM_DISCRIMINANT: int = 10; +const USED_CONST: int = 1; +const CONST_USED_IN_ENUM_DISCRIMINANT: int = 11; pub type typ = *const UsedStruct4; pub struct PubStruct; @@ -68,7 +68,10 @@ pub struct PubStruct2 { pub enum pub_enum { foo1, bar1 } pub enum pub_enum2 { a(*const StructUsedInEnum) } -pub enum pub_enum3 { Foo = STATIC_USED_IN_ENUM_DISCRIMINANT } +pub enum pub_enum3 { + Foo = STATIC_USED_IN_ENUM_DISCRIMINANT, + Bar = CONST_USED_IN_ENUM_DISCRIMINANT, +} enum priv_enum { foo2, bar2 } //~ ERROR: enum is never used enum used_enum { @@ -89,6 +92,7 @@ pub fn pub_fn() { let i = 1i; match i { USED_STATIC => (), + USED_CONST => (), _ => () } f::(); From b26972e28bfc1b797e2dfa14435b551685cb180b Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Mon, 13 Oct 2014 20:58:34 +0200 Subject: [PATCH 18/19] Make bors check that `compiletest` builds from both stage0 and stage1 rustc. ---- To reproduce issue on commit ba246100ca3b0c3bd0d68548677d75e6790c4f60 it does not suffice to add just `check-build-compiletest` to `check-secondary`; one must also ensure that `check-build-compiletest` precedes the satisification of the `check` rule. Otherwise hidden dependencies of `compiletest` would end up getting satisfied when make builds `rustc` at each stage in order to eventually run `check-stage2`. So to handle that I moved `check-secondary` before `check` in the `check-all` rule that bors uses, and for good measure, I also put `check-build-compiltest` at the front of the `check-secondary` rule's dependencies. My understanding is that running `check-secondary` should be relatively cheap, and thus such a reordering will not hurt bors. ---- Fix #17883. --- mk/tests.mk | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/mk/tests.mk b/mk/tests.mk index 04be295c2713..6c8b926404ed 100644 --- a/mk/tests.mk +++ b/mk/tests.mk @@ -199,14 +199,29 @@ check-docs: cleantestlibs cleantmptestlogs check-stage2-docs # Some less critical tests that are not prone to breakage. # Not run as part of the normal test suite, but tested by bors on checkin. -check-secondary: check-lexer check-pretty +check-secondary: check-build-compiletest check-lexer check-pretty # check + check-secondary. -check-all: check check-secondary +# +# Issue #17883: build check-secondary first so hidden dependencies in +# e.g. building compiletest are exercised (resolve those by adding +# deps to rules that need them; not by putting `check` first here). +check-all: check-secondary check # Pretty-printing tests. check-pretty: check-stage2-T-$(CFG_BUILD)-H-$(CFG_BUILD)-pretty-exec +define DEF_CHECK_BUILD_COMPILETEST_FOR_STAGE +check-stage$(1)-build-compiletest: $$(HBIN$(1)_H_$(CFG_BUILD))/compiletest$$(X_$(CFG_BUILD)) +endef + +$(foreach stage,$(STAGES), \ + $(eval $(call DEF_CHECK_BUILD_COMPILETEST_FOR_STAGE,$(stage)))) + +check-build-compiletest: \ + check-stage1-build-compiletest \ + check-stage2-build-compiletest + .PHONY: cleantmptestlogs cleantestlibs cleantmptestlogs: @@ -720,6 +735,13 @@ PRETTY_DEPS_pretty-rpass-full = $(RPASS_FULL_TESTS) PRETTY_DEPS_pretty-rfail = $(RFAIL_TESTS) PRETTY_DEPS_pretty-bench = $(BENCH_TESTS) PRETTY_DEPS_pretty-pretty = $(PRETTY_TESTS) +# The stage- and host-specific dependencies are for e.g. macro_crate_test which pulls in +# external crates. +PRETTY_DEPS$(1)_H_$(3)_pretty-rpass = +PRETTY_DEPS$(1)_H_$(3)_pretty-rpass-full = $$(HLIB$(1)_H_$(3))/stamp.syntax $$(HLIB$(1)_H_$(3))/stamp.rustc +PRETTY_DEPS$(1)_H_$(3)_pretty-rfail = +PRETTY_DEPS$(1)_H_$(3)_pretty-bench = +PRETTY_DEPS$(1)_H_$(3)_pretty-pretty = PRETTY_DIRNAME_pretty-rpass = run-pass PRETTY_DIRNAME_pretty-rpass-full = run-pass-fulldeps PRETTY_DIRNAME_pretty-rfail = run-fail @@ -738,7 +760,8 @@ check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \ $$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \ - $$(PRETTY_DEPS_$(4)) + $$(PRETTY_DEPS_$(4)) \ + $$(PRETTY_DEPS$(1)_H_$(3)_$(4)) @$$(call E, run pretty-rpass [$(2)]: $$<) $$(Q)$$(call CFG_RUN_CTEST_$(2),$(1),$$<,$(3)) \ $$(PRETTY_ARGS$(1)-T-$(2)-H-$(3)-$(4)) \ From 39749a3adc9ad9991fbfe90c667e287433cd1187 Mon Sep 17 00:00:00 2001 From: Stefan Bucur Date: Mon, 13 Oct 2014 22:17:48 +0200 Subject: [PATCH 19/19] Fix typo in char's from_digit error message --- src/libcore/char.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/char.rs b/src/libcore/char.rs index 8f3ecf0633cf..f507556909c8 100644 --- a/src/libcore/char.rs +++ b/src/libcore/char.rs @@ -147,7 +147,7 @@ pub fn to_digit(c: char, radix: uint) -> Option { #[inline] pub fn from_digit(num: uint, radix: uint) -> Option { if radix > 36 { - fail!("from_digit: radix is to high (maximum 36)"); + fail!("from_digit: radix is too high (maximum 36)"); } if num < radix { unsafe {