diff options
| author | bors <bors@rust-lang.org> | 2015-01-31 03:57:01 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-01-31 03:57:01 +0000 |
| commit | 474b324eda10440d6568ef872a7307d38e7de95b (patch) | |
| tree | 53fc5aaa615f1c6e5abd757e42a75b3d19ce3abb | |
| parent | 1d00c545ede609b9d43fdf9f252c15da5a66dac7 (diff) | |
| parent | e8fd9d3d0bf0f4974460337df29c0d3ceb514987 (diff) | |
| download | rust-474b324eda10440d6568ef872a7307d38e7de95b.tar.gz rust-474b324eda10440d6568ef872a7307d38e7de95b.zip | |
Auto merge of #21791 - alexcrichton:rollup, r=alexcrichton
661 files changed, 4539 insertions, 7316 deletions
diff --git a/README.md b/README.md index 6ffffd523c9..605c2fc9a61 100644 --- a/README.md +++ b/README.md @@ -110,12 +110,14 @@ There is a lot more documentation in the [wiki]. The Rust community congregates in a few places: -* [StackOverflow] - Get help here. -* [/r/rust] - General discussion. +* [StackOverflow] - Direct questions about using the language here. +* [users.rust-lang.org] - General discussion, broader questions. * [internals.rust-lang.org] - For development of the Rust language itself. +* [/r/rust] - News and general discussion. [StackOverflow]: http://stackoverflow.com/questions/tagged/rust [/r/rust]: http://reddit.com/r/rust +[users.rust-lang.org]: http://users.rust-lang.org/ [internals.rust-lang.org]: http://internals.rust-lang.org/ ## License diff --git a/src/compiletest/common.rs b/src/compiletest/common.rs index b1deb8a36ad..df2981a6c83 100644 --- a/src/compiletest/common.rs +++ b/src/compiletest/common.rs @@ -25,17 +25,18 @@ pub enum Mode { } impl FromStr for Mode { - fn from_str(s: &str) -> Option<Mode> { + type Err = (); + fn from_str(s: &str) -> Result<Mode, ()> { match s { - "compile-fail" => Some(CompileFail), - "run-fail" => Some(RunFail), - "run-pass" => Some(RunPass), - "run-pass-valgrind" => Some(RunPassValgrind), - "pretty" => Some(Pretty), - "debuginfo-lldb" => Some(DebugInfoLldb), - "debuginfo-gdb" => Some(DebugInfoGdb), - "codegen" => Some(Codegen), - _ => None, + "compile-fail" => Ok(CompileFail), + "run-fail" => Ok(RunFail), + "run-pass" => Ok(RunPass), + "run-pass-valgrind" => Ok(RunPassValgrind), + "pretty" => Ok(Pretty), + "debuginfo-lldb" => Ok(DebugInfoLldb), + "debuginfo-gdb" => Ok(DebugInfoGdb), + "codegen" => Ok(Codegen), + _ => Err(()), } } } diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index 357ccec7cf3..b73623223fd 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -9,21 +9,20 @@ // except according to those terms. #![crate_type = "bin"] -#![allow(unknown_features)] -#![feature(slicing_syntax, unboxed_closures)] + #![feature(box_syntax)] +#![feature(collections)] +#![feature(core)] #![feature(int_uint)] -#![feature(test)] -#![feature(rustc_private)] -#![feature(std_misc)] -#![feature(path)] #![feature(io)] -#![feature(core)] -#![feature(collections)] #![feature(os)] +#![feature(path)] +#![feature(rustc_private)] +#![feature(slicing_syntax, unboxed_closures)] +#![feature(std_misc)] +#![feature(test)] #![feature(unicode)] -#![allow(unstable)] #![deny(warnings)] extern crate test; @@ -35,7 +34,6 @@ extern crate log; use std::os; use std::old_io; use std::old_io::fs; -use std::str::FromStr; use std::thunk::Thunk; use getopts::{optopt, optflag, reqopt}; use common::Config; @@ -140,9 +138,7 @@ pub fn parse_config(args: Vec<String> ) -> Config { build_base: opt_path(matches, "build-base"), aux_base: opt_path(matches, "aux-base"), stage_id: matches.opt_str("stage-id").unwrap(), - mode: FromStr::from_str(matches.opt_str("mode") - .unwrap() - .as_slice()).expect("invalid mode"), + mode: matches.opt_str("mode").unwrap().parse().ok().expect("invalid mode"), run_ignored: matches.opt_present("ignored"), filter: filter, logfile: matches.opt_str("logfile").map(|s| Path::new(s)), diff --git a/src/compiletest/header.rs b/src/compiletest/header.rs index f83c27b75d6..66059d2d13d 100644 --- a/src/compiletest/header.rs +++ b/src/compiletest/header.rs @@ -352,8 +352,8 @@ pub fn gdb_version_to_int(version_string: &str) -> int { panic!("{}", error_string); } - let major: int = components[0].parse().expect(error_string); - let minor: int = components[1].parse().expect(error_string); + let major: int = components[0].parse().ok().expect(error_string); + let minor: int = components[1].parse().ok().expect(error_string); return major * 1000 + minor; } @@ -363,6 +363,6 @@ pub fn lldb_version_to_int(version_string: &str) -> int { "Encountered LLDB version string with unexpected format: {}", version_string); let error_string = error_string.as_slice(); - let major: int = version_string.parse().expect(error_string); + let major: int = version_string.parse().ok().expect(error_string); return major; } diff --git a/src/doc/index.md b/src/doc/index.md index f385a9798ea..252a3125ebd 100644 --- a/src/doc/index.md +++ b/src/doc/index.md @@ -39,10 +39,12 @@ Overflow](http://stackoverflow.com/questions/tagged/rust). Searching for your problem might reveal someone who has asked it before! There is an active [subreddit](http://reddit.com/r/rust) with lots of -discussion about Rust. +discussion and news about Rust. -There is also a [developer forum](http://internals.rust-lang.org/), where the -development of Rust itself is discussed. +There is also a [user forum](http://users.rust-lang.org), for all +user-oriented discussion, and a [developer +forum](http://internals.rust-lang.org/), where the development of Rust +itself is discussed. # Specification diff --git a/src/doc/reference.md b/src/doc/reference.md index 59ac173f97a..936c0aac79f 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -2994,7 +2994,7 @@ Some examples of call expressions: # fn add(x: i32, y: i32) -> i32 { 0 } let x: i32 = add(1i32, 2i32); -let pi: Option<f32> = "3.14".parse(); +let pi: Option<f32> = "3.14".parse().ok(); ``` ### Lambda expressions @@ -3518,7 +3518,7 @@ An example of each kind: ```{rust} let vec: Vec<i32> = vec![1, 2, 3]; let arr: [i32; 3] = [1, 2, 3]; -let s: &[i32] = vec.as_slice(); +let s: &[i32] = &vec; ``` As you can see, the `vec!` macro allows you to create a `Vec<T>` easily. The diff --git a/src/doc/trpl/guessing-game.md b/src/doc/trpl/guessing-game.md index f01b62223ca..162e533d8bb 100644 --- a/src/doc/trpl/guessing-game.md +++ b/src/doc/trpl/guessing-game.md @@ -400,7 +400,7 @@ a function for that: let input = old_io::stdin().read_line() .ok() .expect("Failed to read line"); -let input_num: Option<u32> = input.parse(); +let input_num: Option<u32> = input.parse().ok(); ``` The `parse` function takes in a `&str` value and converts it into something. @@ -422,11 +422,13 @@ In this case, we say `x` is a `u32` explicitly, so Rust is able to properly tell `random()` what to generate. In a similar fashion, both of these work: ```{rust,ignore} -let input_num = "5".parse::<u32>(); // input_num: Option<u32> -let input_num: Option<u32> = "5".parse(); // input_num: Option<u32> +let input_num = "5".parse::<u32>().ok(); // input_num: Option<u32> +let input_num: Option<u32> = "5".parse().ok(); // input_num: Option<u32> ``` -Anyway, with us now converting our input to a number, our code looks like this: +Here we're converting the `Result` returned by `parse` to an `Option` by using +the `ok` method as well. Anyway, with us now converting our input to a number, +our code looks like this: ```{rust,ignore} use std::old_io; @@ -445,7 +447,7 @@ fn main() { let input = old_io::stdin().read_line() .ok() .expect("Failed to read line"); - let input_num: Option<u32> = input.parse(); + let input_num: Option<u32> = input.parse().ok(); println!("You guessed: {}", input_num); @@ -495,7 +497,7 @@ fn main() { let input = old_io::stdin().read_line() .ok() .expect("Failed to read line"); - let input_num: Option<u32> = input.parse(); + let input_num: Option<u32> = input.parse().ok(); let num = match input_num { Some(num) => num, @@ -562,7 +564,7 @@ fn main() { let input = old_io::stdin().read_line() .ok() .expect("Failed to read line"); - let input_num: Option<u32> = input.trim().parse(); + let input_num: Option<u32> = input.trim().parse().ok(); let num = match input_num { Some(num) => num, @@ -638,7 +640,7 @@ fn main() { let input = old_io::stdin().read_line() .ok() .expect("Failed to read line"); - let input_num: Option<u32> = input.trim().parse(); + let input_num: Option<u32> = input.trim().parse().ok(); let num = match input_num { Some(num) => num, @@ -714,7 +716,7 @@ fn main() { let input = old_io::stdin().read_line() .ok() .expect("Failed to read line"); - let input_num: Option<u32> = input.trim().parse(); + let input_num: Option<u32> = input.trim().parse().ok(); let num = match input_num { Some(num) => num, @@ -770,7 +772,7 @@ fn main() { let input = old_io::stdin().read_line() .ok() .expect("Failed to read line"); - let input_num: Option<u32> = input.trim().parse(); + let input_num: Option<u32> = input.trim().parse().ok(); let num = match input_num { Some(num) => num, @@ -847,7 +849,7 @@ fn main() { let input = old_io::stdin().read_line() .ok() .expect("Failed to read line"); - let input_num: Option<u32> = input.trim().parse(); + let input_num: Option<u32> = input.trim().parse().ok(); let num = match input_num { Some(num) => num, diff --git a/src/doc/trpl/more-strings.md b/src/doc/trpl/more-strings.md index b4669b0819f..986ad23c665 100644 --- a/src/doc/trpl/more-strings.md +++ b/src/doc/trpl/more-strings.md @@ -100,7 +100,7 @@ To write a function that's generic over types of strings, use `&str`. ``` fn some_string_length(x: &str) -> uint { - x.len() + x.len() } fn main() { @@ -110,7 +110,7 @@ fn main() { let s = "Hello, world".to_string(); - println!("{}", some_string_length(s.as_slice())); + println!("{}", some_string_length(&s)); } ``` diff --git a/src/doc/trpl/patterns.md b/src/doc/trpl/patterns.md index 5c7b406a6fc..122cffe3697 100644 --- a/src/doc/trpl/patterns.md +++ b/src/doc/trpl/patterns.md @@ -174,13 +174,13 @@ match origin { } ``` -If you want to match against a slice or array, you can use `[]`: +If you want to match against a slice or array, you can use `&`: ```{rust} fn main() { let v = vec!["match_this", "1"]; - match v.as_slice() { + match &v[] { ["match_this", second] => println!("The second element is {}", second), _ => {}, } diff --git a/src/doc/trpl/plugins.md b/src/doc/trpl/plugins.md index 6e8e2c7ffe2..5ff233b4844 100644 --- a/src/doc/trpl/plugins.md +++ b/src/doc/trpl/plugins.md @@ -82,7 +82,7 @@ fn expand_rn(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree]) } }; - let mut text = text.as_slice(); + let mut text = &text; let mut total = 0; while !text.is_empty() { match NUMERALS.iter().find(|&&(rn, _)| text.starts_with(rn)) { diff --git a/src/doc/trpl/standard-input.md b/src/doc/trpl/standard-input.md index 0c26fb2b44f..794b1df7563 100644 --- a/src/doc/trpl/standard-input.md +++ b/src/doc/trpl/standard-input.md @@ -20,7 +20,7 @@ Let's go over these chunks, one by one: std::old_io::stdin(); ``` -This calls a function, `stdin()`, that lives inside the `std::io` module. As +This calls a function, `stdin()`, that lives inside the `std::old_io` module. As you can imagine, everything in `std` is provided by Rust, the 'standard library.' We'll talk more about the module system later. diff --git a/src/doc/trpl/strings.md b/src/doc/trpl/strings.md index 51f9356bd2f..e05c6e172a4 100644 --- a/src/doc/trpl/strings.md +++ b/src/doc/trpl/strings.md @@ -36,36 +36,16 @@ s.push_str(", world."); println!("{}", s); ``` -You can get a `&str` view into a `String` with the `as_slice()` method: +`String`s will coerece into `&str` with an `&`: -```{rust} +``` fn takes_slice(slice: &str) { println!("Got: {}", slice); } fn main() { let s = "Hello".to_string(); - takes_slice(s.as_slice()); -} -``` - -To compare a String to a constant string, prefer `as_slice()`... - -```{rust} -fn compare(string: String) { - if string.as_slice() == "Hello" { - println!("yes"); - } -} -``` - -... over `to_string()`: - -```{rust} -fn compare(string: String) { - if string == "Hello".to_string() { - println!("yes"); - } + takes_slice(&s); } ``` diff --git a/src/doc/trpl/unsafe.md b/src/doc/trpl/unsafe.md index 3acd1eefe89..2bd86fa987f 100644 --- a/src/doc/trpl/unsafe.md +++ b/src/doc/trpl/unsafe.md @@ -576,6 +576,10 @@ extern fn panic_fmt(args: &core::fmt::Arguments, #[lang = "eh_personality"] extern fn eh_personality() {} # #[start] fn start(argc: isize, argv: *const *const u8) -> isize { 0 } # fn main() {} +# mod std { // for-loops +# pub use core::iter; +# pub use core::option; +# } ``` Note that there is one extra lang item here which differs from the examples diff --git a/src/driver/driver.rs b/src/driver/driver.rs index 601f130341b..6b56c2b6303 100644 --- a/src/driver/driver.rs +++ b/src/driver/driver.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![allow(unknown_features)] #![cfg_attr(rustc, feature(rustc_private))] #![cfg_attr(rustdoc, feature(rustdoc))] diff --git a/src/etc/emacs/README.md b/src/etc/emacs/README.md deleted file mode 100644 index 24470c258b3..00000000000 --- a/src/etc/emacs/README.md +++ /dev/null @@ -1,79 +0,0 @@ -`rust-mode`: A major Emacs mode for editing Rust source code -============================================================ - -`rust-mode` makes editing [Rust](http://rust-lang.org) code with Emacs -enjoyable. - - -### Manual Installation - -To install manually, check out this repository and add this to your -`.emacs` file: - -```lisp -(add-to-list 'load-path "/path/to/rust-mode/") -(autoload 'rust-mode "rust-mode" nil t) -(add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-mode)) -``` - -This associates `rust-mode` with `.rs` files. To enable it explicitly, do -<kbd>M-x rust-mode</kbd>. - -### `package.el` installation via Marmalade or MELPA - -It can be more convenient to use Emacs's package manager to handle -installation for you if you use many elisp libraries. If you have -`package.el` but haven't added Marmalade or MELPA, the community -package source, yet, add this to `~/.emacs.d/init.el`: - -Using Marmalade: - -```lisp -(require 'package) -(add-to-list 'package-archives - '("marmalade" . "http://marmalade-repo.org/packages/")) -(package-initialize) -``` - -Using MELPA: - -```lisp -(require 'package) -(add-to-list 'package-archives - '("melpa" . "http://melpa.milkbox.net/packages/") t) -(package-initialize) -``` - -Then do this to load the package listing: - -* <kbd>M-x eval-buffer</kbd> -* <kbd>M-x package-refresh-contents</kbd> - -If you use a version of Emacs prior to 24 that doesn't include -`package.el`, you can get it from [here](http://bit.ly/pkg-el23). - -If you have an older ELPA `package.el` installed from tromey.com, you -should upgrade in order to support installation from multiple sources. -The ELPA archive is deprecated and no longer accepting new packages, -so the version there (1.7.1) is very outdated. - -#### Install `rust-mode` - -One you have `package.el`, you can install `rust-mode` or any other -modes by choosing them from a list: - -* <kbd>M-x package-list-packages</kbd> - -Now, to install packages, move your cursor to them and press -<kbd>i</kbd>. This will mark the packages for installation. When -you're done with marking, press <kbd>x</kbd>, and ELPA will install -the packages for you (under `~/.emacs.d/elpa/`). - -* or using <kbd>M-x package-install rust-mode</kbd> - -### Tests via ERT - -The file `rust-mode-tests.el` contains tests that can be run via -[ERT](http://www.gnu.org/software/emacs/manual/html_node/ert/index.html). -You can use `run_rust_emacs_tests.sh` to run them in batch mode, if -Emacs is somewhere in your `$PATH`. diff --git a/src/etc/emacs/run_rust_emacs_tests.sh b/src/etc/emacs/run_rust_emacs_tests.sh deleted file mode 100755 index b35fcf870c4..00000000000 --- a/src/etc/emacs/run_rust_emacs_tests.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh -# 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 <LICENSE-APACHE or -# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -# option. This file may not be copied, modified, or distributed -# except according to those terms. -# -# This runs the test for emacs rust-mode. -# It must be possible to find emacs via PATH. -emacs -batch -l rust-mode.el -l rust-mode-tests.el -f ert-run-tests-batch-and-exit diff --git a/src/etc/emacs/rust-mode-tests.el b/src/etc/emacs/rust-mode-tests.el deleted file mode 100644 index f255dbf1507..00000000000 --- a/src/etc/emacs/rust-mode-tests.el +++ /dev/null @@ -1,896 +0,0 @@ -;;; rust-mode-tests.el --- ERT tests for rust-mode.el - -(require 'rust-mode) -(require 'ert) -(require 'cl) - -(setq rust-test-fill-column 32) - -(defun rust-compare-code-after-manip (original point-pos manip-func expected got) - (equal expected got)) - -(defun rust-test-explain-bad-manip (original point-pos manip-func expected got) - (if (equal expected got) - nil - (list - ;; The (goto-char) and (insert) business here is just for - ;; convenience--after an error, you can copy-paste that into emacs eval to - ;; insert the bare strings into a buffer - "Rust code was manipulated wrong after:" - `(insert ,original) - `(goto-char ,point-pos) - 'expected `(insert ,expected) - 'got `(insert ,got) - (loop for i from 0 to (max (length original) (length expected)) - for oi = (if (< i (length got)) (elt got i)) - for ei = (if (< i (length expected)) (elt expected i)) - while (equal oi ei) - finally return `(first-difference-at - (goto-char ,(+ 1 i)) - expected ,(char-to-string ei) - got ,(char-to-string oi)))))) -(put 'rust-compare-code-after-manip 'ert-explainer - 'rust-test-explain-bad-manip) - -(defun rust-test-manip-code (original point-pos manip-func expected) - (with-temp-buffer - (rust-mode) - (insert original) - (goto-char point-pos) - (funcall manip-func) - (should (rust-compare-code-after-manip - original point-pos manip-func expected (buffer-string))))) - -(defun test-fill-paragraph (unfilled expected &optional start-pos end-pos) - "We're going to run through many scenarios here--the point should be able to be anywhere from the start-pos (defaults to 1) through end-pos (defaults to the length of what was passed in) and (fill-paragraph) should return the same result. - -Also, the result should be the same regardless of whether the code is at the beginning or end of the file. (If you're not careful, that can make a difference.) So we test each position given above with the passed code at the beginning, the end, neither and both. So we do this a total of (end-pos - start-pos)*4 times. Oy." - (let* ((start-pos (or start-pos 1)) - (end-pos (or end-pos (length unfilled))) - (padding "\n \n") - (padding-len (length padding))) - (loop - for pad-at-beginning from 0 to 1 - do (loop for pad-at-end from 0 to 1 - with padding-beginning = (if (= 0 pad-at-beginning) "" padding) - with padding-end = (if (= 0 pad-at-end) "" padding) - with padding-adjust = (* padding-len pad-at-beginning) - with padding-beginning = (if (= 0 pad-at-beginning) "" padding) - with padding-end = (if (= 0 pad-at-end) "" padding) - ;; If we're adding space to the beginning, and our start position - ;; is at the very beginning, we want to test within the added space. - ;; Otherwise adjust the start and end for the beginning padding. - with start-pos = (if (= 1 start-pos) 1 (+ padding-adjust start-pos)) - with end-pos = (+ end-pos padding-adjust) - do (loop for pos from start-pos to end-pos - do (rust-test-manip-code - (concat padding-beginning unfilled padding-end) - pos - (lambda () - (let ((fill-column rust-test-fill-column)) - (fill-paragraph))) - (concat padding-beginning expected padding-end))))))) - -(ert-deftest fill-paragraph-top-level-multi-line-style-doc-comment-second-line () - (test-fill-paragraph - "/** - * This is a very very very very very very very long string - */" - "/** - * This is a very very very very - * very very very long string - */")) - - -(ert-deftest fill-paragraph-top-level-multi-line-style-doc-comment-first-line () - (test-fill-paragraph - "/** This is a very very very very very very very long string - */" - "/** This is a very very very - * very very very very long - * string - */")) - -(ert-deftest fill-paragraph-multi-paragraph-multi-line-style-doc-comment () - (let - ((multi-paragraph-unfilled - "/** - * This is the first really really really really really really really long paragraph - * - * This is the second really really really really really really long paragraph - */")) - (test-fill-paragraph - multi-paragraph-unfilled - "/** - * This is the first really - * really really really really - * really really long paragraph - * - * This is the second really really really really really really long paragraph - */" - 1 89) - (test-fill-paragraph - multi-paragraph-unfilled - "/** - * This is the first really really really really really really really long paragraph - * - * This is the second really - * really really really really - * really long paragraph - */" - 90))) - -(ert-deftest fill-paragraph-multi-paragraph-single-line-style-doc-comment () - (let - ((multi-paragraph-unfilled - "/// This is the first really really really really really really really long paragraph -/// -/// This is the second really really really really really really long paragraph")) - (test-fill-paragraph - multi-paragraph-unfilled - "/// This is the first really -/// really really really really -/// really really long paragraph -/// -/// This is the second really really really really really really long paragraph" - 1 86) - (test-fill-paragraph - multi-paragraph-unfilled - "/// This is the first really really really really really really really long paragraph -/// -/// This is the second really -/// really really really really -/// really long paragraph" - 87))) - -(ert-deftest fill-paragraph-multi-paragraph-single-line-style-indented () - (test-fill-paragraph - " // This is the first really really really really really really really long paragraph - // - // This is the second really really really really really really long paragraph" - " // This is the first really - // really really really - // really really really - // long paragraph - // - // This is the second really really really really really really long paragraph" 1 89)) - -(ert-deftest fill-paragraph-multi-line-style-inner-doc-comment () - (test-fill-paragraph - "/*! This is a very very very very very very very long string - */" - "/*! This is a very very very - * very very very very long - * string - */")) - -(ert-deftest fill-paragraph-single-line-style-inner-doc-comment () - (test-fill-paragraph - "//! This is a very very very very very very very long string" - "//! This is a very very very -//! very very very very long -//! string")) - -(ert-deftest fill-paragraph-prefixless-multi-line-doc-comment () - (test-fill-paragraph - "/** -This is my summary. Blah blah blah blah blah. Dilly dally dilly dally dilly dally doo. - -This is some more text. Fee fie fo fum. Humpty dumpty sat on a wall. -*/" - "/** -This is my summary. Blah blah -blah blah blah. Dilly dally -dilly dally dilly dally doo. - -This is some more text. Fee fie fo fum. Humpty dumpty sat on a wall. -*/" 4 90)) - -(ert-deftest fill-paragraph-with-no-space-after-star-prefix () - (test-fill-paragraph - "/** - *This is a very very very very very very very long string - */" - "/** - *This is a very very very very - *very very very long string - */")) - -(ert-deftest fill-paragraph-single-line-style-with-code-before () - (test-fill-paragraph - "fn foo() { } -/// This is my comment. This is more of my comment. This is even more." - "fn foo() { } -/// This is my comment. This is -/// more of my comment. This is -/// even more." 14)) - -(ert-deftest fill-paragraph-single-line-style-with-code-after () - (test-fill-paragraph - "/// This is my comment. This is more of my comment. This is even more. -fn foo() { }" - "/// This is my comment. This is -/// more of my comment. This is -/// even more. -fn foo() { }" 1 73)) - -(ert-deftest fill-paragraph-single-line-style-code-before-and-after () - (test-fill-paragraph - "fn foo() { } -/// This is my comment. This is more of my comment. This is even more. -fn bar() { }" - "fn foo() { } -/// This is my comment. This is -/// more of my comment. This is -/// even more. -fn bar() { }" 14 67)) - -(defun test-auto-fill (initial position inserted expected) - (rust-test-manip-code - initial - position - (lambda () - (unwind-protect - (progn - (let ((fill-column rust-test-fill-column)) - (auto-fill-mode) - (goto-char position) - (insert inserted) - (syntax-ppss-flush-cache 1) - (funcall auto-fill-function))) - (auto-fill-mode t))) - expected)) - -(ert-deftest auto-fill-multi-line-doc-comment () - (test-auto-fill - "/** - * - */" - 8 - "This is a very very very very very very very long string" - "/** - * This is a very very very very - * very very very long string - */")) - -(ert-deftest auto-fill-single-line-doc-comment () - (test-auto-fill - "/// This is the first really -/// really really really really -/// really really long paragraph -/// -/// " - 103 - "This is the second really really really really really really long paragraph" - "/// This is the first really -/// really really really really -/// really really long paragraph -/// -/// This is the second really -/// really really really really -/// really long paragraph" - )) - -(ert-deftest auto-fill-multi-line-prefixless () - (test-auto-fill - "/* - - */" - 4 - "This is a very very very very very very very long string" - "/* -This is a very very very very -very very very long string - */" - )) - -(defun test-indent (indented) - (let ((deindented (replace-regexp-in-string "^[[:blank:]]*" " " indented))) - (rust-test-manip-code - deindented - 1 - (lambda () (indent-region 1 (buffer-size))) - indented))) - - -(ert-deftest indent-struct-fields-aligned () - (test-indent - " -struct Foo { bar: int, - baz: int } - -struct Blah {x:int, - y:int, - z:String")) - -(ert-deftest indent-doc-comments () - (test-indent - " -/** - * This is a doc comment - * - */ - -/// So is this - -fn foo() { - /*! - * this is a nested doc comment - */ - - //! And so is this -}")) - -(ert-deftest indent-inside-braces () - (test-indent - " -// struct fields out one level: -struct foo { - a:int, - // comments too - b:char -} - -fn bar(x:Box<int>) { // comment here should not affect the next indent - bla(); - bla(); -}")) - -(ert-deftest indent-top-level () - (test-indent - " -// Everything here is at the top level and should not be indented -#[attrib] -mod foo; - -pub static bar = Quux{a: b()} - -use foo::bar::baz; - -fn foo() { } -")) - -(ert-deftest indent-params-no-align () - (test-indent - " -// Indent out one level because no params appear on the first line -fn xyzzy( - a:int, - b:char) { } - -fn abcdef( - a:int, - b:char) - -> char -{ }")) - -(ert-deftest indent-params-align () - (test-indent - " -// Align the second line of params to the first -fn foo(a:int, - b:char) { } - -fn bar( a:int, - b:char) - -> int -{ } - -fn baz( a:int, // should work with a comment here - b:char) - -> int -{ } -")) - -(ert-deftest indent-square-bracket-alignment () - (test-indent - " -fn args_on_the_next_line( // with a comment - a:int, - b:String) { - let aaaaaa = [ - 1, - 2, - 3]; - let bbbbbbb = [1, 2, 3, - 4, 5, 6]; - let ccc = [ 10, 9, 8, - 7, 6, 5]; -} -")) - -(ert-deftest indent-nested-fns () - (test-indent - " -fn nexted_fns(a: fn(b:int, - c:char) - -> int, - d: int) - -> uint -{ - 0 -} -" - )) - -(ert-deftest indent-multi-line-expr () - (test-indent - " -fn foo() -{ - x(); - let a = - b(); -} -" - )) - -(ert-deftest indent-match () - (test-indent - " -fn foo() { - match blah { - Pattern => stuff(), - _ => whatever - } -} -" - )) - -(ert-deftest indent-match-multiline-pattern () - (test-indent - " -fn foo() { - match blah { - Pattern | - Pattern2 => { - hello() - }, - _ => whatever - } -} -" - )) - -(ert-deftest indent-indented-match () - (test-indent - " -fn foo() { - let x = - match blah { - Pattern | - Pattern2 => { - hello() - }, - _ => whatever - }; - y(); -} -" - )) - -(ert-deftest indent-curly-braces-within-parens () - (test-indent - " -fn foo() { - let x = - foo(bar(|x| { - only_one_indent_here(); - })); - y(); -} -" - )) - -(ert-deftest indent-weirdly-indented-block () - (rust-test-manip-code - " -fn foo() { - { -this_block_is_over_to_the_left_for_some_reason(); - } - -} -" - 16 - #'indent-for-tab-command - " -fn foo() { - { - this_block_is_over_to_the_left_for_some_reason(); - } - -} -" - )) - -(ert-deftest indent-multi-line-attrib () - (test-indent - " -#[attrib( - this, - that, - theotherthing)] -fn function_with_multiline_attribute() {} -" - )) - - -;; Make sure that in effort to cover match patterns we don't mistreat || or expressions -(ert-deftest indent-nonmatch-or-expression () - (test-indent - " -fn foo() { - let x = foo() || - bar(); -} -" - )) - -(setq rust-test-motion-string - " -fn fn1(arg: int) -> bool { - let x = 5; - let y = b(); - true -} - -fn fn2(arg: int) -> bool { - let x = 5; - let y = b(); - true -} - -pub fn fn3(arg: int) -> bool { - let x = 5; - let y = b(); - true -} - -struct Foo { - x: int -} -" - rust-test-region-string rust-test-motion-string - rust-test-indent-motion-string - " -fn blank_line(arg:int) -> bool { - -} - -fn indenting_closing_brace() { - if(true) { -} -} - -fn indenting_middle_of_line() { - if(true) { - push_me_out(); -} else { - pull_me_back_in(); -} -} - -fn indented_already() { - - // The previous line already has its spaces -} -" - - ;; Symbol -> (line column) - rust-test-positions-alist '((start-of-fn1 (2 0)) - (start-of-fn1-middle-of-line (2 15)) - (middle-of-fn1 (3 7)) - (end-of-fn1 (6 0)) - (between-fn1-fn2 (7 0)) - (start-of-fn2 (8 0)) - (middle-of-fn2 (10 4)) - (before-start-of-fn1 (1 0)) - (after-end-of-fn2 (13 0)) - (beginning-of-fn3 (14 0)) - (middle-of-fn3 (16 4)) - (middle-of-struct (21 10)) - (before-start-of-struct (19 0)) - (after-end-of-struct (23 0)) - (blank-line-indent-start (3 0)) - (blank-line-indent-target (3 4)) - (closing-brace-indent-start (8 1)) - (closing-brace-indent-target (8 5)) - (middle-push-indent-start (13 2)) - (middle-push-indent-target (13 9)) - (after-whitespace-indent-start (13 1)) - (after-whitespace-indent-target (13 8)) - (middle-pull-indent-start (15 19)) - (middle-pull-indent-target (15 12)) - (blank-line-indented-already-bol-start (20 0)) - (blank-line-indented-already-bol-target (20 4)) - (blank-line-indented-already-middle-start (20 2)) - (blank-line-indented-already-middle-target (20 4)) - (nonblank-line-indented-already-bol-start (21 0)) - (nonblank-line-indented-already-bol-target (21 4)) - (nonblank-line-indented-already-middle-start (21 2)) - (nonblank-line-indented-already-middle-target (21 4)))) - -(defun rust-get-buffer-pos (pos-symbol) - "Get buffer position from POS-SYMBOL. - -POS-SYMBOL is a symbol found in `rust-test-positions-alist'. -Convert the line-column information from that list into a buffer position value." - (interactive "P") - (pcase-let ((`(,line ,column) (cadr (assoc pos-symbol rust-test-positions-alist)))) - (save-excursion - (goto-line line) - (move-to-column column) - (point)))) - -;;; FIXME: Maybe add an ERT explainer function (something that shows the -;;; surrounding code of the final point, not just the position). -(defun rust-test-motion (source-code init-pos final-pos manip-func &optional &rest args) - "Test that MANIP-FUNC moves point from INIT-POS to FINAL-POS. - -If ARGS are provided, send them to MANIP-FUNC. - -INIT-POS, FINAL-POS are position symbols found in `rust-test-positions-alist'." - (with-temp-buffer - (rust-mode) - (insert source-code) - (goto-char (rust-get-buffer-pos init-pos)) - (apply manip-func args) - (should (equal (point) (rust-get-buffer-pos final-pos))))) - -(defun rust-test-region (source-code init-pos reg-beg reg-end manip-func &optional &rest args) - "Test that MANIP-FUNC marks region from REG-BEG to REG-END. - -INIT-POS is the initial position of point. -If ARGS are provided, send them to MANIP-FUNC. -All positions are position symbols found in `rust-test-positions-alist'." - (with-temp-buffer - (rust-mode) - (insert source-code) - (goto-char (rust-get-buffer-pos init-pos)) - (apply manip-func args) - (should (equal (list (region-beginning) (region-end)) - (list (rust-get-buffer-pos reg-beg) - (rust-get-buffer-pos reg-end)))))) - -(ert-deftest rust-beginning-of-defun-from-middle-of-fn () - (rust-test-motion - rust-test-motion-string - 'middle-of-fn1 - 'start-of-fn1 - #'beginning-of-defun)) - -(ert-deftest rust-beginning-of-defun-from-end () - (rust-test-motion - rust-test-motion-string - 'end-of-fn1 - 'start-of-fn1 - #'beginning-of-defun)) - -(ert-deftest rust-beginning-of-defun-before-open-brace () - (rust-test-motion - rust-test-motion-string - 'start-of-fn1-middle-of-line - 'start-of-fn1 - #'beginning-of-defun)) - -(ert-deftest rust-beginning-of-defun-between-fns () - (rust-test-motion - rust-test-motion-string - 'between-fn1-fn2 - 'start-of-fn1 - #'beginning-of-defun)) - -(ert-deftest rust-beginning-of-defun-with-arg () - (rust-test-motion - rust-test-motion-string - 'middle-of-fn2 - 'start-of-fn1 - #'beginning-of-defun 2)) - -(ert-deftest rust-beginning-of-defun-with-negative-arg () - (rust-test-motion - rust-test-motion-string - 'middle-of-fn1 - 'beginning-of-fn3 - #'beginning-of-defun -2)) - -(ert-deftest rust-beginning-of-defun-pub-fn () - (rust-test-motion - rust-test-motion-string - 'middle-of-fn3 - 'beginning-of-fn3 - #'beginning-of-defun)) - -(ert-deftest rust-end-of-defun-from-middle-of-fn () - (rust-test-motion - rust-test-motion-string - 'middle-of-fn1 - 'between-fn1-fn2 - #'end-of-defun)) - -(ert-deftest rust-end-of-defun-from-beg () - (rust-test-motion - rust-test-motion-string - 'start-of-fn1 - 'between-fn1-fn2 - #'end-of-defun)) - -(ert-deftest rust-end-of-defun-before-open-brace () - (rust-test-motion - rust-test-motion-string - 'start-of-fn1-middle-of-line - 'between-fn1-fn2 - #'end-of-defun)) - -(ert-deftest rust-end-of-defun-between-fns () - (rust-test-motion - rust-test-motion-string - 'between-fn1-fn2 - 'after-end-of-fn2 - #'end-of-defun)) - -(ert-deftest rust-end-of-defun-with-arg () - (rust-test-motion - rust-test-motion-string - 'middle-of-fn1 - 'after-end-of-fn2 - #'end-of-defun 2)) - -(ert-deftest rust-end-of-defun-with-negative-arg () - (rust-test-motion - rust-test-motion-string - 'middle-of-fn3 - 'between-fn1-fn2 - #'end-of-defun -2)) - -(ert-deftest rust-mark-defun-from-middle-of-fn () - (rust-test-region - rust-test-region-string - 'middle-of-fn2 - 'between-fn1-fn2 'after-end-of-fn2 - #'mark-defun)) - -(ert-deftest rust-mark-defun-from-end () - (rust-test-region - rust-test-region-string - 'end-of-fn1 - 'before-start-of-fn1 'between-fn1-fn2 - #'mark-defun)) - -(ert-deftest rust-mark-defun-start-of-defun () - (rust-test-region - rust-test-region-string - 'start-of-fn2 - 'between-fn1-fn2 'after-end-of-fn2 - #'mark-defun)) - -(ert-deftest rust-mark-defun-from-middle-of-struct () - (rust-test-region - rust-test-region-string - 'middle-of-struct - 'before-start-of-struct 'after-end-of-struct - #'mark-defun)) - -(ert-deftest indent-line-blank-line-motion () - (rust-test-motion - rust-test-indent-motion-string - 'blank-line-indent-start - 'blank-line-indent-target - #'indent-for-tab-command)) - -(ert-deftest indent-line-closing-brace-motion () - (rust-test-motion - rust-test-indent-motion-string - 'closing-brace-indent-start - 'closing-brace-indent-target - #'indent-for-tab-command)) - -(ert-deftest indent-line-middle-push-motion () - (rust-test-motion - rust-test-indent-motion-string - 'middle-push-indent-start - 'middle-push-indent-target - #'indent-for-tab-command)) - -(ert-deftest indent-line-after-whitespace-motion () - (rust-test-motion - rust-test-indent-motion-string - 'after-whitespace-indent-start - 'after-whitespace-indent-target - #'indent-for-tab-command)) - -(ert-deftest indent-line-middle-pull-motion () - (rust-test-motion - rust-test-indent-motion-string - 'middle-pull-indent-start - 'middle-pull-indent-target - #'indent-for-tab-command)) - -(ert-deftest indent-line-blank-line-indented-already-bol () - (rust-test-motion - rust-test-indent-motion-string - 'blank-line-indented-already-bol-start - 'blank-line-indented-already-bol-target - #'indent-for-tab-command)) - -(ert-deftest indent-line-blank-line-indented-already-middle () - (rust-test-motion - rust-test-indent-motion-string - 'blank-line-indented-already-middle-start - 'blank-line-indented-already-middle-target - #'indent-for-tab-command)) - -(ert-deftest indent-line-nonblank-line-indented-already-bol () - (rust-test-motion - rust-test-indent-motion-string - 'nonblank-line-indented-already-bol-start - 'nonblank-line-indented-already-bol-target - #'indent-for-tab-command)) - -(ert-deftest indent-line-nonblank-line-indented-already-middle () - (rust-test-motion - rust-test-indent-motion-string - 'nonblank-line-indented-already-middle-start - 'nonblank-line-indented-already-middle-target - #'indent-for-tab-command)) - -(defun rust-test-fontify-string (str) - (with-temp-buffer - (rust-mode) - (insert str) - (font-lock-fontify-buffer) - (buffer-string))) - -(defun rust-test-group-str-by-face (str) - "Fontify `STR' in rust-mode and group it by face, returning a -list of substrings of `STR' each followed by its face." - (cl-loop with fontified = (rust-test-fontify-string str) - for start = 0 then end - while start - for end = (next-single-property-change start 'face fontified) - for prop = (get-text-property start 'face fontified) - for text = (substring-no-properties fontified start end) - if prop - append (list text prop))) - -(defun rust-test-font-lock (source face-groups) - "Test that `SOURCE' fontifies to the expected `FACE-GROUPS'" - (should (equal (rust-test-group-str-by-face source) - face-groups))) - -(ert-deftest font-lock-attribute-simple () - (rust-test-font-lock - "#[foo]" - '("#[foo]" font-lock-preprocessor-face))) - -(ert-deftest font-lock-attribute-inner () - (rust-test-font-lock - "#![foo]" - '("#![foo]" font-lock-preprocessor-face))) - -(ert-deftest font-lock-attribute-key-value () - (rust-test-font-lock - "#[foo = \"bar\"]" - '("#[foo = " font-lock-preprocessor-face - "\"bar\"" font-lock-string-face - "]" font-lock-preprocessor-face))) - -(ert-deftest font-lock-attribute-around-comment () - (rust-test-font-lock - "#[foo /* bar */]" - '("#[foo " font-lock-preprocessor-face - "/* " font-lock-comment-delimiter-face - "bar */" font-lock-comment-face - "]" font-lock-preprocessor-face))) - -(ert-deftest font-lock-attribute-inside-string () - (rust-test-font-lock - "\"#[foo]\"" - '("\"#[foo]\"" font-lock-string-face))) - -(ert-deftest font-lock-attribute-inside-comment () - (rust-test-font-lock - "/* #[foo] */" - '("/* " font-lock-comment-delimiter-face - "#[foo] */" font-lock-comment-face))) diff --git a/src/etc/emacs/rust-mode.el b/src/etc/emacs/rust-mode.el deleted file mode 100644 index dae685f3a54..00000000000 --- a/src/etc/emacs/rust-mode.el +++ /dev/null @@ -1,520 +0,0 @@ -;;; rust-mode.el --- A major emacs mode for editing Rust source code - -;; Version: 0.2.0 -;; Author: Mozilla -;; Url: https://github.com/rust-lang/rust -;; Keywords: languages - -;;; Commentary: -;; - -;;; Code: - -(eval-when-compile (require 'misc)) - -;; for GNU Emacs < 24.3 -(eval-when-compile - (unless (fboundp 'setq-local) - (defmacro setq-local (var val) - "Set variable VAR to value VAL in current buffer." - (list 'set (list 'make-local-variable (list 'quote var)) val)))) - -;; Syntax definitions and helpers -(defvar rust-mode-syntax-table - (let ((table (make-syntax-table))) - - ;; Operators - (dolist (i '(?+ ?- ?* ?/ ?& ?| ?^ ?! ?< ?> ?~ ?@)) - (modify-syntax-entry i "." table)) - - ;; Strings - (modify-syntax-entry ?\" "\"" table) - (modify-syntax-entry ?\\ "\\" table) - - ;; mark _ as a word constituent so that identifiers - ;; such as xyz_type don't cause type to be highlighted - ;; as a keyword - (modify-syntax-entry ?_ "w" table) - - ;; Comments - (modify-syntax-entry ?/ ". 124b" table) - (modify-syntax-entry ?* ". 23" table) - (modify-syntax-entry ?\n "> b" table) - (modify-syntax-entry ?\^m "> b" table) - - table)) - -(defgroup rust-mode nil - "Support for Rust code." - :link '(url-link "http://www.rust-lang.org/") - :group 'languages) - -(defcustom rust-indent-offset 4 - "Indent Rust code by this number of spaces." - :type 'integer - :group 'rust-mode) - -(defcustom rust-indent-method-chain nil - "Indent Rust method chains, aligned by the '.' operators" - :type 'boolean - :group 'rust-mode) - -(defun rust-paren-level () (nth 0 (syntax-ppss))) -(defun rust-in-str-or-cmnt () (nth 8 (syntax-ppss))) -(defun rust-rewind-past-str-cmnt () (goto-char (nth 8 (syntax-ppss)))) -(defun rust-rewind-irrelevant () - (let ((starting (point))) - (skip-chars-backward "[:space:]\n") - (if (looking-back "\\*/") (backward-char)) - (if (rust-in-str-or-cmnt) - (rust-rewind-past-str-cmnt)) - (if (/= starting (point)) - (rust-rewind-irrelevant)))) - -(defun rust-align-to-expr-after-brace () - (save-excursion - (forward-char) - ;; We don't want to indent out to the open bracket if the - ;; open bracket ends the line - (when (not (looking-at "[[:blank:]]*\\(?://.*\\)?$")) - (when (looking-at "[[:space:]]") - (forward-word 1) - (backward-word 1)) - (current-column)))) - -(defun rust-align-to-method-chain () - (save-excursion - (previous-line) - (end-of-line) - (backward-word 1) - (backward-char) - (when (looking-at "\\..+\(.*\)\n") - (- (current-column) rust-indent-offset)))) - -(defun rust-rewind-to-beginning-of-current-level-expr () - (let ((current-level (rust-paren-level))) - (back-to-indentation) - (while (> (rust-paren-level) current-level) - (backward-up-list) - (back-to-indentation)))) - -(defun rust-mode-indent-line () - (interactive) - (let ((indent - (save-excursion - (back-to-indentation) - ;; Point is now at beginning of current line - (let* ((level (rust-paren-level)) - (baseline - ;; Our "baseline" is one level out from the indentation of the expression - ;; containing the innermost enclosing opening bracket. That - ;; way if we are within a block that has a different - ;; indentation than this mode would give it, we still indent - ;; the inside of it correctly relative to the outside. - (if (= 0 level) - 0 - (or - (when rust-indent-method-chain - (rust-align-to-method-chain)) - (save-excursion - (backward-up-list) - (rust-rewind-to-beginning-of-current-level-expr) - (+ (current-column) rust-indent-offset)))))) - (cond - ;; A function return type is indented to the corresponding function arguments - ((looking-at "->") - (save-excursion - (backward-list) - (or (rust-align-to-expr-after-brace) - (+ baseline rust-indent-offset)))) - - ;; A closing brace is 1 level unindended - ((looking-at "}") (- baseline rust-indent-offset)) - - ;;Line up method chains by their .'s - ((when (and rust-indent-method-chain - (looking-at "\..+\(.*\);?\n")) - (or - (let ((method-indent (rust-align-to-method-chain))) - (when method-indent - (+ method-indent rust-indent-offset))) - (+ baseline rust-indent-offset)))) - - - ;; Doc comments in /** style with leading * indent to line up the *s - ((and (nth 4 (syntax-ppss)) (looking-at "*")) - (+ 1 baseline)) - - ;; If we're in any other token-tree / sexp, then: - (t - (or - ;; If we are inside a pair of braces, with something after the - ;; open brace on the same line and ending with a comma, treat - ;; it as fields and align them. - (when (> level 0) - (save-excursion - (rust-rewind-irrelevant) - (backward-up-list) - ;; Point is now at the beginning of the containing set of braces - (rust-align-to-expr-after-brace))) - - (progn - (back-to-indentation) - ;; Point is now at the beginning of the current line - (if (or - ;; If this line begins with "else" or "{", stay on the - ;; baseline as well (we are continuing an expression, - ;; but the "else" or "{" should align with the beginning - ;; of the expression it's in.) - (looking-at "\\<else\\>\\|{") - - (save-excursion - (rust-rewind-irrelevant) - ;; Point is now at the end of the previous ine - (or - ;; If we are at the first line, no indentation is needed, so stay at baseline... - (= 1 (line-number-at-pos (point))) - ;; ..or if the previous line ends with any of these: - ;; { ? : ( , ; [ } - ;; then we are at the beginning of an expression, so stay on the baseline... - (looking-back "[(,:;?[{}]\\|[^|]|") - ;; or if the previous line is the end of an attribute, stay at the baseline... - (progn (rust-rewind-to-beginning-of-current-level-expr) (looking-at "#"))))) - baseline - - ;; Otherwise, we are continuing the same expression from the previous line, - ;; so add one additional indent level - (+ baseline rust-indent-offset)))))))))) - - ;; If we're at the beginning of the line (before or at the current - ;; indentation), jump with the indentation change. Otherwise, save the - ;; excursion so that adding the indentations will leave us at the - ;; equivalent position within the line to where we were before. - (if (<= (current-column) (current-indentation)) - (indent-line-to indent) - (save-excursion (indent-line-to indent))))) - - -;; Font-locking definitions and helpers -(defconst rust-mode-keywords - '("as" - "box" "break" - "const" "continue" "crate" - "do" - "else" "enum" "extern" - "false" "fn" "for" - "if" "impl" "in" - "let" "loop" - "match" "mod" "move" "mut" - "priv" "pub" - "ref" "return" - "self" "static" "struct" "super" - "true" "trait" "type" - "unsafe" "use" - "virtual" - "where" "while")) - -(defconst rust-special-types - '("u8" "i8" - "u16" "i16" - "u32" "i32" - "u64" "i64" - - "f32" "f64" - "float" "int" "uint" "isize" "usize" - "bool" - "str" "char")) - -(defconst rust-re-ident "[[:word:][:multibyte:]_][[:word:][:multibyte:]_[:digit:]]*") -(defconst rust-re-CamelCase "[[:upper:]][[:word:][:multibyte:]_[:digit:]]*") -(defun rust-re-word (inner) (concat "\\<" inner "\\>")) -(defun rust-re-grab (inner) (concat "\\(" inner "\\)")) -(defun rust-re-grabword (inner) (rust-re-grab (rust-re-word inner))) -(defun rust-re-item-def (itype) - (concat (rust-re-word itype) "[[:space:]]+" (rust-re-grab rust-re-ident))) - -(defvar rust-mode-font-lock-keywords - (append - `( - ;; Keywords proper - (,(regexp-opt rust-mode-keywords 'words) . font-lock-keyword-face) - - ;; Special types - (,(regexp-opt rust-special-types 'words) . font-lock-type-face) - - ;; Attributes like `#[bar(baz)]` or `#![bar(baz)]` or `#[bar = "baz"]` - (,(rust-re-grab (concat "#\\!?\\[" rust-re-ident "[^]]*\\]")) - 1 font-lock-preprocessor-face keep) - - ;; Syntax extension invocations like `foo!`, highlight including the ! - (,(concat (rust-re-grab (concat rust-re-ident "!")) "[({[:space:][]") - 1 font-lock-preprocessor-face) - - ;; Field names like `foo:`, highlight excluding the : - (,(concat (rust-re-grab rust-re-ident) ":[^:]") 1 font-lock-variable-name-face) - - ;; Module names like `foo::`, highlight including the :: - (,(rust-re-grab (concat rust-re-ident "::")) 1 font-lock-type-face) - - ;; Lifetimes like `'foo` - (,(concat "'" (rust-re-grab rust-re-ident) "[^']") 1 font-lock-variable-name-face) - - ;; Character constants, since they're not treated as strings - ;; in order to have sufficient leeway to parse 'lifetime above. - (,(rust-re-grab "'[^']'") 1 font-lock-string-face) - (,(rust-re-grab "'\\\\[nrt]'") 1 font-lock-string-face) - (,(rust-re-grab "'\\\\x[[:xdigit:]]\\{2\\}'") 1 font-lock-string-face) - (,(rust-re-grab "'\\\\u[[:xdigit:]]\\{4\\}'") 1 font-lock-string-face) - (,(rust-re-grab "'\\\\U[[:xdigit:]]\\{8\\}'") 1 font-lock-string-face) - - ;; CamelCase Means Type Or Constructor - (,(rust-re-grabword rust-re-CamelCase) 1 font-lock-type-face) - ) - - ;; Item definitions - (mapcar #'(lambda (x) - (list (rust-re-item-def (car x)) - 1 (cdr x))) - '(("enum" . font-lock-type-face) - ("struct" . font-lock-type-face) - ("type" . font-lock-type-face) - ("mod" . font-lock-type-face) - ("use" . font-lock-type-face) - ("fn" . font-lock-function-name-face) - ("static" . font-lock-constant-face))))) - -(defun rust-fill-prefix-for-comment-start (line-start) - "Determine what to use for `fill-prefix' based on what is at the beginning of a line." - (let ((result - ;; Replace /* with same number of spaces - (replace-regexp-in-string - "\\(?:/\\*+\\)[!*]" - (lambda (s) - ;; We want the * to line up with the first * of the comment start - (concat (make-string (- (length s) 2) ?\x20) "*")) - line-start))) - ;; Make sure we've got at least one space at the end - (if (not (= (aref result (- (length result) 1)) ?\x20)) - (setq result (concat result " "))) - result)) - -(defun rust-in-comment-paragraph (body) - ;; We might move the point to fill the next comment, but we don't want it - ;; seeming to jump around on the user - (save-excursion - ;; If we're outside of a comment, with only whitespace and then a comment - ;; in front, jump to the comment and prepare to fill it. - (when (not (nth 4 (syntax-ppss))) - (beginning-of-line) - (when (looking-at (concat "[[:space:]\n]*" comment-start-skip)) - (goto-char (match-end 0)))) - - ;; We need this when we're moving the point around and then checking syntax - ;; while doing paragraph fills, because the cache it uses isn't always - ;; invalidated during this. - (syntax-ppss-flush-cache 1) - ;; If we're at the beginning of a comment paragraph with nothing but - ;; whitespace til the next line, jump to the next line so that we use the - ;; existing prefix to figure out what the new prefix should be, rather than - ;; inferring it from the comment start. - (let ((next-bol (line-beginning-position 2))) - (while (save-excursion - (end-of-line) - (syntax-ppss-flush-cache 1) - (and (nth 4 (syntax-ppss)) - (save-excursion - (beginning-of-line) - (looking-at paragraph-start)) - (looking-at "[[:space:]]*$") - (nth 4 (syntax-ppss next-bol)))) - (goto-char next-bol))) - - (syntax-ppss-flush-cache 1) - ;; If we're on the last line of a multiline-style comment that started - ;; above, back up one line so we don't mistake the * of the */ that ends - ;; the comment for a prefix. - (when (save-excursion - (and (nth 4 (syntax-ppss (line-beginning-position 1))) - (looking-at "[[:space:]]*\\*/"))) - (goto-char (line-end-position 0))) - (funcall body))) - -(defun rust-with-comment-fill-prefix (body) - (let* - ((line-string (buffer-substring-no-properties - (line-beginning-position) (line-end-position))) - (line-comment-start - (when (nth 4 (syntax-ppss)) - (cond - ;; If we're inside the comment and see a * prefix, use it - ((string-match "^\\([[:space:]]*\\*+[[:space:]]*\\)" - line-string) - (match-string 1 line-string)) - ;; If we're at the start of a comment, figure out what prefix - ;; to use for the subsequent lines after it - ((string-match (concat "[[:space:]]*" comment-start-skip) line-string) - (rust-fill-prefix-for-comment-start - (match-string 0 line-string)))))) - (fill-prefix - (or line-comment-start - fill-prefix))) - (funcall body))) - -(defun rust-find-fill-prefix () - (rust-with-comment-fill-prefix (lambda () fill-prefix))) - -(defun rust-fill-paragraph (&rest args) - "Special wrapping for `fill-paragraph' to handle multi-line comments with a * prefix on each line." - (rust-in-comment-paragraph - (lambda () - (rust-with-comment-fill-prefix - (lambda () - (let - ((fill-paragraph-function - (if (not (eq fill-paragraph-function 'rust-fill-paragraph)) - fill-paragraph-function)) - (fill-paragraph-handle-comment t)) - (apply 'fill-paragraph args) - t)))))) - -(defun rust-do-auto-fill (&rest args) - "Special wrapping for `do-auto-fill' to handle multi-line comments with a * prefix on each line." - (rust-with-comment-fill-prefix - (lambda () - (apply 'do-auto-fill args) - t))) - -(defun rust-fill-forward-paragraph (arg) - ;; This is to work around some funny behavior when a paragraph separator is - ;; at the very top of the file and there is a fill prefix. - (let ((fill-prefix nil)) (forward-paragraph arg))) - -(defun rust-comment-indent-new-line (&optional arg) - (rust-with-comment-fill-prefix - (lambda () (comment-indent-new-line arg)))) - -;;; Imenu support -(defvar rust-imenu-generic-expression - (append (mapcar #'(lambda (x) - (list nil (rust-re-item-def x) 1)) - '("enum" "struct" "type" "mod" "fn" "trait")) - `(("Impl" ,(rust-re-item-def "impl") 1))) - "Value for `imenu-generic-expression' in Rust mode. - -Create a flat index of the item definitions in a Rust file. - -Imenu will show all the enums, structs, etc. at the same level. -Implementations will be shown under the `Impl` subheading. Use -idomenu (imenu with `ido-mode') for best mileage.") - -;;; Defun Motions - -;;; Start of a Rust item -(defvar rust-top-item-beg-re - (concat "^\\s-*\\(?:priv\\|pub\\)?\\s-*" - (regexp-opt - '("enum" "struct" "type" "mod" "use" "fn" "static" "impl" - "extern" "impl" "static" "trait")))) - -(defun rust-beginning-of-defun (&optional arg) - "Move backward to the beginning of the current defun. - -With ARG, move backward multiple defuns. Negative ARG means -move forward. - -This is written mainly to be used as `beginning-of-defun-function' for Rust. -Don't move to the beginning of the line. `beginning-of-defun', -which calls this, does that afterwards." - (interactive "p") - (re-search-backward (concat "^\\(" rust-top-item-beg-re "\\)\\_>") - nil 'move (or arg 1))) - -(defun rust-end-of-defun () - "Move forward to the next end of defun. - -With argument, do it that many times. -Negative argument -N means move back to Nth preceding end of defun. - -Assume that this is called after beginning-of-defun. So point is -at the beginning of the defun body. - -This is written mainly to be used as `end-of-defun-function' for Rust." - (interactive "p") - ;; Find the opening brace - (re-search-forward "[{]" nil t) - (goto-char (match-beginning 0)) - ;; Go to the closing brace - (forward-sexp)) - -;; For compatibility with Emacs < 24, derive conditionally -(defalias 'rust-parent-mode - (if (fboundp 'prog-mode) 'prog-mode 'fundamental-mode)) - - -;;;###autoload -(define-derived-mode rust-mode rust-parent-mode "Rust" - "Major mode for Rust code." - :group 'rust-mode - :syntax-table rust-mode-syntax-table - - ;; Indentation - (setq-local indent-line-function 'rust-mode-indent-line) - - ;; Fonts - (setq-local font-lock-defaults '(rust-mode-font-lock-keywords nil nil nil nil)) - - ;; Misc - (setq-local comment-start "// ") - (setq-local comment-end "") - (setq-local indent-tabs-mode nil) - - ;; Allow paragraph fills for comments - (setq-local comment-start-skip "\\(?://[/!]*\\|/\\*[*!]?\\)[[:space:]]*") - (setq-local paragraph-start - (concat "[[:space:]]*\\(?:" comment-start-skip "\\|\\*/?[[:space:]]*\\|\\)$")) - (setq-local paragraph-separate paragraph-start) - (setq-local normal-auto-fill-function 'rust-do-auto-fill) - (setq-local fill-paragraph-function 'rust-fill-paragraph) - (setq-local fill-forward-paragraph-function 'rust-fill-forward-paragraph) - (setq-local adaptive-fill-function 'rust-find-fill-prefix) - (setq-local comment-multi-line t) - (setq-local comment-line-break-function 'rust-comment-indent-new-line) - (setq-local imenu-generic-expression rust-imenu-generic-expression) - (setq-local beginning-of-defun-function 'rust-beginning-of-defun) - (setq-local end-of-defun-function 'rust-end-of-defun)) - -;;;###autoload -(add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-mode)) - -(defun rust-mode-reload () - (interactive) - (unload-feature 'rust-mode) - (require 'rust-mode) - (rust-mode)) - -;; Issue #6887: Rather than inheriting the 'gnu compilation error -;; regexp (which is broken on a few edge cases), add our own 'rust -;; compilation error regexp and use it instead. -(defvar rustc-compilation-regexps - (let ((file "\\([^\n]+\\)") - (start-line "\\([0-9]+\\)") - (start-col "\\([0-9]+\\)") - (end-line "\\([0-9]+\\)") - (end-col "\\([0-9]+\\)") - (error-or-warning "\\(?:[Ee]rror\\|\\([Ww]arning\\)\\)")) - (let ((re (concat "^" file ":" start-line ":" start-col - ": " end-line ":" end-col - " \\(?:[Ee]rror\\|\\([Ww]arning\\)\\):"))) - (cons re '(1 (2 . 4) (3 . 5) (6))))) - "Specifications for matching errors in rustc invocations. -See `compilation-error-regexp-alist for help on their format.") - -(eval-after-load 'compile - '(progn - (add-to-list 'compilation-error-regexp-alist-alist - (cons 'rustc rustc-compilation-regexps)) - (add-to-list 'compilation-error-regexp-alist 'rustc))) - -(provide 'rust-mode) - -;;; rust-mode.el ends here diff --git a/src/etc/gedit/readme.txt b/src/etc/gedit/readme.txt deleted file mode 100644 index e394f191608..00000000000 --- a/src/etc/gedit/readme.txt +++ /dev/null @@ -1,10 +0,0 @@ -Add syntax highlighting for Mozilla Rust in GtkSourceView (used by GEdit). - - -Instructions for Ubuntu Linux 12.04+ - -1) Close all instances of GEdit - -2) Copy the included "share" folder into "~/.local/" - -3) Open a shell in "~/.local/share/" and run "update-mime-database mime" diff --git a/src/etc/gedit/share/gtksourceview-3.0/language-specs/rust.lang b/src/etc/gedit/share/gtksourceview-3.0/language-specs/rust.lang deleted file mode 100644 index 8291b38a9bd..00000000000 --- a/src/etc/gedit/share/gtksourceview-3.0/language-specs/rust.lang +++ /dev/null @@ -1,340 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!-- Syntax highlighting for the under-development Mozilla Rust language --> - -<language id="rust" _name="Rust" version="2.0" _section="Sources"> - <metadata> - <property name="mimetypes">text/x-rust</property> - <property name="globs">*.rs</property> - <property name="line-comment-start">//</property> - <property name="block-comment-start">/*</property> - <property name="block-comment-end">*/</property> - </metadata> - - <styles> - <style id="comment" _name="Comment" map-to="def:comment"/> - <style id="string" _name="String" map-to="def:string"/> - <style id="char" _name="Character" map-to="def:character"/> - <style id="keyword" _name="Keyword" map-to="def:keyword"/> - <style id="type" _name="Data Type" map-to="def:type"/> - <style id="constant" _name="Constant" map-to="def:constant"/> - <style id="identifier" _name="Identifier" map-to="def:identifier"/> - <style id="number" _name="Number" map-to="def:number"/> - <style id="scope" _name="Scope" map-to="def:preprocessor"/> - <style id="attribute" _name="Attribute" map-to="def:preprocessor"/> - <style id="macro" _name="Macro" map-to="def:preprocessor"/> - </styles> - - <definitions> - - <context id="function" style-ref="keyword"> - <keyword>fn</keyword> - </context> - - <context id="type" style-ref="keyword"> - <keyword>type</keyword> - </context> - - <context id="keywords" style-ref="keyword"> - <keyword>as</keyword> - <keyword>assert</keyword> - <keyword>break</keyword> - <keyword>box</keyword> - <keyword>const</keyword> - <keyword>continue</keyword> - <keyword>crate</keyword> - <keyword>do</keyword> - <keyword>drop</keyword> - <keyword>else</keyword> - <keyword>enum</keyword> - <keyword>export</keyword> - <keyword>extern</keyword> - <keyword>fail</keyword> - <keyword>for</keyword> - <keyword>if</keyword> - <keyword>impl</keyword> - <keyword>in</keyword> - <keyword>let</keyword> - <keyword>log</keyword> - <keyword>loop</keyword> - <keyword>match</keyword> - <keyword>mod</keyword> - <keyword>move</keyword> - <keyword>mut</keyword> - <keyword>priv</keyword> - <keyword>pub</keyword> - <keyword>pure</keyword> - <keyword>ref</keyword> - <keyword>return</keyword> - <keyword>static</keyword> - <keyword>struct</keyword> - <keyword>trait</keyword> - <keyword>unsafe</keyword> - <keyword>use</keyword> - <keyword>virtual</keyword> - <keyword>where</keyword> - <keyword>while</keyword> - </context> - - <context id="types" style-ref="type"> - <keyword>bool</keyword> - <keyword>int</keyword> - <keyword>isize</keyword> - <keyword>uint</keyword> - <keyword>usize</keyword> - <keyword>i8</keyword> - <keyword>i16</keyword> - <keyword>i32</keyword> - <keyword>i64</keyword> - <keyword>u8</keyword> - <keyword>u16</keyword> - <keyword>u32</keyword> - <keyword>u64</keyword> - <keyword>f32</keyword> - <keyword>f64</keyword> - <keyword>char</keyword> - <keyword>str</keyword> - <keyword>Option</keyword> - <keyword>Result</keyword> - </context> - - <context id="ctypes" style-ref="type"> - <keyword>c_float</keyword> - <keyword>c_double</keyword> - <keyword>c_void</keyword> - <keyword>FILE</keyword> - <keyword>fpos_t</keyword> - <keyword>DIR</keyword> - <keyword>dirent</keyword> - <keyword>c_char</keyword> - <keyword>c_schar</keyword> - <keyword>c_uchar</keyword> - <keyword>c_short</keyword> - <keyword>c_ushort</keyword> - <keyword>c_int</keyword> - <keyword>c_uint</keyword> - <keyword>c_long</keyword> - <keyword>c_ulong</keyword> - <keyword>size_t</keyword> - <keyword>ptrdiff_t</keyword> - <keyword>clock_t</keyword> - <keyword>time_t</keyword> - <keyword>c_longlong</keyword> - <keyword>c_ulonglong</keyword> - <keyword>intptr_t</keyword> - <keyword>uintptr_t</keyword> - <keyword>off_t</keyword> - <keyword>dev_t</keyword> - <keyword>ino_t</keyword> - <keyword>pid_t</keyword> - <keyword>mode_t</keyword> - <keyword>ssize_t</keyword> - </context> - - <context id="self" style-ref="identifier"> - <keyword>self</keyword> - </context> - - <context id="constants" style-ref="constant"> - <keyword>true</keyword> - <keyword>false</keyword> - <keyword>Some</keyword> - <keyword>None</keyword> - <keyword>Ok</keyword> - <keyword>Err</keyword> - <keyword>Success</keyword> - <keyword>Failure</keyword> - <keyword>Cons</keyword> - <keyword>Nil</keyword> - </context> - - <context id="cconstants" style-ref="constant"> - <keyword>EXIT_FAILURE</keyword> - <keyword>EXIT_SUCCESS</keyword> - <keyword>RAND_MAX</keyword> - <keyword>EOF</keyword> - <keyword>SEEK_SET</keyword> - <keyword>SEEK_CUR</keyword> - <keyword>SEEK_END</keyword> - <keyword>_IOFBF</keyword> - <keyword>_IONBF</keyword> - <keyword>_IOLBF</keyword> - <keyword>BUFSIZ</keyword> - <keyword>FOPEN_MAX</keyword> - <keyword>FILENAME_MAX</keyword> - <keyword>L_tmpnam</keyword> - <keyword>TMP_MAX</keyword> - <keyword>O_RDONLY</keyword> - <keyword>O_WRONLY</keyword> - <keyword>O_RDWR</keyword> - <keyword>O_APPEND</keyword> - <keyword>O_CREAT</keyword> - <keyword>O_EXCL</keyword> - <keyword>O_TRUNC</keyword> - <keyword>S_IFIFO</keyword> - <keyword>S_IFCHR</keyword> - <keyword>S_IFBLK</keyword> - <keyword>S_IFDIR</keyword> - <keyword>S_IFREG</keyword> - <keyword>S_IFMT</keyword> - <keyword>S_IEXEC</keyword> - <keyword>S_IWRITE</keyword> - <keyword>S_IREAD</keyword> - <keyword>S_IRWXU</keyword> - <keyword>S_IXUSR</keyword> - <keyword>S_IWUSR</keyword> - <keyword>S_IRUSR</keyword> - <keyword>F_OK</keyword> - <keyword>R_OK</keyword> - <keyword>W_OK</keyword> - <keyword>X_OK</keyword> - <keyword>STDIN_FILENO</keyword> - <keyword>STDOUT_FILENO</keyword> - <keyword>STDERR_FILENO</keyword> - </context> - - <context id="line-comment" style-ref="comment" end-at-line-end="true" class="comment" class-disabled="no-spell-check"> - <start>//</start> - <include> - <context ref="def:in-line-comment"/> - </include> - </context> - - <context id="block-comment" style-ref="comment" class="comment" class-disabled="no-spell-check"> - <start>/\*</start> - <end>\*/</end> - <include> - <context ref="def:in-comment"/> - </include> - </context> - - <define-regex id="int_suffix" extended="true"> - (i8|i16|i32|i64|i|u8|u16|u32|u64|u) - </define-regex> - - <define-regex id="exponent" extended="true"> - ([eE][+-]?[0-9_]+) - </define-regex> - - <define-regex id="float_suffix" extended="true"> - (\%{exponent}?(f32|f64)?)|(\.[0-9][0-9_]*\%{exponent}?)?(f32|f64)?|\. - </define-regex> - - <define-regex id="num_suffix" extended="true"> - \%{int_suffix}|\%{float_suffix} - </define-regex> - - <define-regex id="hex_digit" extended="true"> - [0-9a-fA-F] - </define-regex> - - <define-regex id="oct_digit" extended="true"> - [0-7] - </define-regex> - - <context id="number" style-ref="number"> - <match extended="true"> - ((?<=\.\.)|(?<![\w\.])) - ( - [1-9][0-9_]*\%{num_suffix}?| - 0[0-9_]*\%{num_suffix}?| - 0b[01_]+\%{int_suffix}?| - 0o(\%{oct_digit}|_)+\%{int_suffix}?| - 0x(\%{hex_digit}|_)+\%{int_suffix}? - ) - ((?![\w\.].)|(?=\.\.)) - </match> - </context> - - <define-regex id="ident" extended="true"> - ([^[:cntrl:][:space:][:punct:][:digit:]]|_)([^[:cntrl:][:punct:][:space:]]|_)* - </define-regex> - - <context id="scope" style-ref="scope"> - <match extended="true"> - \%{ident}:: - </match> - </context> - - <context id="macro" style-ref="macro"> - <match extended="true"> - \%{ident}! - </match> - </context> - - <context id="lifetime" style-ref="keyword"> - <match extended="true"> - '\%{ident} - </match> - </context> - - <define-regex id="common_escape" extended="true"> - '|"| - \\|n|r|t|0| - x\%{hex_digit}{2}| - u{\%{hex_digit}{1,6}}| - u\%{hex_digit}{4}| - U\%{hex_digit}{8} - </define-regex> - - <context id="string_escape" style-ref="def:special-char"> - <match>\\\%{common_escape}</match> - </context> - - <context id="raw-string" style-ref="string" class="string" class-disabled="no-spell-check"> - <start>r(#*)"</start> - <end>"\%{1@start}</end> - <include> - <context ref="def:line-continue"/> - </include> - </context> - - <context id="string" style-ref="string" class="string" class-disabled="no-spell-check"> - <start>"</start> - <end>"</end> - <include> - <context ref="string_escape"/> - <context ref="def:line-continue"/> - </include> - </context> - - <context id="char" style-ref="char"> - <match extended="true">'([^\\']|\\\%{common_escape})'</match> - </context> - - <context id="attribute" style-ref="attribute" class="attribute"> - <start extended="true">\#!?\[</start> - <end>\]</end> - <include> - <context ref="def:in-comment"/> - <context ref="string"/> - <context ref="raw-string"/> - </include> - </context> - - <context id="rust" class="no-spell-check"> - <include> - <context ref="function"/> - <context ref="type"/> - <context ref="keywords"/> - <context ref="types"/> - <context ref="ctypes"/> - <context ref="self"/> - <context ref="macro"/> - <context ref="constants"/> - <context ref="cconstants"/> - <context ref="line-comment"/> - <context ref="block-comment"/> - <context ref="number"/> - <context ref="scope"/> - <context ref="string"/> - <context ref="raw-string"/> - <context ref="char"/> - <context ref="lifetime"/> - <context ref="attribute"/> - </include> - </context> - - </definitions> - -</language> diff --git a/src/etc/gedit/share/mime/packages/rust.xml b/src/etc/gedit/share/mime/packages/rust.xml deleted file mode 100644 index ede1c14907c..00000000000 --- a/src/etc/gedit/share/mime/packages/rust.xml +++ /dev/null @@ -1,6 +0,0 @@ -<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'> - <mime-type type="text/x-rust"> - <comment>Rust Source</comment> - <glob pattern="*.rs"/> - </mime-type> -</mime-info> diff --git a/src/etc/kate/rust.xml b/src/etc/kate/rust.xml deleted file mode 100644 index 3ceec0f250a..00000000000 --- a/src/etc/kate/rust.xml +++ /dev/null @@ -1,304 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE language SYSTEM "language.dtd" -[ - <!-- FIXME: Kate's regex engine has very limited support for - predefined char classes, so making rustIdent consistent with actual - Rust identifiers will be a bit difficult --> - <!ENTITY rustIdent "[a-zA-Z_][a-zA-Z_0-9]*"> - <!ENTITY rustIntSuf "([iu](8|16|32|64)?)?"> -]> -<language name="Rust" version="1.0.0" kateversion="2.4" section="Sources" extensions="*.rs" mimetype="text/x-rust" priority="15"> -<highlighting> - <list name="fn"> - <item> fn </item> - </list> - <list name="type"> - <item> type </item> - </list> - <list name="reserved"> - <item> abstract </item> - <item> alignof </item> - <item> be </item> - <item> do </item> - <item> final </item> - <item> offsetof </item> - <item> override </item> - <item> priv </item> - <item> pure </item> - <item> sizeof </item> - <item> typeof </item> - <item> unsized </item> - <item> yield </item> - </list> - <list name="keywords"> - <item> as </item> - <item> box </item> - <item> break </item> - <item> const </item> - <item> continue </item> - <item> crate </item> - <item> else </item> - <item> enum </item> - <item> extern </item> - <item> for </item> - <item> if </item> - <item> impl </item> - <item> in </item> - <item> let </item> - <item> loop </item> - <item> match </item> - <item> mod </item> - <item> move </item> - <item> mut </item> - <item> pub </item> - <item> ref </item> - <item> return </item> - <item> static </item> - <item> struct </item> - <item> super </item> - <item> trait </item> - <item> unsafe </item> - <item> use </item> - <item> virtual </item> - <item> where </item> - <item> while </item> - </list> - <list name="traits"> - <item> Const </item> - <item> Copy </item> - <item> Send </item> - <item> Owned </item> - <item> Sized </item> - <item> Eq </item> - <item> Ord </item> - <item> Num </item> - <item> Ptr </item> - <item> Drop </item> - <item> Add </item> - <item> Sub </item> - <item> Mul </item> - <item> Quot </item> - <item> Rem </item> - <item> Neg </item> - <item> BitAnd </item> - <item> BitOr </item> - <item> BitXor </item> - <item> Shl </item> - <item> Shr </item> - <item> Index </item> - <item> Not </item> - </list> - <list name="types"> - <item> bool </item> - <item> int </item> - <item> isize </item> - <item> uint </item> - <item> usize </item> - <item> i8 </item> - <item> i16 </item> - <item> i32 </item> - <item> i64 </item> - <item> u8 </item> - <item> u16 </item> - <item> u32 </item> - <item> u64 </item> - <item> f32 </item> - <item> f64 </item> - <item> float </item> - <item> char </item> - <item> str </item> - <item> Option </item> - <item> Result </item> - <item> Self </item> - </list> - <list name="ctypes"> - <item> c_float </item> - <item> c_double </item> - <item> c_void </item> - <item> FILE </item> - <item> fpos_t </item> - <item> DIR </item> - <item> dirent </item> - <item> c_char </item> - <item> c_schar </item> - <item> c_uchar </item> - <item> c_short </item> - <item> c_ushort </item> - <item> c_int </item> - <item> c_uint </item> - <item> c_long </item> - <item> c_ulong </item> - <item> size_t </item> - <item> ptrdiff_t </item> - <item> clock_t </item> - <item> time_t </item> - <item> c_longlong </item> - <item> c_ulonglong </item> - <item> intptr_t </item> - <item> uintptr_t </item> - <item> off_t </item> - <item> dev_t </item> - <item> ino_t </item> - <item> pid_t </item> - <item> mode_t </item> - <item> ssize_t </item> - </list> - <list name="self"> - <item> self </item> - </list> - <list name="constants"> - <item> true </item> - <item> false </item> - <item> Some </item> - <item> None </item> - <item> Ok </item> - <item> Err </item> - <item> Success </item> - <item> Failure </item> - <item> Cons </item> - <item> Nil </item> - </list> - <list name="cconstants"> - <item> EXIT_FAILURE </item> - <item> EXIT_SUCCESS </item> - <item> RAND_MAX </item> - <item> EOF </item> - <item> SEEK_SET </item> - <item> SEEK_CUR </item> - <item> SEEK_END </item> - <item> _IOFBF </item> - <item> _IONBF </item> - <item> _IOLBF </item> - <item> BUFSIZ </item> - <item> FOPEN_MAX </item> - <item> FILENAME_MAX </item> - <item> L_tmpnam </item> - <item> TMP_MAX </item> - <item> O_RDONLY </item> - <item> O_WRONLY </item> - <item> O_RDWR </item> - <item> O_APPEND </item> - <item> O_CREAT </item> - <item> O_EXCL </item> - <item> O_TRUNC </item> - <item> S_IFIFO </item> - <item> S_IFCHR </item> - <item> S_IFBLK </item> - <item> S_IFDIR </item> - <item> S_IFREG </item> - <item> S_IFMT </item> - <item> S_IEXEC </item> - <item> S_IWRITE </item> - <item> S_IREAD </item> - <item> S_IRWXU </item> - <item> S_IXUSR </item> - <item> S_IWUSR </item> - <item> S_IRUSR </item> - <item> F_OK </item> - <item> R_OK </item> - <item> W_OK </item> - <item> X_OK </item> - <item> STDIN_FILENO </item> - <item> STDOUT_FILENO </item> - <item> STDERR_FILENO </item> - </list> - <contexts> - <context attribute="Normal Text" lineEndContext="#stay" name="Normal"> - <DetectSpaces/> - <keyword String="fn" attribute="Keyword" context="Function"/> - <keyword String="type" attribute="Keyword" context="Type"/> - <keyword String="reserved" attribute="Keyword" context="#stay"/> - <keyword String="keywords" attribute="Keyword" context="#stay"/> - <keyword String="types" attribute="Type" context="#stay"/> - <keyword String="traits" attribute="Trait" context="#stay"/> - <keyword String="ctypes" attribute="CType" context="#stay"/> - <keyword String="self" attribute="Self" context="#stay"/> - <keyword String="constants" attribute="Constant" context="#stay"/> - <keyword String="cconstants" attribute="CConstant" context="#stay"/> - <Detect2Chars char="/" char1="/" attribute="Comment" context="Commentar 1"/> - <Detect2Chars char="/" char1="*" attribute="Comment" context="Commentar 2" beginRegion="Comment"/> - <RegExpr String="0x[0-9a-fA-F_]+&rustIntSuf;" attribute="Number" context="#stay"/> - <RegExpr String="0o[0-7_]+&rustIntSuf;" attribute="Number" context="#stay"/> - <RegExpr String="0b[0-1_]+&rustIntSuf;" attribute="Number" context="#stay"/> - <RegExpr String="[0-9][0-9_]*\.[0-9_]*([eE][+-]?[0-9_]+)?(f32|f64|f)?" attribute="Number" context="#stay"/> - <RegExpr String="[0-9][0-9_]*&rustIntSuf;" attribute="Number" context="#stay"/> - <Detect2Chars char="#" char1="[" attribute="Attribute" context="Attribute" beginRegion="Attribute"/> - <StringDetect String="#![" attribute="Attribute" context="Attribute" beginRegion="Attribute"/> - <RegExpr String="&rustIdent;::" attribute="Scope"/> - <RegExpr String="&rustIdent;!" attribute="Macro"/> - <RegExpr String="'&rustIdent;(?!')" attribute="Lifetime"/> - <DetectChar char="{" attribute="Symbol" context="#stay" beginRegion="Brace" /> - <DetectChar char="}" attribute="Symbol" context="#stay" endRegion="Brace" /> - <DetectChar char=""" attribute="String" context="String"/> - <DetectChar char="'" attribute="Character" context="Character"/> - <DetectChar char="[" attribute="Symbol" context="#stay" beginRegion="Bracket" /> - <DetectChar char="]" attribute="Symbol" context="#stay" endRegion="Bracket" /> - <DetectIdentifier/> - </context> - <context attribute="Attribute" lineEndContext="#stay" name="Attribute"> - <DetectChar char="]" attribute="Attribute" context="#pop" endRegion="Attribute"/> - <IncludeRules context="Normal"/> - </context> - <context attribute="Definition" lineEndContext="#stay" name="Function"> - <DetectSpaces/> - <DetectChar char="(" attribute="Normal Text" context="#pop"/> - <DetectChar char="<" attribute="Normal Text" context="#pop"/> - </context> - <context attribute="Definition" lineEndContext="#stay" name="Type"> - <DetectSpaces/> - <DetectChar char="=" attribute="Normal Text" context="#pop"/> - <DetectChar char="<" attribute="Normal Text" context="#pop"/> - </context> - <context attribute="String" lineEndContext="#pop" name="String"> - <LineContinue attribute="String" context="#stay"/> - <DetectChar char="\" attribute="CharEscape" context="CharEscape"/> - <DetectChar attribute="String" context="#pop" char="""/> - </context> - <context attribute="Character" lineEndContext="#pop" name="Character"> - <DetectChar char="\" attribute="CharEscape" context="CharEscape"/> - <DetectChar attribute="Character" context="#pop" char="'"/> - </context> - <context attribute="CharEscape" lineEndContext="#pop" name="CharEscape"> - <AnyChar String="nrt\'"" attribute="CharEscape" context="#pop"/> - <RegExpr String="x[0-9a-fA-F]{2}" attribute="CharEscape" context="#pop"/> - <RegExpr String="u\{[0-9a-fA-F]{1,6}\}" attribute="CharEscape" context="#pop"/> - <RegExpr String="u[0-9a-fA-F]{4}" attribute="CharEscape" context="#pop"/> - <RegExpr String="U[0-9a-fA-F]{8}" attribute="CharEscape" context="#pop"/> - <RegExpr String="." attribute="Error" context="#pop"/> - </context> - <context attribute="Comment" lineEndContext="#pop" name="Commentar 1"/> - <context attribute="Comment" lineEndContext="#stay" name="Commentar 2"> - <DetectSpaces/> - <Detect2Chars char="*" char1="/" attribute="Comment" context="#pop" endRegion="Comment"/> - </context> - </contexts> - <itemDatas> - <itemData name="Normal Text" defStyleNum="dsNormal"/> - <itemData name="Keyword" defStyleNum="dsKeyword" color="#770088" bold="1"/> - <itemData name="Self" defStyleNum="dsKeyword" color="#FF0000" bold="1"/> - <itemData name="Type" defStyleNum="dsKeyword" color="#4e9a06" bold="1"/> - <itemData name="Trait" defStyleNum="dsKeyword" color="#4e9a06" bold="1"/> - <itemData name="CType" defStyleNum="dsNormal" color="#4e9a06"/> - <itemData name="Constant" defStyleNum="dsKeyword" color="#116644"/> - <itemData name="CConstant" defStyleNum="dsNormal" color="#116644"/> - <itemData name="Definition" defStyleNum="dsNormal" color="#0000FF"/> - <itemData name="Comment" defStyleNum="dsComment" color="#AA5500"/> - <itemData name="Scope" defStyleNum="dsNormal" color="#0055AA"/> - <itemData name="Number" defStyleNum="dsDecVal" color="#116644"/> - <itemData name="String" defStyleNum="dsString" color="#FF0000"/> - <itemData name="CharEscape" defStyleNum="dsChar" color="#FF0000" bold="1"/> - <itemData name="Character" defStyleNum="dsChar" color="#FF0000"/> - <itemData name="Macro" defStyleNum="dsOthers"/> - <itemData name="Attribute" defStyleNum="dsOthers"/> - <itemData name="Lifetime" defStyleNum="dsOthers" bold="1"/> - <itemData name="Error" defStyleNum="dsError"/> - </itemDatas> -</highlighting> -<general> - <comments> - <comment name="singleLine" start="//" /> - <comment name="multiLine" start="/*" end="*/" region="Comment"/> - </comments> - <keywords casesensitive="1" /> -</general> -</language> diff --git a/src/etc/nano/rust.nanorc b/src/etc/nano/rust.nanorc deleted file mode 100644 index 1217769096d..00000000000 --- a/src/etc/nano/rust.nanorc +++ /dev/null @@ -1,35 +0,0 @@ -# Nano configuration for Rust -# Copyright 2015 The Rust Project Developers. -# -# NOTE: Rules are applied in order: later rules re-colorize matching text. -syntax "rust" "\.rs" - -# function definition -color magenta "fn [a-z0-9_]+" - -# Reserved words -color yellow "\<(abstract|alignof|as|be|box|break|const|continue|crate|do|else|enum|extern|false|final|fn|for|if|impl|in|let|loop|macro|match|mod|move|mut|offsetof|override|priv|pub|pure|ref|return|sizeof|static|self|struct|super|true|trait|type|typeof|unsafe|unsized|use|virtual|where|while|yield)\>" - -# macros -color red "[a-z_]+!" - -# Constants -color magenta "[A-Z][A-Z_]+" - -# Traits/Enums/Structs/Types/etc. -color magenta "[A-Z][a-z]+" - -# Strings -color green "\".*\"" -color green start="\".*\\$" end=".*\"" -# NOTE: This isn't accurate but matching "#{0,} for the end of the string is too liberal -color green start="r#+\"" end="\"#+" - -# Comments -color blue "//.*" - -# Attributes -color magenta start="#!\[" end="\]" - -# Some common markers -color brightcyan "(XXX|TODO|FIXME|\?\?\?)" diff --git a/src/etc/vim/after/syntax/rust.vim b/src/etc/vim/after/syntax/rust.vim deleted file mode 100644 index 735c1e153a6..00000000000 --- a/src/etc/vim/after/syntax/rust.vim +++ /dev/null @@ -1,31 +0,0 @@ -if !exists('g:rust_conceal') || !has('conceal') || &enc != 'utf-8' - finish -endif - -" For those who don't want to see `::`... -if exists('g:rust_conceal_mod_path') - syn match rustNiceOperator "::" conceal cchar=ㆍ -endif - -syn match rustRightArrowHead contained ">" conceal cchar= -syn match rustRightArrowTail contained "-" conceal cchar=⟶ -syn match rustNiceOperator "->" contains=rustRightArrowHead,rustRightArrowTail - -syn match rustFatRightArrowHead contained ">" conceal cchar= -syn match rustFatRightArrowTail contained "=" conceal cchar=⟹ -syn match rustNiceOperator "=>" contains=rustFatRightArrowHead,rustFatRightArrowTail - -syn match rustNiceOperator /\<\@!_\(_*\>\)\@=/ conceal cchar=′ - -" For those who don't want to see `pub`... -if exists('g:rust_conceal_pub') - syn match rustPublicSigil contained "pu" conceal cchar=* - syn match rustPublicRest contained "b" conceal cchar= - syn match rustNiceOperator "pub " contains=rustPublicSigil,rustPublicRest -endif - -hi link rustNiceOperator Operator - -if !exists('g:rust_conceal_mod_path') - hi! link Conceal Operator -endif diff --git a/src/etc/vim/autoload/rust.vim b/src/etc/vim/autoload/rust.vim deleted file mode 100644 index fe8e743e782..00000000000 --- a/src/etc/vim/autoload/rust.vim +++ /dev/null @@ -1,225 +0,0 @@ -" Author: Kevin Ballard -" Description: Helper functions for Rust commands/mappings -" Last Modified: May 27, 2014 - -" Jump {{{1 - -function! rust#Jump(mode, function) range - let cnt = v:count1 - normal! m' - if a:mode ==# 'v' - norm! gv - endif - let foldenable = &foldenable - set nofoldenable - while cnt > 0 - execute "call <SID>Jump_" . a:function . "()" - let cnt = cnt - 1 - endwhile - let &foldenable = foldenable -endfunction - -function! s:Jump_Back() - call search('{', 'b') - keepjumps normal! w99[{ -endfunction - -function! s:Jump_Forward() - normal! j0 - call search('{', 'b') - keepjumps normal! w99[{% - call search('{') -endfunction - -" Run {{{1 - -function! rust#Run(bang, args) - if a:bang - let idx = index(a:args, '--') - if idx != -1 - let rustc_args = idx == 0 ? [] : a:args[:idx-1] - let args = a:args[idx+1:] - else - let rustc_args = a:args - let args = [] - endif - else - let rustc_args = [] - let args = a:args - endif - - let b:rust_last_rustc_args = rustc_args - let b:rust_last_args = args - - call s:WithPath(function("s:Run"), rustc_args, args) -endfunction - -function! s:Run(path, rustc_args, args) - try - let exepath = tempname() - if has('win32') - let exepath .= '.exe' - endif - - let rustc_args = [a:path, '-o', exepath] + a:rustc_args - - let rustc = exists("g:rustc_path") ? g:rustc_path : "rustc" - - let output = system(shellescape(rustc) . " " . join(map(rustc_args, 'shellescape(v:val)'))) - if output != '' - echohl WarningMsg - echo output - echohl None - endif - if !v:shell_error - exe '!' . shellescape(exepath) . " " . join(map(a:args, 'shellescape(v:val)')) - endif - finally - if exists("exepath") - silent! call delete(exepath) - endif - endtry -endfunction - -" Expand {{{1 - -function! rust#Expand(bang, args) - if a:bang && !empty(a:args) - let pretty = a:args[0] - let args = a:args[1:] - else - let pretty = "expanded" - let args = a:args - endif - call s:WithPath(function("s:Expand"), pretty, args) -endfunction - -function! s:Expand(path, pretty, args) - try - let rustc = exists("g:rustc_path") ? g:rustc_path : "rustc" - - let args = [a:path, '--pretty', a:pretty] + a:args - let output = system(shellescape(rustc) . " " . join(map(args, "shellescape(v:val)"))) - if v:shell_error - echohl WarningMsg - echo output - echohl None - else - new - silent put =output - 1 - d - setl filetype=rust - setl buftype=nofile - setl bufhidden=hide - setl noswapfile - endif - endtry -endfunction - -function! rust#CompleteExpand(lead, line, pos) - if a:line[: a:pos-1] =~ '^RustExpand!\s*\S*$' - " first argument and it has a ! - let list = ["normal", "expanded", "typed", "expanded,identified", "flowgraph="] - if !empty(a:lead) - call filter(list, "v:val[:len(a:lead)-1] == a:lead") - endif - return list - endif - - return glob(escape(a:lead, "*?[") . '*', 0, 1) -endfunction - -" Emit {{{1 - -function! rust#Emit(type, args) - call s:WithPath(function("s:Emit"), a:type, a:args) -endfunction - -function! s:Emit(path, type, args) - try - let rustc = exists("g:rustc_path") ? g:rustc_path : "rustc" - - let args = [a:path, '--emit', a:type, '-o', '-'] + a:args - let output = system(shellescape(rustc) . " " . join(map(args, "shellescape(v:val)"))) - if v:shell_error - echohl WarningMsg - echo output - echohl None - else - new - silent put =output - 1 - d - if a:type == "ir" - setl filetype=llvm - elseif a:type == "asm" - setl filetype=asm - endif - setl buftype=nofile - setl bufhidden=hide - setl noswapfile - endif - endtry -endfunction - -" Utility functions {{{1 - -function! s:WithPath(func, ...) - try - let save_write = &write - set write - let path = expand('%') - let pathisempty = empty(path) - if pathisempty || !save_write - " use a temporary file named 'unnamed.rs' inside a temporary - " directory. This produces better error messages - let tmpdir = tempname() - call mkdir(tmpdir) - - let save_cwd = getcwd() - silent exe 'lcd' fnameescape(tmpdir) - - let path = 'unnamed.rs' - - let save_mod = &mod - set nomod - - silent exe 'keepalt write! ' . fnameescape(path) - if pathisempty - silent keepalt 0file - endif - else - update - endif - - call call(a:func, [path] + a:000) - finally - if exists("save_mod") | let &mod = save_mod | endif - if exists("save_write") | let &write = save_write | endif - if exists("save_cwd") | silent exe 'lcd' fnameescape(save_cwd) | endif - if exists("tmpdir") | silent call s:RmDir(tmpdir) | endif - endtry -endfunction - -function! rust#AppendCmdLine(text) - call setcmdpos(getcmdpos()) - let cmd = getcmdline() . a:text - return cmd -endfunction - -function! s:RmDir(path) - " sanity check; make sure it's not empty, /, or $HOME - if empty(a:path) - echoerr 'Attempted to delete empty path' - return 0 - elseif a:path == '/' || a:path == $HOME - echoerr 'Attempted to delete protected path: ' . a:path - return 0 - endif - silent exe "!rm -rf " . shellescape(a:path) -endfunction - -" }}}1 - -" vim: set noet sw=4 ts=4: diff --git a/src/etc/vim/compiler/cargo.vim b/src/etc/vim/compiler/cargo.vim deleted file mode 100644 index ed487a308e1..00000000000 --- a/src/etc/vim/compiler/cargo.vim +++ /dev/null @@ -1,65 +0,0 @@ -" Vim compiler file -" Compiler: Cargo Compiler -" Maintainer: Damien Radtke <damienradtke@gmail.com> -" Latest Revision: 2014 Sep 24 - -if exists('current_compiler') - finish -endif -runtime compiler/rustc.vim -let current_compiler = "cargo" - -if exists(':CompilerSet') != 2 - command -nargs=* CompilerSet setlocal <args> -endif - -if exists('g:cargo_makeprg_params') - execute 'CompilerSet makeprg=cargo\ '.escape(g:cargo_makeprg_params, ' \|"').'\ $*' -else - CompilerSet makeprg=cargo\ $* -endif - -" Allow a configurable global Cargo.toml name. This makes it easy to -" support variations like 'cargo.toml'. -let s:cargo_manifest_name = get(g:, 'cargo_manifest_name', 'Cargo.toml') - -function! s:is_absolute(path) - return a:path[0] == '/' || a:path =~ '[A-Z]\+:' -endfunction - -let s:local_manifest = findfile(s:cargo_manifest_name, '.;') -if s:local_manifest != '' - let s:local_manifest = fnamemodify(s:local_manifest, ':p:h').'/' - augroup cargo - au! - au QuickfixCmdPost make call s:FixPaths() - augroup END - - " FixPaths() is run after Cargo, and is used to change the file paths - " to be relative to the current directory instead of Cargo.toml. - function! s:FixPaths() - let qflist = getqflist() - let manifest = s:local_manifest - for qf in qflist - if !qf.valid - let m = matchlist(qf.text, '(file://\(.*\))$') - if !empty(m) - let manifest = m[1].'/' - " Manually strip another slash if needed; usually just an - " issue on Windows. - if manifest =~ '^/[A-Z]\+:/' - let manifest = manifest[1:] - endif - endif - continue - endif - let filename = bufname(qf.bufnr) - if s:is_absolute(filename) - continue - endif - let qf.filename = simplify(manifest.filename) - call remove(qf, 'bufnr') - endfor - call setqflist(qflist, 'r') - endfunction -endif diff --git a/src/etc/vim/compiler/rustc.vim b/src/etc/vim/compiler/rustc.vim deleted file mode 100644 index f9b854ed049..00000000000 --- a/src/etc/vim/compiler/rustc.vim +++ /dev/null @@ -1,33 +0,0 @@ -" Vim compiler file -" Compiler: Rust Compiler -" Maintainer: Chris Morgan <me@chrismorgan.info> -" Latest Revision: 2013 Jul 12 - -if exists("current_compiler") - finish -endif -let current_compiler = "rustc" - -let s:cpo_save = &cpo -set cpo&vim - -if exists(":CompilerSet") != 2 - command -nargs=* CompilerSet setlocal <args> -endif - -if exists("g:rustc_makeprg_no_percent") && g:rustc_makeprg_no_percent == 1 - CompilerSet makeprg=rustc -else - CompilerSet makeprg=rustc\ \% -endif - -CompilerSet errorformat= - \%f:%l:%c:\ %t%*[^:]:\ %m, - \%f:%l:%c:\ %*\\d:%*\\d\ %t%*[^:]:\ %m, - \%-G%f:%l\ %s, - \%-G%*[\ ]^, - \%-G%*[\ ]^%*[~], - \%-G%*[\ ]... - -let &cpo = s:cpo_save -unlet s:cpo_save diff --git a/src/etc/vim/doc/rust.txt b/src/etc/vim/doc/rust.txt deleted file mode 100644 index e117b0c155b..00000000000 --- a/src/etc/vim/doc/rust.txt +++ /dev/null @@ -1,178 +0,0 @@ -*rust.txt* Filetype plugin for Rust - -============================================================================== -CONTENTS *rust* *ft-rust* - -1. Introduction |rust-intro| -2. Settings |rust-settings| -3. Commands |rust-commands| -4. Mappings |rust-mappings| - -============================================================================== -INTRODUCTION *rust-intro* - -This plugin provides syntax and supporting functionality for the Rust -filetype. - -============================================================================== -SETTINGS *rust-settings* - -This plugin has a few variables you can define in your vimrc that change the -behavior of the plugin. - - *g:rustc_path* -g:rustc_path~ - Set this option to the path to rustc for use in the |:RustRun| and - |:RustExpand| commands. If unset, "rustc" will be located in $PATH: > - let g:rustc_path = $HOME."/bin/rustc" -< - - *g:rustc_makeprg_no_percent* -g:rustc_makeprg_no_percent~ - Set this option to 1 to have 'makeprg' default to "rustc" instead of - "rustc %": > - let g:rustc_makeprg_no_percent = 1 -< - - *g:rust_conceal* -g:rust_conceal~ - Set this option to turn on the basic |conceal| support: > - let g:rust_conceal = 1 -< - - *g:rust_conceal_mod_path* -g:rust_conceal_mod_path~ - Set this option to turn on |conceal| for the path connecting token - "::": > - let g:rust_conceal_mod_path = 1 -< - - *g:rust_conceal_pub* -g:rust_conceal_pub~ - Set this option to turn on |conceal| for the "pub" token: > - let g:rust_conceal_pub = 1 -< - - *g:rust_recommended_style* -g:rust_recommended_style~ - Set this option to enable vim indentation and textwidth settings to - conform to style conventions of the rust standard library (i.e. use 4 - spaces for indents and sets 'textwidth' to 99). This option is enabled - by default. To disable it: > - let g:rust_recommended_style = 0 -< - - *g:rust_fold* -g:rust_fold~ - Set this option to turn on |folding|: > - let g:rust_fold = 1 -< - Value Effect ~ - 0 No folding - 1 Braced blocks are folded. All folds are open by - default. - 2 Braced blocks are folded. 'foldlevel' is left at the - global value (all folds are closed by default). - - *g:rust_bang_comment_leader* -g:rust_bang_comment_leader~ - Set this option to 1 to preserve the leader on multi-line doc comments - using the /*! syntax: > - let g:rust_bang_comment_leader = 1 -< - - *g:ftplugin_rust_source_path* -g:ftplugin_rust_source_path~ - Set this option to a path that should be prepended to 'path' for Rust - source files: > - let g:ftplugin_rust_source_path = $HOME.'/dev/rust' -< - - *g:cargo_manifest_name* -g:cargo_manifest_name~ - Set this option to the name of the manifest file for your projects. If - not specified it defaults to 'Cargo.toml' : > - let g:cargo_manifest_name = 'Cargo.toml' -< - -============================================================================== -COMMANDS *rust-commands* - -:RustRun [args] *:RustRun* -:RustRun! [rustc-args] [--] [args] - Compiles and runs the current file. If it has unsaved changes, - it will be saved first using |:update|. If the current file is - an unnamed buffer, it will be written to a temporary file - first. The compiled binary is always placed in a temporary - directory, but is run from the current directory. - - The arguments given to |:RustRun| will be passed to the - compiled binary. - - If ! is specified, the arguments are passed to rustc instead. - A "--" argument will separate the rustc arguments from the - arguments passed to the binary. - - If |g:rustc_path| is defined, it is used as the path to rustc. - Otherwise it is assumed rustc can be found in $PATH. - -:RustExpand [args] *:RustExpand* -:RustExpand! [TYPE] [args] - Expands the current file using --pretty and displays the - results in a new split. If the current file has unsaved - changes, it will be saved first using |:update|. If the - current file is an unnamed buffer, it will be written to a - temporary file first. - - The arguments given to |:RustExpand| will be passed to rustc. - This is largely intended for specifying various --cfg - configurations. - - If ! is specified, the first argument is the expansion type to - pass to rustc --pretty. Otherwise it will default to - "expanded". - - If |g:rustc_path| is defined, it is used as the path to rustc. - Otherwise it is assumed rustc can be found in $PATH. - -:RustEmitIr [args] *:RustEmitIr* - Compiles the current file to LLVM IR and displays the results - in a new split. If the current file has unsaved changes, it - will be saved first using |:update|. If the current file is an - unnamed buffer, it will be written to a temporary file first. - - The arguments given to |:RustEmitIr| will be passed to rustc. - - If |g:rustc_path| is defined, it is used as the path to rustc. - Otherwise it is assumed rustc can be found in $PATH. - -:RustEmitAsm [args] *:RustEmitAsm* - Compiles the current file to assembly and displays the results - in a new split. If the current file has unsaved changes, it - will be saved first using |:update|. If the current file is an - unnamed buffer, it will be written to a temporary file first. - - The arguments given to |:RustEmitAsm| will be passed to rustc. - - If |g:rustc_path| is defined, it is used as the path to rustc. - Otherwise it is assumed rustc can be found in $PATH. - -============================================================================== -MAPPINGS *rust-mappings* - -This plugin defines mappings for |[[| and |]]| to support hanging indents. - -It also has a few other mappings: - - *rust_<D-r>* -<D-r> Executes |:RustRun| with no arguments. - Note: This binding is only available in MacVim. - - *rust_<D-R>* -<D-R> Populates the command line with |:RustRun|! using the - arguments given to the last invocation, but does not - execute it. - Note: This binding is only available in MacVim. - -============================================================================== - vim:tw=78:sw=4:noet:ts=8:ft=help:norl: diff --git a/src/etc/vim/ftdetect/rust.vim b/src/etc/vim/ftdetect/rust.vim deleted file mode 100644 index bf685d43243..00000000000 --- a/src/etc/vim/ftdetect/rust.vim +++ /dev/null @@ -1 +0,0 @@ -au BufRead,BufNewFile *.rs set filetype=rust diff --git a/src/etc/vim/ftplugin/rust.vim b/src/etc/vim/ftplugin/rust.vim deleted file mode 100644 index 5d5569945f5..00000000000 --- a/src/etc/vim/ftplugin/rust.vim +++ /dev/null @@ -1,150 +0,0 @@ -" Language: Rust -" Description: Vim syntax file for Rust -" Maintainer: Chris Morgan <me@chrismorgan.info> -" Maintainer: Kevin Ballard <kevin@sb.org> -" Last Change: Jul 07, 2014 - -if exists("b:did_ftplugin") - finish -endif -let b:did_ftplugin = 1 - -let s:save_cpo = &cpo -set cpo&vim - -" Variables {{{1 - -" The rust source code at present seems to typically omit a leader on /*! -" comments, so we'll use that as our default, but make it easy to switch. -" This does not affect indentation at all (I tested it with and without -" leader), merely whether a leader is inserted by default or not. -if exists("g:rust_bang_comment_leader") && g:rust_bang_comment_leader == 1 - " Why is the `,s0:/*,mb:\ ,ex:*/` there, you ask? I don't understand why, - " but without it, */ gets indented one space even if there were no - " leaders. I'm fairly sure that's a Vim bug. - setlocal comments=s1:/*,mb:*,ex:*/,s0:/*,mb:\ ,ex:*/,:///,://!,:// -else - setlocal comments=s0:/*!,m:\ ,ex:*/,s1:/*,mb:*,ex:*/,:///,://!,:// -endif -setlocal commentstring=//%s -setlocal formatoptions-=t formatoptions+=croqnl -" j was only added in 7.3.541, so stop complaints about its nonexistence -silent! setlocal formatoptions+=j - -" smartindent will be overridden by indentexpr if filetype indent is on, but -" otherwise it's better than nothing. -setlocal smartindent nocindent - -if !exists("g:rust_recommended_style") || g:rust_recommended_style == 1 - setlocal tabstop=4 shiftwidth=4 softtabstop=4 expandtab - setlocal textwidth=99 -endif - -" This includeexpr isn't perfect, but it's a good start -setlocal includeexpr=substitute(v:fname,'::','/','g') - -" NOT adding .rc as it's being phased out (0.7) -setlocal suffixesadd=.rs - -if exists("g:ftplugin_rust_source_path") - let &l:path=g:ftplugin_rust_source_path . ',' . &l:path -endif - -if exists("g:loaded_delimitMate") - if exists("b:delimitMate_excluded_regions") - let b:rust_original_delimitMate_excluded_regions = b:delimitMate_excluded_regions - endif - let b:delimitMate_excluded_regions = delimitMate#Get("excluded_regions") . ',rustLifetimeCandidate,rustGenericLifetimeCandidate' -endif - -if has("folding") && exists('g:rust_fold') && g:rust_fold != 0 - let b:rust_set_foldmethod=1 - setlocal foldmethod=syntax - if g:rust_fold == 2 - setlocal foldlevel< - else - setlocal foldlevel=99 - endif -endif - -if has('conceal') && exists('g:rust_conceal') - let b:rust_set_conceallevel=1 - setlocal conceallevel=2 -endif - -" Motion Commands {{{1 - -" Bind motion commands to support hanging indents -nnoremap <silent> <buffer> [[ :call rust#Jump('n', 'Back')<CR> -nnoremap <silent> <buffer> ]] :call rust#Jump('n', 'Forward')<CR> -xnoremap <silent> <buffer> [[ :call rust#Jump('v', 'Back')<CR> -xnoremap <silent> <buffer> ]] :call rust#Jump('v', 'Forward')<CR> -onoremap <silent> <buffer> [[ :call rust#Jump('o', 'Back')<CR> -onoremap <silent> <buffer> ]] :call rust#Jump('o', 'Forward')<CR> - -" Commands {{{1 - -" See |:RustRun| for docs -command! -nargs=* -complete=file -bang -bar -buffer RustRun call rust#Run(<bang>0, [<f-args>]) - -" See |:RustExpand| for docs -command! -nargs=* -complete=customlist,rust#CompleteExpand -bang -bar -buffer RustExpand call rust#Expand(<bang>0, [<f-args>]) - -" See |:RustEmitIr| for docs -command! -nargs=* -bar -buffer RustEmitIr call rust#Emit("ir", [<f-args>]) - -" See |:RustEmitAsm| for docs -command! -nargs=* -bar -buffer RustEmitAsm call rust#Emit("asm", [<f-args>]) - -" Mappings {{{1 - -" Bind ⌘R in MacVim to :RustRun -nnoremap <silent> <buffer> <D-r> :RustRun<CR> -" Bind ⌘⇧R in MacVim to :RustRun! pre-filled with the last args -nnoremap <buffer> <D-R> :RustRun! <C-r>=join(b:rust_last_rustc_args)<CR><C-\>erust#AppendCmdLine(' -- ' . join(b:rust_last_args))<CR> - -if !exists("b:rust_last_rustc_args") || !exists("b:rust_last_args") - let b:rust_last_rustc_args = [] - let b:rust_last_args = [] -endif - -" Cleanup {{{1 - -let b:undo_ftplugin = " - \ setlocal formatoptions< comments< commentstring< includeexpr< suffixesadd< - \|setlocal tabstop< shiftwidth< softtabstop< expandtab< textwidth< - \|if exists('b:rust_original_delimitMate_excluded_regions') - \|let b:delimitMate_excluded_regions = b:rust_original_delimitMate_excluded_regions - \|unlet b:rust_original_delimitMate_excluded_regions - \|else - \|unlet! b:delimitMate_excluded_regions - \|endif - \|if exists('b:rust_set_foldmethod') - \|setlocal foldmethod< foldlevel< - \|unlet b:rust_set_foldmethod - \|endif - \|if exists('b:rust_set_conceallevel') - \|setlocal conceallevel< - \|unlet b:rust_set_conceallevel - \|endif - \|unlet! b:rust_last_rustc_args b:rust_last_args - \|delcommand RustRun - \|delcommand RustExpand - \|delcommand RustEmitIr - \|delcommand RustEmitAsm - \|nunmap <buffer> <D-r> - \|nunmap <buffer> <D-R> - \|nunmap <buffer> [[ - \|nunmap <buffer> ]] - \|xunmap <buffer> [[ - \|xunmap <buffer> ]] - \|ounmap <buffer> [[ - \|ounmap <buffer> ]] - \" - -" }}}1 - -let &cpo = s:save_cpo -unlet s:save_cpo - -" vim: set noet sw=4 ts=4: diff --git a/src/etc/vim/indent/rust.vim b/src/etc/vim/indent/rust.vim deleted file mode 100644 index 300d7dacfa9..00000000000 --- a/src/etc/vim/indent/rust.vim +++ /dev/null @@ -1,196 +0,0 @@ -" Vim indent file -" Language: Rust -" Author: Chris Morgan <me@chrismorgan.info> -" Last Change: 2014 Sep 13 - -" Only load this indent file when no other was loaded. -if exists("b:did_indent") - finish -endif -let b:did_indent = 1 - -setlocal cindent -setlocal cinoptions=L0,(0,Ws,J1,j1 -setlocal cinkeys=0{,0},!^F,o,O,0[,0] -" Don't think cinwords will actually do anything at all... never mind -setlocal cinwords=for,if,else,while,loop,impl,mod,unsafe,trait,struct,enum,fn,extern - -" Some preliminary settings -setlocal nolisp " Make sure lisp indenting doesn't supersede us -setlocal autoindent " indentexpr isn't much help otherwise -" Also do indentkeys, otherwise # gets shoved to column 0 :-/ -setlocal indentkeys=0{,0},!^F,o,O,0[,0] - -setlocal indentexpr=GetRustIndent(v:lnum) - -" Only define the function once. -if exists("*GetRustIndent") - finish -endif - -" Come here when loading the script the first time. - -function! s:get_line_trimmed(lnum) - " Get the line and remove a trailing comment. - " Use syntax highlighting attributes when possible. - " NOTE: this is not accurate; /* */ or a line continuation could trick it - let line = getline(a:lnum) - let line_len = strlen(line) - if has('syntax_items') - " If the last character in the line is a comment, do a binary search for - " the start of the comment. synID() is slow, a linear search would take - " too long on a long line. - if synIDattr(synID(a:lnum, line_len, 1), "name") =~ 'Comment\|Todo' - let min = 1 - let max = line_len - while min < max - let col = (min + max) / 2 - if synIDattr(synID(a:lnum, col, 1), "name") =~ 'Comment\|Todo' - let max = col - else - let min = col + 1 - endif - endwhile - let line = strpart(line, 0, min - 1) - endif - return substitute(line, "\s*$", "", "") - else - " Sorry, this is not complete, nor fully correct (e.g. string "//"). - " Such is life. - return substitute(line, "\s*//.*$", "", "") - endif -endfunction - -function! s:is_string_comment(lnum, col) - if has('syntax_items') - for id in synstack(a:lnum, a:col) - let synname = synIDattr(id, "name") - if synname == "rustString" || synname =~ "^rustComment" - return 1 - endif - endfor - else - " without syntax, let's not even try - return 0 - endif -endfunction - -function GetRustIndent(lnum) - - " Starting assumption: cindent (called at the end) will do it right - " normally. We just want to fix up a few cases. - - let line = getline(a:lnum) - - if has('syntax_items') - let synname = synIDattr(synID(a:lnum, 1, 1), "name") - if synname == "rustString" - " If the start of the line is in a string, don't change the indent - return -1 - elseif synname =~ '\(Comment\|Todo\)' - \ && line !~ '^\s*/\*' " not /* opening line - if synname =~ "CommentML" " multi-line - if line !~ '^\s*\*' && getline(a:lnum - 1) =~ '^\s*/\*' - " This is (hopefully) the line after a /*, and it has no - " leader, so the correct indentation is that of the - " previous line. - return GetRustIndent(a:lnum - 1) - endif - endif - " If it's in a comment, let cindent take care of it now. This is - " for cases like "/*" where the next line should start " * ", not - " "* " as the code below would otherwise cause for module scope - " Fun fact: " /*\n*\n*/" takes two calls to get right! - return cindent(a:lnum) - endif - endif - - " cindent gets second and subsequent match patterns/struct members wrong, - " as it treats the comma as indicating an unfinished statement:: - " - " match a { - " b => c, - " d => e, - " f => g, - " }; - - " Search backwards for the previous non-empty line. - let prevlinenum = prevnonblank(a:lnum - 1) - let prevline = s:get_line_trimmed(prevlinenum) - while prevlinenum > 1 && prevline !~ '[^[:blank:]]' - let prevlinenum = prevnonblank(prevlinenum - 1) - let prevline = s:get_line_trimmed(prevlinenum) - endwhile - if prevline[len(prevline) - 1] == "," - \ && s:get_line_trimmed(a:lnum) !~ '^\s*[\[\]{}]' - \ && prevline !~ '^\s*fn\s' - \ && prevline !~ '([^()]\+,$' - " Oh ho! The previous line ended in a comma! I bet cindent will try to - " take this too far... For now, let's normally use the previous line's - " indent. - - " One case where this doesn't work out is where *this* line contains - " square or curly brackets; then we normally *do* want to be indenting - " further. - " - " Another case where we don't want to is one like a function - " definition with arguments spread over multiple lines: - " - " fn foo(baz: Baz, - " baz: Baz) // <-- cindent gets this right by itself - " - " Another case is similar to the previous, except calling a function - " instead of defining it, or any conditional expression that leaves - " an open paren: - " - " foo(baz, - " baz); - " - " if baz && (foo || - " bar) { - " - " There are probably other cases where we don't want to do this as - " well. Add them as needed. - return indent(prevlinenum) - endif - - if !has("patch-7.4.355") - " cindent before 7.4.355 doesn't do the module scope well at all; e.g.:: - " - " static FOO : &'static [bool] = [ - " true, - " false, - " false, - " true, - " ]; - " - " uh oh, next statement is indented further! - - " Note that this does *not* apply the line continuation pattern properly; - " that's too hard to do correctly for my liking at present, so I'll just - " start with these two main cases (square brackets and not returning to - " column zero) - - call cursor(a:lnum, 1) - if searchpair('{\|(', '', '}\|)', 'nbW', - \ 's:is_string_comment(line("."), col("."))') == 0 - if searchpair('\[', '', '\]', 'nbW', - \ 's:is_string_comment(line("."), col("."))') == 0 - " Global scope, should be zero - return 0 - else - " At the module scope, inside square brackets only - "if getline(a:lnum)[0] == ']' || search('\[', '', '\]', 'nW') == a:lnum - if line =~ "^\\s*]" - " It's the closing line, dedent it - return 0 - else - return &shiftwidth - endif - endif - endif - endif - - " Fall back on cindent, which does it mostly right - return cindent(a:lnum) -endfunction diff --git a/src/etc/vim/plugin/rust.vim b/src/etc/vim/plugin/rust.vim deleted file mode 100644 index 4ec4f33d545..00000000000 --- a/src/etc/vim/plugin/rust.vim +++ /dev/null @@ -1,22 +0,0 @@ -" Vim syntastic plugin helper -" Language: Rust -" Maintainer: Andrew Gallant <jamslam@gmail.com> - -if exists("g:loaded_syntastic_rust_filetype") - finish -endif -let g:loaded_syntastic_rust_filetype = 1 -let s:save_cpo = &cpo -set cpo&vim - -" This is to let Syntastic know about the Rust filetype. -" It enables tab completion for the 'SyntasticInfo' command. -" (This does not actually register the syntax checker.) -if exists('g:syntastic_extra_filetypes') - call add(g:syntastic_extra_filetypes, 'rust') -else - let g:syntastic_extra_filetypes = ['rust'] -endif - -let &cpo = s:save_cpo -unlet s:save_cpo diff --git a/src/etc/vim/syntax/rust.vim b/src/etc/vim/syntax/rust.vim deleted file mode 100644 index a37b7b6d57d..00000000000 --- a/src/etc/vim/syntax/rust.vim +++ /dev/null @@ -1,262 +0,0 @@ -" Vim syntax file -" Language: Rust -" Maintainer: Patrick Walton <pcwalton@mozilla.com> -" Maintainer: Ben Blum <bblum@cs.cmu.edu> -" Maintainer: Chris Morgan <me@chrismorgan.info> -" Last Change: January 5, 2015 - -if version < 600 - syntax clear -elseif exists("b:current_syntax") - finish -endif - -" Syntax definitions {{{1 -" Basic keywords {{{2 -syn keyword rustConditional match if else -syn keyword rustOperator as - -syn match rustAssert "\<assert\(\w\)*!" contained -syn match rustPanic "\<panic\(\w\)*!" contained -syn keyword rustKeyword break -syn keyword rustKeyword box nextgroup=rustBoxPlacement skipwhite skipempty -syn keyword rustKeyword continue -syn keyword rustKeyword extern nextgroup=rustExternCrate,rustObsoleteExternMod skipwhite skipempty -syn keyword rustKeyword fn nextgroup=rustFuncName skipwhite skipempty -syn keyword rustKeyword for in if impl let -syn keyword rustKeyword loop once pub -syn keyword rustKeyword return super -syn keyword rustKeyword unsafe virtual where while -syn keyword rustKeyword use nextgroup=rustModPath skipwhite skipempty -" FIXME: Scoped impl's name is also fallen in this category -syn keyword rustKeyword mod trait struct enum type nextgroup=rustIdentifier skipwhite skipempty -syn keyword rustStorage move mut ref static const - -syn keyword rustInvalidBareKeyword crate - -syn keyword rustExternCrate crate contained nextgroup=rustIdentifier,rustExternCrateString skipwhite skipempty -" This is to get the `bar` part of `extern crate "foo" as bar;` highlighting. -syn match rustExternCrateString /".*"\_s*as/ contained nextgroup=rustIdentifier skipwhite transparent skipempty contains=rustString,rustOperator -syn keyword rustObsoleteExternMod mod contained nextgroup=rustIdentifier skipwhite skipempty - -syn match rustIdentifier contains=rustIdentifierPrime "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained -syn match rustFuncName "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained - -syn region rustBoxPlacement matchgroup=rustBoxPlacementParens start="(" end=")" contains=TOP contained -syn keyword rustBoxPlacementExpr GC containedin=rustBoxPlacement -" Ideally we'd have syntax rules set up to match arbitrary expressions. Since -" we don't, we'll just define temporary contained rules to handle balancing -" delimiters. -syn region rustBoxPlacementBalance start="(" end=")" containedin=rustBoxPlacement transparent -syn region rustBoxPlacementBalance start="\[" end="\]" containedin=rustBoxPlacement transparent -" {} are handled by rustFoldBraces - -syn region rustMacroRepeat matchgroup=rustMacroRepeatDelimiters start="$(" end=")" contains=TOP nextgroup=rustMacroRepeatCount -syn match rustMacroRepeatCount ".\?[*+]" contained -syn match rustMacroVariable "$\w\+" - -" Reserved (but not yet used) keywords {{{2 -syn keyword rustReservedKeyword alignof be do offsetof priv pure sizeof typeof unsized yield abstract final override macro - -" Built-in types {{{2 -syn keyword rustType isize usize float char bool u8 u16 u32 u64 f32 -syn keyword rustType f64 i8 i16 i32 i64 str Self - -" Things from the prelude (src/libstd/prelude.rs) {{{2 -" This section is just straight transformation of the contents of the prelude, -" to make it easy to update. - -" Reexported core operators {{{3 -syn keyword rustTrait Copy Send Sized Sync -syn keyword rustTrait Drop Fn FnMut FnOnce - -" Reexported functions {{{3 -syn keyword rustFunction drop - -" Reexported types and traits {{{3 -syn keyword rustTrait Box -syn keyword rustTrait CharExt -syn keyword rustTrait Clone -syn keyword rustTrait PartialEq PartialOrd Eq Ord -syn keyword rustTrait DoubleEndedIterator -syn keyword rustTrait ExactSizeIterator -syn keyword rustTrait Iterator IteratorExt Extend -syn keyword rustEnum Option -syn keyword rustEnumVariant Some None -syn keyword rustTrait PtrExt MutPtrExt -syn keyword rustEnum Result -syn keyword rustEnumVariant Ok Err -syn keyword rustTrait AsSlice -syn keyword rustTrait SliceExt SliceConcatExt -syn keyword rustTrait Str StrExt -syn keyword rustTrait String ToString -syn keyword rustTrait Vec -" FIXME: remove when path reform lands -syn keyword rustTrait Path GenericPath -" FIXME: remove when I/O reform lands -syn keyword rustTrait Buffer Writer Reader Seek BufferPrelude - -" Other syntax {{{2 -syn keyword rustSelf self -syn keyword rustBoolean true false - -" If foo::bar changes to foo.bar, change this ("::" to "\."). -" If foo::bar changes to Foo::bar, change this (first "\w" to "\u"). -syn match rustModPath "\w\(\w\)*::[^<]"he=e-3,me=e-3 -syn match rustModPathSep "::" - -syn match rustFuncCall "\w\(\w\)*("he=e-1,me=e-1 -syn match rustFuncCall "\w\(\w\)*::<"he=e-3,me=e-3 " foo::<T>(); - -" This is merely a convention; note also the use of [A-Z], restricting it to -" latin identifiers rather than the full Unicode uppercase. I have not used -" [:upper:] as it depends upon 'noignorecase' -"syn match rustCapsIdent display "[A-Z]\w\(\w\)*" - -syn match rustOperator display "\%(+\|-\|/\|*\|=\|\^\|&\||\|!\|>\|<\|%\)=\?" -" This one isn't *quite* right, as we could have binary-& with a reference -syn match rustSigil display /&\s\+[&~@*][^)= \t\r\n]/he=e-1,me=e-1 -syn match rustSigil display /[&~@*][^)= \t\r\n]/he=e-1,me=e-1 -" This isn't actually correct; a closure with no arguments can be `|| { }`. -" Last, because the & in && isn't a sigil -syn match rustOperator display "&&\|||" - -syn match rustMacro '\w\(\w\)*!' contains=rustAssert,rustPanic -syn match rustMacro '#\w\(\w\)*' contains=rustAssert,rustPanic - -syn match rustEscapeError display contained /\\./ -syn match rustEscape display contained /\\\([nrt0\\'"]\|x\x\{2}\)/ -syn match rustEscapeUnicode display contained /\\\(u\x\{4}\|U\x\{8}\)/ -syn match rustEscapeUnicode display contained /\\u{\x\{1,6}}/ -syn match rustStringContinuation display contained /\\\n\s*/ -syn region rustString start=+b"+ skip=+\\\\\|\\"+ end=+"+ contains=rustEscape,rustEscapeError,rustStringContinuation -syn region rustString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=rustEscape,rustEscapeUnicode,rustEscapeError,rustStringContinuation,@Spell -syn region rustString start='b\?r\z(#*\)"' end='"\z1' contains=@Spell - -syn region rustAttribute start="#!\?\[" end="\]" contains=rustString,rustDerive -syn region rustDerive start="derive(" end=")" contained contains=rustTrait - -" Number literals -syn match rustDecNumber display "\<[0-9][0-9_]*\%([iu]\%(s\|8\|16\|32\|64\)\)\=" -syn match rustHexNumber display "\<0x[a-fA-F0-9_]\+\%([iu]\%(s\|8\|16\|32\|64\)\)\=" -syn match rustOctNumber display "\<0o[0-7_]\+\%([iu]\%(s\|8\|16\|32\|64\)\)\=" -syn match rustBinNumber display "\<0b[01_]\+\%([iu]\%(s\|8\|16\|32\|64\)\)\=" - -" Special case for numbers of the form "1." which are float literals, unless followed by -" an identifier, which makes them integer literals with a method call or field access, -" or by another ".", which makes them integer literals followed by the ".." token. -" (This must go first so the others take precedence.) -syn match rustFloat display "\<[0-9][0-9_]*\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\|\.\)\@!" -" To mark a number as a normal float, it must have at least one of the three things integral values don't have: -" a decimal point and more numbers; an exponent; and a type suffix. -syn match rustFloat display "\<[0-9][0-9_]*\%(\.[0-9][0-9_]*\)\%([eE][+-]\=[0-9_]\+\)\=\(f32\|f64\)\=" -syn match rustFloat display "\<[0-9][0-9_]*\%(\.[0-9][0-9_]*\)\=\%([eE][+-]\=[0-9_]\+\)\(f32\|f64\)\=" -syn match rustFloat display "\<[0-9][0-9_]*\%(\.[0-9][0-9_]*\)\=\%([eE][+-]\=[0-9_]\+\)\=\(f32\|f64\)" - -" For the benefit of delimitMate -syn region rustLifetimeCandidate display start=/&'\%(\([^'\\]\|\\\(['nrt0\\\"]\|x\x\{2}\|u\x\{4}\|U\x\{8}\)\)'\)\@!/ end=/[[:cntrl:][:space:][:punct:]]\@=\|$/ contains=rustSigil,rustLifetime -syn region rustGenericRegion display start=/<\%('\|[^[cntrl:][:space:][:punct:]]\)\@=')\S\@=/ end=/>/ contains=rustGenericLifetimeCandidate -syn region rustGenericLifetimeCandidate display start=/\%(<\|,\s*\)\@<='/ end=/[[:cntrl:][:space:][:punct:]]\@=\|$/ contains=rustSigil,rustLifetime - -"rustLifetime must appear before rustCharacter, or chars will get the lifetime highlighting -syn match rustLifetime display "\'\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" -syn match rustCharacterInvalid display contained /b\?'\zs[\n\r\t']\ze'/ -" The groups negated here add up to 0-255 but nothing else (they do not seem to go beyond ASCII). -syn match rustCharacterInvalidUnicode display contained /b'\zs[^[:cntrl:][:graph:][:alnum:][:space:]]\ze'/ -syn match rustCharacter /b'\([^\\]\|\\\(.\|x\x\{2}\)\)'/ contains=rustEscape,rustEscapeError,rustCharacterInvalid,rustCharacterInvalidUnicode -syn match rustCharacter /'\([^\\]\|\\\(.\|x\x\{2}\|u\x\{4}\|U\x\{8}\|u{\x\{1,6}}\)\)'/ contains=rustEscape,rustEscapeUnicode,rustEscapeError,rustCharacterInvalid - -syn region rustCommentLine start="//" end="$" contains=rustTodo,@Spell -syn region rustCommentLineDoc start="//\%(//\@!\|!\)" end="$" contains=rustTodo,@Spell -syn region rustCommentBlock matchgroup=rustCommentBlock start="/\*\%(!\|\*[*/]\@!\)\@!" end="\*/" contains=rustTodo,rustCommentBlockNest,@Spell -syn region rustCommentBlockDoc matchgroup=rustCommentBlockDoc start="/\*\%(!\|\*[*/]\@!\)" end="\*/" contains=rustTodo,rustCommentBlockDocNest,@Spell -syn region rustCommentBlockNest matchgroup=rustCommentBlock start="/\*" end="\*/" contains=rustTodo,rustCommentBlockNest,@Spell contained transparent -syn region rustCommentBlockDocNest matchgroup=rustCommentBlockDoc start="/\*" end="\*/" contains=rustTodo,rustCommentBlockDocNest,@Spell contained transparent -" FIXME: this is a really ugly and not fully correct implementation. Most -" importantly, a case like ``/* */*`` should have the final ``*`` not being in -" a comment, but in practice at present it leaves comments open two levels -" deep. But as long as you stay away from that particular case, I *believe* -" the highlighting is correct. Due to the way Vim's syntax engine works -" (greedy for start matches, unlike Rust's tokeniser which is searching for -" the earliest-starting match, start or end), I believe this cannot be solved. -" Oh you who would fix it, don't bother with things like duplicating the Block -" rules and putting ``\*\@<!`` at the start of them; it makes it worse, as -" then you must deal with cases like ``/*/**/*/``. And don't try making it -" worse with ``\%(/\@<!\*\)\@<!``, either... - -syn keyword rustTodo contained TODO FIXME XXX NB NOTE - -" Folding rules {{{2 -" Trivial folding rules to begin with. -" FIXME: use the AST to make really good folding -syn region rustFoldBraces start="{" end="}" transparent fold - -" Default highlighting {{{1 -hi def link rustDecNumber rustNumber -hi def link rustHexNumber rustNumber -hi def link rustOctNumber rustNumber -hi def link rustBinNumber rustNumber -hi def link rustIdentifierPrime rustIdentifier -hi def link rustTrait rustType - -hi def link rustMacroRepeatCount rustMacroRepeatDelimiters -hi def link rustMacroRepeatDelimiters Macro -hi def link rustMacroVariable Define -hi def link rustSigil StorageClass -hi def link rustEscape Special -hi def link rustEscapeUnicode rustEscape -hi def link rustEscapeError Error -hi def link rustStringContinuation Special -hi def link rustString String -hi def link rustCharacterInvalid Error -hi def link rustCharacterInvalidUnicode rustCharacterInvalid -hi def link rustCharacter Character -hi def link rustNumber Number -hi def link rustBoolean Boolean -hi def link rustEnum rustType -hi def link rustEnumVariant rustConstant -hi def link rustConstant Constant -hi def link rustSelf Constant -hi def link rustFloat Float -hi def link rustOperator Operator -hi def link rustKeyword Keyword -hi def link rustReservedKeyword Error -hi def link rustConditional Conditional -hi def link rustIdentifier Identifier -hi def link rustCapsIdent rustIdentifier -hi def link rustModPath Include -hi def link rustModPathSep Delimiter -hi def link rustFunction Function -hi def link rustFuncName Function -hi def link rustFuncCall Function -hi def link rustCommentLine Comment -hi def link rustCommentLineDoc SpecialComment -hi def link rustCommentBlock rustCommentLine -hi def link rustCommentBlockDoc rustCommentLineDoc -hi def link rustAssert PreCondit -hi def link rustPanic PreCondit -hi def link rustMacro Macro -hi def link rustType Type -hi def link rustTodo Todo -hi def link rustAttribute PreProc -hi def link rustDerive PreProc -hi def link rustStorage StorageClass -hi def link rustObsoleteStorage Error -hi def link rustLifetime Special -hi def link rustInvalidBareKeyword Error -hi def link rustExternCrate rustKeyword -hi def link rustObsoleteExternMod Error -hi def link rustBoxPlacementParens Delimiter -hi def link rustBoxPlacementExpr rustKeyword - -" Other Suggestions: -" hi rustAttribute ctermfg=cyan -" hi rustDerive ctermfg=cyan -" hi rustAssert ctermfg=yellow -" hi rustPanic ctermfg=red -" hi rustMacro ctermfg=magenta - -syn sync minlines=200 -syn sync maxlines=500 - -let b:current_syntax = "rust" diff --git a/src/etc/vim/syntax_checkers/rust/rustc.vim b/src/etc/vim/syntax_checkers/rust/rustc.vim deleted file mode 100644 index 5d196086168..00000000000 --- a/src/etc/vim/syntax_checkers/rust/rustc.vim +++ /dev/null @@ -1,35 +0,0 @@ -" Vim syntastic plugin -" Language: Rust -" Maintainer: Andrew Gallant <jamslam@gmail.com> -" -" See for details on how to add an external Syntastic checker: -" https://github.com/scrooloose/syntastic/wiki/Syntax-Checker-Guide#external - -if exists("g:loaded_syntastic_rust_rustc_checker") - finish -endif -let g:loaded_syntastic_rust_rustc_checker = 1 - -let s:save_cpo = &cpo -set cpo&vim - -function! SyntaxCheckers_rust_rustc_GetLocList() dict - let makeprg = self.makeprgBuild({ 'args': '-Zparse-only' }) - - let errorformat = - \ '%E%f:%l:%c: %\d%#:%\d%# %.%\{-}error:%.%\{-} %m,' . - \ '%W%f:%l:%c: %\d%#:%\d%# %.%\{-}warning:%.%\{-} %m,' . - \ '%C%f:%l %m,' . - \ '%-Z%.%#' - - return SyntasticMake({ - \ 'makeprg': makeprg, - \ 'errorformat': errorformat }) -endfunction - -call g:SyntasticRegistry.CreateAndRegisterChecker({ - \ 'filetype': 'rust', - \ 'name': 'rustc'}) - -let &cpo = s:save_cpo -unlet s:save_cpo diff --git a/src/etc/zsh/_rust b/src/etc/zsh/_rust deleted file mode 100644 index 404f622f970..00000000000 --- a/src/etc/zsh/_rust +++ /dev/null @@ -1,215 +0,0 @@ -#compdef rustc - -local -a _rustc_opts_switches _rustc_opts_lint _rustc_opts_debug - -typeset -A opt_args - -_rustc_debuginfo_levels=( - "0[no debug info]" - "1[line-tables only (for stacktraces and breakpoints)]" - "2[full debug info with variable and type information (same as -g)]" -) - -_rustc_crate_types=( - 'bin' - 'lib' - 'rlib' - 'dylib' - 'staticlib' -) - -_rustc_emit_types=( - 'asm' - 'llvm-bc' - 'llvm-ir' - 'obj' - 'link' - 'dep-info' -) -_rustc_pretty_types=( - 'normal[un-annotated source]' - 'expanded[crates expanded]' - 'typed[crates expanded, with type annotations]' - 'identified[fully parenthesized, AST nodes and blocks with IDs]' - 'flowgraph[graphviz formatted flowgraph for node]:NODEID:' -) -_rustc_color_types=( - 'auto[colorize, if output goes to a tty (default)]' - 'always[always colorize output]' - 'never[never colorize output]' -) -_rustc_info_types=( - 'crate-name[Output the crate name and exit]' - 'file-names[Output the file(s) that would be written if compilation continued and exited]' - 'sysroot[Output the sysroot and exit]' -) - -_rustc_opts_vals=( - --crate-name='[Specify the name of the crate being built]' - --crate-type='[Comma separated list of types of crates for the compiler to emit]:TYPES:_values -s "," "Crate types" "$_rustc_crate_types[@]"' - --emit='[Comma separated list of types of output for the compiler to emit]:TYPES:_values -s "," "Emit Targets" "$_rustc_emit_types[@]"' - --cfg='[Configure the compilation environment]:SPEC:' - --out-dir='[Write output to compiler-chosen filename in <dir>. Ignored if -o is specified. (default the current directory)]:DIR:_files -/' - -o'[Write output to <filename>. Ignored if more than one --emit is specified.]:FILENAME:_files' - --pretty='[Pretty-print the input instead of compiling]::TYPE:_values "TYPES" "$_rustc_pretty_types[@]"' - -L'[Add a directory to the library search path]:DIR:_files -/' - --target='[Target triple cpu-manufacturer-kernel\[-os\] to compile]:TRIPLE:' - --color='[Configure coloring of output]:CONF:_values "COLORS" "$_rustc_color_types[@]"' - {-v,--version}'[Print version info and exit]::VERBOSE:(verbose)' - --explain='[Provide a detailed explanation of an error message]:OPT:' - --extern'[Specify where an external rust library is located]:ARG:' - --print='[Comma separated list of compiler information to print on stdout]:TYPES:_values -s "," "Compiler Information" "$_rustc_info_types[@]"' -) - -_rustc_opts_switches=( - -g'[Equivalent to -C debuginfo=2]' - {-h,--help}'[Display the help message]' - {-V,--verbose}'[use verbose output]' - -O'[Equivalent to -C opt-level=2]' - --test'[Build a test harness]' -) - - -_rustc_opts_link=( - 'static[Path to the library to link statically]:PATH:_files -/' - 'dylib[Path to the library to link dynamically]:PATH:_files -/' - 'framework[Path to the library to link as a framework]:PATH:_files -/' -) - -_rustc_opts_codegen=( - 'ar[Path to the archive utility to use when assembling archives.]:BIN:_path_files' - 'linker[Path to the linker utility to use when linking libraries, executables, and objects.]:BIN:_path_files' - 'link-args[A space-separated list of extra arguments to pass to the linker when the linker is invoked.]:ARGS:' - 'lto[Perform LLVM link-time optimizations]' - 'target-cpu[Selects a target processor. If the value is "help", then a list of available CPUs is printed.]:CPU:' - 'target-feature[A space-separated list of features to enable or disable for the target. A preceding "+" enables a feature while a preceding "-" disables it. Available features can be discovered through target-cpu=help.]:FEATURE:' - 'passes[A space-separated list of extra LLVM passes to run. A value of "list" will cause rustc to print all known passes and exit. The passes specified are appended at the end of the normal pass manager.]:LIST:' - 'llvm-args[A space-separated list of arguments to pass through to LLVM.]:ARGS:' - 'save-temps[If specified, the compiler will save more files (.bc, .o, .no-opt.bc) generated throughout compilation in the output directory.]' - 'rpath[If specified, then the rpath value for dynamic libraries will be set in either dynamic library or executable outputs.]' - 'no-prepopulate-passes[Suppresses pre-population of the LLVM pass manager that is run over the module.]' - 'no-vectorize-loops[Suppresses running the loop vectorization LLVM pass, regardless of optimization level.]' - 'no-vectorize-slp[Suppresses running the LLVM SLP vectorization pass, regardless of optimization level.]' - 'soft-float[Generates software floating point library calls instead of hardware instructions.]' - 'prefer-dynamic[Prefers dynamic linking to static linking.]' - "no-integrated-as[Force usage of an external assembler rather than LLVM's integrated one.]" - 'no-redzone[disable the use of the redzone]' - 'relocation-model[The relocation model to use. (default: pic)]:MODEL:(pic static dynamic-no-pic)' - 'code-model[choose the code model to use (llc -code-model for details)]:MODEL:' - 'metadata[metadata to mangle symbol names with]:VAL:' - 'extra-filenames[extra data to put in each output filename]:VAL:' - 'codegen-units[divide crate into N units to optimize in parallel]:N:' - 'remark[print remarks for these optimization passes (space separated, or "all")]:TYPE:' - 'debuginfo[debug info emission level, 0 = no debug info, 1 = line tables only, 2 = full debug info with variable and type information]:LEVEL:_values "Debug Levels" "$_rustc_debuginfo_levels[@]"' - 'opt-level[Optimize with possible levels 0-3]:LEVEL:(0 1 2 3)' - 'help[Show all codegen options]' -) - -_rustc_opts_lint=( - 'help[Show a list of all lints]' - 'box-pointers[(default: allow) use of owned (Box type) heap memory]' - 'experimental[(default: allow) detects use of #\[experimental\] items]' - 'fat-ptr-transmutes[(default: allow) detects transmutes of fat pointers]' - 'missing-docs[(default: allow) detects missing documentation for public members]' - 'unsafe-blocks[(default: allow) usage of an "unsafe" block]' - 'unstable[(default: allow) detects use of #\[unstable\] items (incl. items with no stability attribute)]' - 'unused-extern-crates[(default: allow) extern crates that are never used]' - 'unused-import-braces[(default: allow) unnecessary braces around an imported item]' - 'unused-qualifications[(default: allow) detects unnecessarily qualified names]' - 'unused-results[(default: allow) unused result of an expression in a statement]' - 'unused-typecasts[(default: allow) detects unnecessary type casts that can be removed]' - 'variant-size-differences[(default: allow) detects enums with widely varying variant sizes]' - 'dead-code[(default: warn) detect unused, unexported items]' - 'deprecated[(default: warn) detects use of #\[deprecated\] items]' - 'improper-ctypes[(default: warn) proper use of libc types in foreign modules]' - 'missing-copy-implementations[(default: warn) detects potentially-forgotten implementations of "Copy"]' - 'non-camel-case-types[(default: warn) types, variants, traits and type parameters should have camel case names]' - 'non-shorthand-field-patterns[(default: warn) using "Struct { x: x }" instead of "Struct { x }"]' - 'non-snake-case[(default: warn) methods, functions, lifetime parameters and modules should have snake case names]' - 'non-upper-case-globals[(default: warn) static constants should have uppercase identifiers]' - 'overflowing-literals[(default: warn) literal out of range for its type]' - 'path-statements[(default: warn) path statements with no effect]' - 'raw-pointer-deriving[(default: warn) uses of #\[derive\] with raw pointers are rarely correct]' - 'unknown-lints[(default: warn) unrecognized lint attribute]' - 'unreachable-code[(default: warn) detects unreachable code paths]' - 'unsigned-negation[(default: warn) using an unary minus operator on unsigned type]' - 'unused-allocation[(default: warn) detects unnecessary allocations that can be eliminated]' - 'unused-assignments[(default: warn) detect assignments that will never be read]' - 'unused-attributes[(default: warn) detects attributes that were not used by the compiler]' - 'unused-comparisons[(default: warn) comparisons made useless by limits of the types involved]' - 'unused-imports[(default: warn) imports that are never used]' - 'unused-must-use[(default: warn) unused result of a type flagged as must_use]' - "unused-mut[(default: warn) detect mut variables which don't need to be mutable]" - 'unused-parens[(default: warn) "if", "match", "while" and "return" do not need parentheses]' - 'unused-unsafe[(default: warn) unnecessary use of an "unsafe" block]' - 'unused-variables[(default: warn) detect variables which are not used in any way]' - 'warnings[(default: warn) mass-change the level for lints which produce warnings]' - 'while-true[(default: warn) suggest using "loop { }" instead of "while true { }"]' - "exceeding-bitshifts[(default: deny) shift exceeds the type's number of bits]" - 'unknown-crate-types[(default: deny) unknown crate type found in #\[crate_type\] directive]' - 'unknown-features[(default: deny) unknown features found in crate-level #\[feature\] directives]' - 'bad-style[non-camel-case-types, non-snake-case, non-upper-case-globals]' - 'unused[unused-imports, unused-variables, unused-assignments, dead-code, unused-mut, unreachable-code, unused-must-use, unused-unsafe, path-statements]' -) - -_rustc_opts_debug=( - 'verbose[in general, enable more debug printouts]' - 'time-passes[measure time of each rustc pass]' - 'count-llvm-insns[count where LLVM instrs originate]' - 'time-llvm-passes[measure time of each LLVM pass]' - 'trans-stats[gather trans statistics]' - 'asm-comments[generate comments into the assembly (may change behavior)]' - 'no-verify[skip LLVM verification]' - 'borrowck-stats[gather borrowck statistics]' - 'no-landing-pads[omit landing pads for unwinding]' - 'debug-llvm[enable debug output from LLVM]' - 'show-span[show spans for compiler debugging]' - 'count-type-sizes[count the sizes of aggregate types]' - 'meta-stats[gather metadata statistics]' - 'print-link-args[Print the arguments passed to the linker]' - 'gc[Garbage collect shared data (experimental)]' - 'print-llvm-passes[Prints the llvm optimization passes being run]' - 'ast-json[Print the AST as JSON and halt]' - 'ast-json-noexpand[Print the pre-expansion AST as JSON and halt]' - 'ls[List the symbols defined by a library crate]' - 'save-analysis[Write syntax and type analysis information in addition to normal output]' - 'flowgraph-print-loans[Include loan analysis data in --pretty flowgraph output]' - 'flowgraph-print-moves[Include move analysis data in --pretty flowgraph output]' - 'flowgraph-print-assigns[Include assignment analysis data in --pretty flowgraph output]' - 'flowgraph-print-all[Include all dataflow analysis data in --pretty flowgraph output]' - 'print-regiion-graph[Prints region inference graph. Use with RUST_REGION_GRAPH=help for more info]' - 'parse-only[Parse only; do not compile, assemble, or link]' - 'no-trans[Run all passes except translation; no output]' - 'no-analysis[Parse and expand the source, but run no analysis]' - 'unstable-options[Adds unstable command line options to rustc interface]' - 'print-enum-sizes[Print the size of enums and their variants]' -) - -_rustc_opts_fun_lint(){ - _values -s , 'options' \ - "$_rustc_opts_lint[@]" -} - -_rustc_opts_fun_debug(){ - _values 'options' "$_rustc_opts_debug[@]" -} - -_rustc_opts_fun_codegen(){ - _values 'options' "$_rustc_opts_codegen[@]" -} - -_rustc_opts_fun_link(){ - _values 'options' "$_rustc_opts_link[@]" -} - -_arguments -s : \ - '(-W --warn)'{-W,--warn=}'[Set lint warnings]:lint options:_rustc_opts_fun_lint' \ - '(-A --allow)'{-A,--allow=}'[Set lint allowed]:lint options:_rustc_opts_fun_lint' \ - '(-D --deny)'{-D,--deny=}'[Set lint denied]:lint options:_rustc_opts_fun_lint' \ - '(-F --forbid)'{-F,--forbid=}'[Set lint forbidden]:lint options:_rustc_opts_fun_lint' \ - '*-Z[Set internal debugging options]:debug options:_rustc_opts_fun_debug' \ - '(-C --codegen)'{-C,--codegen}'[Set internal Codegen options]:codegen options:_rustc_opts_fun_codegen' \ - '*-l[Link the generated crates to the specified native library NAME. the optional KIND can be one of, static, dylib, or framework. If omitted, dylib is assumed.]:ARG:_rustc_opts_fun_link' \ - "$_rustc_opts_switches[@]" \ - "$_rustc_opts_vals[@]" \ - '::files:_files -g "*.rs"' diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index f9f6de2df58..4818e4abaf2 100644 --- a/src/liballoc/arc.rs +++ b/src/liballoc/arc.rs @@ -12,20 +12,22 @@ //! Threadsafe reference-counted boxes (the `Arc<T>` type). //! -//! The `Arc<T>` type provides shared ownership of an immutable value. Destruction is -//! deterministic, and will occur as soon as the last owner is gone. It is marked as `Send` because -//! it uses atomic reference counting. +//! The `Arc<T>` type provides shared ownership of an immutable value. +//! Destruction is deterministic, and will occur as soon as the last owner is +//! gone. It is marked as `Send` because it uses atomic reference counting. //! -//! If you do not need thread-safety, and just need shared ownership, consider the [`Rc<T>` -//! type](../rc/struct.Rc.html). It is the same as `Arc<T>`, but does not use atomics, making it -//! both thread-unsafe as well as significantly faster when updating the reference count. +//! If you do not need thread-safety, and just need shared ownership, consider +//! the [`Rc<T>` type](../rc/struct.Rc.html). It is the same as `Arc<T>`, but +//! does not use atomics, making it both thread-unsafe as well as significantly +//! faster when updating the reference count. //! -//! The `downgrade` method can be used to create a non-owning `Weak<T>` pointer to the box. A -//! `Weak<T>` pointer can be upgraded to an `Arc<T>` pointer, but will return `None` if the value -//! has already been dropped. +//! The `downgrade` method can be used to create a non-owning `Weak<T>` pointer +//! to the box. A `Weak<T>` pointer can be upgraded to an `Arc<T>` pointer, but +//! will return `None` if the value has already been dropped. //! -//! For example, a tree with parent pointers can be represented by putting the nodes behind strong -//! `Arc<T>` pointers, and then storing the parent pointers as `Weak<T>` pointers. +//! For example, a tree with parent pointers can be represented by putting the +//! nodes behind strong `Arc<T>` pointers, and then storing the parent pointers +//! as `Weak<T>` pointers. //! //! # Examples //! @@ -35,7 +37,7 @@ //! use std::sync::Arc; //! use std::thread::Thread; //! -//! let five = Arc::new(5i); +//! let five = Arc::new(5); //! //! for _ in 0u..10 { //! let five = five.clone(); @@ -52,7 +54,7 @@ //! use std::sync::{Arc, Mutex}; //! use std::thread::Thread; //! -//! let five = Arc::new(Mutex::new(5i)); +//! let five = Arc::new(Mutex::new(5)); //! //! for _ in 0u..10 { //! let five = five.clone(); @@ -87,8 +89,9 @@ use heap::deallocate; /// /// # Example /// -/// In this example, a large vector of floats is shared between several tasks. With simple pipes, -/// without `Arc`, a copy would have to be made for each task. +/// In this example, a large vector of floats is shared between several tasks. +/// With simple pipes, without `Arc`, a copy would have to be made for each +/// task. /// /// ```rust /// use std::sync::Arc; @@ -154,7 +157,7 @@ impl<T> Arc<T> { /// ``` /// use std::sync::Arc; /// - /// let five = Arc::new(5i); + /// let five = Arc::new(5); /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] @@ -176,7 +179,7 @@ impl<T> Arc<T> { /// ``` /// use std::sync::Arc; /// - /// let five = Arc::new(5i); + /// let five = Arc::new(5); /// /// let weak_five = five.downgrade(); /// ``` @@ -221,7 +224,7 @@ impl<T> Clone for Arc<T> { /// ``` /// use std::sync::Arc; /// - /// let five = Arc::new(5i); + /// let five = Arc::new(5); /// /// five.clone(); /// ``` @@ -268,7 +271,7 @@ impl<T: Send + Sync + Clone> Arc<T> { /// ``` /// use std::sync::Arc; /// - /// let mut five = Arc::new(5i); + /// let mut five = Arc::new(5); /// /// let mut_five = five.make_unique(); /// ``` @@ -304,14 +307,14 @@ impl<T: Sync + Send> Drop for Arc<T> { /// use std::sync::Arc; /// /// { - /// let five = Arc::new(5i); + /// let five = Arc::new(5); /// /// // stuff /// /// drop(five); // explict drop /// } /// { - /// let five = Arc::new(5i); + /// let five = Arc::new(5); /// /// // stuff /// @@ -371,7 +374,7 @@ impl<T: Sync + Send> Weak<T> { /// ``` /// use std::sync::Arc; /// - /// let five = Arc::new(5i); + /// let five = Arc::new(5); /// /// let weak_five = five.downgrade(); /// @@ -408,7 +411,7 @@ impl<T: Sync + Send> Clone for Weak<T> { /// ``` /// use std::sync::Arc; /// - /// let weak_five = Arc::new(5i).downgrade(); + /// let weak_five = Arc::new(5).downgrade(); /// /// weak_five.clone(); /// ``` @@ -433,7 +436,7 @@ impl<T: Sync + Send> Drop for Weak<T> { /// use std::sync::Arc; /// /// { - /// let five = Arc::new(5i); + /// let five = Arc::new(5); /// let weak_five = five.downgrade(); /// /// // stuff @@ -441,7 +444,7 @@ impl<T: Sync + Send> Drop for Weak<T> { /// drop(weak_five); // explict drop /// } /// { - /// let five = Arc::new(5i); + /// let five = Arc::new(5); /// let weak_five = five.downgrade(); /// /// // stuff @@ -475,9 +478,9 @@ impl<T: PartialEq> PartialEq for Arc<T> { /// ``` /// use std::sync::Arc; /// - /// let five = Arc::new(5i); + /// let five = Arc::new(5); /// - /// five == Arc::new(5i); + /// five == Arc::new(5); /// ``` fn eq(&self, other: &Arc<T>) -> bool { *(*self) == *(*other) } @@ -490,9 +493,9 @@ impl<T: PartialEq> PartialEq for Arc<T> { /// ``` /// use std::sync::Arc; /// - /// let five = Arc::new(5i); + /// let five = Arc::new(5); /// - /// five != Arc::new(5i); + /// five != Arc::new(5); /// ``` fn ne(&self, other: &Arc<T>) -> bool { *(*self) != *(*other) } } @@ -507,9 +510,9 @@ impl<T: PartialOrd> PartialOrd for Arc<T> { /// ``` /// use std::sync::Arc; /// - /// let five = Arc::new(5i); + /// let five = Arc::new(5); /// - /// five.partial_cmp(&Arc::new(5i)); + /// five.partial_cmp(&Arc::new(5)); /// ``` fn partial_cmp(&self, other: &Arc<T>) -> Option<Ordering> { (**self).partial_cmp(&**other) @@ -524,9 +527,9 @@ impl<T: PartialOrd> PartialOrd for Arc<T> { /// ``` /// use std::sync::Arc; /// - /// let five = Arc::new(5i); + /// let five = Arc::new(5); /// - /// five < Arc::new(5i); + /// five < Arc::new(5); /// ``` fn lt(&self, other: &Arc<T>) -> bool { *(*self) < *(*other) } @@ -539,9 +542,9 @@ impl<T: PartialOrd> PartialOrd for Arc<T> { /// ``` /// use std::sync::Arc; /// - /// let five = Arc::new(5i); + /// let five = Arc::new(5); /// - /// five <= Arc::new(5i); + /// five <= Arc::new(5); /// ``` fn le(&self, other: &Arc<T>) -> bool { *(*self) <= *(*other) } @@ -554,9 +557,9 @@ impl<T: PartialOrd> PartialOrd for Arc<T> { /// ``` /// use std::sync::Arc; /// - /// let five = Arc::new(5i); + /// let five = Arc::new(5); /// - /// five > Arc::new(5i); + /// five > Arc::new(5); /// ``` fn gt(&self, other: &Arc<T>) -> bool { *(*self) > *(*other) } @@ -569,9 +572,9 @@ impl<T: PartialOrd> PartialOrd for Arc<T> { /// ``` /// use std::sync::Arc; /// - /// let five = Arc::new(5i); + /// let five = Arc::new(5); /// - /// five >= Arc::new(5i); + /// five >= Arc::new(5); /// ``` fn ge(&self, other: &Arc<T>) -> bool { *(*self) >= *(*other) } } @@ -719,14 +722,14 @@ mod tests { #[test] fn test_live() { - let x = Arc::new(5i); + let x = Arc::new(5); let y = x.downgrade(); assert!(y.upgrade().is_some()); } #[test] fn test_dead() { - let x = Arc::new(5i); + let x = Arc::new(5); let y = x.downgrade(); drop(x); assert!(y.upgrade().is_none()); diff --git a/src/liballoc/boxed_test.rs b/src/liballoc/boxed_test.rs index c47a771f60d..4ffb94e7a61 100644 --- a/src/liballoc/boxed_test.rs +++ b/src/liballoc/boxed_test.rs @@ -20,7 +20,7 @@ use std::boxed::BoxAny; #[test] fn test_owned_clone() { - let a = Box::new(5i); + let a = Box::new(5); let b: Box<int> = a.clone(); assert!(a == b); } diff --git a/src/liballoc/heap.rs b/src/liballoc/heap.rs index 1fb6290c7a3..1d5637a6ad6 100644 --- a/src/liballoc/heap.rs +++ b/src/liballoc/heap.rs @@ -403,7 +403,7 @@ mod test { #[bench] fn alloc_owned_small(b: &mut Bencher) { b.iter(|| { - box 10i + box 10 }) } } diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index 8960667fdfa..99423349020 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -66,12 +66,11 @@ html_root_url = "http://doc.rust-lang.org/nightly/")] #![no_std] -#![allow(unknown_features)] #![feature(lang_items, unsafe_destructor)] #![feature(box_syntax)] #![feature(optin_builtin_traits)] +#![feature(int_uint)] #![feature(unboxed_closures)] -#![allow(unknown_features)] #![feature(int_uint)] #![feature(core)] #![feature(hash)] #![feature(libc)] diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index d41673f56ed..8a542e1b8cb 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -192,7 +192,7 @@ impl<T> Rc<T> { /// ``` /// use std::rc::Rc; /// - /// let five = Rc::new(5i); + /// let five = Rc::new(5); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn new(value: T) -> Rc<T> { @@ -217,7 +217,7 @@ impl<T> Rc<T> { /// ``` /// use std::rc::Rc; /// - /// let five = Rc::new(5i); + /// let five = Rc::new(5); /// /// let weak_five = five.downgrade(); /// ``` @@ -247,7 +247,7 @@ pub fn strong_count<T>(this: &Rc<T>) -> uint { this.strong() } /// use std::rc; /// use std::rc::Rc; /// -/// let five = Rc::new(5i); +/// let five = Rc::new(5); /// /// rc::is_unique(&five); /// ``` @@ -329,7 +329,7 @@ impl<T: Clone> Rc<T> { /// ``` /// use std::rc::Rc; /// - /// let mut five = Rc::new(5i); + /// let mut five = Rc::new(5); /// /// let mut_five = five.make_unique(); /// ``` @@ -378,14 +378,14 @@ impl<T> Drop for Rc<T> { /// use std::rc::Rc; /// /// { - /// let five = Rc::new(5i); + /// let five = Rc::new(5); /// /// // stuff /// /// drop(five); // explict drop /// } /// { - /// let five = Rc::new(5i); + /// let five = Rc::new(5); /// /// // stuff /// @@ -425,7 +425,7 @@ impl<T> Clone for Rc<T> { /// ``` /// use std::rc::Rc; /// - /// let five = Rc::new(5i); + /// let five = Rc::new(5); /// /// five.clone(); /// ``` @@ -466,9 +466,9 @@ impl<T: PartialEq> PartialEq for Rc<T> { /// ``` /// use std::rc::Rc; /// - /// let five = Rc::new(5i); + /// let five = Rc::new(5); /// - /// five == Rc::new(5i); + /// five == Rc::new(5); /// ``` #[inline(always)] fn eq(&self, other: &Rc<T>) -> bool { **self == **other } @@ -482,9 +482,9 @@ impl<T: PartialEq> PartialEq for Rc<T> { /// ``` /// use std::rc::Rc; /// - /// let five = Rc::new(5i); + /// let five = Rc::new(5); /// - /// five != Rc::new(5i); + /// five != Rc::new(5); /// ``` #[inline(always)] fn ne(&self, other: &Rc<T>) -> bool { **self != **other } @@ -504,9 +504,9 @@ impl<T: PartialOrd> PartialOrd for Rc<T> { /// ``` /// use std::rc::Rc; /// - /// let five = Rc::new(5i); + /// let five = Rc::new(5); /// - /// five.partial_cmp(&Rc::new(5i)); + /// five.partial_cmp(&Rc::new(5)); /// ``` #[inline(always)] fn partial_cmp(&self, other: &Rc<T>) -> Option<Ordering> { @@ -522,9 +522,9 @@ impl<T: PartialOrd> PartialOrd for Rc<T> { /// ``` /// use std::rc::Rc; /// - /// let five = Rc::new(5i); + /// let five = Rc::new(5); /// - /// five < Rc::new(5i); + /// five < Rc::new(5); /// ``` #[inline(always)] fn lt(&self, other: &Rc<T>) -> bool { **self < **other } @@ -538,9 +538,9 @@ impl<T: PartialOrd> PartialOrd for Rc<T> { /// ``` /// use std::rc::Rc; /// - /// let five = Rc::new(5i); + /// let five = Rc::new(5); /// - /// five <= Rc::new(5i); + /// five <= Rc::new(5); /// ``` #[inline(always)] fn le(&self, other: &Rc<T>) -> bool { **self <= **other } @@ -554,9 +554,9 @@ impl<T: PartialOrd> PartialOrd for Rc<T> { /// ``` /// use std::rc::Rc; /// - /// let five = Rc::new(5i); + /// let five = Rc::new(5); /// - /// five > Rc::new(5i); + /// five > Rc::new(5); /// ``` #[inline(always)] fn gt(&self, other: &Rc<T>) -> bool { **self > **other } @@ -570,9 +570,9 @@ impl<T: PartialOrd> PartialOrd for Rc<T> { /// ``` /// use std::rc::Rc; /// - /// let five = Rc::new(5i); + /// let five = Rc::new(5); /// - /// five >= Rc::new(5i); + /// five >= Rc::new(5); /// ``` #[inline(always)] fn ge(&self, other: &Rc<T>) -> bool { **self >= **other } @@ -589,9 +589,9 @@ impl<T: Ord> Ord for Rc<T> { /// ``` /// use std::rc::Rc; /// - /// let five = Rc::new(5i); + /// let five = Rc::new(5); /// - /// five.partial_cmp(&Rc::new(5i)); + /// five.partial_cmp(&Rc::new(5)); /// ``` #[inline] fn cmp(&self, other: &Rc<T>) -> Ordering { (**self).cmp(&**other) } @@ -653,7 +653,7 @@ impl<T> Weak<T> { /// ``` /// use std::rc::Rc; /// - /// let five = Rc::new(5i); + /// let five = Rc::new(5); /// /// let weak_five = five.downgrade(); /// @@ -682,7 +682,7 @@ impl<T> Drop for Weak<T> { /// use std::rc::Rc; /// /// { - /// let five = Rc::new(5i); + /// let five = Rc::new(5); /// let weak_five = five.downgrade(); /// /// // stuff @@ -690,7 +690,7 @@ impl<T> Drop for Weak<T> { /// drop(weak_five); // explict drop /// } /// { - /// let five = Rc::new(5i); + /// let five = Rc::new(5); /// let weak_five = five.downgrade(); /// /// // stuff @@ -726,7 +726,7 @@ impl<T> Clone for Weak<T> { /// ``` /// use std::rc::Rc; /// - /// let weak_five = Rc::new(5i).downgrade(); + /// let weak_five = Rc::new(5).downgrade(); /// /// weak_five.clone(); /// ``` @@ -789,7 +789,7 @@ mod tests { #[test] fn test_clone() { - let x = Rc::new(RefCell::new(5i)); + let x = Rc::new(RefCell::new(5)); let y = x.clone(); *x.borrow_mut() = 20; assert_eq!(*y.borrow(), 20); @@ -797,13 +797,13 @@ mod tests { #[test] fn test_simple() { - let x = Rc::new(5i); + let x = Rc::new(5); assert_eq!(*x, 5); } #[test] fn test_simple_clone() { - let x = Rc::new(5i); + let x = Rc::new(5); let y = x.clone(); assert_eq!(*x, 5); assert_eq!(*y, 5); @@ -811,20 +811,20 @@ mod tests { #[test] fn test_destructor() { - let x = Rc::new(box 5i); + let x = Rc::new(box 5); assert_eq!(**x, 5); } #[test] fn test_live() { - let x = Rc::new(5i); + let x = Rc::new(5); let y = x.downgrade(); assert!(y.upgrade().is_some()); } #[test] fn test_dead() { - let x = Rc::new(5i); + let x = Rc::new(5); let y = x.downgrade(); drop(x); assert!(y.upgrade().is_none()); diff --git a/src/libarena/lib.rs b/src/libarena/lib.rs index 9744feb4ee7..5ada51976ac 100644 --- a/src/libarena/lib.rs +++ b/src/libarena/lib.rs @@ -21,7 +21,6 @@ #![crate_name = "arena"] #![unstable(feature = "rustc_private")] -#![feature(staged_api)] #![staged_api] #![crate_type = "rlib"] #![crate_type = "dylib"] @@ -29,16 +28,14 @@ html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_root_url = "http://doc.rust-lang.org/nightly/")] -#![allow(unknown_features)] -#![feature(unsafe_destructor)] -#![feature(unboxed_closures)] -#![feature(box_syntax)] -#![allow(unknown_features)] #![feature(int_uint)] -#![allow(missing_docs)] #![feature(alloc)] +#![feature(box_syntax)] #![feature(core)] +#![feature(int_uint)] +#![feature(staged_api)] +#![feature(unboxed_closures)] +#![feature(unsafe_destructor)] #![cfg_attr(test, feature(test))] -#![cfg_attr(test, feature(collections))] extern crate alloc; diff --git a/src/libcollections/binary_heap.rs b/src/libcollections/binary_heap.rs index f717fc6075d..8aa4c77f6f9 100644 --- a/src/libcollections/binary_heap.rs +++ b/src/libcollections/binary_heap.rs @@ -153,7 +153,7 @@ use core::prelude::*; use core::default::Default; -use core::iter::FromIterator; +use core::iter::{FromIterator, IntoIterator}; use core::mem::{zeroed, replace, swap}; use core::ptr; @@ -212,7 +212,7 @@ impl<T: Ord> BinaryHeap<T> { /// /// ``` /// use std::collections::BinaryHeap; - /// let heap = BinaryHeap::from_vec(vec![9i, 1, 2, 7, 3, 2]); + /// let heap = BinaryHeap::from_vec(vec![9, 1, 2, 7, 3, 2]); /// ``` pub fn from_vec(vec: Vec<T>) -> BinaryHeap<T> { let mut heap = BinaryHeap { data: vec }; @@ -231,7 +231,7 @@ impl<T: Ord> BinaryHeap<T> { /// /// ``` /// use std::collections::BinaryHeap; - /// let heap = BinaryHeap::from_vec(vec![1i, 2, 3, 4]); + /// let heap = BinaryHeap::from_vec(vec![1, 2, 3, 4]); /// /// // Print 1, 2, 3, 4 in arbitrary order /// for x in heap.iter() { @@ -251,7 +251,7 @@ impl<T: Ord> BinaryHeap<T> { /// /// ``` /// use std::collections::BinaryHeap; - /// let heap = BinaryHeap::from_vec(vec![1i, 2, 3, 4]); + /// let heap = BinaryHeap::from_vec(vec![1, 2, 3, 4]); /// /// // Print 1, 2, 3, 4 in arbitrary order /// for x in heap.into_iter() { @@ -273,7 +273,7 @@ impl<T: Ord> BinaryHeap<T> { /// let mut heap = BinaryHeap::new(); /// assert_eq!(heap.peek(), None); /// - /// heap.push(1i); + /// heap.push(1); /// heap.push(5); /// heap.push(2); /// assert_eq!(heap.peek(), Some(&5)); @@ -356,7 +356,7 @@ impl<T: Ord> BinaryHeap<T> { /// /// ``` /// use std::collections::BinaryHeap; - /// let mut heap = BinaryHeap::from_vec(vec![1i, 3]); + /// let mut heap = BinaryHeap::from_vec(vec![1, 3]); /// /// assert_eq!(heap.pop(), Some(3)); /// assert_eq!(heap.pop(), Some(1)); @@ -380,7 +380,7 @@ impl<T: Ord> BinaryHeap<T> { /// ``` /// use std::collections::BinaryHeap; /// let mut heap = BinaryHeap::new(); - /// heap.push(3i); + /// heap.push(3); /// heap.push(5); /// heap.push(1); /// @@ -402,7 +402,7 @@ impl<T: Ord> BinaryHeap<T> { /// ``` /// use std::collections::BinaryHeap; /// let mut heap = BinaryHeap::new(); - /// heap.push(1i); + /// heap.push(1); /// heap.push(5); /// /// assert_eq!(heap.push_pop(3), 5); @@ -434,7 +434,7 @@ impl<T: Ord> BinaryHeap<T> { /// use std::collections::BinaryHeap; /// let mut heap = BinaryHeap::new(); /// - /// assert_eq!(heap.replace(1i), None); + /// assert_eq!(heap.replace(1), None); /// assert_eq!(heap.replace(3), Some(1)); /// assert_eq!(heap.len(), 1); /// assert_eq!(heap.peek(), Some(&3)); @@ -457,7 +457,7 @@ impl<T: Ord> BinaryHeap<T> { /// /// ``` /// use std::collections::BinaryHeap; - /// let heap = BinaryHeap::from_vec(vec![1i, 2, 3, 4, 5, 6, 7]); + /// let heap = BinaryHeap::from_vec(vec![1, 2, 3, 4, 5, 6, 7]); /// let vec = heap.into_vec(); /// /// // Will print in some order @@ -475,12 +475,12 @@ impl<T: Ord> BinaryHeap<T> { /// ``` /// use std::collections::BinaryHeap; /// - /// let mut heap = BinaryHeap::from_vec(vec![1i, 2, 4, 5, 7]); + /// let mut heap = BinaryHeap::from_vec(vec![1, 2, 4, 5, 7]); /// heap.push(6); /// heap.push(3); /// /// let vec = heap.into_sorted_vec(); - /// assert_eq!(vec, vec![1i, 2, 3, 4, 5, 6, 7]); + /// assert_eq!(vec, vec![1, 2, 3, 4, 5, 6, 7]); /// ``` pub fn into_sorted_vec(mut self) -> Vec<T> { let mut end = self.len(); @@ -655,6 +655,22 @@ impl<T: Ord> FromIterator<T> for BinaryHeap<T> { } } +impl<T: Ord> IntoIterator for BinaryHeap<T> { + type Iter = IntoIter<T>; + + fn into_iter(self) -> IntoIter<T> { + self.into_iter() + } +} + +impl<'a, T> IntoIterator for &'a BinaryHeap<T> where T: Ord { + type Iter = Iter<'a, T>; + + fn into_iter(self) -> Iter<'a, T> { + self.iter() + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl<T: Ord> Extend<T> for BinaryHeap<T> { fn extend<Iter: Iterator<Item=T>>(&mut self, mut iter: Iter) { @@ -676,8 +692,8 @@ mod tests { #[test] fn test_iterator() { - let data = vec!(5i, 9, 3); - let iterout = [9i, 5, 3]; + let data = vec!(5, 9, 3); + let iterout = [9, 5, 3]; let heap = BinaryHeap::from_vec(data); let mut i = 0; for el in heap.iter() { @@ -688,8 +704,8 @@ mod tests { #[test] fn test_iterator_reverse() { - let data = vec!(5i, 9, 3); - let iterout = vec!(3i, 5, 9); + let data = vec!(5, 9, 3); + let iterout = vec!(3, 5, 9); let pq = BinaryHeap::from_vec(data); let v: Vec<int> = pq.iter().rev().map(|&x| x).collect(); @@ -698,8 +714,8 @@ mod tests { #[test] fn test_move_iter() { - let data = vec!(5i, 9, 3); - let iterout = vec!(9i, 5, 3); + let data = vec!(5, 9, 3); + let iterout = vec!(9, 5, 3); let pq = BinaryHeap::from_vec(data); let v: Vec<int> = pq.into_iter().collect(); @@ -708,16 +724,16 @@ mod tests { #[test] fn test_move_iter_size_hint() { - let data = vec!(5i, 9); + let data = vec!(5, 9); let pq = BinaryHeap::from_vec(data); let mut it = pq.into_iter(); assert_eq!(it.size_hint(), (2, Some(2))); - assert_eq!(it.next(), Some(9i)); + assert_eq!(it.next(), Some(9)); assert_eq!(it.size_hint(), (1, Some(1))); - assert_eq!(it.next(), Some(5i)); + assert_eq!(it.next(), Some(5)); assert_eq!(it.size_hint(), (0, Some(0))); assert_eq!(it.next(), None); @@ -725,8 +741,8 @@ mod tests { #[test] fn test_move_iter_reverse() { - let data = vec!(5i, 9, 3); - let iterout = vec!(3i, 5, 9); + let data = vec!(5, 9, 3); + let iterout = vec!(3, 5, 9); let pq = BinaryHeap::from_vec(data); let v: Vec<int> = pq.into_iter().rev().collect(); @@ -747,7 +763,7 @@ mod tests { #[test] fn test_push() { - let mut heap = BinaryHeap::from_vec(vec!(2i, 4, 9)); + let mut heap = BinaryHeap::from_vec(vec!(2, 4, 9)); assert_eq!(heap.len(), 3); assert!(*heap.peek().unwrap() == 9); heap.push(11); @@ -769,7 +785,7 @@ mod tests { #[test] fn test_push_unique() { - let mut heap = BinaryHeap::from_vec(vec!(box 2i, box 4, box 9)); + let mut heap = BinaryHeap::from_vec(vec!(box 2, box 4, box 9)); assert_eq!(heap.len(), 3); assert!(*heap.peek().unwrap() == box 9); heap.push(box 11); @@ -791,7 +807,7 @@ mod tests { #[test] fn test_push_pop() { - let mut heap = BinaryHeap::from_vec(vec!(5i, 5, 2, 1, 3)); + let mut heap = BinaryHeap::from_vec(vec!(5, 5, 2, 1, 3)); assert_eq!(heap.len(), 5); assert_eq!(heap.push_pop(6), 6); assert_eq!(heap.len(), 5); @@ -805,7 +821,7 @@ mod tests { #[test] fn test_replace() { - let mut heap = BinaryHeap::from_vec(vec!(5i, 5, 2, 1, 3)); + let mut heap = BinaryHeap::from_vec(vec!(5, 5, 2, 1, 3)); assert_eq!(heap.len(), 5); assert_eq!(heap.replace(6).unwrap(), 5); assert_eq!(heap.len(), 5); @@ -830,18 +846,18 @@ mod tests { #[test] fn test_to_vec() { check_to_vec(vec!()); - check_to_vec(vec!(5i)); - check_to_vec(vec!(3i, 2)); - check_to_vec(vec!(2i, 3)); - check_to_vec(vec!(5i, 1, 2)); - check_to_vec(vec!(1i, 100, 2, 3)); - check_to_vec(vec!(1i, 3, 5, 7, 9, 2, 4, 6, 8, 0)); - check_to_vec(vec!(2i, 4, 6, 2, 1, 8, 10, 3, 5, 7, 0, 9, 1)); - check_to_vec(vec!(9i, 11, 9, 9, 9, 9, 11, 2, 3, 4, 11, 9, 0, 0, 0, 0)); - check_to_vec(vec!(0i, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); - check_to_vec(vec!(10i, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)); - check_to_vec(vec!(0i, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 1, 2)); - check_to_vec(vec!(5i, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1)); + check_to_vec(vec!(5)); + check_to_vec(vec!(3, 2)); + check_to_vec(vec!(2, 3)); + check_to_vec(vec!(5, 1, 2)); + check_to_vec(vec!(1, 100, 2, 3)); + check_to_vec(vec!(1, 3, 5, 7, 9, 2, 4, 6, 8, 0)); + check_to_vec(vec!(2, 4, 6, 2, 1, 8, 10, 3, 5, 7, 0, 9, 1)); + check_to_vec(vec!(9, 11, 9, 9, 9, 9, 11, 2, 3, 4, 11, 9, 0, 0, 0, 0)); + check_to_vec(vec!(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); + check_to_vec(vec!(10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)); + check_to_vec(vec!(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 1, 2)); + check_to_vec(vec!(5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1)); } #[test] diff --git a/src/libcollections/bit.rs b/src/libcollections/bit.rs index c6275740579..ec2a274a45d 100644 --- a/src/libcollections/bit.rs +++ b/src/libcollections/bit.rs @@ -89,7 +89,7 @@ use core::fmt; use core::hash; use core::iter::RandomAccessIterator; use core::iter::{Chain, Enumerate, Repeat, Skip, Take, repeat, Cloned}; -use core::iter::{self, FromIterator}; +use core::iter::{self, FromIterator, IntoIterator}; use core::num::Int; use core::ops::Index; use core::slice; @@ -1070,6 +1070,14 @@ impl<'a> RandomAccessIterator for Iter<'a> { } } +impl<'a> IntoIterator for &'a Bitv { + type Iter = Iter<'a>; + + fn into_iter(self) -> Iter<'a> { + self.iter() + } +} + /// An implementation of a set using a bit vector as an underlying /// representation for holding unsigned numerical elements. /// @@ -1730,6 +1738,7 @@ impl BitvSet { } } +#[stable(feature = "rust1", since = "1.0.0")] impl fmt::Debug for BitvSet { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { try!(write!(fmt, "BitvSet {{")); @@ -1873,6 +1882,13 @@ impl<'a> Iterator for SymmetricDifference<'a> { #[inline] fn size_hint(&self) -> (uint, Option<uint>) { self.0.size_hint() } } +impl<'a> IntoIterator for &'a BitvSet { + type Iter = SetIter<'a>; + + fn into_iter(self) -> SetIter<'a> { + self.iter() + } +} #[cfg(test)] mod tests { diff --git a/src/libcollections/btree/map.rs b/src/libcollections/btree/map.rs index 4f2c2cb6028..ce5e8f07be1 100644 --- a/src/libcollections/btree/map.rs +++ b/src/libcollections/btree/map.rs @@ -24,7 +24,7 @@ use core::cmp::Ordering; use core::default::Default; use core::fmt::Debug; use core::hash::{Hash, Hasher}; -use core::iter::{Map, FromIterator}; +use core::iter::{Map, FromIterator, IntoIterator}; use core::ops::{Index, IndexMut}; use core::{iter, fmt, mem}; use Bound::{self, Included, Excluded, Unbounded}; @@ -478,6 +478,30 @@ impl<K: Ord, V> BTreeMap<K, V> { } } +impl<K, V> IntoIterator for BTreeMap<K, V> { + type Iter = IntoIter<K, V>; + + fn into_iter(self) -> IntoIter<K, V> { + self.into_iter() + } +} + +impl<'a, K, V> IntoIterator for &'a BTreeMap<K, V> { + type Iter = Iter<'a, K, V>; + + fn into_iter(self) -> Iter<'a, K, V> { + self.iter() + } +} + +impl<'a, K, V> IntoIterator for &'a mut BTreeMap<K, V> { + type Iter = IterMut<'a, K, V>; + + fn into_iter(mut self) -> IterMut<'a, K, V> { + self.iter_mut() + } +} + /// A helper enum useful for deciding whether to continue a loop since we can't /// return from a closure enum Continuation<A, B> { @@ -1782,7 +1806,7 @@ mod test { #[test] fn test_entry(){ - let xs = [(1i, 10i), (2, 20), (3, 30), (4, 40), (5, 50), (6, 60)]; + let xs = [(1, 10), (2, 20), (3, 30), (4, 40), (5, 50), (6, 60)]; let mut map: BTreeMap<int, int> = xs.iter().map(|&x| x).collect(); diff --git a/src/libcollections/btree/node.rs b/src/libcollections/btree/node.rs index ea167348a64..8d6f06b25c5 100644 --- a/src/libcollections/btree/node.rs +++ b/src/libcollections/btree/node.rs @@ -271,7 +271,7 @@ impl<T> DoubleEndedIterator for RawItems<T> { #[unsafe_destructor] impl<T> Drop for RawItems<T> { fn drop(&mut self) { - for _ in *self {} + for _ in self.by_ref() {} } } @@ -1374,9 +1374,9 @@ impl<K, V> Drop for MoveTraversalImpl<K, V> { fn drop(&mut self) { // We need to cleanup the stored values manually, as the RawItems destructor would run // after our deallocation. - for _ in self.keys {} - for _ in self.vals {} - for _ in self.edges {} + for _ in self.keys.by_ref() {} + for _ in self.vals.by_ref() {} + for _ in self.edges.by_ref() {} let (alignment, size) = calculate_allocation_generic::<K, V>(self.capacity, self.is_leaf); diff --git a/src/libcollections/btree/set.rs b/src/libcollections/btree/set.rs index a090e4f24ce..72d5bf6d799 100644 --- a/src/libcollections/btree/set.rs +++ b/src/libcollections/btree/set.rs @@ -18,7 +18,7 @@ use core::cmp::Ordering::{self, Less, Greater, Equal}; use core::default::Default; use core::fmt::Debug; use core::fmt; -use core::iter::{Peekable, Map, FromIterator}; +use core::iter::{Peekable, Map, FromIterator, IntoIterator}; use core::ops::{BitOr, BitAnd, BitXor, Sub}; use btree_map::{BTreeMap, Keys}; @@ -282,7 +282,7 @@ impl<T: Ord> BTreeSet<T> { /// /// let mut v = BTreeSet::new(); /// assert_eq!(v.len(), 0); - /// v.insert(1i); + /// v.insert(1); /// assert_eq!(v.len(), 1); /// ``` #[stable(feature = "rust1", since = "1.0.0")] @@ -297,7 +297,7 @@ impl<T: Ord> BTreeSet<T> { /// /// let mut v = BTreeSet::new(); /// assert!(v.is_empty()); - /// v.insert(1i); + /// v.insert(1); /// assert!(!v.is_empty()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] @@ -311,7 +311,7 @@ impl<T: Ord> BTreeSet<T> { /// use std::collections::BTreeSet; /// /// let mut v = BTreeSet::new(); - /// v.insert(1i); + /// v.insert(1); /// v.clear(); /// assert!(v.is_empty()); /// ``` @@ -331,7 +331,7 @@ impl<T: Ord> BTreeSet<T> { /// ``` /// use std::collections::BTreeSet; /// - /// let set: BTreeSet<int> = [1i, 2, 3].iter().map(|&x| x).collect(); + /// let set: BTreeSet<int> = [1, 2, 3].iter().map(|&x| x).collect(); /// assert_eq!(set.contains(&1), true); /// assert_eq!(set.contains(&4), false); /// ``` @@ -348,7 +348,7 @@ impl<T: Ord> BTreeSet<T> { /// ``` /// use std::collections::BTreeSet; /// - /// let a: BTreeSet<int> = [1i, 2, 3].iter().map(|&x| x).collect(); + /// let a: BTreeSet<int> = [1, 2, 3].iter().map(|&x| x).collect(); /// let mut b: BTreeSet<int> = BTreeSet::new(); /// /// assert_eq!(a.is_disjoint(&b), true); @@ -369,7 +369,7 @@ impl<T: Ord> BTreeSet<T> { /// ``` /// use std::collections::BTreeSet; /// - /// let sup: BTreeSet<int> = [1i, 2, 3].iter().map(|&x| x).collect(); + /// let sup: BTreeSet<int> = [1, 2, 3].iter().map(|&x| x).collect(); /// let mut set: BTreeSet<int> = BTreeSet::new(); /// /// assert_eq!(set.is_subset(&sup), true); @@ -411,7 +411,7 @@ impl<T: Ord> BTreeSet<T> { /// ``` /// use std::collections::BTreeSet; /// - /// let sub: BTreeSet<int> = [1i, 2].iter().map(|&x| x).collect(); + /// let sub: BTreeSet<int> = [1, 2].iter().map(|&x| x).collect(); /// let mut set: BTreeSet<int> = BTreeSet::new(); /// /// assert_eq!(set.is_superset(&sub), false); @@ -438,8 +438,8 @@ impl<T: Ord> BTreeSet<T> { /// /// let mut set = BTreeSet::new(); /// - /// assert_eq!(set.insert(2i), true); - /// assert_eq!(set.insert(2i), false); + /// assert_eq!(set.insert(2), true); + /// assert_eq!(set.insert(2), false); /// assert_eq!(set.len(), 1); /// ``` #[stable(feature = "rust1", since = "1.0.0")] @@ -461,7 +461,7 @@ impl<T: Ord> BTreeSet<T> { /// /// let mut set = BTreeSet::new(); /// - /// set.insert(2i); + /// set.insert(2); /// assert_eq!(set.remove(&2), true); /// assert_eq!(set.remove(&2), false); /// ``` @@ -480,6 +480,22 @@ impl<T: Ord> FromIterator<T> for BTreeSet<T> { } } +impl<T> IntoIterator for BTreeSet<T> { + type Iter = IntoIter<T>; + + fn into_iter(self) -> IntoIter<T> { + self.into_iter() + } +} + +impl<'a, T> IntoIterator for &'a BTreeSet<T> { + type Iter = Iter<'a, T>; + + fn into_iter(self) -> Iter<'a, T> { + self.iter() + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl<T: Ord> Extend<T> for BTreeSet<T> { #[inline] @@ -731,7 +747,7 @@ mod test { fn test_clone_eq() { let mut m = BTreeSet::new(); - m.insert(1i); + m.insert(1); m.insert(2); assert!(m.clone() == m); @@ -742,11 +758,11 @@ mod test { let mut x = BTreeSet::new(); let mut y = BTreeSet::new(); - x.insert(1i); + x.insert(1); x.insert(2); x.insert(3); - y.insert(3i); + y.insert(3); y.insert(2); y.insert(1); @@ -874,7 +890,7 @@ mod test { #[test] fn test_from_iter() { - let xs = [1i, 2, 3, 4, 5, 6, 7, 8, 9]; + let xs = [1, 2, 3, 4, 5, 6, 7, 8, 9]; let set: BTreeSet<int> = xs.iter().map(|&x| x).collect(); diff --git a/src/libcollections/dlist.rs b/src/libcollections/dlist.rs index aded4b8a7ac..911ed58b6ee 100644 --- a/src/libcollections/dlist.rs +++ b/src/libcollections/dlist.rs @@ -28,7 +28,7 @@ use core::cmp::Ordering; use core::default::Default; use core::fmt; use core::hash::{Writer, Hasher, Hash}; -use core::iter::{self, FromIterator}; +use core::iter::{self, FromIterator, IntoIterator}; use core::mem; use core::ptr; @@ -235,9 +235,9 @@ impl<T> DList<T> { /// /// let mut a = DList::new(); /// let mut b = DList::new(); - /// a.push_back(1i); + /// a.push_back(1); /// a.push_back(2); - /// b.push_back(3i); + /// b.push_back(3); /// b.push_back(4); /// /// a.append(&mut b); @@ -529,7 +529,7 @@ impl<T> DList<T> { /// use std::collections::DList; /// /// let mut d = DList::new(); - /// d.push_back(1i); + /// d.push_back(1); /// d.push_back(3); /// assert_eq!(3, *d.back().unwrap()); /// ``` @@ -548,7 +548,7 @@ impl<T> DList<T> { /// /// let mut d = DList::new(); /// assert_eq!(d.pop_back(), None); - /// d.push_back(1i); + /// d.push_back(1); /// d.push_back(3); /// assert_eq!(d.pop_back(), Some(3)); /// ``` @@ -766,7 +766,7 @@ impl<'a, A> IterMut<'a, A> { /// } /// { /// let vec: Vec<int> = list.into_iter().collect(); - /// assert_eq!(vec, vec![1i, 2, 3, 4]); + /// assert_eq!(vec, vec![1, 2, 3, 4]); /// } /// ``` #[inline] @@ -830,6 +830,30 @@ impl<A> FromIterator<A> for DList<A> { } } +impl<T> IntoIterator for DList<T> { + type Iter = IntoIter<T>; + + fn into_iter(self) -> IntoIter<T> { + self.into_iter() + } +} + +impl<'a, T> IntoIterator for &'a DList<T> { + type Iter = Iter<'a, T>; + + fn into_iter(self) -> Iter<'a, T> { + self.iter() + } +} + +impl<'a, T> IntoIterator for &'a mut DList<T> { + type Iter = IterMut<'a, T>; + + fn into_iter(mut self) -> IterMut<'a, T> { + self.iter_mut() + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl<A> Extend<A> for DList<A> { fn extend<T: Iterator<Item=A>>(&mut self, mut iterator: T) { @@ -964,7 +988,7 @@ mod tests { assert_eq!(m.pop_front(), Some(box 1)); let mut n = DList::new(); - n.push_front(2i); + n.push_front(2); n.push_front(3); { assert_eq!(n.front().unwrap(), &3); @@ -984,7 +1008,7 @@ mod tests { #[cfg(test)] fn generate_test() -> DList<int> { - list_from(&[0i,1,2,3,4,5,6]) + list_from(&[0,1,2,3,4,5,6]) } #[cfg(test)] @@ -1007,7 +1031,7 @@ mod tests { { let mut m = DList::new(); let mut n = DList::new(); - n.push_back(2i); + n.push_back(2); m.append(&mut n); check_links(&m); assert_eq!(m.len(), 1); @@ -1019,7 +1043,7 @@ mod tests { { let mut m = DList::new(); let mut n = DList::new(); - m.push_back(2i); + m.push_back(2); m.append(&mut n); check_links(&m); assert_eq!(m.len(), 1); @@ -1028,8 +1052,8 @@ mod tests { } // Non-empty to non-empty - let v = vec![1i,2,3,4,5]; - let u = vec![9i,8,1,2,3,4,5]; + let v = vec![1,2,3,4,5]; + let u = vec![9,8,1,2,3,4,5]; let mut m = list_from(v.as_slice()); let mut n = list_from(u.as_slice()); m.append(&mut n); @@ -1054,7 +1078,7 @@ mod tests { // singleton { let mut m = DList::new(); - m.push_back(1i); + m.push_back(1); let p = m.split_off(0); assert_eq!(m.len(), 0); @@ -1065,29 +1089,29 @@ mod tests { // not singleton, forwards { - let u = vec![1i,2,3,4,5]; + let u = vec![1,2,3,4,5]; let mut m = list_from(u.as_slice()); let mut n = m.split_off(2); assert_eq!(m.len(), 2); assert_eq!(n.len(), 3); - for elt in 1i..3 { + for elt in 1..3 { assert_eq!(m.pop_front(), Some(elt)); } - for elt in 3i..6 { + for elt in 3..6 { assert_eq!(n.pop_front(), Some(elt)); } } // not singleton, backwards { - let u = vec![1i,2,3,4,5]; + let u = vec![1,2,3,4,5]; let mut m = list_from(u.as_slice()); let mut n = m.split_off(4); assert_eq!(m.len(), 4); assert_eq!(n.len(), 1); - for elt in 1i..5 { + for elt in 1..5 { assert_eq!(m.pop_front(), Some(elt)); } - for elt in 5i..6 { + for elt in 5..6 { assert_eq!(n.pop_front(), Some(elt)); } } @@ -1102,7 +1126,7 @@ mod tests { } let mut n = DList::new(); assert_eq!(n.iter().next(), None); - n.push_front(4i); + n.push_front(4); let mut it = n.iter(); assert_eq!(it.size_hint(), (1, Some(1))); assert_eq!(it.next().unwrap(), &4); @@ -1113,7 +1137,7 @@ mod tests { #[test] fn test_iterator_clone() { let mut n = DList::new(); - n.push_back(2i); + n.push_back(2); n.push_back(3); n.push_back(4); let mut it = n.iter(); @@ -1128,7 +1152,7 @@ mod tests { fn test_iterator_double_end() { let mut n = DList::new(); assert_eq!(n.iter().next(), None); - n.push_front(4i); + n.push_front(4); n.push_front(5); n.push_front(6); let mut it = n.iter(); @@ -1150,7 +1174,7 @@ mod tests { } let mut n = DList::new(); assert_eq!(n.iter().rev().next(), None); - n.push_front(4i); + n.push_front(4); let mut it = n.iter().rev(); assert_eq!(it.size_hint(), (1, Some(1))); assert_eq!(it.next().unwrap(), &4); @@ -1169,7 +1193,7 @@ mod tests { assert_eq!(len, 0); let mut n = DList::new(); assert!(n.iter_mut().next().is_none()); - n.push_front(4i); + n.push_front(4); n.push_back(5); let mut it = n.iter_mut(); assert_eq!(it.size_hint(), (2, Some(2))); @@ -1183,7 +1207,7 @@ mod tests { fn test_iterator_mut_double_end() { let mut n = DList::new(); assert!(n.iter_mut().next_back().is_none()); - n.push_front(4i); + n.push_front(4); n.push_front(5); n.push_front(6); let mut it = n.iter_mut(); @@ -1199,7 +1223,7 @@ mod tests { #[test] fn test_insert_prev() { - let mut m = list_from(&[0i,2,4,6,8]); + let mut m = list_from(&[0,2,4,6,8]); let len = m.len(); { let mut it = m.iter_mut(); @@ -1232,7 +1256,7 @@ mod tests { } let mut n = DList::new(); assert!(n.iter_mut().rev().next().is_none()); - n.push_front(4i); + n.push_front(4); let mut it = n.iter_mut().rev(); assert!(it.next().is_some()); assert!(it.next().is_none()); @@ -1240,7 +1264,7 @@ mod tests { #[test] fn test_send() { - let n = list_from(&[1i,2,3]); + let n = list_from(&[1,2,3]); Thread::scoped(move || { check_links(&n); let a: &[_] = &[&1,&2,&3]; @@ -1258,8 +1282,8 @@ mod tests { m.push_back(1); assert!(n == m); - let n = list_from(&[2i,3,4]); - let m = list_from(&[1i,2,3]); + let n = list_from(&[2,3,4]); + let m = list_from(&[1,2,3]); assert!(n != m); } @@ -1270,11 +1294,11 @@ mod tests { assert!(hash::hash::<_, SipHasher>(&x) == hash::hash::<_, SipHasher>(&y)); - x.push_back(1i); + x.push_back(1); x.push_back(2); x.push_back(3); - y.push_front(3i); + y.push_front(3); y.push_front(2); y.push_front(1); @@ -1284,7 +1308,7 @@ mod tests { #[test] fn test_ord() { let n: DList<int> = list_from(&[]); - let m = list_from(&[1i,2,3]); + let m = list_from(&[1,2,3]); assert!(n < m); assert!(m > n); assert!(n <= n); @@ -1334,7 +1358,7 @@ mod tests { #[test] fn test_show() { - let list: DList<int> = (0i..10).collect(); + let list: DList<i32> = (0..10).collect(); assert_eq!(format!("{:?}", list), "DList [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"); let list: DList<&str> = vec!["just", "one", "test", "more"].iter() @@ -1384,7 +1408,7 @@ mod tests { #[bench] fn bench_collect_into(b: &mut test::Bencher) { - let v = &[0i; 64]; + let v = &[0; 64]; b.iter(|| { let _: DList<int> = v.iter().map(|x| *x).collect(); }) @@ -1426,7 +1450,7 @@ mod tests { #[bench] fn bench_iter(b: &mut test::Bencher) { - let v = &[0i; 128]; + let v = &[0; 128]; let m: DList<int> = v.iter().map(|&x|x).collect(); b.iter(|| { assert!(m.iter().count() == 128); @@ -1434,7 +1458,7 @@ mod tests { } #[bench] fn bench_iter_mut(b: &mut test::Bencher) { - let v = &[0i; 128]; + let v = &[0; 128]; let mut m: DList<int> = v.iter().map(|&x|x).collect(); b.iter(|| { assert!(m.iter_mut().count() == 128); @@ -1442,7 +1466,7 @@ mod tests { } #[bench] fn bench_iter_rev(b: &mut test::Bencher) { - let v = &[0i; 128]; + let v = &[0; 128]; let m: DList<int> = v.iter().map(|&x|x).collect(); b.iter(|| { assert!(m.iter().rev().count() == 128); @@ -1450,7 +1474,7 @@ mod tests { } #[bench] fn bench_iter_mut_rev(b: &mut test::Bencher) { - let v = &[0i; 128]; + let v = &[0; 128]; let mut m: DList<int> = v.iter().map(|&x|x).collect(); b.iter(|| { assert!(m.iter_mut().rev().count() == 128); diff --git a/src/libcollections/enum_set.rs b/src/libcollections/enum_set.rs index b542259eba0..9765bb5875e 100644 --- a/src/libcollections/enum_set.rs +++ b/src/libcollections/enum_set.rs @@ -16,7 +16,7 @@ use core::prelude::*; use core::fmt; use core::num::Int; -use core::iter::FromIterator; +use core::iter::{FromIterator, IntoIterator}; use core::ops::{Sub, BitOr, BitAnd, BitXor}; // FIXME(contentions): implement union family of methods? (general design may be wrong here) @@ -31,6 +31,7 @@ pub struct EnumSet<E> { impl<E> Copy for EnumSet<E> {} +#[stable(feature = "rust1", since = "1.0.0")] impl<E:CLike + fmt::Debug> fmt::Debug for EnumSet<E> { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { try!(write!(fmt, "EnumSet {{")); @@ -256,6 +257,14 @@ impl<E:CLike> FromIterator<E> for EnumSet<E> { } } +impl<'a, E> IntoIterator for &'a EnumSet<E> where E: CLike { + type Iter = Iter<E>; + + fn into_iter(self) -> Iter<E> { + self.iter() + } +} + impl<E:CLike> Extend<E> for EnumSet<E> { fn extend<I: Iterator<Item=E>>(&mut self, mut iterator: I) { for element in iterator { diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs index 82b92d26d28..ce00bd48bb8 100644 --- a/src/libcollections/lib.rs +++ b/src/libcollections/lib.rs @@ -15,7 +15,6 @@ #![crate_name = "collections"] #![unstable(feature = "collections")] -#![feature(staged_api)] #![staged_api] #![crate_type = "rlib"] #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", @@ -23,18 +22,21 @@ html_root_url = "http://doc.rust-lang.org/nightly/", html_playground_url = "http://play.rust-lang.org/")] -#![allow(unknown_features)] -#![feature(unsafe_destructor, slicing_syntax)] +#![cfg_attr(not(stage0), allow(unused_mut))] // NOTE: remove after stage0 snap + +#![feature(alloc)] #![feature(box_syntax)] -#![feature(unboxed_closures)] -#![allow(unknown_features)] #![feature(int_uint)] -#![no_std] #![feature(core)] -#![feature(alloc)] -#![feature(unicode)] #![feature(hash)] +#![feature(int_uint)] +#![feature(staged_api)] +#![feature(unboxed_closures)] +#![feature(unicode)] +#![feature(unsafe_destructor, slicing_syntax)] #![cfg_attr(test, feature(test))] +#![no_std] + #[macro_use] extern crate core; @@ -114,6 +116,8 @@ mod std { pub use core::marker; // derive(Copy) pub use core::hash; // derive(Hash) pub use core::ops; // RangeFull + // for-loops + pub use core::iter; } #[cfg(test)] diff --git a/src/libcollections/ring_buf.rs b/src/libcollections/ring_buf.rs index 34910f59fe0..7032a3d9137 100644 --- a/src/libcollections/ring_buf.rs +++ b/src/libcollections/ring_buf.rs @@ -19,7 +19,7 @@ use core::prelude::*; use core::cmp::Ordering; use core::default::Default; use core::fmt; -use core::iter::{self, repeat, FromIterator, RandomAccessIterator}; +use core::iter::{self, repeat, FromIterator, IntoIterator, RandomAccessIterator}; use core::marker; use core::mem; use core::num::{Int, UnsignedInt}; @@ -186,7 +186,7 @@ impl<T> RingBuf<T> { /// use std::collections::RingBuf; /// /// let mut buf = RingBuf::new(); - /// buf.push_back(3i); + /// buf.push_back(3); /// buf.push_back(4); /// buf.push_back(5); /// assert_eq!(buf.get(1).unwrap(), &4); @@ -209,7 +209,7 @@ impl<T> RingBuf<T> { /// use std::collections::RingBuf; /// /// let mut buf = RingBuf::new(); - /// buf.push_back(3i); + /// buf.push_back(3); /// buf.push_back(4); /// buf.push_back(5); /// match buf.get_mut(1) { @@ -243,7 +243,7 @@ impl<T> RingBuf<T> { /// use std::collections::RingBuf; /// /// let mut buf = RingBuf::new(); - /// buf.push_back(3i); + /// buf.push_back(3); /// buf.push_back(4); /// buf.push_back(5); /// buf.swap(0, 2); @@ -269,7 +269,7 @@ impl<T> RingBuf<T> { /// ``` /// use std::collections::RingBuf; /// - /// let buf: RingBuf<int> = RingBuf::with_capacity(10); + /// let buf: RingBuf<i32> = RingBuf::with_capacity(10); /// assert!(buf.capacity() >= 10); /// ``` #[inline] @@ -292,7 +292,7 @@ impl<T> RingBuf<T> { /// ``` /// use std::collections::RingBuf; /// - /// let mut buf: RingBuf<int> = vec![1].into_iter().collect(); + /// let mut buf: RingBuf<i32> = vec![1].into_iter().collect(); /// buf.reserve_exact(10); /// assert!(buf.capacity() >= 11); /// ``` @@ -313,7 +313,7 @@ impl<T> RingBuf<T> { /// ``` /// use std::collections::RingBuf; /// - /// let mut buf: RingBuf<int> = vec![1].into_iter().collect(); + /// let mut buf: RingBuf<i32> = vec![1].into_iter().collect(); /// buf.reserve(10); /// assert!(buf.capacity() >= 11); /// ``` @@ -473,8 +473,8 @@ impl<T> RingBuf<T> { /// use std::collections::RingBuf; /// /// let mut buf = RingBuf::new(); - /// buf.push_back(5i); - /// buf.push_back(10i); + /// buf.push_back(5); + /// buf.push_back(10); /// buf.push_back(15); /// buf.truncate(1); /// assert_eq!(buf.len(), 1); @@ -496,11 +496,11 @@ impl<T> RingBuf<T> { /// use std::collections::RingBuf; /// /// let mut buf = RingBuf::new(); - /// buf.push_back(5i); + /// buf.push_back(5); /// buf.push_back(3); /// buf.push_back(4); /// let b: &[_] = &[&5, &3, &4]; - /// assert_eq!(buf.iter().collect::<Vec<&int>>().as_slice(), b); + /// assert_eq!(buf.iter().collect::<Vec<&i32>>().as_slice(), b); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn iter(&self) -> Iter<T> { @@ -519,14 +519,14 @@ impl<T> RingBuf<T> { /// use std::collections::RingBuf; /// /// let mut buf = RingBuf::new(); - /// buf.push_back(5i); + /// buf.push_back(5); /// buf.push_back(3); /// buf.push_back(4); /// for num in buf.iter_mut() { /// *num = *num - 2; /// } /// let b: &[_] = &[&mut 3, &mut 1, &mut 2]; - /// assert_eq!(&buf.iter_mut().collect::<Vec<&mut int>>()[], b); + /// assert_eq!(&buf.iter_mut().collect::<Vec<&mut i32>>()[], b); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn iter_mut<'a>(&'a mut self) -> IterMut<'a, T> { @@ -600,7 +600,7 @@ impl<T> RingBuf<T> { /// /// let mut v = RingBuf::new(); /// assert_eq!(v.len(), 0); - /// v.push_back(1i); + /// v.push_back(1); /// assert_eq!(v.len(), 1); /// ``` #[stable(feature = "rust1", since = "1.0.0")] @@ -615,7 +615,7 @@ impl<T> RingBuf<T> { /// /// let mut v = RingBuf::new(); /// assert!(v.is_empty()); - /// v.push_front(1i); + /// v.push_front(1); /// assert!(!v.is_empty()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] @@ -630,7 +630,7 @@ impl<T> RingBuf<T> { /// use std::collections::RingBuf; /// /// let mut v = RingBuf::new(); - /// v.push_back(1i); + /// v.push_back(1); /// assert_eq!(v.drain().next(), Some(1)); /// assert!(v.is_empty()); /// ``` @@ -651,7 +651,7 @@ impl<T> RingBuf<T> { /// use std::collections::RingBuf; /// /// let mut v = RingBuf::new(); - /// v.push_back(1i); + /// v.push_back(1); /// v.clear(); /// assert!(v.is_empty()); /// ``` @@ -672,9 +672,9 @@ impl<T> RingBuf<T> { /// let mut d = RingBuf::new(); /// assert_eq!(d.front(), None); /// - /// d.push_back(1i); - /// d.push_back(2i); - /// assert_eq!(d.front(), Some(&1i)); + /// d.push_back(1); + /// d.push_back(2); + /// assert_eq!(d.front(), Some(&1)); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn front(&self) -> Option<&T> { @@ -692,13 +692,13 @@ impl<T> RingBuf<T> { /// let mut d = RingBuf::new(); /// assert_eq!(d.front_mut(), None); /// - /// d.push_back(1i); - /// d.push_back(2i); + /// d.push_back(1); + /// d.push_back(2); /// match d.front_mut() { - /// Some(x) => *x = 9i, + /// Some(x) => *x = 9, /// None => (), /// } - /// assert_eq!(d.front(), Some(&9i)); + /// assert_eq!(d.front(), Some(&9)); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn front_mut(&mut self) -> Option<&mut T> { @@ -716,9 +716,9 @@ impl<T> RingBuf<T> { /// let mut d = RingBuf::new(); /// assert_eq!(d.back(), None); /// - /// d.push_back(1i); - /// d.push_back(2i); - /// assert_eq!(d.back(), Some(&2i)); + /// d.push_back(1); + /// d.push_back(2); + /// assert_eq!(d.back(), Some(&2)); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn back(&self) -> Option<&T> { @@ -736,13 +736,13 @@ impl<T> RingBuf<T> { /// let mut d = RingBuf::new(); /// assert_eq!(d.back(), None); /// - /// d.push_back(1i); - /// d.push_back(2i); + /// d.push_back(1); + /// d.push_back(2); /// match d.back_mut() { - /// Some(x) => *x = 9i, + /// Some(x) => *x = 9, /// None => (), /// } - /// assert_eq!(d.back(), Some(&9i)); + /// assert_eq!(d.back(), Some(&9)); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn back_mut(&mut self) -> Option<&mut T> { @@ -759,11 +759,11 @@ impl<T> RingBuf<T> { /// use std::collections::RingBuf; /// /// let mut d = RingBuf::new(); - /// d.push_back(1i); - /// d.push_back(2i); + /// d.push_back(1); + /// d.push_back(2); /// - /// assert_eq!(d.pop_front(), Some(1i)); - /// assert_eq!(d.pop_front(), Some(2i)); + /// assert_eq!(d.pop_front(), Some(1)); + /// assert_eq!(d.pop_front(), Some(2)); /// assert_eq!(d.pop_front(), None); /// ``` #[stable(feature = "rust1", since = "1.0.0")] @@ -785,9 +785,9 @@ impl<T> RingBuf<T> { /// use std::collections::RingBuf; /// /// let mut d = RingBuf::new(); - /// d.push_front(1i); - /// d.push_front(2i); - /// assert_eq!(d.front(), Some(&2i)); + /// d.push_front(1); + /// d.push_front(2); + /// assert_eq!(d.front(), Some(&2)); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn push_front(&mut self, t: T) { @@ -809,7 +809,7 @@ impl<T> RingBuf<T> { /// use std::collections::RingBuf; /// /// let mut buf = RingBuf::new(); - /// buf.push_back(1i); + /// buf.push_back(1); /// buf.push_back(3); /// assert_eq!(3, *buf.back().unwrap()); /// ``` @@ -835,7 +835,7 @@ impl<T> RingBuf<T> { /// /// let mut buf = RingBuf::new(); /// assert_eq!(buf.pop_back(), None); - /// buf.push_back(1i); + /// buf.push_back(1); /// buf.push_back(3); /// assert_eq!(buf.pop_back(), Some(3)); /// ``` @@ -869,7 +869,7 @@ impl<T> RingBuf<T> { /// /// let mut buf = RingBuf::new(); /// assert_eq!(buf.swap_back_remove(0), None); - /// buf.push_back(5i); + /// buf.push_back(5); /// buf.push_back(99); /// buf.push_back(15); /// buf.push_back(20); @@ -902,11 +902,11 @@ impl<T> RingBuf<T> { /// /// let mut buf = RingBuf::new(); /// assert_eq!(buf.swap_front_remove(0), None); - /// buf.push_back(15i); + /// buf.push_back(15); /// buf.push_back(5); /// buf.push_back(10); /// buf.push_back(99); - /// buf.push_back(20i); + /// buf.push_back(20); /// assert_eq!(buf.swap_front_remove(3), Some(99)); /// ``` #[unstable(feature = "collections", @@ -934,7 +934,7 @@ impl<T> RingBuf<T> { /// use std::collections::RingBuf; /// /// let mut buf = RingBuf::new(); - /// buf.push_back(10i); + /// buf.push_back(10); /// buf.push_back(12); /// buf.insert(1,11); /// assert_eq!(Some(&11), buf.get(1)); @@ -1136,9 +1136,9 @@ impl<T> RingBuf<T> { /// use std::collections::RingBuf; /// /// let mut buf = RingBuf::new(); - /// buf.push_back(5i); - /// buf.push_back(10i); - /// buf.push_back(12i); + /// buf.push_back(5); + /// buf.push_back(10); + /// buf.push_back(12); /// buf.push_back(15); /// buf.remove(2); /// assert_eq!(Some(&15), buf.get(2)); @@ -1301,8 +1301,8 @@ impl<T: Clone> RingBuf<T> { /// use std::collections::RingBuf; /// /// let mut buf = RingBuf::new(); - /// buf.push_back(5i); - /// buf.push_back(10i); + /// buf.push_back(5); + /// buf.push_back(10); /// buf.push_back(15); /// buf.resize(2, 0); /// buf.resize(6, 20); @@ -1510,7 +1510,7 @@ pub struct Drain<'a, T: 'a> { #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T: 'a> Drop for Drain<'a, T> { fn drop(&mut self) { - for _ in *self {} + for _ in self.by_ref() {} self.inner.head = 0; self.inner.tail = 0; } @@ -1609,6 +1609,30 @@ impl<A> FromIterator<A> for RingBuf<A> { } } +impl<T> IntoIterator for RingBuf<T> { + type Iter = IntoIter<T>; + + fn into_iter(self) -> IntoIter<T> { + self.into_iter() + } +} + +impl<'a, T> IntoIterator for &'a RingBuf<T> { + type Iter = Iter<'a, T>; + + fn into_iter(self) -> Iter<'a, T> { + self.iter() + } +} + +impl<'a, T> IntoIterator for &'a mut RingBuf<T> { + type Iter = IterMut<'a, T>; + + fn into_iter(mut self) -> IterMut<'a, T> { + self.iter_mut() + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl<A> Extend<A> for RingBuf<A> { fn extend<T: Iterator<Item=A>>(&mut self, mut iterator: T) { @@ -1650,8 +1674,8 @@ mod tests { fn test_simple() { let mut d = RingBuf::new(); assert_eq!(d.len(), 0u); - d.push_front(17i); - d.push_front(42i); + d.push_front(17); + d.push_front(42); d.push_back(137); assert_eq!(d.len(), 3u); d.push_back(137); @@ -1769,7 +1793,7 @@ mod tests { fn bench_push_back_100(b: &mut test::Bencher) { let mut deq = RingBuf::with_capacity(101); b.iter(|| { - for i in 0i..100 { + for i in 0..100 { deq.push_back(i); } deq.head = 0; @@ -1781,7 +1805,7 @@ mod tests { fn bench_push_front_100(b: &mut test::Bencher) { let mut deq = RingBuf::with_capacity(101); b.iter(|| { - for i in 0i..100 { + for i in 0..100 { deq.push_front(i); } deq.head = 0; @@ -1791,7 +1815,7 @@ mod tests { #[bench] fn bench_pop_back_100(b: &mut test::Bencher) { - let mut deq: RingBuf<int> = RingBuf::with_capacity(101); + let mut deq: RingBuf<i32> = RingBuf::with_capacity(101); b.iter(|| { deq.head = 100; @@ -1804,7 +1828,7 @@ mod tests { #[bench] fn bench_pop_front_100(b: &mut test::Bencher) { - let mut deq: RingBuf<int> = RingBuf::with_capacity(101); + let mut deq: RingBuf<i32> = RingBuf::with_capacity(101); b.iter(|| { deq.head = 100; @@ -1819,7 +1843,7 @@ mod tests { fn bench_grow_1025(b: &mut test::Bencher) { b.iter(|| { let mut deq = RingBuf::new(); - for i in 0i..1025 { + for i in 0..1025 { deq.push_front(i); } test::black_box(deq); @@ -1828,7 +1852,7 @@ mod tests { #[bench] fn bench_iter_1000(b: &mut test::Bencher) { - let ring: RingBuf<int> = (0i..1000).collect(); + let ring: RingBuf<i32> = (0..1000).collect(); b.iter(|| { let mut sum = 0; @@ -1841,7 +1865,7 @@ mod tests { #[bench] fn bench_mut_iter_1000(b: &mut test::Bencher) { - let mut ring: RingBuf<int> = (0i..1000).collect(); + let mut ring: RingBuf<i32> = (0..1000).collect(); b.iter(|| { let mut sum = 0; @@ -1854,28 +1878,28 @@ mod tests { #[derive(Clone, PartialEq, Debug)] enum Taggy { - One(int), - Two(int, int), - Three(int, int, int), + One(i32), + Two(i32, i32), + Three(i32, i32, i32), } #[derive(Clone, PartialEq, Debug)] enum Taggypar<T> { - Onepar(int), - Twopar(int, int), - Threepar(int, int, int), + Onepar(i32), + Twopar(i32, i32), + Threepar(i32, i32, i32), } #[derive(Clone, PartialEq, Debug)] struct RecCy { - x: int, - y: int, + x: i32, + y: i32, t: Taggy } #[test] fn test_param_int() { - test_parameterized::<int>(5, 72, 64, 175); + test_parameterized::<i32>(5, 72, 64, 175); } #[test] @@ -1885,10 +1909,10 @@ mod tests { #[test] fn test_param_taggypar() { - test_parameterized::<Taggypar<int>>(Onepar::<int>(1), - Twopar::<int>(1, 2), - Threepar::<int>(1, 2, 3), - Twopar::<int>(17, 42)); + test_parameterized::<Taggypar<i32>>(Onepar::<i32>(1), + Twopar::<i32>(1, 2), + Threepar::<i32>(1, 2, 3), + Twopar::<i32>(17, 42)); } #[test] @@ -1903,17 +1927,17 @@ mod tests { #[test] fn test_with_capacity() { let mut d = RingBuf::with_capacity(0); - d.push_back(1i); + d.push_back(1); assert_eq!(d.len(), 1); let mut d = RingBuf::with_capacity(50); - d.push_back(1i); + d.push_back(1); assert_eq!(d.len(), 1); } #[test] fn test_with_capacity_non_power_two() { let mut d3 = RingBuf::with_capacity(3); - d3.push_back(1i); + d3.push_back(1); // X = None, | = lo // [|1, X, X] @@ -1977,10 +2001,10 @@ mod tests { #[test] fn test_swap() { - let mut d: RingBuf<int> = (0i..5).collect(); + let mut d: RingBuf<i32> = (0..5).collect(); d.pop_front(); d.swap(0, 3); - assert_eq!(d.iter().map(|&x|x).collect::<Vec<int>>(), vec!(4, 2, 3, 1)); + assert_eq!(d.iter().map(|&x|x).collect::<Vec<i32>>(), vec!(4, 2, 3, 1)); } #[test] @@ -1989,20 +2013,20 @@ mod tests { assert_eq!(d.iter().next(), None); assert_eq!(d.iter().size_hint(), (0, Some(0))); - for i in 0i..5 { + for i in 0..5 { d.push_back(i); } { let b: &[_] = &[&0,&1,&2,&3,&4]; - assert_eq!(d.iter().collect::<Vec<&int>>(), b); + assert_eq!(d.iter().collect::<Vec<&i32>>(), b); } - for i in 6i..9 { + for i in 6..9 { d.push_front(i); } { let b: &[_] = &[&8,&7,&6,&0,&1,&2,&3,&4]; - assert_eq!(d.iter().collect::<Vec<&int>>(), b); + assert_eq!(d.iter().collect::<Vec<&i32>>(), b); } let mut it = d.iter(); @@ -2020,19 +2044,19 @@ mod tests { let mut d = RingBuf::new(); assert_eq!(d.iter().rev().next(), None); - for i in 0i..5 { + for i in 0..5 { d.push_back(i); } { let b: &[_] = &[&4,&3,&2,&1,&0]; - assert_eq!(d.iter().rev().collect::<Vec<&int>>(), b); + assert_eq!(d.iter().rev().collect::<Vec<&i32>>(), b); } - for i in 6i..9 { + for i in 6..9 { d.push_front(i); } let b: &[_] = &[&4,&3,&2,&1,&0,&6,&7,&8]; - assert_eq!(d.iter().rev().collect::<Vec<&int>>(), b); + assert_eq!(d.iter().rev().collect::<Vec<&i32>>(), b); } #[test] @@ -2040,13 +2064,13 @@ mod tests { let mut d = RingBuf::with_capacity(3); assert!(d.iter_mut().rev().next().is_none()); - d.push_back(1i); + d.push_back(1); d.push_back(2); d.push_back(3); assert_eq!(d.pop_front(), Some(1)); d.push_back(4); - assert_eq!(d.iter_mut().rev().map(|x| *x).collect::<Vec<int>>(), + assert_eq!(d.iter_mut().rev().map(|x| *x).collect::<Vec<i32>>(), vec!(4, 3, 2)); } @@ -2101,7 +2125,7 @@ mod tests { // Empty iter { - let d: RingBuf<int> = RingBuf::new(); + let d: RingBuf<i32> = RingBuf::new(); let mut iter = d.into_iter(); assert_eq!(iter.size_hint(), (0, Some(0))); @@ -2112,35 +2136,35 @@ mod tests { // simple iter { let mut d = RingBuf::new(); - for i in 0i..5 { + for i in 0..5 { d.push_back(i); } let b = vec![0,1,2,3,4]; - assert_eq!(d.into_iter().collect::<Vec<int>>(), b); + assert_eq!(d.into_iter().collect::<Vec<i32>>(), b); } // wrapped iter { let mut d = RingBuf::new(); - for i in 0i..5 { + for i in 0..5 { d.push_back(i); } - for i in 6i..9 { + for i in 6..9 { d.push_front(i); } let b = vec![8,7,6,0,1,2,3,4]; - assert_eq!(d.into_iter().collect::<Vec<int>>(), b); + assert_eq!(d.into_iter().collect::<Vec<i32>>(), b); } // partially used { let mut d = RingBuf::new(); - for i in 0i..5 { + for i in 0..5 { d.push_back(i); } - for i in 6i..9 { + for i in 6..9 { d.push_front(i); } @@ -2160,7 +2184,7 @@ mod tests { // Empty iter { - let mut d: RingBuf<int> = RingBuf::new(); + let mut d: RingBuf<i32> = RingBuf::new(); { let mut iter = d.drain(); @@ -2176,35 +2200,35 @@ mod tests { // simple iter { let mut d = RingBuf::new(); - for i in 0i..5 { + for i in 0..5 { d.push_back(i); } - assert_eq!(d.drain().collect::<Vec<int>>(), [0, 1, 2, 3, 4]); + assert_eq!(d.drain().collect::<Vec<_>>(), [0, 1, 2, 3, 4]); assert!(d.is_empty()); } // wrapped iter { let mut d = RingBuf::new(); - for i in 0i..5 { + for i in 0..5 { d.push_back(i); } - for i in 6i..9 { + for i in 6..9 { d.push_front(i); } - assert_eq!(d.drain().collect::<Vec<int>>(), [8,7,6,0,1,2,3,4]); + assert_eq!(d.drain().collect::<Vec<_>>(), [8,7,6,0,1,2,3,4]); assert!(d.is_empty()); } // partially used { - let mut d = RingBuf::new(); - for i in 0i..5 { + let mut d: RingBuf<i32> = RingBuf::new(); + for i in 0..5 { d.push_back(i); } - for i in 6i..9 { + for i in 6..9 { d.push_front(i); } @@ -2225,9 +2249,9 @@ mod tests { #[test] fn test_from_iter() { use core::iter; - let v = vec!(1i,2,3,4,5,6,7); - let deq: RingBuf<int> = v.iter().map(|&x| x).collect(); - let u: Vec<int> = deq.iter().map(|&x| x).collect(); + let v = vec!(1,2,3,4,5,6,7); + let deq: RingBuf<i32> = v.iter().map(|&x| x).collect(); + let u: Vec<i32> = deq.iter().map(|&x| x).collect(); assert_eq!(u, v); let seq = iter::count(0u, 2).take(256); @@ -2241,7 +2265,7 @@ mod tests { #[test] fn test_clone() { let mut d = RingBuf::new(); - d.push_front(17i); + d.push_front(17); d.push_front(42); d.push_back(137); d.push_back(137); @@ -2259,7 +2283,7 @@ mod tests { fn test_eq() { let mut d = RingBuf::new(); assert!(d == RingBuf::with_capacity(0)); - d.push_front(137i); + d.push_front(137); d.push_front(17); d.push_front(42); d.push_back(137); @@ -2281,12 +2305,12 @@ mod tests { let mut x = RingBuf::new(); let mut y = RingBuf::new(); - x.push_back(1i); + x.push_back(1); x.push_back(2); x.push_back(3); - y.push_back(0i); - y.push_back(1i); + y.push_back(0); + y.push_back(1); y.pop_front(); y.push_back(2); y.push_back(3); @@ -2298,7 +2322,7 @@ mod tests { fn test_ord() { let x = RingBuf::new(); let mut y = RingBuf::new(); - y.push_back(1i); + y.push_back(1); y.push_back(2); y.push_back(3); assert!(x < y); @@ -2309,7 +2333,7 @@ mod tests { #[test] fn test_show() { - let ringbuf: RingBuf<int> = (0i..10).collect(); + let ringbuf: RingBuf<i32> = (0..10).collect(); assert_eq!(format!("{:?}", ringbuf), "RingBuf [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"); let ringbuf: RingBuf<&str> = vec!["just", "one", "test", "more"].iter() @@ -2389,41 +2413,41 @@ mod tests { // test growth path A // [T o o H] -> [T o o H . . . . ] let mut ring = RingBuf::with_capacity(4); - for i in 0i..3 { + for i in 0..3 { ring.push_back(i); } ring.reserve(7); - for i in 0i..3 { + for i in 0..3 { assert_eq!(ring.pop_front(), Some(i)); } // test growth path B // [H T o o] -> [. T o o H . . . ] let mut ring = RingBuf::with_capacity(4); - for i in 0i..1 { + for i in 0..1 { ring.push_back(i); assert_eq!(ring.pop_front(), Some(i)); } - for i in 0i..3 { + for i in 0..3 { ring.push_back(i); } ring.reserve(7); - for i in 0i..3 { + for i in 0..3 { assert_eq!(ring.pop_front(), Some(i)); } // test growth path C // [o o H T] -> [o o H . . . . T ] let mut ring = RingBuf::with_capacity(4); - for i in 0i..3 { + for i in 0..3 { ring.push_back(i); assert_eq!(ring.pop_front(), Some(i)); } - for i in 0i..3 { + for i in 0..3 { ring.push_back(i); } ring.reserve(7); - for i in 0i..3 { + for i in 0..3 { assert_eq!(ring.pop_front(), Some(i)); } } @@ -2431,7 +2455,7 @@ mod tests { #[test] fn test_get() { let mut ring = RingBuf::new(); - ring.push_back(0i); + ring.push_back(0); assert_eq!(ring.get(0), Some(&0)); assert_eq!(ring.get(1), None); @@ -2463,7 +2487,7 @@ mod tests { #[test] fn test_get_mut() { let mut ring = RingBuf::new(); - for i in 0i..3 { + for i in 0..3 { ring.push_back(i); } @@ -2633,8 +2657,8 @@ mod tests { #[test] fn test_front() { let mut ring = RingBuf::new(); - ring.push_back(10i); - ring.push_back(20i); + ring.push_back(10); + ring.push_back(20); assert_eq!(ring.front(), Some(&10)); ring.pop_front(); assert_eq!(ring.front(), Some(&20)); @@ -2644,8 +2668,8 @@ mod tests { #[test] fn test_as_slices() { - let mut ring: RingBuf<int> = RingBuf::with_capacity(127); - let cap = ring.capacity() as int; + let mut ring: RingBuf<i32> = RingBuf::with_capacity(127); + let cap = ring.capacity() as i32; let first = cap/2; let last = cap - first; for i in 0..first { @@ -2666,14 +2690,14 @@ mod tests { assert_eq!(right, expected_right); } - assert_eq!(ring.len() as int, cap); - assert_eq!(ring.capacity() as int, cap); + assert_eq!(ring.len() as i32, cap); + assert_eq!(ring.capacity() as i32, cap); } #[test] fn test_as_mut_slices() { - let mut ring: RingBuf<int> = RingBuf::with_capacity(127); - let cap = ring.capacity() as int; + let mut ring: RingBuf<i32> = RingBuf::with_capacity(127); + let cap = ring.capacity() as i32; let first = cap/2; let last = cap - first; for i in 0..first { @@ -2694,7 +2718,7 @@ mod tests { assert_eq!(right, expected_right); } - assert_eq!(ring.len() as int, cap); - assert_eq!(ring.capacity() as int, cap); + assert_eq!(ring.len() as i32, cap); + assert_eq!(ring.capacity() as i32, cap); } } diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 56d969b8946..d2f92d1c8db 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -15,7 +15,7 @@ //! //! ```rust //! // slicing a Vec -//! let vec = vec!(1i, 2, 3); +//! let vec = vec!(1, 2, 3); //! let int_slice = vec.as_slice(); //! // coercing an array to a slice //! let str_slice: &[&str] = &["one", "two", "three"]; @@ -26,7 +26,7 @@ //! block of memory that a mutable slice points to: //! //! ```rust -//! let x: &mut[int] = &mut [1i, 2, 3]; +//! let x: &mut[int] = &mut [1, 2, 3]; //! x[1] = 7; //! assert_eq!(x[0], 1); //! assert_eq!(x[1], 7); @@ -54,9 +54,9 @@ //! ```rust //! #![feature(slicing_syntax)] //! fn main() { -//! let numbers = [0i, 1i, 2i]; +//! let numbers = [0, 1, 2]; //! let last_numbers = &numbers[1..3]; -//! // last_numbers is now &[1i, 2i] +//! // last_numbers is now &[1, 2] //! } //! ``` //! @@ -76,7 +76,7 @@ //! type of the slice is `int`, the element type of the iterator is `&int`. //! //! ```rust -//! let numbers = [0i, 1i, 2i]; +//! let numbers = [0, 1, 2]; //! for &x in numbers.iter() { //! println!("{} is a number!", x); //! } @@ -137,7 +137,7 @@ pub trait SliceExt { /// # Examples /// /// ```rust - /// let mut v = [5i, 4, 1, 3, 2]; + /// let mut v = [5, 4, 1, 3, 2]; /// v.sort_by(|a, b| a.cmp(b)); /// assert!(v == [1, 2, 3, 4, 5]); /// @@ -163,11 +163,11 @@ pub trait SliceExt { /// # Examples /// /// ```rust - /// let mut a = [1i, 2, 3, 4, 5]; - /// let b = vec![6i, 7, 8]; + /// let mut a = [1, 2, 3, 4, 5]; + /// let b = vec![6, 7, 8]; /// let num_moved = a.move_from(b, 0, 3); /// assert_eq!(num_moved, 3); - /// assert!(a == [6i, 7, 8, 4, 5]); + /// assert!(a == [6, 7, 8, 4, 5]); /// ``` #[unstable(feature = "collections", reason = "uncertain about this API approach")] @@ -285,7 +285,7 @@ pub trait SliceExt { /// `[3,4]`): /// /// ```rust - /// let v = &[1i, 2, 3, 4]; + /// let v = &[1, 2, 3, 4]; /// for win in v.windows(2) { /// println!("{:?}", win); /// } @@ -308,7 +308,7 @@ pub trait SliceExt { /// `[3,4]`, `[5]`): /// /// ```rust - /// let v = &[1i, 2, 3, 4, 5]; + /// let v = &[1, 2, 3, 4, 5]; /// for win in v.chunks(2) { /// println!("{:?}", win); /// } @@ -399,7 +399,7 @@ pub trait SliceExt { /// found; the fourth could match any position in `[1,4]`. /// /// ```rust - /// let s = [0i, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]; + /// let s = [0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]; /// let s = s.as_slice(); /// /// let seek = 13; @@ -421,7 +421,7 @@ pub trait SliceExt { /// # Example /// /// ``` - /// let a = [1i, 2, 3]; + /// let a = [1, 2, 3]; /// assert_eq!(a.len(), 3); /// ``` #[stable(feature = "rust1", since = "1.0.0")] @@ -432,7 +432,7 @@ pub trait SliceExt { /// # Example /// /// ``` - /// let a = [1i, 2, 3]; + /// let a = [1, 2, 3]; /// assert!(!a.is_empty()); /// ``` #[inline] @@ -554,24 +554,24 @@ pub trait SliceExt { /// # Example /// /// ```rust - /// let mut v = [1i, 2, 3, 4, 5, 6]; + /// let mut v = [1, 2, 3, 4, 5, 6]; /// /// // scoped to restrict the lifetime of the borrows /// { /// let (left, right) = v.split_at_mut(0); /// assert!(left == []); - /// assert!(right == [1i, 2, 3, 4, 5, 6]); + /// assert!(right == [1, 2, 3, 4, 5, 6]); /// } /// /// { /// let (left, right) = v.split_at_mut(2); - /// assert!(left == [1i, 2]); - /// assert!(right == [3i, 4, 5, 6]); + /// assert!(left == [1, 2]); + /// assert!(right == [3, 4, 5, 6]); /// } /// /// { /// let (left, right) = v.split_at_mut(6); - /// assert!(left == [1i, 2, 3, 4, 5, 6]); + /// assert!(left == [1, 2, 3, 4, 5, 6]); /// assert!(right == []); /// } /// ``` @@ -583,9 +583,9 @@ pub trait SliceExt { /// # Example /// /// ```rust - /// let mut v = [1i, 2, 3]; + /// let mut v = [1, 2, 3]; /// v.reverse(); - /// assert!(v == [3i, 2, 1]); + /// assert!(v == [3, 2, 1]); /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn reverse(&mut self); @@ -615,7 +615,7 @@ pub trait SliceExt { /// # Examples /// /// ```rust - /// let v = [1i, 2, 3]; + /// let v = [1, 2, 3]; /// let mut perms = v.permutations(); /// /// for p in perms { @@ -626,12 +626,12 @@ pub trait SliceExt { /// Iterating through permutations one by one. /// /// ```rust - /// let v = [1i, 2, 3]; + /// let v = [1, 2, 3]; /// let mut perms = v.permutations(); /// - /// assert_eq!(Some(vec![1i, 2, 3]), perms.next()); - /// assert_eq!(Some(vec![1i, 3, 2]), perms.next()); - /// assert_eq!(Some(vec![3i, 1, 2]), perms.next()); + /// assert_eq!(Some(vec![1, 2, 3]), perms.next()); + /// assert_eq!(Some(vec![1, 3, 2]), perms.next()); + /// assert_eq!(Some(vec![3, 1, 2]), perms.next()); /// ``` #[unstable(feature = "collections")] fn permutations(&self) -> Permutations<Self::Item> where Self::Item: Clone; @@ -643,15 +643,15 @@ pub trait SliceExt { /// # Example /// /// ```rust - /// let mut dst = [0i, 0, 0]; - /// let src = [1i, 2]; + /// let mut dst = [0, 0, 0]; + /// let src = [1, 2]; /// /// assert!(dst.clone_from_slice(&src) == 2); /// assert!(dst == [1, 2, 0]); /// - /// let src2 = [3i, 4, 5, 6]; + /// let src2 = [3, 4, 5, 6]; /// assert!(dst.clone_from_slice(&src2) == 3); - /// assert!(dst == [3i, 4, 5]); + /// assert!(dst == [3, 4, 5]); /// ``` #[unstable(feature = "collections")] fn clone_from_slice(&mut self, &[Self::Item]) -> uint where Self::Item: Clone; @@ -663,10 +663,10 @@ pub trait SliceExt { /// # Examples /// /// ```rust - /// let mut v = [-5i, 4, 1, -3, 2]; + /// let mut v = [-5, 4, 1, -3, 2]; /// /// v.sort(); - /// assert!(v == [-5i, -3, 1, 2, 4]); + /// assert!(v == [-5, -3, 1, 2, 4]); /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn sort(&mut self) where Self::Item: Ord; @@ -685,7 +685,7 @@ pub trait SliceExt { /// found; the fourth could match any position in `[1,4]`. /// /// ```rust - /// let s = [0i, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]; + /// let s = [0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]; /// let s = s.as_slice(); /// /// assert_eq!(s.binary_search(&13), Ok(9)); @@ -712,12 +712,12 @@ pub trait SliceExt { /// # Example /// /// ```rust - /// let v: &mut [_] = &mut [0i, 1, 2]; + /// let v: &mut [_] = &mut [0, 1, 2]; /// v.next_permutation(); - /// let b: &mut [_] = &mut [0i, 2, 1]; + /// let b: &mut [_] = &mut [0, 2, 1]; /// assert!(v == b); /// v.next_permutation(); - /// let b: &mut [_] = &mut [1i, 0, 2]; + /// let b: &mut [_] = &mut [1, 0, 2]; /// assert!(v == b); /// ``` #[unstable(feature = "collections", @@ -732,12 +732,12 @@ pub trait SliceExt { /// # Example /// /// ```rust - /// let v: &mut [_] = &mut [1i, 0, 2]; + /// let v: &mut [_] = &mut [1, 0, 2]; /// v.prev_permutation(); - /// let b: &mut [_] = &mut [0i, 2, 1]; + /// let b: &mut [_] = &mut [0, 2, 1]; /// assert!(v == b); /// v.prev_permutation(); - /// let b: &mut [_] = &mut [0i, 1, 2]; + /// let b: &mut [_] = &mut [0, 1, 2]; /// assert!(v == b); /// ``` #[unstable(feature = "collections", @@ -1582,7 +1582,7 @@ mod tests { fn test_is_empty() { let xs: [int; 0] = []; assert!(xs.is_empty()); - assert!(![0i].is_empty()); + assert!(![0].is_empty()); } #[test] @@ -1599,11 +1599,11 @@ mod tests { #[test] fn test_get() { - let mut a = vec![11i]; + let mut a = vec![11]; assert_eq!(a.get(1), None); - a = vec![11i, 12]; + a = vec![11, 12]; assert_eq!(a.get(1).unwrap(), &12); - a = vec![11i, 12, 13]; + a = vec![11, 12, 13]; assert_eq!(a.get(1).unwrap(), &12); } @@ -1611,9 +1611,9 @@ mod tests { fn test_first() { let mut a = vec![]; assert_eq!(a.first(), None); - a = vec![11i]; + a = vec![11]; assert_eq!(a.first().unwrap(), &11); - a = vec![11i, 12]; + a = vec![11, 12]; assert_eq!(a.first().unwrap(), &11); } @@ -1621,28 +1621,28 @@ mod tests { fn test_first_mut() { let mut a = vec![]; assert_eq!(a.first_mut(), None); - a = vec![11i]; + a = vec![11]; assert_eq!(*a.first_mut().unwrap(), 11); - a = vec![11i, 12]; + a = vec![11, 12]; assert_eq!(*a.first_mut().unwrap(), 11); } #[test] fn test_tail() { - let mut a = vec![11i]; + let mut a = vec![11]; let b: &[int] = &[]; assert_eq!(a.tail(), b); - a = vec![11i, 12]; + a = vec![11, 12]; let b: &[int] = &[12]; assert_eq!(a.tail(), b); } #[test] fn test_tail_mut() { - let mut a = vec![11i]; + let mut a = vec![11]; let b: &mut [int] = &mut []; assert!(a.tail_mut() == b); - a = vec![11i, 12]; + a = vec![11, 12]; let b: &mut [int] = &mut [12]; assert!(a.tail_mut() == b); } @@ -1663,20 +1663,20 @@ mod tests { #[test] fn test_init() { - let mut a = vec![11i]; + let mut a = vec![11]; let b: &[int] = &[]; assert_eq!(a.init(), b); - a = vec![11i, 12]; + a = vec![11, 12]; let b: &[int] = &[11]; assert_eq!(a.init(), b); } #[test] fn test_init_mut() { - let mut a = vec![11i]; + let mut a = vec![11]; let b: &mut [int] = &mut []; assert!(a.init_mut() == b); - a = vec![11i, 12]; + a = vec![11, 12]; let b: &mut [int] = &mut [11]; assert!(a.init_mut() == b); } @@ -1699,9 +1699,9 @@ mod tests { fn test_last() { let mut a = vec![]; assert_eq!(a.last(), None); - a = vec![11i]; + a = vec![11]; assert_eq!(a.last().unwrap(), &11); - a = vec![11i, 12]; + a = vec![11, 12]; assert_eq!(a.last().unwrap(), &12); } @@ -1709,16 +1709,16 @@ mod tests { fn test_last_mut() { let mut a = vec![]; assert_eq!(a.last_mut(), None); - a = vec![11i]; + a = vec![11]; assert_eq!(*a.last_mut().unwrap(), 11); - a = vec![11i, 12]; + a = vec![11, 12]; assert_eq!(*a.last_mut().unwrap(), 12); } #[test] fn test_slice() { // Test fixed length vector. - let vec_fixed = [1i, 2, 3, 4]; + let vec_fixed = [1, 2, 3, 4]; let v_a = vec_fixed[1u..vec_fixed.len()].to_vec(); assert_eq!(v_a.len(), 3u); let v_a = v_a.as_slice(); @@ -1727,7 +1727,7 @@ mod tests { assert_eq!(v_a[2], 4); // Test on stack. - let vec_stack: &[_] = &[1i, 2, 3]; + let vec_stack: &[_] = &[1, 2, 3]; let v_b = vec_stack[1u..3u].to_vec(); assert_eq!(v_b.len(), 2u); let v_b = v_b.as_slice(); @@ -1735,7 +1735,7 @@ mod tests { assert_eq!(v_b[1], 3); // Test `Box<[T]>` - let vec_unique = vec![1i, 2, 3, 4, 5, 6]; + let vec_unique = vec![1, 2, 3, 4, 5, 6]; let v_d = vec_unique[1u..6u].to_vec(); assert_eq!(v_d.len(), 5u); let v_d = v_d.as_slice(); @@ -1769,7 +1769,7 @@ mod tests { #[test] fn test_pop() { - let mut v = vec![5i]; + let mut v = vec![5]; let e = v.pop(); assert_eq!(v.len(), 0); assert_eq!(e, Some(5)); @@ -1781,19 +1781,19 @@ mod tests { #[test] fn test_swap_remove() { - let mut v = vec![1i, 2, 3, 4, 5]; + let mut v = vec![1, 2, 3, 4, 5]; let mut e = v.swap_remove(0); assert_eq!(e, 1); - assert_eq!(v, vec![5i, 2, 3, 4]); + assert_eq!(v, vec![5, 2, 3, 4]); e = v.swap_remove(3); assert_eq!(e, 4); - assert_eq!(v, vec![5i, 2, 3]); + assert_eq!(v, vec![5, 2, 3]); } #[test] #[should_fail] fn test_swap_remove_fail() { - let mut v = vec![1i]; + let mut v = vec![1]; let _ = v.swap_remove(0); let _ = v.swap_remove(0); } @@ -1817,12 +1817,12 @@ mod tests { fn test_push() { // Test on-stack push(). let mut v = vec![]; - v.push(1i); + v.push(1); assert_eq!(v.len(), 1u); assert_eq!(v.as_slice()[0], 1); // Test on-heap push(). - v.push(2i); + v.push(2); assert_eq!(v.len(), 2u); assert_eq!(v.as_slice()[0], 1); assert_eq!(v.as_slice()[1], 2); @@ -1830,7 +1830,7 @@ mod tests { #[test] fn test_truncate() { - let mut v = vec![box 6i,box 5,box 4]; + let mut v = vec![box 6,box 5,box 4]; v.truncate(1); let v = v.as_slice(); assert_eq!(v.len(), 1); @@ -1840,7 +1840,7 @@ mod tests { #[test] fn test_clear() { - let mut v = vec![box 6i,box 5,box 4]; + let mut v = vec![box 6,box 5,box 4]; v.clear(); assert_eq!(v.len(), 0); // If the unsafe block didn't drop things properly, we blow up here. @@ -1865,11 +1865,11 @@ mod tests { #[test] fn test_dedup_unique() { - let mut v0 = vec![box 1i, box 1, box 2, box 3]; + let mut v0 = vec![box 1, box 1, box 2, box 3]; v0.dedup(); - let mut v1 = vec![box 1i, box 2, box 2, box 3]; + let mut v1 = vec![box 1, box 2, box 2, box 3]; v1.dedup(); - let mut v2 = vec![box 1i, box 2, box 3, box 3]; + let mut v2 = vec![box 1, box 2, box 3, box 3]; v2.dedup(); /* * If the boxed pointers were leaked or otherwise misused, valgrind @@ -1879,11 +1879,11 @@ mod tests { #[test] fn test_dedup_shared() { - let mut v0 = vec![box 1i, box 1, box 2, box 3]; + let mut v0 = vec![box 1, box 1, box 2, box 3]; v0.dedup(); - let mut v1 = vec![box 1i, box 2, box 2, box 3]; + let mut v1 = vec![box 1, box 2, box 2, box 3]; v1.dedup(); - let mut v2 = vec![box 1i, box 2, box 3, box 3]; + let mut v2 = vec![box 1, box 2, box 3, box 3]; v2.dedup(); /* * If the pointers were leaked or otherwise misused, valgrind and/or @@ -1900,7 +1900,7 @@ mod tests { #[test] fn test_element_swaps() { - let mut v = [1i, 2, 3]; + let mut v = [1, 2, 3]; for (i, (a, b)) in ElementSwaps::new(v.len()).enumerate() { v.swap(a, b); match i { @@ -1936,7 +1936,7 @@ mod tests { assert_eq!(it.next(), None); } { - let v = [1i, 2, 3]; + let v = [1, 2, 3]; let mut it = v.permutations(); let (min_size, max_opt) = it.size_hint(); assert_eq!(min_size, 3*2); @@ -1958,7 +1958,7 @@ mod tests { let mut amt = 0; let mut it = v.permutations(); let (min_size, max_opt) = it.size_hint(); - for _perm in it { + for _perm in it.by_ref() { amt += 1; } assert_eq!(amt, it.swaps.swaps_made); @@ -1970,7 +1970,7 @@ mod tests { #[test] fn test_lexicographic_permutations() { - let v : &mut[int] = &mut[1i, 2, 3, 4, 5]; + let v : &mut[int] = &mut[1, 2, 3, 4, 5]; assert!(v.prev_permutation() == false); assert!(v.next_permutation()); let b: &mut[int] = &mut[1, 2, 3, 5, 4]; @@ -1986,7 +1986,7 @@ mod tests { let b: &mut[int] = &mut[1, 2, 4, 5, 3]; assert!(v == b); - let v : &mut[int] = &mut[1i, 0, 0, 0]; + let v : &mut[int] = &mut[1, 0, 0, 0]; assert!(v.next_permutation() == false); assert!(v.prev_permutation()); let b: &mut[int] = &mut[0, 1, 0, 0]; @@ -2009,14 +2009,14 @@ mod tests { assert!(empty.prev_permutation() == false); assert!(empty == b); - let one_elem : &mut[int] = &mut[4i]; + let one_elem : &mut[int] = &mut[4]; assert!(one_elem.prev_permutation() == false); let b: &mut[int] = &mut[4]; assert!(one_elem == b); assert!(one_elem.next_permutation() == false); assert!(one_elem == b); - let two_elem : &mut[int] = &mut[1i, 2]; + let two_elem : &mut[int] = &mut[1, 2]; assert!(two_elem.prev_permutation() == false); let b : &mut[int] = &mut[1, 2]; let c : &mut[int] = &mut[2, 1]; @@ -2033,9 +2033,9 @@ mod tests { #[test] fn test_position_elem() { - assert!([].position_elem(&1i).is_none()); + assert!([].position_elem(&1).is_none()); - let v1 = vec![1i, 2, 3, 3, 2, 5]; + let v1 = vec![1, 2, 3, 3, 2, 5]; assert_eq!(v1.position_elem(&1), Some(0u)); assert_eq!(v1.position_elem(&2), Some(1u)); assert_eq!(v1.position_elem(&5), Some(5u)); @@ -2044,52 +2044,52 @@ mod tests { #[test] fn test_binary_search() { - assert_eq!([1i,2,3,4,5].binary_search(&5).ok(), Some(4)); - assert_eq!([1i,2,3,4,5].binary_search(&4).ok(), Some(3)); - assert_eq!([1i,2,3,4,5].binary_search(&3).ok(), Some(2)); - assert_eq!([1i,2,3,4,5].binary_search(&2).ok(), Some(1)); - assert_eq!([1i,2,3,4,5].binary_search(&1).ok(), Some(0)); + assert_eq!([1,2,3,4,5].binary_search(&5).ok(), Some(4)); + assert_eq!([1,2,3,4,5].binary_search(&4).ok(), Some(3)); + assert_eq!([1,2,3,4,5].binary_search(&3).ok(), Some(2)); + assert_eq!([1,2,3,4,5].binary_search(&2).ok(), Some(1)); + assert_eq!([1,2,3,4,5].binary_search(&1).ok(), Some(0)); - assert_eq!([2i,4,6,8,10].binary_search(&1).ok(), None); - assert_eq!([2i,4,6,8,10].binary_search(&5).ok(), None); - assert_eq!([2i,4,6,8,10].binary_search(&4).ok(), Some(1)); - assert_eq!([2i,4,6,8,10].binary_search(&10).ok(), Some(4)); + assert_eq!([2,4,6,8,10].binary_search(&1).ok(), None); + assert_eq!([2,4,6,8,10].binary_search(&5).ok(), None); + assert_eq!([2,4,6,8,10].binary_search(&4).ok(), Some(1)); + assert_eq!([2,4,6,8,10].binary_search(&10).ok(), Some(4)); - assert_eq!([2i,4,6,8].binary_search(&1).ok(), None); - assert_eq!([2i,4,6,8].binary_search(&5).ok(), None); - assert_eq!([2i,4,6,8].binary_search(&4).ok(), Some(1)); - assert_eq!([2i,4,6,8].binary_search(&8).ok(), Some(3)); + assert_eq!([2,4,6,8].binary_search(&1).ok(), None); + assert_eq!([2,4,6,8].binary_search(&5).ok(), None); + assert_eq!([2,4,6,8].binary_search(&4).ok(), Some(1)); + assert_eq!([2,4,6,8].binary_search(&8).ok(), Some(3)); - assert_eq!([2i,4,6].binary_search(&1).ok(), None); - assert_eq!([2i,4,6].binary_search(&5).ok(), None); - assert_eq!([2i,4,6].binary_search(&4).ok(), Some(1)); - assert_eq!([2i,4,6].binary_search(&6).ok(), Some(2)); + assert_eq!([2,4,6].binary_search(&1).ok(), None); + assert_eq!([2,4,6].binary_search(&5).ok(), None); + assert_eq!([2,4,6].binary_search(&4).ok(), Some(1)); + assert_eq!([2,4,6].binary_search(&6).ok(), Some(2)); - assert_eq!([2i,4].binary_search(&1).ok(), None); - assert_eq!([2i,4].binary_search(&5).ok(), None); - assert_eq!([2i,4].binary_search(&2).ok(), Some(0)); - assert_eq!([2i,4].binary_search(&4).ok(), Some(1)); + assert_eq!([2,4].binary_search(&1).ok(), None); + assert_eq!([2,4].binary_search(&5).ok(), None); + assert_eq!([2,4].binary_search(&2).ok(), Some(0)); + assert_eq!([2,4].binary_search(&4).ok(), Some(1)); - assert_eq!([2i].binary_search(&1).ok(), None); - assert_eq!([2i].binary_search(&5).ok(), None); - assert_eq!([2i].binary_search(&2).ok(), Some(0)); + assert_eq!([2].binary_search(&1).ok(), None); + assert_eq!([2].binary_search(&5).ok(), None); + assert_eq!([2].binary_search(&2).ok(), Some(0)); - assert_eq!([].binary_search(&1i).ok(), None); - assert_eq!([].binary_search(&5i).ok(), None); + assert_eq!([].binary_search(&1).ok(), None); + assert_eq!([].binary_search(&5).ok(), None); - assert!([1i,1,1,1,1].binary_search(&1).ok() != None); - assert!([1i,1,1,1,2].binary_search(&1).ok() != None); - assert!([1i,1,1,2,2].binary_search(&1).ok() != None); - assert!([1i,1,2,2,2].binary_search(&1).ok() != None); - assert_eq!([1i,2,2,2,2].binary_search(&1).ok(), Some(0)); + assert!([1,1,1,1,1].binary_search(&1).ok() != None); + assert!([1,1,1,1,2].binary_search(&1).ok() != None); + assert!([1,1,1,2,2].binary_search(&1).ok() != None); + assert!([1,1,2,2,2].binary_search(&1).ok() != None); + assert_eq!([1,2,2,2,2].binary_search(&1).ok(), Some(0)); - assert_eq!([1i,2,3,4,5].binary_search(&6).ok(), None); - assert_eq!([1i,2,3,4,5].binary_search(&0).ok(), None); + assert_eq!([1,2,3,4,5].binary_search(&6).ok(), None); + assert_eq!([1,2,3,4,5].binary_search(&0).ok(), None); } #[test] fn test_reverse() { - let mut v: Vec<int> = vec![10i, 20]; + let mut v: Vec<int> = vec![10, 20]; assert_eq!(v[0], 10); assert_eq!(v[1], 20); v.reverse(); @@ -2104,7 +2104,7 @@ mod tests { #[test] fn test_sort() { for len in 4u..25 { - for _ in 0i..100 { + for _ in 0..100 { let mut v = thread_rng().gen_iter::<uint>().take(len) .collect::<Vec<uint>>(); let mut v1 = v.clone(); @@ -2131,9 +2131,9 @@ mod tests { #[test] fn test_sort_stability() { - for len in 4i..25 { + for len in 4..25 { for _ in 0u..10 { - let mut counts = [0i; 10]; + let mut counts = [0; 10]; // create a vector like [(6, 1), (5, 1), (6, 2), ...], // where the first item of each tuple is random, but @@ -2165,21 +2165,21 @@ mod tests { let v: [Vec<int>; 0] = []; let c: Vec<int> = v.concat(); assert_eq!(c, []); - let d: Vec<int> = [vec![1i], vec![2i,3i]].concat(); - assert_eq!(d, vec![1i, 2, 3]); + let d: Vec<int> = [vec![1], vec![2,3]].concat(); + assert_eq!(d, vec![1, 2, 3]); let v: [&[int]; 2] = [&[1], &[2, 3]]; - assert_eq!(v.connect(&0), vec![1i, 0, 2, 3]); - let v: [&[int]; 3] = [&[1i], &[2], &[3]]; - assert_eq!(v.connect(&0), vec![1i, 0, 2, 0, 3]); + assert_eq!(v.connect(&0), vec![1, 0, 2, 3]); + let v: [&[int]; 3] = [&[1], &[2], &[3]]; + assert_eq!(v.connect(&0), vec![1, 0, 2, 0, 3]); } #[test] fn test_connect() { let v: [Vec<int>; 0] = []; assert_eq!(v.connect(&0), vec![]); - assert_eq!([vec![1i], vec![2i, 3]].connect(&0), vec![1, 0, 2, 3]); - assert_eq!([vec![1i], vec![2i], vec![3i]].connect(&0), vec![1, 0, 2, 0, 3]); + assert_eq!([vec![1], vec![2, 3]].connect(&0), vec![1, 0, 2, 3]); + assert_eq!([vec![1], vec![2], vec![3]].connect(&0), vec![1, 0, 2, 0, 3]); let v: [&[int]; 2] = [&[1], &[2, 3]]; assert_eq!(v.connect(&0), vec![1, 0, 2, 3]); @@ -2189,42 +2189,42 @@ mod tests { #[test] fn test_insert() { - let mut a = vec![1i, 2, 4]; + let mut a = vec![1, 2, 4]; a.insert(2, 3); assert_eq!(a, vec![1, 2, 3, 4]); - let mut a = vec![1i, 2, 3]; + let mut a = vec![1, 2, 3]; a.insert(0, 0); assert_eq!(a, vec![0, 1, 2, 3]); - let mut a = vec![1i, 2, 3]; + let mut a = vec![1, 2, 3]; a.insert(3, 4); assert_eq!(a, vec![1, 2, 3, 4]); let mut a = vec![]; - a.insert(0, 1i); + a.insert(0, 1); assert_eq!(a, vec![1]); } #[test] #[should_fail] fn test_insert_oob() { - let mut a = vec![1i, 2, 3]; + let mut a = vec![1, 2, 3]; a.insert(4, 5); } #[test] fn test_remove() { - let mut a = vec![1i,2,3,4]; + let mut a = vec![1,2,3,4]; assert_eq!(a.remove(2), 3); - assert_eq!(a, vec![1i,2,4]); + assert_eq!(a, vec![1,2,4]); assert_eq!(a.remove(2), 4); - assert_eq!(a, vec![1i,2]); + assert_eq!(a, vec![1,2]); assert_eq!(a.remove(0), 1); - assert_eq!(a, vec![2i]); + assert_eq!(a, vec![2]); assert_eq!(a.remove(0), 2); assert_eq!(a, vec![]); @@ -2233,7 +2233,7 @@ mod tests { #[test] #[should_fail] fn test_remove_fail() { - let mut a = vec![1i]; + let mut a = vec![1]; let _ = a.remove(0); let _ = a.remove(0); } @@ -2250,7 +2250,7 @@ mod tests { #[test] fn test_slice_2() { - let v = vec![1i, 2, 3, 4, 5]; + let v = vec![1, 2, 3, 4, 5]; let v = v.slice(1u, 3u); assert_eq!(v.len(), 2u); assert_eq!(v[0], 2); @@ -2260,8 +2260,8 @@ mod tests { #[test] #[should_fail] fn test_permute_fail() { - let v = [(box 0i, Rc::new(0i)), (box 0i, Rc::new(0i)), - (box 0i, Rc::new(0i)), (box 0i, Rc::new(0i))]; + let v = [(box 0, Rc::new(0)), (box 0, Rc::new(0)), + (box 0, Rc::new(0)), (box 0, Rc::new(0))]; let mut i = 0u; for _ in v.permutations() { if i == 2 { @@ -2287,7 +2287,7 @@ mod tests { #[test] fn test_iterator() { - let xs = [1i, 2, 5, 10, 11]; + let xs = [1, 2, 5, 10, 11]; let mut it = xs.iter(); assert_eq!(it.size_hint(), (5, Some(5))); assert_eq!(it.next().unwrap(), &1); @@ -2305,7 +2305,7 @@ mod tests { #[test] fn test_random_access_iterator() { - let xs = [1i, 2, 5, 10, 11]; + let xs = [1, 2, 5, 10, 11]; let mut it = xs.iter(); assert_eq!(it.indexable(), 5); @@ -2343,14 +2343,14 @@ mod tests { #[test] fn test_iter_size_hints() { - let mut xs = [1i, 2, 5, 10, 11]; + let mut xs = [1, 2, 5, 10, 11]; assert_eq!(xs.iter().size_hint(), (5, Some(5))); assert_eq!(xs.iter_mut().size_hint(), (5, Some(5))); } #[test] fn test_iter_clone() { - let xs = [1i, 2, 5]; + let xs = [1, 2, 5]; let mut it = xs.iter(); it.next(); let mut jt = it.clone(); @@ -2361,7 +2361,7 @@ mod tests { #[test] fn test_mut_iterator() { - let mut xs = [1i, 2, 3, 4, 5]; + let mut xs = [1, 2, 3, 4, 5]; for x in xs.iter_mut() { *x += 1; } @@ -2371,7 +2371,7 @@ mod tests { #[test] fn test_rev_iterator() { - let xs = [1i, 2, 5, 10, 11]; + let xs = [1, 2, 5, 10, 11]; let ys = [11, 10, 5, 2, 1]; let mut i = 0; for &x in xs.iter().rev() { @@ -2404,7 +2404,7 @@ mod tests { #[test] fn test_splitator() { - let xs = &[1i,2,3,4,5]; + let xs = &[1,2,3,4,5]; let splits: &[&[int]] = &[&[1], &[3], &[5]]; assert_eq!(xs.split(|x| *x % 2 == 0).collect::<Vec<&[int]>>(), @@ -2429,7 +2429,7 @@ mod tests { #[test] fn test_splitnator() { - let xs = &[1i,2,3,4,5]; + let xs = &[1,2,3,4,5]; let splits: &[&[int]] = &[&[1,2,3,4,5]]; assert_eq!(xs.splitn(0, |x| *x % 2 == 0).collect::<Vec<&[int]>>(), @@ -2448,7 +2448,7 @@ mod tests { #[test] fn test_splitnator_mut() { - let xs = &mut [1i,2,3,4,5]; + let xs = &mut [1,2,3,4,5]; let splits: &[&mut [int]] = &[&mut [1,2,3,4,5]]; assert_eq!(xs.splitn_mut(0, |x| *x % 2 == 0).collect::<Vec<&mut [int]>>(), @@ -2468,7 +2468,7 @@ mod tests { #[test] fn test_rsplitator() { - let xs = &[1i,2,3,4,5]; + let xs = &[1,2,3,4,5]; let splits: &[&[int]] = &[&[5], &[3], &[1]]; assert_eq!(xs.split(|x| *x % 2 == 0).rev().collect::<Vec<&[int]>>(), @@ -2509,11 +2509,11 @@ mod tests { #[test] fn test_windowsator() { - let v = &[1i,2,3,4]; + let v = &[1,2,3,4]; let wins: &[&[int]] = &[&[1,2], &[2,3], &[3,4]]; assert_eq!(v.windows(2).collect::<Vec<&[int]>>(), wins); - let wins: &[&[int]] = &[&[1i,2,3], &[2,3,4]]; + let wins: &[&[int]] = &[&[1,2,3], &[2,3,4]]; assert_eq!(v.windows(3).collect::<Vec<&[int]>>(), wins); assert!(v.windows(6).next().is_none()); } @@ -2521,7 +2521,7 @@ mod tests { #[test] #[should_fail] fn test_windowsator_0() { - let v = &[1i,2,3,4]; + let v = &[1,2,3,4]; let _it = v.windows(0); } @@ -2529,18 +2529,18 @@ mod tests { fn test_chunksator() { use core::iter::ExactSizeIterator; - let v = &[1i,2,3,4,5]; + let v = &[1,2,3,4,5]; assert_eq!(v.chunks(2).len(), 3); - let chunks: &[&[int]] = &[&[1i,2], &[3,4], &[5]]; + let chunks: &[&[int]] = &[&[1,2], &[3,4], &[5]]; assert_eq!(v.chunks(2).collect::<Vec<&[int]>>(), chunks); - let chunks: &[&[int]] = &[&[1i,2,3], &[4,5]]; + let chunks: &[&[int]] = &[&[1,2,3], &[4,5]]; assert_eq!(v.chunks(3).collect::<Vec<&[int]>>(), chunks); - let chunks: &[&[int]] = &[&[1i,2,3,4,5]]; + let chunks: &[&[int]] = &[&[1,2,3,4,5]]; assert_eq!(v.chunks(6).collect::<Vec<&[int]>>(), chunks); - let chunks: &[&[int]] = &[&[5i], &[3,4], &[1,2]]; + let chunks: &[&[int]] = &[&[5], &[3,4], &[1,2]]; assert_eq!(v.chunks(2).rev().collect::<Vec<&[int]>>(), chunks); let mut it = v.chunks(2); assert_eq!(it.indexable(), 3); @@ -2556,33 +2556,33 @@ mod tests { #[test] #[should_fail] fn test_chunksator_0() { - let v = &[1i,2,3,4]; + let v = &[1,2,3,4]; let _it = v.chunks(0); } #[test] fn test_move_from() { - let mut a = [1i,2,3,4,5]; - let b = vec![6i,7,8]; + let mut a = [1,2,3,4,5]; + let b = vec![6,7,8]; assert_eq!(a.move_from(b, 0, 3), 3); - assert!(a == [6i,7,8,4,5]); - let mut a = [7i,2,8,1]; - let b = vec![3i,1,4,1,5,9]; + assert!(a == [6,7,8,4,5]); + let mut a = [7,2,8,1]; + let b = vec![3,1,4,1,5,9]; assert_eq!(a.move_from(b, 0, 6), 4); - assert!(a == [3i,1,4,1]); - let mut a = [1i,2,3,4]; - let b = vec![5i,6,7,8,9,0]; + assert!(a == [3,1,4,1]); + let mut a = [1,2,3,4]; + let b = vec![5,6,7,8,9,0]; assert_eq!(a.move_from(b, 2, 3), 1); - assert!(a == [7i,2,3,4]); - let mut a = [1i,2,3,4,5]; - let b = vec![5i,6,7,8,9,0]; + assert!(a == [7,2,3,4]); + let mut a = [1,2,3,4,5]; + let b = vec![5,6,7,8,9,0]; assert_eq!(a[2..4].move_from(b,1,6), 2); - assert!(a == [1i,2,6,7,5]); + assert!(a == [1,2,6,7,5]); } #[test] fn test_reverse_part() { - let mut values = [1i,2,3,4,5]; + let mut values = [1,2,3,4,5]; values[1..4].reverse(); assert!(values == [1,4,3,2,5]); } @@ -2598,8 +2598,8 @@ mod tests { } let empty: Vec<int> = vec![]; test_show_vec!(empty, "[]"); - test_show_vec!(vec![1i], "[1]"); - test_show_vec!(vec![1i, 2, 3], "[1, 2, 3]"); + test_show_vec!(vec![1], "[1]"); + test_show_vec!(vec![1, 2, 3], "[1, 2, 3]"); test_show_vec!(vec![vec![], vec![1u], vec![1u, 1u]], "[[], [1], [1, 1]]"); @@ -2641,16 +2641,16 @@ mod tests { fn test_overflow_does_not_cause_segfault() { let mut v = vec![]; v.reserve_exact(-1); - v.push(1i); + v.push(1); v.push(2); } #[test] #[should_fail] fn test_overflow_does_not_cause_segfault_managed() { - let mut v = vec![Rc::new(1i)]; + let mut v = vec![Rc::new(1)]; v.reserve_exact(-1); - v.push(Rc::new(2i)); + v.push(Rc::new(2)); } #[test] @@ -2723,13 +2723,13 @@ mod tests { #[test] fn test_shrink_to_fit() { let mut xs = vec![0, 1, 2, 3]; - for i in 4i..100 { + for i in 4..100 { xs.push(i) } assert_eq!(xs.capacity(), 128); xs.shrink_to_fit(); assert_eq!(xs.capacity(), 100); - assert_eq!(xs, (0i..100i).collect::<Vec<_>>()); + assert_eq!(xs, (0..100).collect::<Vec<_>>()); } #[test] @@ -2762,14 +2762,14 @@ mod tests { #[test] fn test_mut_splitator() { - let mut xs = [0i,1,0,2,3,0,0,4,5,0]; + let mut xs = [0,1,0,2,3,0,0,4,5,0]; assert_eq!(xs.split_mut(|x| *x == 0).count(), 6); for slice in xs.split_mut(|x| *x == 0) { slice.reverse(); } assert!(xs == [0,1,0,3,2,0,0,5,4,0]); - let mut xs = [0i,1,0,2,3,0,0,4,5,0,6,7]; + let mut xs = [0,1,0,2,3,0,0,4,5,0,6,7]; for slice in xs.split_mut(|x| *x == 0).take(5) { slice.reverse(); } @@ -2778,7 +2778,7 @@ mod tests { #[test] fn test_mut_splitator_rev() { - let mut xs = [1i,2,0,3,4,0,0,5,6,0]; + let mut xs = [1,2,0,3,4,0,0,5,6,0]; for slice in xs.split_mut(|x| *x == 0).rev().take(4) { slice.reverse(); } @@ -2787,7 +2787,7 @@ mod tests { #[test] fn test_get_mut() { - let mut v = [0i,1,2]; + let mut v = [0,1,2]; assert_eq!(v.get_mut(3), None); v.get_mut(1).map(|e| *e = 7); assert_eq!(v[1], 7); @@ -2825,13 +2825,13 @@ mod tests { #[test] #[should_fail] fn test_mut_chunks_0() { - let mut v = [1i, 2, 3, 4]; + let mut v = [1, 2, 3, 4]; let _it = v.chunks_mut(0); } #[test] fn test_mut_last() { - let mut x = [1i, 2, 3, 4, 5]; + let mut x = [1, 2, 3, 4, 5]; let h = x.last_mut(); assert_eq!(*h.unwrap(), 5); @@ -2874,10 +2874,10 @@ mod bench { #[bench] fn mut_iterator(b: &mut Bencher) { - let mut v = repeat(0i).take(100).collect::<Vec<_>>(); + let mut v = repeat(0).take(100).collect::<Vec<_>>(); b.iter(|| { - let mut i = 0i; + let mut i = 0; for x in v.iter_mut() { *x = i; i += 1; @@ -3013,7 +3013,7 @@ mod bench { v.set_len(1024); } for x in v.iter_mut() { - *x = 0i; + *x = 0; } v }); diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index 35591a5e9ef..ded6385d293 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -68,6 +68,7 @@ use core::ops::FullRange; #[cfg(not(stage0))] use core::ops::RangeFull; use core::option::Option::{self, Some, None}; +use core::result::Result; use core::slice::AsSlice; use core::str as core_str; use unicode::str::{UnicodeStr, Utf16Encoder}; @@ -199,7 +200,7 @@ impl<'a> Iterator for Decompositions<'a> { } if !self.sorted { - for ch in self.iter { + for ch in self.iter.by_ref() { let buffer = &mut self.buffer; let sorted = &mut self.sorted; { @@ -279,7 +280,7 @@ impl<'a> Iterator for Recompositions<'a> { loop { match self.state { Composing => { - for ch in self.iter { + for ch in self.iter.by_ref() { let ch_class = unicode::char::canonical_combining_class(ch); if self.composee.is_none() { if ch_class != 0 { @@ -443,12 +444,9 @@ pub trait StrExt: Index<RangeFull, Output = str> { /// # Examples /// /// ```rust - /// let s = "Do you know the muffin man, - /// The muffin man, the muffin man, ...".to_string(); + /// let s = "this is old"; /// - /// assert_eq!(s.replace("muffin man", "little lamb"), - /// "Do you know the little lamb, - /// The little lamb, the little lamb, ...".to_string()); + /// assert_eq!(s.replace("old", "new"), "this is new"); /// /// // not found, so no change. /// assert_eq!(s.replace("cookie monster", "little lamb"), s); @@ -1231,13 +1229,12 @@ pub trait StrExt: Index<RangeFull, Output = str> { /// # Example /// /// ``` - /// assert_eq!("4".parse::<u32>(), Some(4)); - /// assert_eq!("j".parse::<u32>(), None); + /// assert_eq!("4".parse::<u32>(), Ok(4)); + /// assert!("j".parse::<u32>().is_err()); /// ``` #[inline] - #[unstable(feature = "collections", - reason = "this method was just created")] - fn parse<F: FromStr>(&self) -> Option<F> { + #[stable(feature = "rust1", since = "1.0.0")] + fn parse<F: FromStr>(&self) -> Result<F, F::Err> { core_str::StrExt::parse(&self[]) } @@ -2154,7 +2151,7 @@ mod tests { let s = "ศไทย中华Việt Nam"; let mut it = s.chars(); it.next(); - assert!(it.zip(it.clone()).all(|(x,y)| x == y)); + assert!(it.clone().zip(it).all(|(x,y)| x == y)); } #[test] diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 035529c7365..4cb7b05f967 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -940,19 +940,24 @@ pub fn as_string<'a>(x: &'a str) -> DerefString<'a> { DerefString { x: as_vec(x.as_bytes()) } } +#[unstable(feature = "collections", reason = "associated error type may change")] impl FromStr for String { + type Err = (); #[inline] - fn from_str(s: &str) -> Option<String> { - Some(String::from_str(s)) + fn from_str(s: &str) -> Result<String, ()> { + Ok(String::from_str(s)) } } /// A generic trait for converting a value to a string +#[stable(feature = "rust1", since = "1.0.0")] pub trait ToString { /// Converts the value of `self` to an owned string + #[stable(feature = "rust1", since = "1.0.0")] fn to_string(&self) -> String; } +#[stable(feature = "rust1", since = "1.0.0")] impl<T: fmt::Display + ?Sized> ToString for T { #[inline] fn to_string(&self) -> String { @@ -989,6 +994,7 @@ impl<'a> Str for CowString<'a> { } } +#[stable(feature = "rust1", since = "1.0.0")] impl fmt::Writer for String { #[inline] fn write_str(&mut self, s: &str) -> fmt::Result { @@ -1016,7 +1022,7 @@ mod tests { #[test] fn test_from_str() { - let owned: Option<::std::string::String> = "string".parse(); + let owned: Option<::std::string::String> = "string".parse().ok(); assert_eq!(owned.as_ref().map(|s| s.as_slice()), Some("string")); } @@ -1302,8 +1308,8 @@ mod tests { #[test] fn test_simple_types() { - assert_eq!(1i.to_string(), "1"); - assert_eq!((-1i).to_string(), "-1"); + assert_eq!(1.to_string(), "1"); + assert_eq!((-1).to_string(), "-1"); assert_eq!(200u.to_string(), "200"); assert_eq!(2u8.to_string(), "2"); assert_eq!(true.to_string(), "true"); @@ -1315,9 +1321,9 @@ mod tests { fn test_vectors() { let x: Vec<int> = vec![]; assert_eq!(format!("{:?}", x), "[]"); - assert_eq!(format!("{:?}", vec![1i]), "[1]"); - assert_eq!(format!("{:?}", vec![1i, 2, 3]), "[1, 2, 3]"); - assert!(format!("{:?}", vec![vec![], vec![1i], vec![1i, 1]]) == + assert_eq!(format!("{:?}", vec![1]), "[1]"); + assert_eq!(format!("{:?}", vec![1, 2, 3]), "[1, 2, 3]"); + assert!(format!("{:?}", vec![vec![], vec![1], vec![1, 1]]) == "[[], [1], [1, 1]]"); } diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 5dd88dbb025..c45879ae251 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -56,7 +56,7 @@ use core::cmp::{Ordering}; use core::default::Default; use core::fmt; use core::hash::{self, Hash}; -use core::iter::{repeat, FromIterator}; +use core::iter::{repeat, FromIterator, IntoIterator}; use core::marker::{ContravariantLifetime, InvariantType}; use core::mem; use core::nonzero::NonZero; @@ -65,6 +65,7 @@ use core::ops::{Index, IndexMut, Deref, Add}; use core::ops; use core::ptr; use core::raw::Slice as RawSlice; +use core::slice; use core::uint; /// A growable list type, written `Vec<T>` but pronounced 'vector.' @@ -73,8 +74,8 @@ use core::uint; /// /// ``` /// let mut vec = Vec::new(); -/// vec.push(1i); -/// vec.push(2i); +/// vec.push(1); +/// vec.push(2); /// /// assert_eq!(vec.len(), 2); /// assert_eq!(vec[0], 1); @@ -82,7 +83,7 @@ use core::uint; /// assert_eq!(vec.pop(), Some(2)); /// assert_eq!(vec.len(), 1); /// -/// vec[0] = 7i; +/// vec[0] = 7; /// assert_eq!(vec[0], 7); /// /// vec.push_all(&[1, 2, 3]); @@ -90,13 +91,13 @@ use core::uint; /// for x in vec.iter() { /// println!("{}", x); /// } -/// assert_eq!(vec, vec![7i, 1, 2, 3]); +/// assert_eq!(vec, vec![7, 1, 2, 3]); /// ``` /// /// The `vec!` macro is provided to make initialization more convenient: /// /// ``` -/// let mut vec = vec![1i, 2i, 3i]; +/// let mut vec = vec![1, 2, 3]; /// vec.push(4); /// assert_eq!(vec, vec![1, 2, 3, 4]); /// ``` @@ -106,9 +107,9 @@ use core::uint; /// ``` /// let mut stack = Vec::new(); /// -/// stack.push(1i); -/// stack.push(2i); -/// stack.push(3i); +/// stack.push(1); +/// stack.push(2); +/// stack.push(3); /// /// loop { /// let top = match stack.pop() { @@ -180,13 +181,13 @@ impl<T> Vec<T> { /// # Examples /// /// ``` - /// let mut vec: Vec<int> = Vec::with_capacity(10); + /// let mut vec: Vec<_> = Vec::with_capacity(10); /// /// // The vector contains no items, even though it has capacity for more /// assert_eq!(vec.len(), 0); /// /// // These are all done without reallocating... - /// for i in 0i..10 { + /// for i in 0..10 { /// vec.push(i); /// } /// @@ -220,7 +221,7 @@ impl<T> Vec<T> { /// use std::mem; /// /// fn main() { - /// let mut v = vec![1i, 2, 3]; + /// let mut v = vec![1, 2, 3]; /// /// // Pull out the various important pieces of information about `v` /// let p = v.as_mut_ptr(); @@ -239,7 +240,7 @@ impl<T> Vec<T> { /// /// // Put everything back together into a Vec /// let rebuilt = Vec::from_raw_parts(p, len, cap); - /// assert_eq!(rebuilt, vec![4i, 5i, 6i]); + /// assert_eq!(rebuilt, vec![4, 5, 6]); /// } /// } /// ``` @@ -395,7 +396,7 @@ impl<T> Vec<T> { /// # Examples /// /// ``` - /// let mut vec = vec![1i, 2, 3, 4]; + /// let mut vec = vec![1, 2, 3, 4]; /// vec.truncate(2); /// assert_eq!(vec, vec![1, 2]); /// ``` @@ -419,7 +420,7 @@ impl<T> Vec<T> { /// ``` /// fn foo(slice: &mut [int]) {} /// - /// let mut vec = vec![1i, 2]; + /// let mut vec = vec![1, 2]; /// foo(vec.as_mut_slice()); /// ``` #[inline] @@ -522,7 +523,7 @@ impl<T> Vec<T> { /// # Examples /// /// ``` - /// let mut vec = vec![1i, 2, 3]; + /// let mut vec = vec![1, 2, 3]; /// vec.insert(1, 4); /// assert_eq!(vec, vec![1, 4, 2, 3]); /// vec.insert(4, 5); @@ -560,7 +561,7 @@ impl<T> Vec<T> { /// # Examples /// /// ``` - /// let mut v = vec![1i, 2, 3]; + /// let mut v = vec![1, 2, 3]; /// assert_eq!(v.remove(1), 2); /// assert_eq!(v, vec![1, 3]); /// ``` @@ -594,7 +595,7 @@ impl<T> Vec<T> { /// # Examples /// /// ``` - /// let mut vec = vec![1i, 2, 3, 4]; + /// let mut vec = vec![1, 2, 3, 4]; /// vec.retain(|&x| x%2 == 0); /// assert_eq!(vec, vec![2, 4]); /// ``` @@ -627,7 +628,7 @@ impl<T> Vec<T> { /// # Examples /// /// ```rust - /// let mut vec = vec!(1i, 2); + /// let mut vec = vec!(1, 2); /// vec.push(3); /// assert_eq!(vec, vec!(1, 2, 3)); /// ``` @@ -665,7 +666,7 @@ impl<T> Vec<T> { /// # Examples /// /// ```rust - /// let mut vec = vec![1i, 2, 3]; + /// let mut vec = vec![1, 2, 3]; /// assert_eq!(vec.pop(), Some(3)); /// assert_eq!(vec, vec![1, 2]); /// ``` @@ -758,7 +759,7 @@ impl<T> Vec<T> { /// # Examples /// /// ``` - /// let mut v = vec![1i, 2, 3]; + /// let mut v = vec![1, 2, 3]; /// /// v.clear(); /// @@ -775,7 +776,7 @@ impl<T> Vec<T> { /// # Examples /// /// ``` - /// let a = vec![1i, 2, 3]; + /// let a = vec![1, 2, 3]; /// assert_eq!(a.len(), 3); /// ``` #[inline] @@ -790,7 +791,7 @@ impl<T> Vec<T> { /// let mut v = Vec::new(); /// assert!(v.is_empty()); /// - /// v.push(1i); + /// v.push(1); /// assert!(!v.is_empty()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] @@ -1045,7 +1046,7 @@ impl<T: Clone> Vec<T> { /// vec.resize(3, "world"); /// assert_eq!(vec, vec!["hello", "world", "world"]); /// - /// let mut vec = vec![1i, 2, 3, 4]; + /// let mut vec = vec![1, 2, 3, 4]; /// vec.resize(2, 0); /// assert_eq!(vec, vec![1, 2]); /// ``` @@ -1069,8 +1070,8 @@ impl<T: Clone> Vec<T> { /// # Examples /// /// ``` - /// let mut vec = vec![1i]; - /// vec.push_all(&[2i, 3, 4]); + /// let mut vec = vec![1]; + /// vec.push_all(&[2, 3, 4]); /// assert_eq!(vec, vec![1, 2, 3, 4]); /// ``` #[inline] @@ -1103,11 +1104,11 @@ impl<T: PartialEq> Vec<T> { /// # Examples /// /// ``` - /// let mut vec = vec![1i, 2, 2, 3, 2]; + /// let mut vec = vec![1, 2, 2, 3, 2]; /// /// vec.dedup(); /// - /// assert_eq!(vec, vec![1i, 2, 3, 2]); + /// assert_eq!(vec, vec![1, 2, 3, 2]); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn dedup(&mut self) { @@ -1404,6 +1405,30 @@ impl<T> FromIterator<T> for Vec<T> { } } +impl<T> IntoIterator for Vec<T> { + type Iter = IntoIter<T>; + + fn into_iter(self) -> IntoIter<T> { + self.into_iter() + } +} + +impl<'a, T> IntoIterator for &'a Vec<T> { + type Iter = slice::Iter<'a, T>; + + fn into_iter(self) -> slice::Iter<'a, T> { + self.iter() + } +} + +impl<'a, T> IntoIterator for &'a mut Vec<T> { + type Iter = slice::IterMut<'a, T>; + + fn into_iter(mut self) -> slice::IterMut<'a, T> { + self.iter_mut() + } +} + #[unstable(feature = "collections", reason = "waiting on Extend stability")] impl<T> Extend<T> for Vec<T> { #[inline] @@ -1507,7 +1532,7 @@ impl<T> AsSlice<T> for Vec<T> { /// ``` /// fn foo(slice: &[int]) {} /// - /// let vec = vec![1i, 2]; + /// let vec = vec![1, 2]; /// foo(vec.as_slice()); /// ``` #[inline] @@ -1566,13 +1591,6 @@ impl<T: fmt::Debug> fmt::Debug for Vec<T> { } } -impl<'a> fmt::Writer for Vec<u8> { - fn write_str(&mut self, s: &str) -> fmt::Result { - self.push_all(s.as_bytes()); - Ok(()) - } -} - //////////////////////////////////////////////////////////////////////////////// // Clone-on-write //////////////////////////////////////////////////////////////////////////////// @@ -1623,7 +1641,7 @@ impl<T> IntoIter<T> { #[unstable(feature = "collections")] pub fn into_inner(mut self) -> Vec<T> { unsafe { - for _x in self { } + for _x in self.by_ref() { } let IntoIter { allocation, cap, ptr: _ptr, end: _end } = self; mem::forget(self); Vec { ptr: NonZero::new(allocation), cap: cap, len: 0 } @@ -1701,7 +1719,7 @@ impl<T> Drop for IntoIter<T> { fn drop(&mut self) { // destroy the remaining elements if self.cap != 0 { - for _x in *self {} + for _x in self.by_ref() {} unsafe { dealloc(self.allocation, self.cap); } @@ -1791,7 +1809,7 @@ impl<'a, T> Drop for Drain<'a, T> { // so we can use #[unsafe_no_drop_flag]. // destroy the remaining elements - for _x in *self {} + for _x in self.by_ref() {} } } @@ -1990,7 +2008,7 @@ mod tests { v.reserve(2); assert!(v.capacity() >= 2); - for i in 0i..16 { + for i in 0..16 { v.push(i); } @@ -2009,13 +2027,13 @@ mod tests { let mut v = Vec::new(); let mut w = Vec::new(); - v.extend(0i..3); - for i in 0i..3 { w.push(i) } + v.extend(0..3); + for i in 0..3 { w.push(i) } assert_eq!(v, w); - v.extend(3i..10); - for i in 3i..10 { w.push(i) } + v.extend(3..10); + for i in 3..10 { w.push(i) } assert_eq!(v, w); } @@ -2076,7 +2094,7 @@ mod tests { #[test] fn test_clone() { let v: Vec<int> = vec!(); - let w = vec!(1i, 2, 3); + let w = vec!(1, 2, 3); assert_eq!(v, v.clone()); @@ -2089,8 +2107,8 @@ mod tests { #[test] fn test_clone_from() { let mut v = vec!(); - let three = vec!(box 1i, box 2, box 3); - let two = vec!(box 4i, box 5); + let three = vec!(box 1, box 2, box 3); + let two = vec!(box 4, box 5); // zero, long v.clone_from(&three); assert_eq!(v, three); @@ -2149,14 +2167,14 @@ mod tests { #[test] fn test_partition() { assert_eq!(vec![].into_iter().partition(|x: &int| *x < 3), (vec![], vec![])); - assert_eq!(vec![1i, 2, 3].into_iter().partition(|x: &int| *x < 4), (vec![1, 2, 3], vec![])); - assert_eq!(vec![1i, 2, 3].into_iter().partition(|x: &int| *x < 2), (vec![1], vec![2, 3])); - assert_eq!(vec![1i, 2, 3].into_iter().partition(|x: &int| *x < 0), (vec![], vec![1, 2, 3])); + assert_eq!(vec![1, 2, 3].into_iter().partition(|x: &int| *x < 4), (vec![1, 2, 3], vec![])); + assert_eq!(vec![1, 2, 3].into_iter().partition(|x: &int| *x < 2), (vec![1], vec![2, 3])); + assert_eq!(vec![1, 2, 3].into_iter().partition(|x: &int| *x < 0), (vec![], vec![1, 2, 3])); } #[test] fn test_zip_unzip() { - let z1 = vec![(1i, 4i), (2, 5), (3, 6)]; + let z1 = vec![(1, 4), (2, 5), (3, 6)]; let (left, right): (Vec<_>, Vec<_>) = z1.iter().map(|&x| x).unzip(); @@ -2169,13 +2187,13 @@ mod tests { fn test_unsafe_ptrs() { unsafe { // Test on-stack copy-from-buf. - let a = [1i, 2, 3]; + let a = [1, 2, 3]; let ptr = a.as_ptr(); let b = Vec::from_raw_buf(ptr, 3u); assert_eq!(b, vec![1, 2, 3]); // Test on-heap copy-from-buf. - let c = vec![1i, 2, 3, 4, 5]; + let c = vec![1, 2, 3, 4, 5]; let ptr = c.as_ptr(); let d = Vec::from_raw_buf(ptr, 5u); assert_eq!(d, vec![1, 2, 3, 4, 5]); @@ -2219,14 +2237,14 @@ mod tests { #[test] fn test_index() { - let vec = vec!(1i, 2, 3); + let vec = vec!(1, 2, 3); assert!(vec[1] == 2); } #[test] #[should_fail] fn test_index_out_of_bounds() { - let vec = vec!(1i, 2, 3); + let vec = vec!(1, 2, 3); let _ = vec[3]; } @@ -2294,7 +2312,7 @@ mod tests { #[test] fn test_map_in_place() { let v = vec![0u, 1, 2]; - assert_eq!(v.map_in_place(|i: uint| i as int - 1), [-1i, 0, 1]); + assert_eq!(v.map_in_place(|i: uint| i as int - 1), [-1, 0, 1]); } #[test] diff --git a/src/libcollections/vec_map.rs b/src/libcollections/vec_map.rs index 9f83b91fc9b..f2a9bb4392c 100644 --- a/src/libcollections/vec_map.rs +++ b/src/libcollections/vec_map.rs @@ -19,7 +19,7 @@ use core::cmp::Ordering; use core::default::Default; use core::fmt; use core::hash::{Hash, Writer, Hasher}; -use core::iter::{Enumerate, FilterMap, Map, FromIterator}; +use core::iter::{Enumerate, FilterMap, Map, FromIterator, IntoIterator}; use core::iter; use core::mem::replace; use core::ops::{Index, IndexMut}; @@ -536,6 +536,30 @@ impl<V> FromIterator<(uint, V)> for VecMap<V> { } } +impl<T> IntoIterator for VecMap<T> { + type Iter = IntoIter<T>; + + fn into_iter(self) -> IntoIter<T> { + self.into_iter() + } +} + +impl<'a, T> IntoIterator for &'a VecMap<T> { + type Iter = Iter<'a, T>; + + fn into_iter(self) -> Iter<'a, T> { + self.iter() + } +} + +impl<'a, T> IntoIterator for &'a mut VecMap<T> { + type Iter = IterMut<'a, T>; + + fn into_iter(mut self) -> IterMut<'a, T> { + self.iter_mut() + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl<V> Extend<(uint, V)> for VecMap<V> { fn extend<Iter: Iterator<Item=(uint, V)>>(&mut self, mut iter: Iter) { @@ -768,7 +792,7 @@ mod test_map { #[test] fn test_get_mut() { let mut m = VecMap::new(); - assert!(m.insert(1, 12i).is_none()); + assert!(m.insert(1, 12).is_none()); assert!(m.insert(2, 8).is_none()); assert!(m.insert(5, 14).is_none()); let new = 100; @@ -783,7 +807,7 @@ mod test_map { let mut map = VecMap::new(); assert_eq!(map.len(), 0); assert!(map.is_empty()); - assert!(map.insert(5, 20i).is_none()); + assert!(map.insert(5, 20).is_none()); assert_eq!(map.len(), 1); assert!(!map.is_empty()); assert!(map.insert(11, 12).is_none()); @@ -797,7 +821,7 @@ mod test_map { #[test] fn test_clear() { let mut map = VecMap::new(); - assert!(map.insert(5, 20i).is_none()); + assert!(map.insert(5, 20).is_none()); assert!(map.insert(11, 12).is_none()); assert!(map.insert(14, 22).is_none()); map.clear(); @@ -810,15 +834,15 @@ mod test_map { #[test] fn test_insert() { let mut m = VecMap::new(); - assert_eq!(m.insert(1, 2i), None); - assert_eq!(m.insert(1, 3i), Some(2)); - assert_eq!(m.insert(1, 4i), Some(3)); + assert_eq!(m.insert(1, 2), None); + assert_eq!(m.insert(1, 3), Some(2)); + assert_eq!(m.insert(1, 4), Some(3)); } #[test] fn test_remove() { let mut m = VecMap::new(); - m.insert(1, 2i); + m.insert(1, 2); assert_eq!(m.remove(&1), Some(2)); assert_eq!(m.remove(&1), None); } @@ -853,7 +877,7 @@ mod test_map { fn test_iterator() { let mut m = VecMap::new(); - assert!(m.insert(0, 1i).is_none()); + assert!(m.insert(0, 1).is_none()); assert!(m.insert(1, 2).is_none()); assert!(m.insert(3, 5).is_none()); assert!(m.insert(6, 10).is_none()); @@ -878,7 +902,7 @@ mod test_map { fn test_iterator_size_hints() { let mut m = VecMap::new(); - assert!(m.insert(0, 1i).is_none()); + assert!(m.insert(0, 1).is_none()); assert!(m.insert(1, 2).is_none()); assert!(m.insert(3, 5).is_none()); assert!(m.insert(6, 10).is_none()); @@ -894,7 +918,7 @@ mod test_map { fn test_mut_iterator() { let mut m = VecMap::new(); - assert!(m.insert(0, 1i).is_none()); + assert!(m.insert(0, 1).is_none()); assert!(m.insert(1, 2).is_none()); assert!(m.insert(3, 5).is_none()); assert!(m.insert(6, 10).is_none()); @@ -917,7 +941,7 @@ mod test_map { fn test_rev_iterator() { let mut m = VecMap::new(); - assert!(m.insert(0, 1i).is_none()); + assert!(m.insert(0, 1).is_none()); assert!(m.insert(1, 2).is_none()); assert!(m.insert(3, 5).is_none()); assert!(m.insert(6, 10).is_none()); @@ -936,7 +960,7 @@ mod test_map { fn test_mut_rev_iterator() { let mut m = VecMap::new(); - assert!(m.insert(0, 1i).is_none()); + assert!(m.insert(0, 1).is_none()); assert!(m.insert(1, 2).is_none()); assert!(m.insert(3, 5).is_none()); assert!(m.insert(6, 10).is_none()); @@ -958,13 +982,13 @@ mod test_map { #[test] fn test_move_iter() { let mut m = VecMap::new(); - m.insert(1, box 2i); + m.insert(1, box 2); let mut called = false; for (k, v) in m.into_iter() { assert!(!called); called = true; assert_eq!(k, 1); - assert_eq!(v, box 2i); + assert_eq!(v, box 2); } assert!(called); } @@ -987,8 +1011,8 @@ mod test_map { let mut map = VecMap::new(); let empty = VecMap::<int>::new(); - map.insert(1, 2i); - map.insert(3, 4i); + map.insert(1, 2); + map.insert(3, 4); let map_str = format!("{:?}", map); assert!(map_str == "VecMap {1: 2, 3: 4}" || map_str == "{3: 4, 1: 2}"); @@ -1012,9 +1036,9 @@ mod test_map { let mut b = VecMap::new(); assert!(a == b); - assert!(a.insert(0, 5i).is_none()); + assert!(a.insert(0, 5).is_none()); assert!(a != b); - assert!(b.insert(0, 4i).is_none()); + assert!(b.insert(0, 4).is_none()); assert!(a != b); assert!(a.insert(5, 19).is_none()); assert!(a != b); @@ -1034,7 +1058,7 @@ mod test_map { let mut b = VecMap::new(); assert!(!(a < b) && !(b < a)); - assert!(b.insert(2u, 5i).is_none()); + assert!(b.insert(2u, 5).is_none()); assert!(a < b); assert!(a.insert(2, 7).is_none()); assert!(!(a < b) && b < a); @@ -1052,7 +1076,7 @@ mod test_map { let mut b = VecMap::new(); assert!(a <= b && a >= b); - assert!(a.insert(1u, 1i).is_none()); + assert!(a.insert(1u, 1).is_none()); assert!(a > b && a >= b); assert!(b < a && b <= a); assert!(b.insert(2, 2).is_none()); diff --git a/src/libcore/array.rs b/src/libcore/array.rs index a81615944fb..ec3d9783255 100644 --- a/src/libcore/array.rs +++ b/src/libcore/array.rs @@ -18,12 +18,14 @@ use clone::Clone; use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering}; use fmt; use hash::{Hash, Hasher, self}; +use iter::IntoIterator; use marker::Copy; #[cfg(stage0)] use ops::{Deref, FullRange}; #[cfg(not(stage0))] use ops::Deref; use option::Option; +use slice::{Iter, IterMut, SliceExt}; // macro for implementing n-ary tuple functions and operations macro_rules! array_impls { @@ -49,6 +51,22 @@ macro_rules! array_impls { } } + impl<'a, T> IntoIterator for &'a [T; $N] { + type Iter = Iter<'a, T>; + + fn into_iter(self) -> Iter<'a, T> { + self.iter() + } + } + + impl<'a, T> IntoIterator for &'a mut [T; $N] { + type Iter = IterMut<'a, T>; + + fn into_iter(self) -> IterMut<'a, T> { + self.iter_mut() + } + } + #[stable(feature = "rust1", since = "1.0.0")] impl<A, B> PartialEq<[B; $N]> for [A; $N] where A: PartialEq<B> { #[inline] diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index 8b7a4c677ac..2ff67ebd550 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -10,7 +10,6 @@ //! Utilities for formatting and printing strings -#![allow(unused_variables)] #![stable(feature = "rust1", since = "1.0.0")] use any; @@ -27,6 +26,7 @@ use result; use slice::SliceExt; use slice; use str::{self, StrExt}; +use self::rt::v1::Alignment; pub use self::num::radix; pub use self::num::Radix; @@ -34,10 +34,15 @@ pub use self::num::RadixFmt; mod num; mod float; -pub mod rt; -#[unstable(feature = "core", - reason = "core and I/O reconciliation may alter this definition")] +#[stable(feature = "rust1", since = "1.0.0")] +#[doc(hidden)] +pub mod rt { + #[cfg(stage0)] pub use self::v1::*; + pub mod v1; +} + +#[stable(feature = "rust1", since = "1.0.0")] /// The type returned by formatter methods. pub type Result = result::Result<(), Error>; @@ -46,8 +51,7 @@ pub type Result = result::Result<(), Error>; /// This type does not support transmission of an error other than that an error /// occurred. Any extra information must be arranged to be transmitted through /// some other means. -#[unstable(feature = "core", - reason = "core and I/O reconciliation may alter this definition")] +#[stable(feature = "rust1", since = "1.0.0")] #[derive(Copy, Debug)] pub struct Error; @@ -60,8 +64,7 @@ pub struct Error; /// This trait should generally not be implemented by consumers of the standard /// library. The `write!` macro accepts an instance of `io::Writer`, and the /// `io::Writer` trait is favored over implementing this trait. -#[unstable(feature = "core", - reason = "waiting for core and I/O reconciliation")] +#[stable(feature = "rust1", since = "1.0.0")] pub trait Writer { /// Writes a slice of bytes into this writer, returning whether the write /// succeeded. @@ -73,12 +76,14 @@ pub trait Writer { /// # Errors /// /// This function will return an instance of `FormatError` on error. + #[stable(feature = "rust1", since = "1.0.0")] fn write_str(&mut self, s: &str) -> Result; /// Glue for usage of the `write!` macro with implementers of this trait. /// /// This method should generally not be invoked manually, but rather through /// the `write!` macro itself. + #[stable(feature = "rust1", since = "1.0.0")] fn write_fmt(&mut self, args: Arguments) -> Result { // This Adapter is needed to allow `self` (of type `&mut // Self`) to be cast to a FormatWriter (below) without @@ -104,18 +109,17 @@ pub trait Writer { /// A struct to represent both where to emit formatting strings to and how they /// should be formatted. A mutable version of this is passed to all formatting /// traits. -#[unstable(feature = "core", - reason = "name may change and implemented traits are also unstable")] +#[stable(feature = "rust1", since = "1.0.0")] pub struct Formatter<'a> { flags: uint, fill: char, - align: rt::Alignment, + align: rt::v1::Alignment, width: Option<uint>, precision: Option<uint>, buf: &'a mut (Writer+'a), - curarg: slice::Iter<'a, Argument<'a>>, - args: &'a [Argument<'a>], + curarg: slice::Iter<'a, ArgumentV1<'a>>, + args: &'a [ArgumentV1<'a>], } // NB. Argument is essentially an optimized partially applied formatting function, @@ -127,35 +131,40 @@ enum Void {} /// family of functions. It contains a function to format the given value. At /// compile time it is ensured that the function and the value have the correct /// types, and then this struct is used to canonicalize arguments to one type. -#[unstable(feature = "core", - reason = "implementation detail of the `format_args!` macro")] #[derive(Copy)] -pub struct Argument<'a> { +#[stable(feature = "rust1", since = "1.0.0")] +#[doc(hidden)] +pub struct ArgumentV1<'a> { value: &'a Void, formatter: fn(&Void, &mut Formatter) -> Result, } -impl<'a> Argument<'a> { +impl<'a> ArgumentV1<'a> { #[inline(never)] fn show_uint(x: &uint, f: &mut Formatter) -> Result { Display::fmt(x, f) } - fn new<'b, T>(x: &'b T, f: fn(&T, &mut Formatter) -> Result) -> Argument<'b> { + #[doc(hidden)] + #[stable(feature = "rust1", since = "1.0.0")] + pub fn new<'b, T>(x: &'b T, + f: fn(&T, &mut Formatter) -> Result) -> ArgumentV1<'b> { unsafe { - Argument { + ArgumentV1 { formatter: mem::transmute(f), value: mem::transmute(x) } } } - fn from_uint(x: &uint) -> Argument { - Argument::new(x, Argument::show_uint) + #[doc(hidden)] + #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_uint(x: &uint) -> ArgumentV1 { + ArgumentV1::new(x, ArgumentV1::show_uint) } fn as_uint(&self) -> Option<uint> { - if self.formatter as uint == Argument::show_uint as uint { + if self.formatter as uint == ArgumentV1::show_uint as uint { Some(unsafe { *(self.value as *const _ as *const uint) }) } else { None @@ -163,14 +172,32 @@ impl<'a> Argument<'a> { } } +// flags available in the v1 format of format_args +#[derive(Copy)] +#[allow(dead_code)] // SignMinus isn't currently used +enum FlagV1 { SignPlus, SignMinus, Alternate, SignAwareZeroPad, } + impl<'a> Arguments<'a> { /// When using the format_args!() macro, this function is used to generate the /// Arguments structure. #[doc(hidden)] #[inline] - #[unstable(feature = "core", - reason = "implementation detail of the `format_args!` macro")] + #[stable(feature = "rust1", since = "1.0.0")] + pub fn new_v1(pieces: &'a [&'a str], + args: &'a [ArgumentV1<'a>]) -> Arguments<'a> { + Arguments { + pieces: pieces, + fmt: None, + args: args + } + } + + /// When using the format_args!() macro, this function is used to generate the + /// Arguments structure. + #[doc(hidden)] #[inline] + #[cfg(stage0)] + #[stable(feature = "rust1", since = "1.0.0")] pub fn new(pieces: &'a [&'a str], - args: &'a [Argument<'a>]) -> Arguments<'a> { + args: &'a [ArgumentV1<'a>]) -> Arguments<'a> { Arguments { pieces: pieces, fmt: None, @@ -185,11 +212,28 @@ impl<'a> Arguments<'a> { /// created with `argumentuint`. However, failing to do so doesn't cause /// unsafety, but will ignore invalid . #[doc(hidden)] #[inline] - #[unstable(feature = "core", - reason = "implementation detail of the `format_args!` macro")] + #[cfg(stage0)] + #[stable(feature = "rust1", since = "1.0.0")] pub fn with_placeholders(pieces: &'a [&'a str], - fmt: &'a [rt::Argument], - args: &'a [Argument<'a>]) -> Arguments<'a> { + fmt: &'a [rt::v1::Argument], + args: &'a [ArgumentV1<'a>]) -> Arguments<'a> { + Arguments { + pieces: pieces, + fmt: Some(fmt), + args: args + } + } + /// This function is used to specify nonstandard formatting parameters. + /// The `pieces` array must be at least as long as `fmt` to construct + /// a valid Arguments structure. Also, any `Count` within `fmt` that is + /// `CountIsParam` or `CountIsNextParam` has to point to an argument + /// created with `argumentuint`. However, failing to do so doesn't cause + /// unsafety, but will ignore invalid . + #[doc(hidden)] #[inline] + #[cfg(not(stage0))] + pub fn new_v1_formatted(pieces: &'a [&'a str], + args: &'a [ArgumentV1<'a>], + fmt: &'a [rt::v1::Argument]) -> Arguments<'a> { Arguments { pieces: pieces, fmt: Some(fmt), @@ -214,11 +258,11 @@ pub struct Arguments<'a> { pieces: &'a [&'a str], // Placeholder specs, or `None` if all specs are default (as in "{}{}"). - fmt: Option<&'a [rt::Argument]>, + fmt: Option<&'a [rt::v1::Argument]>, // Dynamic arguments for interpolation, to be interleaved with string // pieces. (Every argument is preceded by a string piece.) - args: &'a [Argument<'a>], + args: &'a [ArgumentV1<'a>], } #[stable(feature = "rust1", since = "1.0.0")] @@ -237,20 +281,20 @@ impl<'a> Display for Arguments<'a> { /// Format trait for the `:?` format. Useful for debugging, all types /// should implement this. -#[unstable(feature = "core", - reason = "I/O and core have yet to be reconciled")] #[deprecated(since = "1.0.0", reason = "renamed to Debug")] +#[unstable(feature = "old_fmt")] pub trait Show { /// Formats the value using the given formatter. + #[stable(feature = "rust1", since = "1.0.0")] fn fmt(&self, &mut Formatter) -> Result; } /// Format trait for the `:?` format. Useful for debugging, all types /// should implement this. -#[unstable(feature = "core", - reason = "I/O and core have yet to be reconciled")] -#[rustc_on_unimplemented = "`{Self}` cannot be formatted using `:?`; if it is defined in your \ - crate, add `#[derive(Debug)]` or manually implement it"] +#[stable(feature = "rust1", since = "1.0.0")] +#[rustc_on_unimplemented = "`{Self}` cannot be formatted using `:?`; if it is \ + defined in your crate, add `#[derive(Debug)]` or \ + manually implement it"] #[lang = "debug_trait"] pub trait Debug { /// Formats the value using the given formatter. @@ -264,19 +308,20 @@ impl<T: Show + ?Sized> Debug for T { /// When a value can be semantically expressed as a String, this trait may be /// used. It corresponds to the default format, `{}`. -#[unstable(feature = "core")] #[deprecated(since = "1.0.0", reason = "renamed to Display")] +#[unstable(feature = "old_fmt")] pub trait String { /// Formats the value using the given formatter. + #[stable(feature = "rust1", since = "1.0.0")] fn fmt(&self, &mut Formatter) -> Result; } /// When a value can be semantically expressed as a String, this trait may be /// used. It corresponds to the default format, `{}`. -#[unstable(feature = "core", - reason = "I/O and core have yet to be reconciled")] -#[rustc_on_unimplemented = "`{Self}` cannot be formatted with the default formatter; try using \ - `:?` instead if you are using a format string"] +#[rustc_on_unimplemented = "`{Self}` cannot be formatted with the default \ + formatter; try using `:?` instead if you are using \ + a format string"] +#[stable(feature = "rust1", since = "1.0.0")] pub trait Display { /// Formats the value using the given formatter. fn fmt(&self, &mut Formatter) -> Result; @@ -288,58 +333,58 @@ impl<T: String + ?Sized> Display for T { } /// Format trait for the `o` character -#[unstable(feature = "core", - reason = "I/O and core have yet to be reconciled")] +#[stable(feature = "rust1", since = "1.0.0")] pub trait Octal { /// Formats the value using the given formatter. + #[stable(feature = "rust1", since = "1.0.0")] fn fmt(&self, &mut Formatter) -> Result; } /// Format trait for the `b` character -#[unstable(feature = "core", - reason = "I/O and core have yet to be reconciled")] +#[stable(feature = "rust1", since = "1.0.0")] pub trait Binary { /// Formats the value using the given formatter. + #[stable(feature = "rust1", since = "1.0.0")] fn fmt(&self, &mut Formatter) -> Result; } /// Format trait for the `x` character -#[unstable(feature = "core", - reason = "I/O and core have yet to be reconciled")] +#[stable(feature = "rust1", since = "1.0.0")] pub trait LowerHex { /// Formats the value using the given formatter. + #[stable(feature = "rust1", since = "1.0.0")] fn fmt(&self, &mut Formatter) -> Result; } /// Format trait for the `X` character -#[unstable(feature = "core", - reason = "I/O and core have yet to be reconciled")] +#[stable(feature = "rust1", since = "1.0.0")] pub trait UpperHex { /// Formats the value using the given formatter. + #[stable(feature = "rust1", since = "1.0.0")] fn fmt(&self, &mut Formatter) -> Result; } /// Format trait for the `p` character -#[unstable(feature = "core", - reason = "I/O and core have yet to be reconciled")] +#[stable(feature = "rust1", since = "1.0.0")] pub trait Pointer { /// Formats the value using the given formatter. + #[stable(feature = "rust1", since = "1.0.0")] fn fmt(&self, &mut Formatter) -> Result; } /// Format trait for the `e` character -#[unstable(feature = "core", - reason = "I/O and core have yet to be reconciled")] +#[stable(feature = "rust1", since = "1.0.0")] pub trait LowerExp { /// Formats the value using the given formatter. + #[stable(feature = "rust1", since = "1.0.0")] fn fmt(&self, &mut Formatter) -> Result; } /// Format trait for the `E` character -#[unstable(feature = "core", - reason = "I/O and core have yet to be reconciled")] +#[stable(feature = "rust1", since = "1.0.0")] pub trait UpperExp { /// Formats the value using the given formatter. + #[stable(feature = "rust1", since = "1.0.0")] fn fmt(&self, &mut Formatter) -> Result; } @@ -351,16 +396,14 @@ pub trait UpperExp { /// /// * output - the buffer to write output to /// * args - the precompiled arguments generated by `format_args!` -#[unstable(feature = "core", - reason = "libcore and I/O have yet to be reconciled, and this is an \ - implementation detail which should not otherwise be exported")] +#[stable(feature = "rust1", since = "1.0.0")] pub fn write(output: &mut Writer, args: Arguments) -> Result { let mut formatter = Formatter { flags: 0, width: None, precision: None, buf: output, - align: rt::AlignUnknown, + align: Alignment::Unknown, fill: ' ', args: args.args, curarg: args.args.iter(), @@ -402,7 +445,7 @@ impl<'a> Formatter<'a> { // First up is the collection of functions used to execute a format string // at runtime. This consumes all of the compile-time statics generated by // the format! syntax extension. - fn run(&mut self, arg: &rt::Argument) -> Result { + fn run(&mut self, arg: &rt::v1::Argument) -> Result { // Fill in the format parameters into the formatter self.fill = arg.format.fill; self.align = arg.format.align; @@ -412,22 +455,22 @@ impl<'a> Formatter<'a> { // Extract the correct argument let value = match arg.position { - rt::ArgumentNext => { *self.curarg.next().unwrap() } - rt::ArgumentIs(i) => self.args[i], + rt::v1::Position::Next => { *self.curarg.next().unwrap() } + rt::v1::Position::At(i) => self.args[i], }; // Then actually do some printing (value.formatter)(value.value, self) } - fn getcount(&mut self, cnt: &rt::Count) -> Option<uint> { + fn getcount(&mut self, cnt: &rt::v1::Count) -> Option<uint> { match *cnt { - rt::CountIs(n) => Some(n), - rt::CountImplied => None, - rt::CountIsParam(i) => { + rt::v1::Count::Is(n) => Some(n), + rt::v1::Count::Implied => None, + rt::v1::Count::Param(i) => { self.args[i].as_uint() } - rt::CountIsNextParam => { + rt::v1::Count::NextParam => { self.curarg.next().and_then(|arg| arg.as_uint()) } } @@ -437,8 +480,8 @@ impl<'a> Formatter<'a> { // all formatting traits can use. /// Performs the correct padding for an integer which has already been - /// emitted into a byte-array. The byte-array should *not* contain the sign - /// for the integer, that will be added by this method. + /// emitted into a str. The str should *not* contain the sign for the + /// integer, that will be added by this method. /// /// # Arguments /// @@ -449,27 +492,25 @@ impl<'a> Formatter<'a> { /// /// This function will correctly account for the flags provided as well as /// the minimum width. It will not take precision into account. - #[unstable(feature = "core", - reason = "definition may change slightly over time")] + #[stable(feature = "rust1", since = "1.0.0")] pub fn pad_integral(&mut self, is_positive: bool, prefix: &str, buf: &str) -> Result { use char::CharExt; - use fmt::rt::{FlagAlternate, FlagSignPlus, FlagSignAwareZeroPad}; let mut width = buf.len(); let mut sign = None; if !is_positive { sign = Some('-'); width += 1; - } else if self.flags & (1 << (FlagSignPlus as uint)) != 0 { + } else if self.flags & (1 << (FlagV1::SignPlus as uint)) != 0 { sign = Some('+'); width += 1; } let mut prefixed = false; - if self.flags & (1 << (FlagAlternate as uint)) != 0 { + if self.flags & (1 << (FlagV1::Alternate as uint)) != 0 { prefixed = true; width += prefix.char_len(); } @@ -499,16 +540,16 @@ impl<'a> Formatter<'a> { } // The sign and prefix goes before the padding if the fill character // is zero - Some(min) if self.flags & (1 << (FlagSignAwareZeroPad as uint)) != 0 => { + Some(min) if self.flags & (1 << (FlagV1::SignAwareZeroPad as uint)) != 0 => { self.fill = '0'; try!(write_prefix(self)); - self.with_padding(min - width, rt::AlignRight, |f| { + self.with_padding(min - width, Alignment::Right, |f| { f.buf.write_str(buf) }) } // Otherwise, the sign and prefix goes after the padding Some(min) => { - self.with_padding(min - width, rt::AlignRight, |f| { + self.with_padding(min - width, Alignment::Right, |f| { try!(write_prefix(f)); f.buf.write_str(buf) }) } @@ -526,8 +567,7 @@ impl<'a> Formatter<'a> { /// is longer than this length /// /// Notably this function ignored the `flag` parameters - #[unstable(feature = "core", - reason = "definition may change slightly over time")] + #[stable(feature = "rust1", since = "1.0.0")] pub fn pad(&mut self, s: &str) -> Result { // Make sure there's a fast path up front if self.width.is_none() && self.precision.is_none() { @@ -561,7 +601,7 @@ impl<'a> Formatter<'a> { // If we're under both the maximum and the minimum width, then fill // up the minimum width with the specified string + some alignment. Some(width) => { - self.with_padding(width - s.char_len(), rt::AlignLeft, |me| { + self.with_padding(width - s.char_len(), Alignment::Left, |me| { me.buf.write_str(s) }) } @@ -570,19 +610,20 @@ impl<'a> Formatter<'a> { /// Runs a callback, emitting the correct padding either before or /// afterwards depending on whether right or left alignment is requested. - fn with_padding<F>(&mut self, padding: uint, default: rt::Alignment, f: F) -> Result where - F: FnOnce(&mut Formatter) -> Result, + fn with_padding<F>(&mut self, padding: uint, default: Alignment, + f: F) -> Result + where F: FnOnce(&mut Formatter) -> Result, { use char::CharExt; let align = match self.align { - rt::AlignUnknown => default, + Alignment::Unknown => default, _ => self.align }; let (pre_pad, post_pad) = match align { - rt::AlignLeft => (0, padding), - rt::AlignRight | rt::AlignUnknown => (padding, 0), - rt::AlignCenter => (padding / 2, (padding + 1) / 2), + Alignment::Left => (0, padding), + Alignment::Right | Alignment::Unknown => (padding, 0), + Alignment::Center => (padding / 2, (padding + 1) / 2), }; let mut fill = [0u8; 4]; @@ -604,23 +645,20 @@ impl<'a> Formatter<'a> { /// Writes some data to the underlying buffer contained within this /// formatter. - #[unstable(feature = "core", - reason = "reconciling core and I/O may alter this definition")] + #[stable(feature = "rust1", since = "1.0.0")] pub fn write_str(&mut self, data: &str) -> Result { self.buf.write_str(data) } /// Writes some formatted information into this instance - #[unstable(feature = "core", - reason = "reconciling core and I/O may alter this definition")] + #[stable(feature = "rust1", since = "1.0.0")] pub fn write_fmt(&mut self, fmt: Arguments) -> Result { write(self.buf, fmt) } /// Flags for formatting (packed version of rt::Flag) - #[unstable(feature = "core", - reason = "return type may change and method was just created")] - pub fn flags(&self) -> uint { self.flags } + #[stable(feature = "rust1", since = "1.0.0")] + pub fn flags(&self) -> usize { self.flags } /// Character used as 'fill' whenever there is alignment #[unstable(feature = "core", reason = "method was just created")] @@ -628,7 +666,7 @@ impl<'a> Formatter<'a> { /// Flag indicating what form of alignment was requested #[unstable(feature = "core", reason = "method was just created")] - pub fn align(&self) -> rt::Alignment { self.align } + pub fn align(&self) -> Alignment { self.align } /// Optionally specified integer width that the output should be #[unstable(feature = "core", reason = "method was just created")] @@ -649,20 +687,20 @@ impl Display for Error { /// This is a function which calls are emitted to by the compiler itself to /// create the Argument structures that are passed into the `format` function. #[doc(hidden)] #[inline] -#[unstable(feature = "core", - reason = "implementation detail of the `format_args!` macro")] +#[cfg(stage0)] +#[stable(feature = "rust1", since = "1.0.0")] pub fn argument<'a, T>(f: fn(&T, &mut Formatter) -> Result, - t: &'a T) -> Argument<'a> { - Argument::new(t, f) + t: &'a T) -> ArgumentV1<'a> { + ArgumentV1::new(t, f) } /// When the compiler determines that the type of an argument *must* be a uint /// (such as for width and precision), then it invokes this method. #[doc(hidden)] #[inline] -#[unstable(feature = "core", - reason = "implementation detail of the `format_args!` macro")] -pub fn argumentuint<'a>(s: &'a uint) -> Argument<'a> { - Argument::from_uint(s) +#[cfg(stage0)] +#[stable(feature = "rust1", since = "1.0.0")] +pub fn argumentuint<'a>(s: &'a uint) -> ArgumentV1<'a> { + ArgumentV1::from_uint(s) } // Implementations of the core formatting traits @@ -741,9 +779,9 @@ impl Display for char { #[stable(feature = "rust1", since = "1.0.0")] impl<T> Pointer for *const T { fn fmt(&self, f: &mut Formatter) -> Result { - f.flags |= 1 << (rt::FlagAlternate as uint); + f.flags |= 1 << (FlagV1::Alternate as uint); let ret = LowerHex::fmt(&(*self as uint), f); - f.flags &= !(1 << (rt::FlagAlternate as uint)); + f.flags &= !(1 << (FlagV1::Alternate as uint)); ret } } @@ -899,7 +937,7 @@ impl<'a> Debug for &'a (any::Any+'a) { #[stable(feature = "rust1", since = "1.0.0")] impl<T: Debug> Debug for [T] { fn fmt(&self, f: &mut Formatter) -> Result { - if f.flags & (1 << (rt::FlagAlternate as uint)) == 0 { + if f.flags & (1 << (FlagV1::Alternate as uint)) == 0 { try!(write!(f, "[")); } let mut is_first = true; @@ -911,7 +949,7 @@ impl<T: Debug> Debug for [T] { } try!(write!(f, "{:?}", *x)) } - if f.flags & (1 << (rt::FlagAlternate as uint)) == 0 { + if f.flags & (1 << (FlagV1::Alternate as uint)) == 0 { try!(write!(f, "]")); } Ok(()) diff --git a/src/libcore/fmt/rt.rs b/src/libcore/fmt/rt.rs deleted file mode 100644 index 0b2c1efbc5d..00000000000 --- a/src/libcore/fmt/rt.rs +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2013 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 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! This is an internal module used by the ifmt! runtime. These structures are -//! emitted to static arrays to precompile format strings ahead of time. -//! -//! These definitions are similar to their `ct` equivalents, but differ in that -//! these can be statically allocated and are slightly optimized for the runtime - -#![unstable(feature = "core", - reason = "implementation detail of the `format_args!` macro")] - -pub use self::Alignment::*; -pub use self::Count::*; -pub use self::Position::*; -pub use self::Flag::*; - -#[doc(hidden)] -#[derive(Copy)] -pub struct Argument { - pub position: Position, - pub format: FormatSpec, -} - -#[doc(hidden)] -#[derive(Copy)] -pub struct FormatSpec { - pub fill: char, - pub align: Alignment, - pub flags: uint, - pub precision: Count, - pub width: Count, -} - -/// Possible alignments that can be requested as part of a formatting directive. -#[derive(Copy, PartialEq)] -pub enum Alignment { - /// Indication that contents should be left-aligned. - AlignLeft, - /// Indication that contents should be right-aligned. - AlignRight, - /// Indication that contents should be center-aligned. - AlignCenter, - /// No alignment was requested. - AlignUnknown, -} - -#[doc(hidden)] -#[derive(Copy)] -pub enum Count { - CountIs(uint), CountIsParam(uint), CountIsNextParam, CountImplied, -} - -#[doc(hidden)] -#[derive(Copy)] -pub enum Position { - ArgumentNext, ArgumentIs(uint) -} - -/// Flags which can be passed to formatting via a directive. -/// -/// These flags are discovered through the `flags` field of the `Formatter` -/// structure. The flag in that structure is a union of these flags into a -/// `uint` where each flag's discriminant is the corresponding bit. -#[derive(Copy)] -pub enum Flag { - /// A flag which enables number formatting to always print the sign of a - /// number. - FlagSignPlus, - /// Currently not a used flag - FlagSignMinus, - /// Indicates that the "alternate formatting" for a type should be used. - /// - /// The meaning of this flag is type-specific. - FlagAlternate, - /// Indicates that padding should be done with a `0` character as well as - /// being aware of the sign to be printed. - FlagSignAwareZeroPad, -} diff --git a/src/libcore/fmt/rt/v1.rs b/src/libcore/fmt/rt/v1.rs new file mode 100644 index 00000000000..f0c82759b70 --- /dev/null +++ b/src/libcore/fmt/rt/v1.rs @@ -0,0 +1,94 @@ +// Copyright 2013 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! This is an internal module used by the ifmt! runtime. These structures are +//! emitted to static arrays to precompile format strings ahead of time. +//! +//! These definitions are similar to their `ct` equivalents, but differ in that +//! these can be statically allocated and are slightly optimized for the runtime + +#![stable(feature = "rust1", since = "1.0.0")] + +#[cfg(stage0)] pub use self::Position::*; + +#[cfg(stage0)] pub use self::Alignment::Left as AlignLeft; +#[cfg(stage0)] pub use self::Alignment::Right as AlignRight; +#[cfg(stage0)] pub use self::Alignment::Center as AlignCenter; +#[cfg(stage0)] pub use self::Alignment::Unknown as AlignUnknown; +#[cfg(stage0)] pub use self::Count::Is as CountIs; +#[cfg(stage0)] pub use self::Count::Implied as CountImplied; +#[cfg(stage0)] pub use self::Count::Param as CountIsParam; +#[cfg(stage0)] pub use self::Count::NextParam as CountIsNextParam; +#[cfg(stage0)] pub use self::Position::Next as ArgumentNext; +#[cfg(stage0)] pub use self::Position::At as ArgumentIs; + +#[derive(Copy)] +#[stable(feature = "rust1", since = "1.0.0")] +pub struct Argument { + #[stable(feature = "rust1", since = "1.0.0")] + pub position: Position, + #[stable(feature = "rust1", since = "1.0.0")] + pub format: FormatSpec, +} + +#[derive(Copy)] +#[stable(feature = "rust1", since = "1.0.0")] +pub struct FormatSpec { + #[stable(feature = "rust1", since = "1.0.0")] + pub fill: char, + #[stable(feature = "rust1", since = "1.0.0")] + pub align: Alignment, + #[stable(feature = "rust1", since = "1.0.0")] + pub flags: uint, + #[stable(feature = "rust1", since = "1.0.0")] + pub precision: Count, + #[stable(feature = "rust1", since = "1.0.0")] + pub width: Count, +} + +/// Possible alignments that can be requested as part of a formatting directive. +#[derive(Copy, PartialEq)] +#[stable(feature = "rust1", since = "1.0.0")] +pub enum Alignment { + /// Indication that contents should be left-aligned. + #[stable(feature = "rust1", since = "1.0.0")] + Left, + /// Indication that contents should be right-aligned. + #[stable(feature = "rust1", since = "1.0.0")] + Right, + /// Indication that contents should be center-aligned. + #[stable(feature = "rust1", since = "1.0.0")] + Center, + /// No alignment was requested. + #[stable(feature = "rust1", since = "1.0.0")] + Unknown, +} + +#[derive(Copy)] +#[stable(feature = "rust1", since = "1.0.0")] +pub enum Count { + #[stable(feature = "rust1", since = "1.0.0")] + Is(usize), + #[stable(feature = "rust1", since = "1.0.0")] + Param(usize), + #[stable(feature = "rust1", since = "1.0.0")] + NextParam, + #[stable(feature = "rust1", since = "1.0.0")] + Implied, +} + +#[derive(Copy)] +#[stable(feature = "rust1", since = "1.0.0")] +pub enum Position { + #[stable(feature = "rust1", since = "1.0.0")] + Next, + #[stable(feature = "rust1", since = "1.0.0")] + At(usize) +} diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index b6b2f9c57fe..b0906651da8 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -122,6 +122,22 @@ pub trait FromIterator<A> { fn from_iter<T: Iterator<Item=A>>(iterator: T) -> Self; } +/// Conversion into an `Iterator` +pub trait IntoIterator { + type Iter: Iterator; + + /// Consumes `Self` and returns an iterator over it + fn into_iter(self) -> Self::Iter; +} + +impl<I> IntoIterator for I where I: Iterator { + type Iter = I; + + fn into_iter(self) -> I { + self + } +} + /// A type growable from an `Iterator` implementation #[stable(feature = "rust1", since = "1.0.0")] pub trait Extend<A> { @@ -178,7 +194,7 @@ pub trait IteratorExt: Iterator + Sized { #[inline] #[stable(feature = "rust1", since = "1.0.0")] fn nth(&mut self, mut n: usize) -> Option<Self::Item> { - for x in *self { + for x in self.by_ref() { if n == 0 { return Some(x) } n -= 1; } @@ -475,7 +491,7 @@ pub trait IteratorExt: Iterator + Sized { /// fn process<U: Iterator<Item=isize>>(it: U) -> isize { /// let mut it = it.fuse(); /// let mut sum = 0; - /// for x in it { + /// for x in it.by_ref() { /// if x > 5 { /// break; /// } @@ -643,7 +659,7 @@ pub trait IteratorExt: Iterator + Sized { #[inline] #[stable(feature = "rust1", since = "1.0.0")] fn any<F>(&mut self, mut f: F) -> bool where F: FnMut(Self::Item) -> bool { - for x in *self { if f(x) { return true; } } + for x in self.by_ref() { if f(x) { return true; } } false } @@ -663,7 +679,7 @@ pub trait IteratorExt: Iterator + Sized { fn find<P>(&mut self, mut predicate: P) -> Option<Self::Item> where P: FnMut(&Self::Item) -> bool, { - for x in *self { + for x in self.by_ref() { if predicate(&x) { return Some(x) } } None @@ -686,7 +702,7 @@ pub trait IteratorExt: Iterator + Sized { P: FnMut(Self::Item) -> bool, { let mut i = 0; - for x in *self { + for x in self.by_ref() { if predicate(x) { return Some(i); } @@ -1312,7 +1328,7 @@ impl<T, D, I> ExactSizeIterator for Cloned<I> where {} /// An iterator that repeats endlessly -#[derive(Clone, Copy)] +#[derive(Clone)] #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable(feature = "rust1", since = "1.0.0")] pub struct Cycle<I> { @@ -1647,7 +1663,7 @@ impl<A, I, P> Iterator for Filter<A, I, P> where I: Iterator<Item=A>, P: FnMut(& #[inline] fn next(&mut self) -> Option<A> { - for x in self.iter { + for x in self.iter.by_ref() { if (self.predicate)(&x) { return Some(x); } else { @@ -1711,7 +1727,7 @@ impl<A, B, I, F> Iterator for FilterMap<A, B, I, F> where #[inline] fn next(&mut self) -> Option<B> { - for x in self.iter { + for x in self.iter.by_ref() { match (self.f)(x) { Some(y) => return Some(y), None => () @@ -1810,7 +1826,6 @@ impl<I> RandomAccessIterator for Enumerate<I> where I: RandomAccessIterator { /// An iterator with a `peek()` that returns an optional reference to the next element. #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[stable(feature = "rust1", since = "1.0.0")] -#[derive(Copy)] pub struct Peekable<T, I> where I: Iterator<Item=T> { iter: I, peeked: Option<T>, @@ -1897,7 +1912,7 @@ impl<A, I, P> Iterator for SkipWhile<A, I, P> where I: Iterator<Item=A>, P: FnMu #[inline] fn next(&mut self) -> Option<A> { - for x in self.iter { + for x in self.iter.by_ref() { if self.flag || !(self.predicate)(&x) { self.flag = true; return Some(x); @@ -2190,7 +2205,7 @@ impl<A, B, I, U, F> Iterator for FlatMap<A, B, I, U, F> where fn next(&mut self) -> Option<B> { loop { for inner in self.frontiter.iter_mut() { - for x in *inner { + for x in inner.by_ref() { return Some(x) } } @@ -2484,7 +2499,7 @@ impl<A, St, F> Iterator for Unfold<A, St, F> where F: FnMut(&mut St) -> Option<A /// An infinite iterator starting at `start` and advancing by `step` with each /// iteration -#[derive(Clone, Copy)] +#[derive(Clone)] #[unstable(feature = "core", reason = "may be renamed or replaced by range notation adapaters")] pub struct Counter<A> { @@ -2520,7 +2535,7 @@ impl<A: Add<Output=A> + Clone> Iterator for Counter<A> { } /// An iterator over the range [start, stop) -#[derive(Clone, Copy)] +#[derive(Clone)] #[unstable(feature = "core", reason = "will be replaced by range notation")] pub struct Range<A> { diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 1032c56fa22..d2bc30fa74a 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -49,7 +49,6 @@ #![crate_name = "core"] #![unstable(feature = "core")] -#![feature(staged_api)] #![staged_api] #![crate_type = "rlib"] #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", @@ -58,13 +57,16 @@ html_playground_url = "http://play.rust-lang.org/")] #![no_std] -#![allow(unknown_features, raw_pointer_derive)] -#![allow(unknown_features)] #![feature(intrinsics, lang_items)] +#![allow(raw_pointer_derive)] +#![deny(missing_docs)] +#![cfg_attr(not(stage0), allow(unused_mut))] // NOTE: remove after stage0 snap + +#![feature(int_uint)] +#![feature(intrinsics, lang_items)] +#![feature(on_unimplemented)] #![feature(simd, unsafe_destructor, slicing_syntax)] +#![feature(staged_api)] #![feature(unboxed_closures)] -#![allow(unknown_features)] #![feature(int_uint)] -#![feature(on_unimplemented)] -#![deny(missing_docs)] #[macro_use] mod macros; @@ -158,4 +160,6 @@ mod std { pub use marker; pub use ops; pub use option; + // for-loops + pub use iter; } diff --git a/src/libcore/nonzero.rs b/src/libcore/nonzero.rs index 9ccea3b0739..3f83302742c 100644 --- a/src/libcore/nonzero.rs +++ b/src/libcore/nonzero.rs @@ -11,12 +11,14 @@ //! Exposes the NonZero lang item which provides optimization hints. use ops::Deref; +use ptr::Unique; /// Unsafe trait to indicate what types are usable with the NonZero struct pub unsafe trait Zeroable {} unsafe impl<T> Zeroable for *const T {} unsafe impl<T> Zeroable for *mut T {} +unsafe impl<T> Zeroable for Unique<T> { } unsafe impl Zeroable for int {} unsafe impl Zeroable for uint {} unsafe impl Zeroable for i8 {} diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index dd9cc553c7c..b7c5c6640ce 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -17,16 +17,17 @@ use char::CharExt; use clone::Clone; -use cmp::{PartialEq, Eq}; -use cmp::{PartialOrd, Ord}; +use cmp::{PartialEq, Eq, PartialOrd, Ord}; +use error::Error; +use fmt; use intrinsics; use iter::IteratorExt; use marker::Copy; use mem::size_of; use ops::{Add, Sub, Mul, Div, Rem, Neg}; use ops::{Not, BitAnd, BitOr, BitXor, Shl, Shr}; -use option::Option; -use option::Option::{Some, None}; +use option::Option::{self, Some, None}; +use result::Result::{self, Ok, Err}; use str::{FromStr, StrExt}; /// A built-in signed or unsigned integer. @@ -1428,22 +1429,25 @@ pub trait Float } /// A generic trait for converting a string with a radix (base) to a value -#[unstable(feature = "core", reason = "might need to return Result")] +#[unstable(feature = "core", reason = "needs reevaluation")] pub trait FromStrRadix { - fn from_str_radix(str: &str, radix: uint) -> Option<Self>; + type Err; + fn from_str_radix(str: &str, radix: uint) -> Result<Self, Self::Err>; } /// A utility function that just calls FromStrRadix::from_str_radix. -#[unstable(feature = "core", reason = "might need to return Result")] -pub fn from_str_radix<T: FromStrRadix>(str: &str, radix: uint) -> Option<T> { +#[unstable(feature = "core", reason = "needs reevaluation")] +pub fn from_str_radix<T: FromStrRadix>(str: &str, radix: uint) + -> Result<T, T::Err> { FromStrRadix::from_str_radix(str, radix) } macro_rules! from_str_radix_float_impl { ($T:ty) => { - #[unstable(feature = "core", - reason = "might need to return Result")] + #[stable(feature = "rust1", since = "1.0.0")] impl FromStr for $T { + type Err = ParseFloatError; + /// Convert a string in base 10 to a float. /// Accepts an optional decimal exponent. /// @@ -1470,14 +1474,15 @@ macro_rules! from_str_radix_float_impl { /// `None` if the string did not represent a valid number. Otherwise, /// `Some(n)` where `n` is the floating-point number represented by `src`. #[inline] - fn from_str(src: &str) -> Option<$T> { + fn from_str(src: &str) -> Result<$T, ParseFloatError> { from_str_radix(src, 10) } } - #[unstable(feature = "core", - reason = "might need to return Result")] + #[stable(feature = "rust1", since = "1.0.0")] impl FromStrRadix for $T { + type Err = ParseFloatError; + /// Convert a string in a given base to a float. /// /// Due to possible conflicts, this function does **not** accept @@ -1493,24 +1498,28 @@ macro_rules! from_str_radix_float_impl { /// /// # Return value /// - /// `None` if the string did not represent a valid number. Otherwise, - /// `Some(n)` where `n` is the floating-point number represented by `src`. - fn from_str_radix(src: &str, radix: uint) -> Option<$T> { - assert!(radix >= 2 && radix <= 36, + /// `None` if the string did not represent a valid number. + /// Otherwise, `Some(n)` where `n` is the floating-point number + /// represented by `src`. + fn from_str_radix(src: &str, radix: uint) + -> Result<$T, ParseFloatError> { + use self::FloatErrorKind::*; + use self::ParseFloatError as PFE; + assert!(radix >= 2 && radix <= 36, "from_str_radix_float: must lie in the range `[2, 36]` - found {}", radix); // Special values match src { - "inf" => return Some(Float::infinity()), - "-inf" => return Some(Float::neg_infinity()), - "NaN" => return Some(Float::nan()), + "inf" => return Ok(Float::infinity()), + "-inf" => return Ok(Float::neg_infinity()), + "NaN" => return Ok(Float::nan()), _ => {}, } let (is_positive, src) = match src.slice_shift_char() { - None => return None, - Some(('-', "")) => return None, + None => return Err(PFE { kind: Empty }), + Some(('-', "")) => return Err(PFE { kind: Empty }), Some(('-', src)) => (false, src), Some((_, _)) => (true, src), }; @@ -1524,7 +1533,7 @@ macro_rules! from_str_radix_float_impl { let mut exp_info = None::<(char, uint)>; // Parse the integer part of the significand - for (i, c) in cs { + for (i, c) in cs.by_ref() { match c.to_digit(radix) { Some(digit) => { // shift significand one digit left @@ -1541,15 +1550,15 @@ macro_rules! from_str_radix_float_impl { // if we've not seen any non-zero digits. if prev_sig != 0.0 { if is_positive && sig <= prev_sig - { return Some(Float::infinity()); } + { return Ok(Float::infinity()); } if !is_positive && sig >= prev_sig - { return Some(Float::neg_infinity()); } + { return Ok(Float::neg_infinity()); } // Detect overflow by reversing the shift-and-add process if is_positive && (prev_sig != (sig - digit as $T) / radix as $T) - { return Some(Float::infinity()); } + { return Ok(Float::infinity()); } if !is_positive && (prev_sig != (sig + digit as $T) / radix as $T) - { return Some(Float::neg_infinity()); } + { return Ok(Float::neg_infinity()); } } prev_sig = sig; }, @@ -1562,7 +1571,7 @@ macro_rules! from_str_radix_float_impl { break; // start of fractional part }, _ => { - return None; + return Err(PFE { kind: Invalid }); }, }, } @@ -1572,7 +1581,7 @@ macro_rules! from_str_radix_float_impl { // part of the significand if exp_info.is_none() { let mut power = 1.0; - for (i, c) in cs { + for (i, c) in cs.by_ref() { match c.to_digit(radix) { Some(digit) => { // Decrease power one order of magnitude @@ -1585,9 +1594,9 @@ macro_rules! from_str_radix_float_impl { }; // Detect overflow by comparing to last value if is_positive && sig < prev_sig - { return Some(Float::infinity()); } + { return Ok(Float::infinity()); } if !is_positive && sig > prev_sig - { return Some(Float::neg_infinity()); } + { return Ok(Float::neg_infinity()); } prev_sig = sig; }, None => match c { @@ -1596,7 +1605,7 @@ macro_rules! from_str_radix_float_impl { break; // start of exponent }, _ => { - return None; // invalid number + return Err(PFE { kind: Invalid }); }, }, } @@ -1609,7 +1618,7 @@ macro_rules! from_str_radix_float_impl { let base = match c { 'E' | 'e' if radix == 10 => 10.0, 'P' | 'p' if radix == 16 => 2.0, - _ => return None, + _ => return Err(PFE { kind: Invalid }), }; // Parse the exponent as decimal integer @@ -1618,19 +1627,19 @@ macro_rules! from_str_radix_float_impl { Some(('-', src)) => (false, src.parse::<uint>()), Some(('+', src)) => (true, src.parse::<uint>()), Some((_, _)) => (true, src.parse::<uint>()), - None => return None, + None => return Err(PFE { kind: Invalid }), }; match (is_positive, exp) { - (true, Some(exp)) => base.powi(exp as i32), - (false, Some(exp)) => 1.0 / base.powi(exp as i32), - (_, None) => return None, + (true, Ok(exp)) => base.powi(exp as i32), + (false, Ok(exp)) => 1.0 / base.powi(exp as i32), + (_, Err(_)) => return Err(PFE { kind: Invalid }), } }, None => 1.0, // no exponent }; - Some(sig * exp) + Ok(sig * exp) } } } @@ -1640,19 +1649,22 @@ from_str_radix_float_impl! { f64 } macro_rules! from_str_radix_int_impl { ($T:ty) => { - #[unstable(feature = "core", - reason = "might need to return Result")] + #[stable(feature = "rust1", since = "1.0.0")] impl FromStr for $T { + type Err = ParseIntError; #[inline] - fn from_str(src: &str) -> Option<$T> { + fn from_str(src: &str) -> Result<$T, ParseIntError> { from_str_radix(src, 10) } } - #[unstable(feature = "core", - reason = "might need to return Result")] + #[stable(feature = "rust1", since = "1.0.0")] impl FromStrRadix for $T { - fn from_str_radix(src: &str, radix: uint) -> Option<$T> { + type Err = ParseIntError; + fn from_str_radix(src: &str, radix: uint) + -> Result<$T, ParseIntError> { + use self::IntErrorKind::*; + use self::ParseIntError as PIE; assert!(radix >= 2 && radix <= 36, "from_str_radix_int: must lie in the range `[2, 36]` - found {}", radix); @@ -1666,18 +1678,18 @@ macro_rules! from_str_radix_int_impl { for c in src.chars() { let x = match c.to_digit(radix) { Some(x) => x, - None => return None, + None => return Err(PIE { kind: InvalidDigit }), }; result = match result.checked_mul(radix as $T) { Some(result) => result, - None => return None, + None => return Err(PIE { kind: Underflow }), }; result = match result.checked_sub(x as $T) { Some(result) => result, - None => return None, + None => return Err(PIE { kind: Underflow }), }; } - Some(result) + Ok(result) }, Some((_, _)) => { // The number is signed @@ -1685,20 +1697,20 @@ macro_rules! from_str_radix_int_impl { for c in src.chars() { let x = match c.to_digit(radix) { Some(x) => x, - None => return None, + None => return Err(PIE { kind: InvalidDigit }), }; result = match result.checked_mul(radix as $T) { Some(result) => result, - None => return None, + None => return Err(PIE { kind: Overflow }), }; result = match result.checked_add(x as $T) { Some(result) => result, - None => return None, + None => return Err(PIE { kind: Overflow }), }; } - Some(result) + Ok(result) }, - None => None, + None => Err(ParseIntError { kind: Empty }), } } } @@ -1714,3 +1726,63 @@ from_str_radix_int_impl! { u8 } from_str_radix_int_impl! { u16 } from_str_radix_int_impl! { u32 } from_str_radix_int_impl! { u64 } + +/// An error which can be returned when parsing an integer. +#[derive(Debug, Clone, PartialEq)] +#[stable(feature = "rust1", since = "1.0.0")] +pub struct ParseIntError { kind: IntErrorKind } + +#[derive(Debug, Clone, PartialEq)] +enum IntErrorKind { + Empty, + InvalidDigit, + Overflow, + Underflow, +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl fmt::Display for ParseIntError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.description().fmt(f) + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl Error for ParseIntError { + fn description(&self) -> &str { + match self.kind { + IntErrorKind::Empty => "cannot parse integer from empty string", + IntErrorKind::InvalidDigit => "invalid digit found in string", + IntErrorKind::Overflow => "number too large to fit in target type", + IntErrorKind::Underflow => "number too small to fit in target type", + } + } +} + +/// An error which can be returned when parsing a float. +#[derive(Debug, Clone, PartialEq)] +#[stable(feature = "rust1", since = "1.0.0")] +pub struct ParseFloatError { kind: FloatErrorKind } + +#[derive(Debug, Clone, PartialEq)] +enum FloatErrorKind { + Empty, + Invalid, +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl fmt::Display for ParseFloatError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.description().fmt(f) + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl Error for ParseFloatError { + fn description(&self) -> &str { + match self.kind { + FloatErrorKind::Empty => "cannot parse float from empty string", + FloatErrorKind::Invalid => "invalid float literal", + } + } +} diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 0b9b865c137..4b19d29330b 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -1134,55 +1134,6 @@ impl<'a, T: ?Sized> DerefMut for &'a mut T { #[lang="fn"] #[unstable(feature = "core", reason = "uncertain about variadic generics, input versus associated types")] -#[cfg(stage0)] -pub trait Fn<Args,Output> { - /// This is called when the call operator is used. - extern "rust-call" fn call(&self, args: Args) -> Output; -} - -/// A version of the call operator that takes a mutable receiver. -#[lang="fn_mut"] -#[unstable(feature = "core", - reason = "uncertain about variadic generics, input versus associated types")] -#[cfg(stage0)] -pub trait FnMut<Args,Output> { - /// This is called when the call operator is used. - extern "rust-call" fn call_mut(&mut self, args: Args) -> Output; -} - -/// A version of the call operator that takes a by-value receiver. -#[lang="fn_once"] -#[unstable(feature = "core", - reason = "uncertain about variadic generics, input versus associated types")] -#[cfg(stage0)] -pub trait FnOnce<Args,Output> { - /// This is called when the call operator is used. - extern "rust-call" fn call_once(self, args: Args) -> Output; -} - -#[cfg(stage0)] -impl<F: ?Sized, A, R> FnMut<A, R> for F - where F : Fn<A, R> -{ - extern "rust-call" fn call_mut(&mut self, args: A) -> R { - self.call(args) - } -} - -#[cfg(stage0)] -impl<F,A,R> FnOnce<A,R> for F - where F : FnMut<A,R> -{ - extern "rust-call" fn call_once(mut self, args: A) -> R { - self.call_mut(args) - } -} - -/// A version of the call operator that takes an immutable receiver. -#[lang="fn"] -#[unstable(feature = "core", - reason = "uncertain about variadic generics, input versus associated types")] -#[cfg(not(stage0))] #[rustc_paren_sugar] pub trait Fn<Args> { type Output; @@ -1195,7 +1146,6 @@ pub trait Fn<Args> { #[lang="fn_mut"] #[unstable(feature = "core", reason = "uncertain about variadic generics, input versus associated types")] -#[cfg(not(stage0))] #[rustc_paren_sugar] pub trait FnMut<Args> { type Output; @@ -1208,7 +1158,6 @@ pub trait FnMut<Args> { #[lang="fn_once"] #[unstable(feature = "core", reason = "uncertain about variadic generics, input versus associated types")] -#[cfg(not(stage0))] #[rustc_paren_sugar] pub trait FnOnce<Args> { type Output; @@ -1217,7 +1166,6 @@ pub trait FnOnce<Args> { extern "rust-call" fn call_once(self, args: Args) -> Self::Output; } -#[cfg(not(stage0))] impl<F: ?Sized, A> FnMut<A> for F where F : Fn<A> { @@ -1228,7 +1176,6 @@ impl<F: ?Sized, A> FnMut<A> for F } } -#[cfg(not(stage0))] impl<F,A> FnOnce<A> for F where F : FnMut<A> { diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 5cb8e5e5565..2f261b0628f 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -728,8 +728,8 @@ impl<T: Default> Option<T> { /// ``` /// let good_year_from_input = "1909"; /// let bad_year_from_input = "190blarg"; - /// let good_year = good_year_from_input.parse().unwrap_or_default(); - /// let bad_year = bad_year_from_input.parse().unwrap_or_default(); + /// let good_year = good_year_from_input.parse().ok().unwrap_or_default(); + /// let bad_year = bad_year_from_input.parse().ok().unwrap_or_default(); /// /// assert_eq!(1909, good_year); /// assert_eq!(0, bad_year); diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 92a7465038b..fc7d4e868f7 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -229,7 +229,7 @@ use self::Result::{Ok, Err}; use clone::Clone; -use fmt::Debug; +use fmt; use iter::{Iterator, IteratorExt, DoubleEndedIterator, FromIterator, ExactSizeIterator}; use ops::{FnMut, FnOnce}; use option::Option::{self, None, Some}; @@ -715,7 +715,7 @@ impl<T, E> Result<T, E> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<T, E: Debug> Result<T, E> { +impl<T, E: fmt::Debug> Result<T, E> { /// Unwraps a result, yielding the content of an `Ok`. /// /// # Panics @@ -746,7 +746,7 @@ impl<T, E: Debug> Result<T, E> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<T: Debug, E> Result<T, E> { +impl<T: fmt::Debug, E> Result<T, E> { /// Unwraps a result, yielding the content of an `Err`. /// /// # Panics diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index 40e66db3ae5..a368ddba9bc 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -41,7 +41,6 @@ use cmp::Ordering::{Less, Equal, Greater}; use cmp; use default::Default; use iter::*; -use marker::Copy; use num::Int; use ops::{FnMut, self, Index}; #[cfg(stage0)] @@ -637,6 +636,22 @@ impl<'a, T> Default for &'a [T] { // Iterators // +impl<'a, T> IntoIterator for &'a [T] { + type Iter = Iter<'a, T>; + + fn into_iter(self) -> Iter<'a, T> { + self.iter() + } +} + +impl<'a, T> IntoIterator for &'a mut [T] { + type Iter = IterMut<'a, T>; + + fn into_iter(self) -> IterMut<'a, T> { + self.iter_mut() + } +} + // The shared definition of the `Iter` and `IterMut` iterators macro_rules! iterator { (struct $name:ident -> $ptr:ty, $elem:ty) => { @@ -784,8 +799,6 @@ impl<'a, T> Iter<'a, T> { } } -impl<'a,T> Copy for Iter<'a,T> {} - iterator!{struct Iter -> *const T, &'a T} #[stable(feature = "rust1", since = "1.0.0")] @@ -793,7 +806,7 @@ impl<'a, T> ExactSizeIterator for Iter<'a, T> {} #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> Clone for Iter<'a, T> { - fn clone(&self) -> Iter<'a, T> { *self } + fn clone(&self) -> Iter<'a, T> { Iter { ptr: self.ptr, end: self.end, marker: self.marker } } } #[unstable(feature = "core", reason = "trait is experimental")] diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 8495a03747e..cb7af3b3d35 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -18,6 +18,7 @@ use self::Searcher::{Naive, TwoWay, TwoWayLong}; +use clone::Clone; use cmp::{self, Eq}; use default::Default; use error::Error; @@ -108,37 +109,62 @@ macro_rules! delegate_iter { /// A trait to abstract the idea of creating a new instance of a type from a /// string. -// FIXME(#17307): there should be an `E` associated type for a `Result` return -#[unstable(feature = "core", - reason = "will return a Result once associated types are working")] +#[stable(feature = "rust1", since = "1.0.0")] pub trait FromStr { + /// The associated error which can be returned from parsing. + #[stable(feature = "rust1", since = "1.0.0")] + type Err; + /// Parses a string `s` to return an optional value of this type. If the /// string is ill-formatted, the None is returned. - fn from_str(s: &str) -> Option<Self>; + #[stable(feature = "rust1", since = "1.0.0")] + fn from_str(s: &str) -> Result<Self, Self::Err>; } +#[stable(feature = "rust1", since = "1.0.0")] impl FromStr for bool { + type Err = ParseBoolError; + /// Parse a `bool` from a string. /// - /// Yields an `Option<bool>`, because `s` may or may not actually be parseable. + /// Yields an `Option<bool>`, because `s` may or may not actually be + /// parseable. /// /// # Examples /// /// ```rust - /// assert_eq!("true".parse(), Some(true)); - /// assert_eq!("false".parse(), Some(false)); - /// assert_eq!("not even a boolean".parse::<bool>(), None); + /// assert_eq!("true".parse(), Ok(true)); + /// assert_eq!("false".parse(), Ok(false)); + /// assert!("not even a boolean".parse::<bool>().is_err()); /// ``` #[inline] - fn from_str(s: &str) -> Option<bool> { + fn from_str(s: &str) -> Result<bool, ParseBoolError> { match s { - "true" => Some(true), - "false" => Some(false), - _ => None, + "true" => Ok(true), + "false" => Ok(false), + _ => Err(ParseBoolError { _priv: () }), } } } +/// An error returned when parsing a `bool` from a string fails. +#[derive(Debug, Clone, PartialEq)] +#[allow(missing_copy_implementations)] +#[stable(feature = "rust1", since = "1.0.0")] +pub struct ParseBoolError { _priv: () } + +#[stable(feature = "rust1", since = "1.0.0")] +impl fmt::Display for ParseBoolError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + "provided string was not `true` or `false`".fmt(f) + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl Error for ParseBoolError { + fn description(&self) -> &str { "failed to parse bool" } +} + /* Section: Creating a string */ @@ -279,7 +305,7 @@ Section: Iterators /// Iterator for the char (representing *Unicode Scalar Values*) of a string /// /// Created with the method `.chars()`. -#[derive(Clone, Copy)] +#[derive(Clone)] #[stable(feature = "rust1", since = "1.0.0")] pub struct Chars<'a> { iter: slice::Iter<'a, u8> @@ -460,15 +486,6 @@ delegate_iter!{exact u8 : Bytes<'a>} #[derive(Copy, Clone)] struct BytesDeref; -#[cfg(stage0)] -impl<'a> Fn(&'a u8) -> u8 for BytesDeref { - #[inline] - extern "rust-call" fn call(&self, (ptr,): (&'a u8,)) -> u8 { - *ptr - } -} - -#[cfg(not(stage0))] impl<'a> Fn<(&'a u8,)> for BytesDeref { type Output = u8; @@ -1007,11 +1024,11 @@ fn run_utf8_validation_iterator(iter: &mut slice::Iter<u8>) let whole = iter.as_slice(); loop { // save the current thing we're pointing at. - let old = *iter; + let old = iter.clone(); // restore the iterator we had at the start of this codepoint. macro_rules! err { () => {{ - *iter = old; + *iter = old.clone(); return Err(Utf8Error::InvalidByte(whole.len() - iter.as_slice().len())) }}} @@ -1355,7 +1372,7 @@ pub trait StrExt { fn as_ptr(&self) -> *const u8; fn len(&self) -> uint; fn is_empty(&self) -> bool; - fn parse<T: FromStr>(&self) -> Option<T>; + fn parse<T: FromStr>(&self) -> Result<T, T::Err>; } #[inline(never)] @@ -1670,7 +1687,7 @@ impl StrExt for str { fn is_empty(&self) -> bool { self.len() == 0 } #[inline] - fn parse<T: FromStr>(&self) -> Option<T> { FromStr::from_str(self) } + fn parse<T: FromStr>(&self) -> Result<T, T::Err> { FromStr::from_str(self) } } /// Pluck a code point out of a UTF-8-like byte slice and return the diff --git a/src/libcoretest/any.rs b/src/libcoretest/any.rs index 7c71c733662..5ad3833a5ef 100644 --- a/src/libcoretest/any.rs +++ b/src/libcoretest/any.rs @@ -123,7 +123,7 @@ fn any_fixed_vec() { #[bench] fn bench_downcast_ref(b: &mut Bencher) { b.iter(|| { - let mut x = 0i; + let mut x = 0; let mut y = &mut x as &mut Any; test::black_box(&mut y); test::black_box(y.downcast_ref::<int>() == Some(&0)); diff --git a/src/libcoretest/cell.rs b/src/libcoretest/cell.rs index 8bd2ed95ed5..5815dbc0acc 100644 --- a/src/libcoretest/cell.rs +++ b/src/libcoretest/cell.rs @@ -14,14 +14,14 @@ use std::mem::drop; #[test] fn smoketest_cell() { - let x = Cell::new(10i); + let x = Cell::new(10); assert!(x == Cell::new(10)); assert!(x.get() == 10); x.set(20); assert!(x == Cell::new(20)); assert!(x.get() == 20); - let y = Cell::new((30i, 40i)); + let y = Cell::new((30, 40)); assert!(y == Cell::new((30, 40))); assert!(y.get() == (30, 40)); } @@ -50,35 +50,35 @@ fn ref_and_refmut_have_sensible_show() { #[test] fn double_imm_borrow() { - let x = RefCell::new(0i); + let x = RefCell::new(0); let _b1 = x.borrow(); x.borrow(); } #[test] fn no_mut_then_imm_borrow() { - let x = RefCell::new(0i); + let x = RefCell::new(0); let _b1 = x.borrow_mut(); assert!(x.try_borrow().is_none()); } #[test] fn no_imm_then_borrow_mut() { - let x = RefCell::new(0i); + let x = RefCell::new(0); let _b1 = x.borrow(); assert!(x.try_borrow_mut().is_none()); } #[test] fn no_double_borrow_mut() { - let x = RefCell::new(0i); + let x = RefCell::new(0); let _b1 = x.borrow_mut(); assert!(x.try_borrow_mut().is_none()); } #[test] fn imm_release_borrow_mut() { - let x = RefCell::new(0i); + let x = RefCell::new(0); { let _b1 = x.borrow(); } @@ -87,7 +87,7 @@ fn imm_release_borrow_mut() { #[test] fn mut_release_borrow_mut() { - let x = RefCell::new(0i); + let x = RefCell::new(0); { let _b1 = x.borrow_mut(); } @@ -96,7 +96,7 @@ fn mut_release_borrow_mut() { #[test] fn double_borrow_single_release_no_borrow_mut() { - let x = RefCell::new(0i); + let x = RefCell::new(0); let _b1 = x.borrow(); { let _b2 = x.borrow(); @@ -107,7 +107,7 @@ fn double_borrow_single_release_no_borrow_mut() { #[test] #[should_fail] fn discard_doesnt_unborrow() { - let x = RefCell::new(0i); + let x = RefCell::new(0); let _b = x.borrow(); let _ = _b; let _b = x.borrow_mut(); @@ -115,7 +115,7 @@ fn discard_doesnt_unborrow() { #[test] fn clone_ref_updates_flag() { - let x = RefCell::new(0i); + let x = RefCell::new(0); { let b1 = x.borrow(); assert!(x.try_borrow_mut().is_none()); diff --git a/src/libcoretest/clone.rs b/src/libcoretest/clone.rs index 67c30d945d4..5ab6ab27ba1 100644 --- a/src/libcoretest/clone.rs +++ b/src/libcoretest/clone.rs @@ -10,7 +10,7 @@ #[test] fn test_borrowed_clone() { - let x = 5i; + let x = 5; let y: &int = &x; let z: &int = (&y).clone(); assert_eq!(*z, 5); @@ -18,8 +18,8 @@ fn test_borrowed_clone() { #[test] fn test_clone_from() { - let a = box 5i; - let mut b = box 10i; + let a = box 5; + let mut b = box 10; b.clone_from(&a); assert_eq!(*b, 5); } diff --git a/src/libcoretest/cmp.rs b/src/libcoretest/cmp.rs index 992c99f1f9f..6bc1f14cc5a 100644 --- a/src/libcoretest/cmp.rs +++ b/src/libcoretest/cmp.rs @@ -13,20 +13,20 @@ use core::cmp::Ordering::{Less, Greater, Equal}; #[test] fn test_int_totalord() { - assert_eq!(5i.cmp(&10), Less); - assert_eq!(10i.cmp(&5), Greater); - assert_eq!(5i.cmp(&5), Equal); - assert_eq!((-5i).cmp(&12), Less); - assert_eq!(12i.cmp(&-5), Greater); + assert_eq!(5.cmp(&10), Less); + assert_eq!(10.cmp(&5), Greater); + assert_eq!(5.cmp(&5), Equal); + assert_eq!((-5).cmp(&12), Less); + assert_eq!(12.cmp(&-5), Greater); } #[test] fn test_mut_int_totalord() { - assert_eq!((&mut 5i).cmp(&&mut 10), Less); - assert_eq!((&mut 10i).cmp(&&mut 5), Greater); - assert_eq!((&mut 5i).cmp(&&mut 5), Equal); - assert_eq!((&mut -5i).cmp(&&mut 12), Less); - assert_eq!((&mut 12i).cmp(&&mut -5), Greater); + assert_eq!((&mut 5).cmp(&&mut 10), Less); + assert_eq!((&mut 10).cmp(&&mut 5), Greater); + assert_eq!((&mut 5).cmp(&&mut 5), Equal); + assert_eq!((&mut -5).cmp(&&mut 12), Less); + assert_eq!((&mut 12).cmp(&&mut -5), Greater); } #[test] @@ -47,11 +47,11 @@ fn test_partial_min() { use core::f64::NAN; let data_integer = [ // a, b, result - (0i, 0i, Some(0i)), - (1i, 0i, Some(0i)), - (0i, 1i, Some(0i)), - (-1i, 0i, Some(-1i)), - (0i, -1i, Some(-1i)) + (0, 0, Some(0)), + (1, 0, Some(0)), + (0, 1, Some(0)), + (-1, 0, Some(-1)), + (0, -1, Some(-1)) ]; let data_float = [ @@ -80,11 +80,11 @@ fn test_partial_max() { use core::f64::NAN; let data_integer = [ // a, b, result - (0i, 0i, Some(0i)), - (1i, 0i, Some(1i)), - (0i, 1i, Some(1i)), - (-1i, 0i, Some(0i)), - (0i, -1i, Some(0i)) + (0, 0, Some(0)), + (1, 0, Some(1)), + (0, 1, Some(1)), + (-1, 0, Some(0)), + (0, -1, Some(0)) ]; let data_float = [ diff --git a/src/libcoretest/finally.rs b/src/libcoretest/finally.rs index 6ec87203e00..22917b09ce9 100644 --- a/src/libcoretest/finally.rs +++ b/src/libcoretest/finally.rs @@ -15,7 +15,7 @@ use std::thread::Thread; #[test] fn test_success() { - let mut i = 0i; + let mut i = 0; try_finally( &mut i, (), |i, ()| { @@ -32,7 +32,7 @@ fn test_success() { #[test] #[should_fail] fn test_fail() { - let mut i = 0i; + let mut i = 0; try_finally( &mut i, (), |i, ()| { @@ -47,7 +47,7 @@ fn test_fail() { #[test] fn test_retval() { - let mut closure = |&mut:| 10i; + let mut closure = |&mut:| 10; let i = closure.finally(|| { }); assert_eq!(i, 10); } diff --git a/src/libcoretest/hash/mod.rs b/src/libcoretest/hash/mod.rs index d48820aee06..ae23024cf20 100644 --- a/src/libcoretest/hash/mod.rs +++ b/src/libcoretest/hash/mod.rs @@ -56,7 +56,7 @@ fn test_writer_hasher() { assert_eq!(hash(&5i16), 5); assert_eq!(hash(&5i32), 5); assert_eq!(hash(&5i64), 5); - assert_eq!(hash(&5i), 5); + assert_eq!(hash(&5), 5); assert_eq!(hash(&false), 0); assert_eq!(hash(&true), 1); @@ -76,12 +76,12 @@ fn test_writer_hasher() { // FIXME (#18248) Add tests for hashing Rc<str> and Rc<[T]> unsafe { - let ptr: *const int = mem::transmute(5i); + let ptr: *const i32 = mem::transmute(5is); assert_eq!(hash(&ptr), 5); } unsafe { - let ptr: *mut int = mem::transmute(5i); + let ptr: *mut i32 = mem::transmute(5is); assert_eq!(hash(&ptr), 5); } } diff --git a/src/libcoretest/iter.rs b/src/libcoretest/iter.rs index 8bcd4982fba..3102abb660f 100644 --- a/src/libcoretest/iter.rs +++ b/src/libcoretest/iter.rs @@ -20,8 +20,8 @@ use test::Bencher; #[test] fn test_lt() { let empty: [int; 0] = []; - let xs = [1i,2,3]; - let ys = [1i,2,0]; + let xs = [1,2,3]; + let ys = [1,2,0]; assert!(!lt(xs.iter(), ys.iter())); assert!(!le(xs.iter(), ys.iter())); @@ -64,15 +64,15 @@ fn test_lt() { #[test] fn test_multi_iter() { - let xs = [1i,2,3,4]; - let ys = [4i,3,2,1]; + let xs = [1,2,3,4]; + let ys = [4,3,2,1]; assert!(eq(xs.iter(), ys.iter().rev())); assert!(lt(xs.iter(), xs.iter().skip(2))); } #[test] fn test_counter_from_iter() { - let it = count(0i, 5).take(10); + let it = count(0, 5).take(10); let xs: Vec<int> = FromIterator::from_iter(it); assert!(xs == vec![0, 5, 10, 15, 20, 25, 30, 35, 40, 45]); } @@ -304,7 +304,7 @@ fn test_cycle() { #[test] fn test_iterator_nth() { - let v: &[_] = &[0i, 1, 2, 3, 4]; + let v: &[_] = &[0, 1, 2, 3, 4]; for i in 0u..v.len() { assert_eq!(v.iter().nth(i).unwrap(), &v[i]); } @@ -313,14 +313,14 @@ fn test_iterator_nth() { #[test] fn test_iterator_last() { - let v: &[_] = &[0i, 1, 2, 3, 4]; + let v: &[_] = &[0, 1, 2, 3, 4]; assert_eq!(v.iter().last().unwrap(), &4); assert_eq!(v[..1].iter().last().unwrap(), &0); } #[test] fn test_iterator_len() { - let v: &[_] = &[0i, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + let v: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; assert_eq!(v[..4].iter().count(), 4); assert_eq!(v[..10].iter().count(), 10); assert_eq!(v[..0].iter().count(), 0); @@ -328,7 +328,7 @@ fn test_iterator_len() { #[test] fn test_iterator_sum() { - let v: &[_] = &[0i, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + let v: &[i32] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; assert_eq!(v[..4].iter().map(|&x| x).sum(), 6); assert_eq!(v.iter().map(|&x| x).sum(), 55); assert_eq!(v[..0].iter().map(|&x| x).sum(), 0); @@ -336,7 +336,7 @@ fn test_iterator_sum() { #[test] fn test_iterator_product() { - let v: &[_] = &[0i, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + let v: &[i32] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; assert_eq!(v[..4].iter().map(|&x| x).product(), 0); assert_eq!(v[1..5].iter().map(|&x| x).product(), 24); assert_eq!(v[..0].iter().map(|&x| x).product(), 1); @@ -344,7 +344,7 @@ fn test_iterator_product() { #[test] fn test_iterator_max() { - let v: &[_] = &[0i, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + let v: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; assert_eq!(v[..4].iter().map(|&x| x).max(), Some(3)); assert_eq!(v.iter().map(|&x| x).max(), Some(10)); assert_eq!(v[..0].iter().map(|&x| x).max(), None); @@ -352,7 +352,7 @@ fn test_iterator_max() { #[test] fn test_iterator_min() { - let v: &[_] = &[0i, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + let v: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; assert_eq!(v[..4].iter().map(|&x| x).min(), Some(0)); assert_eq!(v.iter().map(|&x| x).min(), Some(0)); assert_eq!(v[..0].iter().map(|&x| x).min(), None); @@ -360,51 +360,51 @@ fn test_iterator_min() { #[test] fn test_iterator_size_hint() { - let c = count(0i, 1); - let v: &[_] = &[0i, 1, 2, 3, 4, 5, 6, 7, 8, 9]; - let v2 = &[10i, 11, 12]; + let c = count(0, 1); + let v: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; + let v2 = &[10, 11, 12]; let vi = v.iter(); assert_eq!(c.size_hint(), (uint::MAX, None)); - assert_eq!(vi.size_hint(), (10, Some(10))); - - assert_eq!(c.take(5).size_hint(), (5, Some(5))); - assert_eq!(c.skip(5).size_hint().1, None); - assert_eq!(c.take_while(|_| false).size_hint(), (0, None)); - assert_eq!(c.skip_while(|_| false).size_hint(), (0, None)); - assert_eq!(c.enumerate().size_hint(), (uint::MAX, None)); - assert_eq!(c.chain(vi.map(|&i| i)).size_hint(), (uint::MAX, None)); - assert_eq!(c.zip(vi).size_hint(), (10, Some(10))); - assert_eq!(c.scan(0i, |_,_| Some(0i)).size_hint(), (0, None)); - assert_eq!(c.filter(|_| false).size_hint(), (0, None)); - assert_eq!(c.map(|_| 0i).size_hint(), (uint::MAX, None)); - assert_eq!(c.filter_map(|_| Some(0i)).size_hint(), (0, None)); - - assert_eq!(vi.take(5).size_hint(), (5, Some(5))); - assert_eq!(vi.take(12).size_hint(), (10, Some(10))); - assert_eq!(vi.skip(3).size_hint(), (7, Some(7))); - assert_eq!(vi.skip(12).size_hint(), (0, Some(0))); - assert_eq!(vi.take_while(|_| false).size_hint(), (0, Some(10))); - assert_eq!(vi.skip_while(|_| false).size_hint(), (0, Some(10))); - assert_eq!(vi.enumerate().size_hint(), (10, Some(10))); - assert_eq!(vi.chain(v2.iter()).size_hint(), (13, Some(13))); - assert_eq!(vi.zip(v2.iter()).size_hint(), (3, Some(3))); - assert_eq!(vi.scan(0i, |_,_| Some(0i)).size_hint(), (0, Some(10))); - assert_eq!(vi.filter(|_| false).size_hint(), (0, Some(10))); - assert_eq!(vi.map(|&i| i+1).size_hint(), (10, Some(10))); - assert_eq!(vi.filter_map(|_| Some(0i)).size_hint(), (0, Some(10))); + assert_eq!(vi.clone().size_hint(), (10, Some(10))); + + assert_eq!(c.clone().take(5).size_hint(), (5, Some(5))); + assert_eq!(c.clone().skip(5).size_hint().1, None); + assert_eq!(c.clone().take_while(|_| false).size_hint(), (0, None)); + assert_eq!(c.clone().skip_while(|_| false).size_hint(), (0, None)); + assert_eq!(c.clone().enumerate().size_hint(), (uint::MAX, None)); + assert_eq!(c.clone().chain(vi.clone().map(|&i| i)).size_hint(), (uint::MAX, None)); + assert_eq!(c.clone().zip(vi.clone()).size_hint(), (10, Some(10))); + assert_eq!(c.clone().scan(0i, |_,_| Some(0)).size_hint(), (0, None)); + assert_eq!(c.clone().filter(|_| false).size_hint(), (0, None)); + assert_eq!(c.clone().map(|_| 0).size_hint(), (uint::MAX, None)); + assert_eq!(c.filter_map(|_| Some(0)).size_hint(), (0, None)); + + assert_eq!(vi.clone().take(5).size_hint(), (5, Some(5))); + assert_eq!(vi.clone().take(12).size_hint(), (10, Some(10))); + assert_eq!(vi.clone().skip(3).size_hint(), (7, Some(7))); + assert_eq!(vi.clone().skip(12).size_hint(), (0, Some(0))); + assert_eq!(vi.clone().take_while(|_| false).size_hint(), (0, Some(10))); + assert_eq!(vi.clone().skip_while(|_| false).size_hint(), (0, Some(10))); + assert_eq!(vi.clone().enumerate().size_hint(), (10, Some(10))); + assert_eq!(vi.clone().chain(v2.iter()).size_hint(), (13, Some(13))); + assert_eq!(vi.clone().zip(v2.iter()).size_hint(), (3, Some(3))); + assert_eq!(vi.clone().scan(0i, |_,_| Some(0)).size_hint(), (0, Some(10))); + assert_eq!(vi.clone().filter(|_| false).size_hint(), (0, Some(10))); + assert_eq!(vi.clone().map(|&i| i+1).size_hint(), (10, Some(10))); + assert_eq!(vi.filter_map(|_| Some(0)).size_hint(), (0, Some(10))); } #[test] fn test_collect() { - let a = vec![1i, 2, 3, 4, 5]; + let a = vec![1, 2, 3, 4, 5]; let b: Vec<int> = a.iter().map(|&x| x).collect(); assert!(a == b); } #[test] fn test_all() { - let v: Box<[int]> = box [1i, 2, 3, 4, 5]; + let v: Box<[int]> = box [1, 2, 3, 4, 5]; assert!(v.iter().all(|&x| x < 10)); assert!(!v.iter().all(|&x| x % 2 == 0)); assert!(!v.iter().all(|&x| x > 100)); @@ -413,7 +413,7 @@ fn test_all() { #[test] fn test_any() { - let v: Box<[int]> = box [1i, 2, 3, 4, 5]; + let v: Box<[int]> = box [1, 2, 3, 4, 5]; assert!(v.iter().any(|&x| x < 10)); assert!(v.iter().any(|&x| x % 2 == 0)); assert!(!v.iter().any(|&x| x > 100)); @@ -422,7 +422,7 @@ fn test_any() { #[test] fn test_find() { - let v: &[int] = &[1i, 3, 9, 27, 103, 14, 11]; + let v: &[int] = &[1, 3, 9, 27, 103, 14, 11]; assert_eq!(*v.iter().find(|&&x| x & 1 == 0).unwrap(), 14); assert_eq!(*v.iter().find(|&&x| x % 3 == 0).unwrap(), 3); assert!(v.iter().find(|&&x| x % 12 == 0).is_none()); @@ -430,7 +430,7 @@ fn test_find() { #[test] fn test_position() { - let v = &[1i, 3, 9, 27, 103, 14, 11]; + let v = &[1, 3, 9, 27, 103, 14, 11]; assert_eq!(v.iter().position(|x| *x & 1 == 0).unwrap(), 5); assert_eq!(v.iter().position(|x| *x % 3 == 0).unwrap(), 1); assert!(v.iter().position(|x| *x % 12 == 0).is_none()); @@ -438,7 +438,7 @@ fn test_position() { #[test] fn test_count() { - let xs = &[1i, 2, 2, 1, 5, 9, 0, 2]; + let xs = &[1, 2, 2, 1, 5, 9, 0, 2]; assert_eq!(xs.iter().filter(|x| **x == 2).count(), 3); assert_eq!(xs.iter().filter(|x| **x == 5).count(), 1); assert_eq!(xs.iter().filter(|x| **x == 95).count(), 0); @@ -446,19 +446,19 @@ fn test_count() { #[test] fn test_max_by() { - let xs: &[int] = &[-3i, 0, 1, 5, -10]; + let xs: &[int] = &[-3, 0, 1, 5, -10]; assert_eq!(*xs.iter().max_by(|x| x.abs()).unwrap(), -10); } #[test] fn test_min_by() { - let xs: &[int] = &[-3i, 0, 1, 5, -10]; + let xs: &[int] = &[-3, 0, 1, 5, -10]; assert_eq!(*xs.iter().min_by(|x| x.abs()).unwrap(), 0); } #[test] fn test_by_ref() { - let mut xs = 0i..10; + let mut xs = 0..10; // sum the first five values let partial_sum = xs.by_ref().take(5).fold(0, |a, b| a + b); assert_eq!(partial_sum, 10); @@ -467,7 +467,7 @@ fn test_by_ref() { #[test] fn test_rev() { - let xs = [2i, 4, 6, 8, 10, 12, 14, 16]; + let xs = [2, 4, 6, 8, 10, 12, 14, 16]; let mut it = xs.iter(); it.next(); it.next(); @@ -494,7 +494,7 @@ fn test_cloned() { #[test] fn test_double_ended_map() { - let xs = [1i, 2, 3, 4, 5, 6]; + let xs = [1, 2, 3, 4, 5, 6]; let mut it = xs.iter().map(|&x| x * -1); assert_eq!(it.next(), Some(-1)); assert_eq!(it.next(), Some(-2)); @@ -507,7 +507,7 @@ fn test_double_ended_map() { #[test] fn test_double_ended_enumerate() { - let xs = [1i, 2, 3, 4, 5, 6]; + let xs = [1, 2, 3, 4, 5, 6]; let mut it = xs.iter().map(|&x| x).enumerate(); assert_eq!(it.next(), Some((0, 1))); assert_eq!(it.next(), Some((1, 2))); @@ -520,8 +520,8 @@ fn test_double_ended_enumerate() { #[test] fn test_double_ended_zip() { - let xs = [1i, 2, 3, 4, 5, 6]; - let ys = [1i, 2, 3, 7]; + let xs = [1, 2, 3, 4, 5, 6]; + let ys = [1, 2, 3, 7]; let a = xs.iter().map(|&x| x); let b = ys.iter().map(|&x| x); let mut it = a.zip(b); @@ -534,7 +534,7 @@ fn test_double_ended_zip() { #[test] fn test_double_ended_filter() { - let xs = [1i, 2, 3, 4, 5, 6]; + let xs = [1, 2, 3, 4, 5, 6]; let mut it = xs.iter().filter(|&x| *x & 1 == 0); assert_eq!(it.next_back().unwrap(), &6); assert_eq!(it.next_back().unwrap(), &4); @@ -544,7 +544,7 @@ fn test_double_ended_filter() { #[test] fn test_double_ended_filter_map() { - let xs = [1i, 2, 3, 4, 5, 6]; + let xs = [1, 2, 3, 4, 5, 6]; let mut it = xs.iter().filter_map(|&x| if x & 1 == 0 { Some(x * 2) } else { None }); assert_eq!(it.next_back().unwrap(), 12); assert_eq!(it.next_back().unwrap(), 8); @@ -554,8 +554,8 @@ fn test_double_ended_filter_map() { #[test] fn test_double_ended_chain() { - let xs = [1i, 2, 3, 4, 5]; - let ys = [7i, 9, 11]; + let xs = [1, 2, 3, 4, 5]; + let ys = [7, 9, 11]; let mut it = xs.iter().chain(ys.iter()).rev(); assert_eq!(it.next().unwrap(), &11); assert_eq!(it.next().unwrap(), &9); @@ -572,7 +572,7 @@ fn test_double_ended_chain() { fn test_rposition() { fn f(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'b' } fn g(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'd' } - let v = [(0i, 'a'), (1, 'b'), (2, 'c'), (3, 'b')]; + let v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')]; assert_eq!(v.iter().rposition(f), Some(3u)); assert!(v.iter().rposition(g).is_none()); @@ -581,9 +581,9 @@ fn test_rposition() { #[test] #[should_fail] fn test_rposition_panic() { - let v = [(box 0i, box 0i), (box 0i, box 0i), - (box 0i, box 0i), (box 0i, box 0i)]; - let mut i = 0i; + let v = [(box 0, box 0), (box 0, box 0), + (box 0, box 0), (box 0, box 0)]; + let mut i = 0; v.iter().rposition(|_elt| { if i == 2 { panic!() @@ -635,8 +635,8 @@ fn test_double_ended_flat_map() { #[test] fn test_random_access_chain() { - let xs = [1i, 2, 3, 4, 5]; - let ys = [7i, 9, 11]; + let xs = [1, 2, 3, 4, 5]; + let ys = [7, 9, 11]; let mut it = xs.iter().chain(ys.iter()); assert_eq!(it.idx(0).unwrap(), &1); assert_eq!(it.idx(5).unwrap(), &7); @@ -656,13 +656,13 @@ fn test_random_access_chain() { #[test] fn test_random_access_enumerate() { - let xs = [1i, 2, 3, 4, 5]; + let xs = [1, 2, 3, 4, 5]; check_randacc_iter(xs.iter().enumerate(), xs.len()); } #[test] fn test_random_access_rev() { - let xs = [1i, 2, 3, 4, 5]; + let xs = [1, 2, 3, 4, 5]; check_randacc_iter(xs.iter().rev(), xs.len()); let mut it = xs.iter().rev(); it.next(); @@ -673,14 +673,14 @@ fn test_random_access_rev() { #[test] fn test_random_access_zip() { - let xs = [1i, 2, 3, 4, 5]; - let ys = [7i, 9, 11]; + let xs = [1, 2, 3, 4, 5]; + let ys = [7, 9, 11]; check_randacc_iter(xs.iter().zip(ys.iter()), cmp::min(xs.len(), ys.len())); } #[test] fn test_random_access_take() { - let xs = [1i, 2, 3, 4, 5]; + let xs = [1, 2, 3, 4, 5]; let empty: &[int] = &[]; check_randacc_iter(xs.iter().take(3), 3); check_randacc_iter(xs.iter().take(20), xs.len()); @@ -690,7 +690,7 @@ fn test_random_access_take() { #[test] fn test_random_access_skip() { - let xs = [1i, 2, 3, 4, 5]; + let xs = [1, 2, 3, 4, 5]; let empty: &[int] = &[]; check_randacc_iter(xs.iter().skip(2), xs.len() - 2); check_randacc_iter(empty.iter().skip(2), 0); @@ -698,7 +698,7 @@ fn test_random_access_skip() { #[test] fn test_random_access_inspect() { - let xs = [1i, 2, 3, 4, 5]; + let xs = [1, 2, 3, 4, 5]; // test .map and .inspect that don't implement Clone let mut it = xs.iter().inspect(|_| {}); @@ -711,7 +711,7 @@ fn test_random_access_inspect() { #[test] fn test_random_access_map() { - let xs = [1i, 2, 3, 4, 5]; + let xs = [1, 2, 3, 4, 5]; let mut it = xs.iter().map(|x| *x); assert_eq!(xs.len(), it.indexable()); @@ -722,7 +722,7 @@ fn test_random_access_map() { #[test] fn test_random_access_cycle() { - let xs = [1i, 2, 3, 4, 5]; + let xs = [1, 2, 3, 4, 5]; let empty: &[int] = &[]; check_randacc_iter(xs.iter().cycle().take(27), 27); check_randacc_iter(empty.iter().cycle(), 0); @@ -730,86 +730,86 @@ fn test_random_access_cycle() { #[test] fn test_double_ended_range() { - assert!((11i..14).rev().collect::<Vec<int>>() == vec![13i, 12, 11]); - for _ in (10i..0).rev() { + assert!((11..14).rev().collect::<Vec<_>>() == vec![13, 12, 11]); + for _ in (10..0).rev() { panic!("unreachable"); } - assert!((11u..14).rev().collect::<Vec<uint>>() == vec![13u, 12, 11]); - for _ in (10u..0).rev() { + assert!((11..14).rev().collect::<Vec<_>>() == vec![13, 12, 11]); + for _ in (10..0).rev() { panic!("unreachable"); } } #[test] fn test_range() { - assert!((0i..5).collect::<Vec<int>>() == vec![0i, 1, 2, 3, 4]); - assert!((-10i..-1).collect::<Vec<int>>() == + assert!((0..5).collect::<Vec<_>>() == vec![0, 1, 2, 3, 4]); + assert!((-10..-1).collect::<Vec<_>>() == vec![-10, -9, -8, -7, -6, -5, -4, -3, -2]); - assert!((0i..5).rev().collect::<Vec<int>>() == vec![4, 3, 2, 1, 0]); - assert_eq!((200i..-5).count(), 0); - assert_eq!((200i..-5).rev().count(), 0); - assert_eq!((200i..200).count(), 0); - assert_eq!((200i..200).rev().count(), 0); + assert!((0..5).rev().collect::<Vec<_>>() == vec![4, 3, 2, 1, 0]); + assert_eq!((200..-5).count(), 0); + assert_eq!((200..-5).rev().count(), 0); + assert_eq!((200..200).count(), 0); + assert_eq!((200..200).rev().count(), 0); - assert_eq!((0i..100).size_hint(), (100, Some(100))); + assert_eq!((0..100).size_hint(), (100, Some(100))); // this test is only meaningful when sizeof uint < sizeof u64 assert_eq!((uint::MAX - 1..uint::MAX).size_hint(), (1, Some(1))); - assert_eq!((-10i..-1).size_hint(), (9, Some(9))); + assert_eq!((-10..-1).size_hint(), (9, Some(9))); } #[test] fn test_range_inclusive() { - assert!(range_inclusive(0i, 5).collect::<Vec<int>>() == - vec![0i, 1, 2, 3, 4, 5]); - assert!(range_inclusive(0i, 5).rev().collect::<Vec<int>>() == - vec![5i, 4, 3, 2, 1, 0]); - assert_eq!(range_inclusive(200i, -5).count(), 0); - assert_eq!(range_inclusive(200i, -5).rev().count(), 0); - assert!(range_inclusive(200i, 200).collect::<Vec<int>>() == vec![200]); - assert!(range_inclusive(200i, 200).rev().collect::<Vec<int>>() == vec![200]); + assert!(range_inclusive(0, 5).collect::<Vec<int>>() == + vec![0, 1, 2, 3, 4, 5]); + assert!(range_inclusive(0, 5).rev().collect::<Vec<int>>() == + vec![5, 4, 3, 2, 1, 0]); + assert_eq!(range_inclusive(200, -5).count(), 0); + assert_eq!(range_inclusive(200, -5).rev().count(), 0); + assert!(range_inclusive(200, 200).collect::<Vec<int>>() == vec![200]); + assert!(range_inclusive(200, 200).rev().collect::<Vec<int>>() == vec![200]); } #[test] fn test_range_step() { - assert!(range_step(0i, 20, 5).collect::<Vec<int>>() == + assert!(range_step(0, 20, 5).collect::<Vec<int>>() == vec![0, 5, 10, 15]); - assert!(range_step(20i, 0, -5).collect::<Vec<int>>() == + assert!(range_step(20, 0, -5).collect::<Vec<int>>() == vec![20, 15, 10, 5]); - assert!(range_step(20i, 0, -6).collect::<Vec<int>>() == + assert!(range_step(20, 0, -6).collect::<Vec<int>>() == vec![20, 14, 8, 2]); assert!(range_step(200u8, 255, 50).collect::<Vec<u8>>() == vec![200u8, 250]); - assert!(range_step(200i, -5, 1).collect::<Vec<int>>() == vec![]); - assert!(range_step(200i, 200, 1).collect::<Vec<int>>() == vec![]); + assert!(range_step(200, -5, 1).collect::<Vec<int>>() == vec![]); + assert!(range_step(200, 200, 1).collect::<Vec<int>>() == vec![]); } #[test] fn test_range_step_inclusive() { - assert!(range_step_inclusive(0i, 20, 5).collect::<Vec<int>>() == + assert!(range_step_inclusive(0, 20, 5).collect::<Vec<int>>() == vec![0, 5, 10, 15, 20]); - assert!(range_step_inclusive(20i, 0, -5).collect::<Vec<int>>() == + assert!(range_step_inclusive(20, 0, -5).collect::<Vec<int>>() == vec![20, 15, 10, 5, 0]); - assert!(range_step_inclusive(20i, 0, -6).collect::<Vec<int>>() == + assert!(range_step_inclusive(20, 0, -6).collect::<Vec<int>>() == vec![20, 14, 8, 2]); assert!(range_step_inclusive(200u8, 255, 50).collect::<Vec<u8>>() == vec![200u8, 250]); - assert!(range_step_inclusive(200i, -5, 1).collect::<Vec<int>>() == + assert!(range_step_inclusive(200, -5, 1).collect::<Vec<int>>() == vec![]); - assert!(range_step_inclusive(200i, 200, 1).collect::<Vec<int>>() == + assert!(range_step_inclusive(200, 200, 1).collect::<Vec<int>>() == vec![200]); } #[test] fn test_reverse() { - let mut ys = [1i, 2, 3, 4, 5]; + let mut ys = [1, 2, 3, 4, 5]; ys.iter_mut().reverse_in_place(); assert!(ys == [5, 4, 3, 2, 1]); } #[test] fn test_peekable_is_empty() { - let a = [1i]; + let a = [1]; let mut it = a.iter().peekable(); assert!( !it.is_empty() ); it.next(); @@ -821,16 +821,16 @@ fn test_min_max() { let v: [int; 0] = []; assert_eq!(v.iter().min_max(), NoElements); - let v = [1i]; + let v = [1]; assert!(v.iter().min_max() == OneElement(&1)); - let v = [1i, 2, 3, 4, 5]; + let v = [1, 2, 3, 4, 5]; assert!(v.iter().min_max() == MinMax(&1, &5)); - let v = [1i, 2, 3, 4, 5, 6]; + let v = [1, 2, 3, 4, 5, 6]; assert!(v.iter().min_max() == MinMax(&1, &6)); - let v = [1i, 1, 1, 1]; + let v = [1, 1, 1, 1]; assert!(v.iter().min_max() == MinMax(&1, &1)); } @@ -839,10 +839,10 @@ fn test_min_max_result() { let r: MinMaxResult<int> = NoElements; assert_eq!(r.into_option(), None); - let r = OneElement(1i); + let r = OneElement(1); assert_eq!(r.into_option(), Some((1,1))); - let r = MinMax(1i,2); + let r = MinMax(1,2); assert_eq!(r.into_option(), Some((1,2))); } @@ -904,7 +904,7 @@ fn bench_multiple_take(b: &mut Bencher) { b.iter(|| { let n = it.next().unwrap(); for _ in 0u..n { - it.take(it.next().unwrap()).all(|_| true); + it.clone().take(it.next().unwrap()).all(|_| true); } }); } diff --git a/src/libcoretest/lib.rs b/src/libcoretest/lib.rs index 0d371dbe153..c26d3e7bb8a 100644 --- a/src/libcoretest/lib.rs +++ b/src/libcoretest/lib.rs @@ -8,10 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(unsafe_destructor, slicing_syntax)] -#![feature(unboxed_closures)] #![feature(box_syntax)] -#![allow(unknown_features)] #![feature(int_uint)] +#![feature(int_uint)] +#![feature(unboxed_closures)] +#![feature(unsafe_destructor, slicing_syntax)] extern crate core; extern crate test; diff --git a/src/libcoretest/mem.rs b/src/libcoretest/mem.rs index 3dc209e6fcb..fd9dc696bdf 100644 --- a/src/libcoretest/mem.rs +++ b/src/libcoretest/mem.rs @@ -70,8 +70,8 @@ fn align_of_val_basic() { #[test] fn test_swap() { - let mut x = 31337i; - let mut y = 42i; + let mut x = 31337; + let mut y = 42; swap(&mut x, &mut y); assert_eq!(x, 42); assert_eq!(y, 31337); @@ -87,7 +87,7 @@ fn test_replace() { #[test] fn test_transmute_copy() { - assert_eq!(1u, unsafe { transmute_copy(&1i) }); + assert_eq!(1u, unsafe { transmute_copy(&1) }); } #[test] @@ -95,7 +95,7 @@ fn test_transmute() { trait Foo {} impl Foo for int {} - let a = box 100i as Box<Foo>; + let a = box 100 as Box<Foo>; unsafe { let x: ::core::raw::TraitObject = transmute(a); assert!(*(x.data as *const int) == 100); @@ -146,7 +146,7 @@ fn trait_static_method_call(b: &mut Bencher) { #[bench] fn match_option_some(b: &mut Bencher) { - let x = Some(10i); + let x = Some(10); b.iter(|| { match x { Some(y) => y, @@ -157,11 +157,11 @@ fn match_option_some(b: &mut Bencher) { #[bench] fn match_vec_pattern(b: &mut Bencher) { - let x = [1i,2,3,4,5,6]; + let x = [1,2,3,4,5,6]; b.iter(|| { match x { - [1,2,3,..] => 10i, - _ => 11i, + [1,2,3,..] => 10, + _ => 11, } }); } diff --git a/src/libcoretest/nonzero.rs b/src/libcoretest/nonzero.rs index ab2f6da1cf7..be4c83d23e8 100644 --- a/src/libcoretest/nonzero.rs +++ b/src/libcoretest/nonzero.rs @@ -16,7 +16,7 @@ use std::mem::size_of; #[test] fn test_create_nonzero_instance() { let _a = unsafe { - NonZero::new(21i) + NonZero::new(21) }; } @@ -28,14 +28,14 @@ fn test_size_nonzero_in_option() { #[test] fn test_match_on_nonzero_option() { let a = Some(unsafe { - NonZero::new(42i) + NonZero::new(42) }); match a { Some(val) => assert_eq!(*val, 42), None => panic!("unexpected None while matching on Some(NonZero(_))") } - match unsafe { Some(NonZero::new(43i)) } { + match unsafe { Some(NonZero::new(43)) } { Some(val) => assert_eq!(*val, 43), None => panic!("unexpected None while matching on Some(NonZero(_))") } @@ -52,9 +52,9 @@ fn test_match_option_empty_vec() { #[test] fn test_match_option_vec() { - let a = Some(vec![1i, 2, 3, 4]); + let a = Some(vec![1, 2, 3, 4]); match a { - Some(v) => assert_eq!(v, vec![1i, 2, 3, 4]), + Some(v) => assert_eq!(v, vec![1, 2, 3, 4]), None => panic!("unexpected None while matching on Some(vec![1, 2, 3, 4])") } } @@ -63,9 +63,9 @@ fn test_match_option_vec() { fn test_match_option_rc() { use std::rc::Rc; - let five = Rc::new(5i); + let five = Rc::new(5); match Some(five) { - Some(r) => assert_eq!(*r, 5i), + Some(r) => assert_eq!(*r, 5), None => panic!("unexpected None while matching on Some(Rc::new(5))") } } @@ -74,9 +74,9 @@ fn test_match_option_rc() { fn test_match_option_arc() { use std::sync::Arc; - let five = Arc::new(5i); + let five = Arc::new(5); match Some(five) { - Some(a) => assert_eq!(*a, 5i), + Some(a) => assert_eq!(*a, 5), None => panic!("unexpected None while matching on Some(Arc::new(5))") } } diff --git a/src/libcoretest/num/int_macros.rs b/src/libcoretest/num/int_macros.rs index b98432e26b2..f5657d939b2 100644 --- a/src/libcoretest/num/int_macros.rs +++ b/src/libcoretest/num/int_macros.rs @@ -151,15 +151,15 @@ mod tests { #[test] fn test_signed_checked_div() { - assert!(10i.checked_div(2) == Some(5)); - assert!(5i.checked_div(0) == None); + assert!(10.checked_div(2) == Some(5)); + assert!(5.checked_div(0) == None); assert!(int::MIN.checked_div(-1) == None); } #[test] fn test_from_str() { fn from_str<T: ::std::str::FromStr>(t: &str) -> Option<T> { - ::std::str::FromStr::from_str(t) + ::std::str::FromStr::from_str(t).ok() } assert_eq!(from_str::<$T>("0"), Some(0 as $T)); assert_eq!(from_str::<$T>("3"), Some(3 as $T)); @@ -180,26 +180,26 @@ mod tests { #[test] fn test_from_str_radix() { - assert_eq!(FromStrRadix::from_str_radix("123", 10), Some(123 as $T)); - assert_eq!(FromStrRadix::from_str_radix("1001", 2), Some(9 as $T)); - assert_eq!(FromStrRadix::from_str_radix("123", 8), Some(83 as $T)); - assert_eq!(FromStrRadix::from_str_radix("123", 16), Some(291 as i32)); - assert_eq!(FromStrRadix::from_str_radix("ffff", 16), Some(65535 as i32)); - assert_eq!(FromStrRadix::from_str_radix("FFFF", 16), Some(65535 as i32)); - assert_eq!(FromStrRadix::from_str_radix("z", 36), Some(35 as $T)); - assert_eq!(FromStrRadix::from_str_radix("Z", 36), Some(35 as $T)); - - assert_eq!(FromStrRadix::from_str_radix("-123", 10), Some(-123 as $T)); - assert_eq!(FromStrRadix::from_str_radix("-1001", 2), Some(-9 as $T)); - assert_eq!(FromStrRadix::from_str_radix("-123", 8), Some(-83 as $T)); - assert_eq!(FromStrRadix::from_str_radix("-123", 16), Some(-291 as i32)); - assert_eq!(FromStrRadix::from_str_radix("-ffff", 16), Some(-65535 as i32)); - assert_eq!(FromStrRadix::from_str_radix("-FFFF", 16), Some(-65535 as i32)); - assert_eq!(FromStrRadix::from_str_radix("-z", 36), Some(-35 as $T)); - assert_eq!(FromStrRadix::from_str_radix("-Z", 36), Some(-35 as $T)); - - assert_eq!(FromStrRadix::from_str_radix("Z", 35), None::<$T>); - assert_eq!(FromStrRadix::from_str_radix("-9", 2), None::<$T>); + assert_eq!(FromStrRadix::from_str_radix("123", 10), Ok(123 as $T)); + assert_eq!(FromStrRadix::from_str_radix("1001", 2), Ok(9 as $T)); + assert_eq!(FromStrRadix::from_str_radix("123", 8), Ok(83 as $T)); + assert_eq!(FromStrRadix::from_str_radix("123", 16), Ok(291 as i32)); + assert_eq!(FromStrRadix::from_str_radix("ffff", 16), Ok(65535 as i32)); + assert_eq!(FromStrRadix::from_str_radix("FFFF", 16), Ok(65535 as i32)); + assert_eq!(FromStrRadix::from_str_radix("z", 36), Ok(35 as $T)); + assert_eq!(FromStrRadix::from_str_radix("Z", 36), Ok(35 as $T)); + + assert_eq!(FromStrRadix::from_str_radix("-123", 10), Ok(-123 as $T)); + assert_eq!(FromStrRadix::from_str_radix("-1001", 2), Ok(-9 as $T)); + assert_eq!(FromStrRadix::from_str_radix("-123", 8), Ok(-83 as $T)); + assert_eq!(FromStrRadix::from_str_radix("-123", 16), Ok(-291 as i32)); + assert_eq!(FromStrRadix::from_str_radix("-ffff", 16), Ok(-65535 as i32)); + assert_eq!(FromStrRadix::from_str_radix("-FFFF", 16), Ok(-65535 as i32)); + assert_eq!(FromStrRadix::from_str_radix("-z", 36), Ok(-35 as $T)); + assert_eq!(FromStrRadix::from_str_radix("-Z", 36), Ok(-35 as $T)); + + assert_eq!(FromStrRadix::from_str_radix("Z", 35).ok(), None::<$T>); + assert_eq!(FromStrRadix::from_str_radix("-9", 2).ok(), None::<$T>); } } diff --git a/src/libcoretest/num/mod.rs b/src/libcoretest/num/mod.rs index e0623bade5c..2c6efc0040f 100644 --- a/src/libcoretest/num/mod.rs +++ b/src/libcoretest/num/mod.rs @@ -40,11 +40,11 @@ pub fn test_num<T>(ten: T, two: T) where + Rem<Output=T> + Debug + Copy { - assert_eq!(ten.add(two), cast(12i).unwrap()); - assert_eq!(ten.sub(two), cast(8i).unwrap()); - assert_eq!(ten.mul(two), cast(20i).unwrap()); - assert_eq!(ten.div(two), cast(5i).unwrap()); - assert_eq!(ten.rem(two), cast(0i).unwrap()); + assert_eq!(ten.add(two), cast(12).unwrap()); + assert_eq!(ten.sub(two), cast(8).unwrap()); + assert_eq!(ten.mul(two), cast(20).unwrap()); + assert_eq!(ten.div(two), cast(5).unwrap()); + assert_eq!(ten.rem(two), cast(0).unwrap()); assert_eq!(ten.add(two), ten + two); assert_eq!(ten.sub(two), ten - two); @@ -62,64 +62,64 @@ mod test { #[test] fn from_str_issue7588() { - let u : Option<u8> = from_str_radix("1000", 10); + let u : Option<u8> = from_str_radix("1000", 10).ok(); assert_eq!(u, None); - let s : Option<i16> = from_str_radix("80000", 10); + let s : Option<i16> = from_str_radix("80000", 10).ok(); assert_eq!(s, None); - let f : Option<f32> = from_str_radix("10000000000000000000000000000000000000000", 10); + let f : Option<f32> = from_str_radix("10000000000000000000000000000000000000000", 10).ok(); assert_eq!(f, Some(Float::infinity())); - let fe : Option<f32> = from_str_radix("1e40", 10); + let fe : Option<f32> = from_str_radix("1e40", 10).ok(); assert_eq!(fe, Some(Float::infinity())); } #[test] fn test_from_str_radix_float() { - let x1 : Option<f64> = from_str_radix("-123.456", 10); + let x1 : Option<f64> = from_str_radix("-123.456", 10).ok(); assert_eq!(x1, Some(-123.456)); - let x2 : Option<f32> = from_str_radix("123.456", 10); + let x2 : Option<f32> = from_str_radix("123.456", 10).ok(); assert_eq!(x2, Some(123.456)); - let x3 : Option<f32> = from_str_radix("-0.0", 10); + let x3 : Option<f32> = from_str_radix("-0.0", 10).ok(); assert_eq!(x3, Some(-0.0)); - let x4 : Option<f32> = from_str_radix("0.0", 10); + let x4 : Option<f32> = from_str_radix("0.0", 10).ok(); assert_eq!(x4, Some(0.0)); - let x4 : Option<f32> = from_str_radix("1.0", 10); + let x4 : Option<f32> = from_str_radix("1.0", 10).ok(); assert_eq!(x4, Some(1.0)); - let x5 : Option<f32> = from_str_radix("-1.0", 10); + let x5 : Option<f32> = from_str_radix("-1.0", 10).ok(); assert_eq!(x5, Some(-1.0)); } #[test] fn test_int_from_str_overflow() { let mut i8_val: i8 = 127_i8; - assert_eq!("127".parse::<i8>(), Some(i8_val)); - assert_eq!("128".parse::<i8>(), None); + assert_eq!("127".parse::<i8>().ok(), Some(i8_val)); + assert_eq!("128".parse::<i8>().ok(), None); i8_val += 1 as i8; - assert_eq!("-128".parse::<i8>(), Some(i8_val)); - assert_eq!("-129".parse::<i8>(), None); + assert_eq!("-128".parse::<i8>().ok(), Some(i8_val)); + assert_eq!("-129".parse::<i8>().ok(), None); let mut i16_val: i16 = 32_767_i16; - assert_eq!("32767".parse::<i16>(), Some(i16_val)); - assert_eq!("32768".parse::<i16>(), None); + assert_eq!("32767".parse::<i16>().ok(), Some(i16_val)); + assert_eq!("32768".parse::<i16>().ok(), None); i16_val += 1 as i16; - assert_eq!("-32768".parse::<i16>(), Some(i16_val)); - assert_eq!("-32769".parse::<i16>(), None); + assert_eq!("-32768".parse::<i16>().ok(), Some(i16_val)); + assert_eq!("-32769".parse::<i16>().ok(), None); let mut i32_val: i32 = 2_147_483_647_i32; - assert_eq!("2147483647".parse::<i32>(), Some(i32_val)); - assert_eq!("2147483648".parse::<i32>(), None); + assert_eq!("2147483647".parse::<i32>().ok(), Some(i32_val)); + assert_eq!("2147483648".parse::<i32>().ok(), None); i32_val += 1 as i32; - assert_eq!("-2147483648".parse::<i32>(), Some(i32_val)); - assert_eq!("-2147483649".parse::<i32>(), None); + assert_eq!("-2147483648".parse::<i32>().ok(), Some(i32_val)); + assert_eq!("-2147483649".parse::<i32>().ok(), None); let mut i64_val: i64 = 9_223_372_036_854_775_807_i64; - assert_eq!("9223372036854775807".parse::<i64>(), Some(i64_val)); - assert_eq!("9223372036854775808".parse::<i64>(), None); + assert_eq!("9223372036854775807".parse::<i64>().ok(), Some(i64_val)); + assert_eq!("9223372036854775808".parse::<i64>().ok(), None); i64_val += 1 as i64; - assert_eq!("-9223372036854775808".parse::<i64>(), Some(i64_val)); - assert_eq!("-9223372036854775809".parse::<i64>(), None); + assert_eq!("-9223372036854775808".parse::<i64>().ok(), Some(i64_val)); + assert_eq!("-9223372036854775809".parse::<i64>().ok(), None); } } diff --git a/src/libcoretest/option.rs b/src/libcoretest/option.rs index bb9d1524786..b32ae68b5d3 100644 --- a/src/libcoretest/option.rs +++ b/src/libcoretest/option.rs @@ -16,7 +16,7 @@ use core::clone::Clone; #[test] fn test_get_ptr() { unsafe { - let x = box 0i; + let x = box 0; let addr_x: *const int = mem::transmute(&*x); let opt = Some(x); let y = opt.unwrap(); @@ -59,7 +59,7 @@ fn test_get_resource() { } } - let i = Rc::new(RefCell::new(0i)); + let i = Rc::new(RefCell::new(0)); { let x = r(i.clone()); let opt = Some(x); @@ -71,7 +71,7 @@ fn test_get_resource() { #[test] fn test_option_dance() { let x = Some(()); - let mut y = Some(5i); + let mut y = Some(5); let mut y2 = 0; for _x in x.iter() { y2 = y.take().unwrap(); @@ -89,12 +89,12 @@ fn test_option_too_much_dance() { #[test] fn test_and() { - let x: Option<int> = Some(1i); - assert_eq!(x.and(Some(2i)), Some(2)); + let x: Option<int> = Some(1); + assert_eq!(x.and(Some(2)), Some(2)); assert_eq!(x.and(None::<int>), None); let x: Option<int> = None; - assert_eq!(x.and(Some(2i)), None); + assert_eq!(x.and(Some(2)), None); assert_eq!(x.and(None::<int>), None); } @@ -133,7 +133,7 @@ fn test_or_else() { #[test] fn test_unwrap() { - assert_eq!(Some(1i).unwrap(), 1); + assert_eq!(Some(1).unwrap(), 1); let s = Some("hello".to_string()).unwrap(); assert_eq!(s, "hello"); } @@ -172,7 +172,7 @@ fn test_unwrap_or_else() { #[test] fn test_iter() { - let val = 5i; + let val = 5; let x = Some(val); let mut it = x.iter(); @@ -185,8 +185,8 @@ fn test_iter() { #[test] fn test_mut_iter() { - let val = 5i; - let new_val = 11i; + let val = 5; + let new_val = 11; let mut x = Some(val); { @@ -223,13 +223,13 @@ fn test_ord() { /* FIXME(#20575) #[test] fn test_collect() { - let v: Option<Vec<int>> = (0i..0).map(|_| Some(0i)).collect(); + let v: Option<Vec<int>> = (0..0).map(|_| Some(0i)).collect(); assert!(v == Some(vec![])); - let v: Option<Vec<int>> = (0i..3).map(|x| Some(x)).collect(); + let v: Option<Vec<int>> = (0..3).map(|x| Some(x)).collect(); assert!(v == Some(vec![0, 1, 2])); - let v: Option<Vec<int>> = (0i..3).map(|x| { + let v: Option<Vec<int>> = (0..3).map(|x| { if x > 1 { None } else { Some(x) } }).collect(); assert!(v == None); diff --git a/src/libcoretest/ptr.rs b/src/libcoretest/ptr.rs index 875affe0ac7..7f0b97c53d4 100644 --- a/src/libcoretest/ptr.rs +++ b/src/libcoretest/ptr.rs @@ -84,7 +84,7 @@ fn test_as_ref() { assert_eq!(q.as_ref().unwrap(), &2); // Lifetime inference - let u = 2i; + let u = 2; { let p: *const int = &u as *const _; assert_eq!(p.as_ref().unwrap(), &2); @@ -102,7 +102,7 @@ fn test_as_mut() { assert!(q.as_mut().unwrap() == &mut 2); // Lifetime inference - let mut u = 2i; + let mut u = 2; { let p: *mut int = &mut u as *mut _; assert!(p.as_mut().unwrap() == &mut 2); @@ -113,7 +113,7 @@ fn test_as_mut() { #[test] fn test_ptr_addition() { unsafe { - let xs = repeat(5i).take(16).collect::<Vec<_>>(); + let xs = repeat(5).take(16).collect::<Vec<_>>(); let mut ptr = xs.as_ptr(); let end = ptr.offset(16); @@ -131,7 +131,7 @@ fn test_ptr_addition() { m_ptr = m_ptr.offset(1); } - assert!(xs_mut == repeat(10i).take(16).collect::<Vec<_>>()); + assert!(xs_mut == repeat(10).take(16).collect::<Vec<_>>()); } } diff --git a/src/libcoretest/result.rs b/src/libcoretest/result.rs index d36228fa3d7..ab7b5101e72 100644 --- a/src/libcoretest/result.rs +++ b/src/libcoretest/result.rs @@ -13,11 +13,11 @@ pub fn op2() -> Result<int, &'static str> { Err("sadface") } #[test] pub fn test_and() { - assert_eq!(op1().and(Ok(667i)).unwrap(), 667); + assert_eq!(op1().and(Ok(667)).unwrap(), 667); assert_eq!(op1().and(Err::<i32, &'static str>("bad")).unwrap_err(), "bad"); - assert_eq!(op2().and(Ok(667i)).unwrap_err(), "sadface"); + assert_eq!(op2().and(Ok(667)).unwrap_err(), "sadface"); assert_eq!(op2().and(Err::<i32,&'static str>("bad")).unwrap_err(), "sadface"); } @@ -68,20 +68,20 @@ pub fn test_impl_map_err() { /* FIXME(#20575) #[test] fn test_collect() { - let v: Result<Vec<int>, ()> = (0i..0).map(|_| Ok::<int, ()>(0)).collect(); + let v: Result<Vec<int>, ()> = (0..0).map(|_| Ok::<int, ()>(0)).collect(); assert!(v == Ok(vec![])); - let v: Result<Vec<int>, ()> = (0i..3).map(|x| Ok::<int, ()>(x)).collect(); + let v: Result<Vec<int>, ()> = (0..3).map(|x| Ok::<int, ()>(x)).collect(); assert!(v == Ok(vec![0, 1, 2])); - let v: Result<Vec<int>, int> = (0i..3).map(|x| { + let v: Result<Vec<int>, int> = (0..3).map(|x| { if x > 1 { Err(x) } else { Ok(x) } }).collect(); assert!(v == Err(2)); // test that it does not take more elements than it needs let mut functions: [Box<Fn() -> Result<(), int>>; 3] = - [box || Ok(()), box || Err(1i), box || panic!()]; + [box || Ok(()), box || Err(1), box || panic!()]; let v: Result<Vec<()>, int> = functions.iter_mut().map(|f| (*f)()).collect(); assert!(v == Err(1)); @@ -101,7 +101,7 @@ pub fn test_fmt_default() { #[test] pub fn test_unwrap_or() { - let ok: Result<int, &'static str> = Ok(100i); + let ok: Result<int, &'static str> = Ok(100); let ok_err: Result<int, &'static str> = Err("Err"); assert_eq!(ok.unwrap_or(50), 100); @@ -112,7 +112,7 @@ pub fn test_unwrap_or() { pub fn test_unwrap_or_else() { fn handler(msg: &'static str) -> int { if msg == "I got this." { - 50i + 50 } else { panic!("BadBad") } @@ -130,7 +130,7 @@ pub fn test_unwrap_or_else() { pub fn test_unwrap_or_else_panic() { fn handler(msg: &'static str) -> int { if msg == "I got this." { - 50i + 50 } else { panic!("BadBad") } diff --git a/src/libcoretest/slice.rs b/src/libcoretest/slice.rs index 6fae384763f..6d5cc38ef0a 100644 --- a/src/libcoretest/slice.rs +++ b/src/libcoretest/slice.rs @@ -12,25 +12,25 @@ use core::result::Result::{Ok, Err}; #[test] fn binary_search_not_found() { - let b = [1i, 2, 4, 6, 8, 9]; + let b = [1, 2, 4, 6, 8, 9]; assert!(b.binary_search_by(|v| v.cmp(&6)) == Ok(3)); - let b = [1i, 2, 4, 6, 8, 9]; + let b = [1, 2, 4, 6, 8, 9]; assert!(b.binary_search_by(|v| v.cmp(&5)) == Err(3)); - let b = [1i, 2, 4, 6, 7, 8, 9]; + let b = [1, 2, 4, 6, 7, 8, 9]; assert!(b.binary_search_by(|v| v.cmp(&6)) == Ok(3)); - let b = [1i, 2, 4, 6, 7, 8, 9]; + let b = [1, 2, 4, 6, 7, 8, 9]; assert!(b.binary_search_by(|v| v.cmp(&5)) == Err(3)); - let b = [1i, 2, 4, 6, 8, 9]; + let b = [1, 2, 4, 6, 8, 9]; assert!(b.binary_search_by(|v| v.cmp(&8)) == Ok(4)); - let b = [1i, 2, 4, 6, 8, 9]; + let b = [1, 2, 4, 6, 8, 9]; assert!(b.binary_search_by(|v| v.cmp(&7)) == Err(4)); - let b = [1i, 2, 4, 6, 7, 8, 9]; + let b = [1, 2, 4, 6, 7, 8, 9]; assert!(b.binary_search_by(|v| v.cmp(&8)) == Ok(5)); - let b = [1i, 2, 4, 5, 6, 8, 9]; + let b = [1, 2, 4, 5, 6, 8, 9]; assert!(b.binary_search_by(|v| v.cmp(&7)) == Err(5)); - let b = [1i, 2, 4, 5, 6, 8, 9]; + let b = [1, 2, 4, 5, 6, 8, 9]; assert!(b.binary_search_by(|v| v.cmp(&0)) == Err(0)); - let b = [1i, 2, 4, 5, 6, 8]; + let b = [1, 2, 4, 5, 6, 8]; assert!(b.binary_search_by(|v| v.cmp(&9)) == Err(6)); } diff --git a/src/libcoretest/str.rs b/src/libcoretest/str.rs index 938755113b5..f2a1b0ac584 100644 --- a/src/libcoretest/str.rs +++ b/src/libcoretest/str.rs @@ -10,9 +10,9 @@ #[test] fn test_bool_from_str() { - assert_eq!("true".parse(), Some(true)); - assert_eq!("false".parse(), Some(false)); - assert_eq!("not even a boolean".parse::<bool>(), None); + assert_eq!("true".parse().ok(), Some(true)); + assert_eq!("false".parse().ok(), Some(false)); + assert_eq!("not even a boolean".parse::<bool>().ok(), None); } fn check_contains_all_substrings(s: &str) { diff --git a/src/libcoretest/tuple.rs b/src/libcoretest/tuple.rs index e524d8de056..57844f5995f 100644 --- a/src/libcoretest/tuple.rs +++ b/src/libcoretest/tuple.rs @@ -12,7 +12,7 @@ use std::cmp::Ordering::{Equal, Less, Greater}; #[test] fn test_clone() { - let a = (1i, "2"); + let a = (1, "2"); let b = a.clone(); assert_eq!(a, b); } @@ -59,10 +59,10 @@ fn test_tuple_cmp() { #[test] fn test_show() { - let s = format!("{:?}", (1i,)); + let s = format!("{:?}", (1,)); assert_eq!(s, "(1,)"); - let s = format!("{:?}", (1i, true)); + let s = format!("{:?}", (1, true)); assert_eq!(s, "(1, true)"); - let s = format!("{:?}", (1i, "hi", true)); + let s = format!("{:?}", (1, "hi", true)); assert_eq!(s, "(1, \"hi\", true)"); } diff --git a/src/libflate/lib.rs b/src/libflate/lib.rs index 5c868ce6910..e7fb2ba56ab 100644 --- a/src/libflate/lib.rs +++ b/src/libflate/lib.rs @@ -16,17 +16,17 @@ #![crate_name = "flate"] #![unstable(feature = "rustc_private")] -#![feature(staged_api)] #![staged_api] -#![allow(unknown_features)] #![feature(int_uint)] #![crate_type = "rlib"] #![crate_type = "dylib"] #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_root_url = "http://doc.rust-lang.org/nightly/")] -#![feature(hash)] + #![feature(core)] +#![feature(int_uint)] #![feature(libc)] +#![feature(staged_api)] #[cfg(test)] #[macro_use] extern crate log; diff --git a/src/libfmt_macros/lib.rs b/src/libfmt_macros/lib.rs index 9bc7acb67ad..8a473ad43af 100644 --- a/src/libfmt_macros/lib.rs +++ b/src/libfmt_macros/lib.rs @@ -16,7 +16,6 @@ #![crate_name = "fmt_macros"] #![unstable(feature = "rustc_private")] -#![feature(staged_api)] #![staged_api] #![crate_type = "rlib"] #![crate_type = "dylib"] @@ -25,10 +24,10 @@ html_root_url = "http://doc.rust-lang.org/nightly/", html_playground_url = "http://play.rust-lang.org/")] +#![cfg_attr(stage0, feature(core))] +#![feature(int_uint)] #![feature(slicing_syntax)] -#![allow(unknown_features)] #![feature(int_uint)] -#![feature(collections)] -#![feature(core)] +#![feature(staged_api)] #![feature(unicode)] pub use self::Piece::*; diff --git a/src/libgetopts/lib.rs b/src/libgetopts/lib.rs index 7b86dab8a7c..055672df5d1 100644 --- a/src/libgetopts/lib.rs +++ b/src/libgetopts/lib.rs @@ -80,7 +80,6 @@ #![crate_name = "getopts"] #![unstable(feature = "rustc_private", reason = "use the crates.io `getopts` library instead")] -#![feature(staged_api)] #![staged_api] #![crate_type = "rlib"] #![crate_type = "dylib"] @@ -88,11 +87,13 @@ html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_root_url = "http://doc.rust-lang.org/nightly/", html_playground_url = "http://play.rust-lang.org/")] -#![feature(slicing_syntax)] -#![allow(unknown_features)] #![feature(int_uint)] + #![deny(missing_docs)] #![feature(collections)] #![feature(core)] +#![feature(int_uint)] +#![feature(slicing_syntax)] +#![feature(staged_api)] #![cfg_attr(test, feature(rustc_private))] #[cfg(test)] #[macro_use] extern crate log; diff --git a/src/libgraphviz/lib.rs b/src/libgraphviz/lib.rs index 21d5cd3d516..3606387ad23 100644 --- a/src/libgraphviz/lib.rs +++ b/src/libgraphviz/lib.rs @@ -274,7 +274,7 @@ html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_root_url = "http://doc.rust-lang.org/nightly/")] #![feature(slicing_syntax)] -#![allow(unknown_features)] #![feature(int_uint)] +#![feature(int_uint)] #![feature(collections)] #![feature(core)] #![feature(io)] @@ -362,19 +362,19 @@ impl<'a> Id<'a> { /// /// Passing an invalid string (containing spaces, brackets, /// quotes, ...) will return an empty `Err` value. - pub fn new<Name: IntoCow<'a, String, str>>(name: Name) -> Option<Id<'a>> { + pub fn new<Name: IntoCow<'a, String, str>>(name: Name) -> Result<Id<'a>, ()> { let name = name.into_cow(); { let mut chars = name.chars(); match chars.next() { Some(c) if is_letter_or_underscore(c) => { ; }, - _ => return None + _ => return Err(()) } if !chars.all(is_constituent) { - return None + return Err(()) } } - return Some(Id{ name: name }); + return Ok(Id{ name: name }); fn is_letter_or_underscore(c: char) -> bool { in_range('a', c, 'z') || in_range('A', c, 'Z') || c == '_' @@ -878,8 +878,8 @@ r#"digraph syntax_tree { fn simple_id_construction() { let id1 = Id::new("hello"); match id1 { - Some(_) => {;}, - None => panic!("'hello' is not a valid value for id anymore") + Ok(_) => {;}, + Err(..) => panic!("'hello' is not a valid value for id anymore") } } @@ -887,8 +887,8 @@ r#"digraph syntax_tree { fn badly_formatted_id() { let id2 = Id::new("Weird { struct : ure } !!!"); match id2 { - Some(_) => panic!("graphviz id suddenly allows spaces, brackets and stuff"), - None => {;} + Ok(_) => panic!("graphviz id suddenly allows spaces, brackets and stuff"), + Err(..) => {;} } } } diff --git a/src/liblibc/lib.rs b/src/liblibc/lib.rs index 96717a38cba..bd8537f53cd 100644 --- a/src/liblibc/lib.rs +++ b/src/liblibc/lib.rs @@ -15,7 +15,7 @@ #![cfg_attr(not(feature = "cargo-build"), feature(staged_api))] #![cfg_attr(not(feature = "cargo-build"), staged_api)] #![cfg_attr(not(feature = "cargo-build"), feature(core))] -#![allow(unknown_features)] #![feature(int_uint)] +#![feature(int_uint)] #![no_std] #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "http://www.rust-lang.org/favicon.ico", diff --git a/src/liblog/directive.rs b/src/liblog/directive.rs index edd93358bfa..46b9b2ed865 100644 --- a/src/liblog/directive.rs +++ b/src/liblog/directive.rs @@ -22,7 +22,7 @@ pub static LOG_LEVEL_NAMES: [&'static str; 4] = ["ERROR", "WARN", "INFO", /// Parse an individual log level that is either a number or a symbolic log level fn parse_log_level(level: &str) -> Option<u32> { - level.parse::<u32>().or_else(|| { + level.parse::<u32>().ok().or_else(|| { let pos = LOG_LEVEL_NAMES.iter().position(|&name| name.eq_ignore_ascii_case(level)); pos.map(|p| p as u32 + 1) }).map(|p| cmp::min(p, ::MAX_LOG_LEVEL)) diff --git a/src/liblog/lib.rs b/src/liblog/lib.rs index 0e2ab008e13..81d8c60f893 100644 --- a/src/liblog/lib.rs +++ b/src/liblog/lib.rs @@ -20,7 +20,7 @@ //! error!("this is printed by default"); //! //! if log_enabled!(log::INFO) { -//! let x = 3i * 4i; // expensive computation +//! let x = 3 * 4; // expensive computation //! info!("the answer was: {:?}", x); //! } //! } @@ -158,7 +158,6 @@ #![crate_name = "log"] #![unstable(feature = "rustc_private", reason = "use the crates.io `log` library instead")] -#![feature(staged_api)] #![staged_api] #![crate_type = "rlib"] #![crate_type = "dylib"] @@ -166,17 +165,15 @@ html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_root_url = "http://doc.rust-lang.org/nightly/", html_playground_url = "http://play.rust-lang.org/")] +#![deny(missing_docs)] -#![allow(unknown_features)] +#![feature(staged_api)] #![feature(slicing_syntax)] #![feature(box_syntax)] -#![allow(unknown_features)] #![feature(int_uint)] -#![deny(missing_docs)] -#![feature(collections)] +#![feature(int_uint)] #![feature(core)] #![feature(io)] #![feature(os)] -#![feature(rustc_private)] #![feature(std_misc)] use std::cell::RefCell; diff --git a/src/liblog/macros.rs b/src/liblog/macros.rs index 5249e971439..5c7085b7b6c 100644 --- a/src/liblog/macros.rs +++ b/src/liblog/macros.rs @@ -119,7 +119,7 @@ macro_rules! warn { /// #[macro_use] extern crate log; /// /// fn main() { -/// let ret = 3i; +/// let ret = 3; /// info!("this function is about to return: {}", ret); /// } /// ``` @@ -145,7 +145,7 @@ macro_rules! info { /// #[macro_use] extern crate log; /// /// fn main() { -/// debug!("x = {x}, y = {y}", x=10i, y=20i); +/// debug!("x = {x}, y = {y}", x=10, y=20); /// } /// ``` /// diff --git a/src/librand/distributions/mod.rs b/src/librand/distributions/mod.rs index 8d87a8e5f0e..1b5e5ae8398 100644 --- a/src/librand/distributions/mod.rs +++ b/src/librand/distributions/mod.rs @@ -311,36 +311,36 @@ mod tests { }} } - t!(vec!(Weighted { weight: 1, item: 10i}), [10]); + t!(vec!(Weighted { weight: 1, item: 10}), [10]); // skip some - t!(vec!(Weighted { weight: 0, item: 20i}, - Weighted { weight: 2, item: 21i}, - Weighted { weight: 0, item: 22i}, - Weighted { weight: 1, item: 23i}), + t!(vec!(Weighted { weight: 0, item: 20}, + Weighted { weight: 2, item: 21}, + Weighted { weight: 0, item: 22}, + Weighted { weight: 1, item: 23}), [21,21, 23]); // different weights - t!(vec!(Weighted { weight: 4, item: 30i}, - Weighted { weight: 3, item: 31i}), + t!(vec!(Weighted { weight: 4, item: 30}, + Weighted { weight: 3, item: 31}), [30,30,30,30, 31,31,31]); // check that we're binary searching // correctly with some vectors of odd // length. - t!(vec!(Weighted { weight: 1, item: 40i}, - Weighted { weight: 1, item: 41i}, - Weighted { weight: 1, item: 42i}, - Weighted { weight: 1, item: 43i}, - Weighted { weight: 1, item: 44i}), + t!(vec!(Weighted { weight: 1, item: 40}, + Weighted { weight: 1, item: 41}, + Weighted { weight: 1, item: 42}, + Weighted { weight: 1, item: 43}, + Weighted { weight: 1, item: 44}), [40, 41, 42, 43, 44]); - t!(vec!(Weighted { weight: 1, item: 50i}, - Weighted { weight: 1, item: 51i}, - Weighted { weight: 1, item: 52i}, - Weighted { weight: 1, item: 53i}, - Weighted { weight: 1, item: 54i}, - Weighted { weight: 1, item: 55i}, - Weighted { weight: 1, item: 56i}), + t!(vec!(Weighted { weight: 1, item: 50}, + Weighted { weight: 1, item: 51}, + Weighted { weight: 1, item: 52}, + Weighted { weight: 1, item: 53}, + Weighted { weight: 1, item: 54}, + Weighted { weight: 1, item: 55}, + Weighted { weight: 1, item: 56}), [50, 51, 52, 53, 54, 55, 56]); } @@ -350,15 +350,15 @@ mod tests { } #[test] #[should_fail] fn test_weighted_choice_zero_weight() { - WeightedChoice::new(&mut [Weighted { weight: 0, item: 0i}, - Weighted { weight: 0, item: 1i}]); + WeightedChoice::new(&mut [Weighted { weight: 0, item: 0}, + Weighted { weight: 0, item: 1}]); } #[test] #[should_fail] fn test_weighted_choice_weight_overflows() { let x = (-1) as uint / 2; // x + x + 2 is the overflow - WeightedChoice::new(&mut [Weighted { weight: x, item: 0i }, - Weighted { weight: 1, item: 1i }, - Weighted { weight: x, item: 2i }, - Weighted { weight: 1, item: 3i }]); + WeightedChoice::new(&mut [Weighted { weight: x, item: 0 }, + Weighted { weight: 1, item: 1 }, + Weighted { weight: x, item: 2 }, + Weighted { weight: 1, item: 3 }]); } } diff --git a/src/librand/distributions/range.rs b/src/librand/distributions/range.rs index e8dedeb8d60..16830c84c46 100644 --- a/src/librand/distributions/range.rs +++ b/src/librand/distributions/range.rs @@ -171,12 +171,12 @@ mod tests { #[should_fail] #[test] fn test_range_bad_limits_equal() { - Range::new(10i, 10i); + Range::new(10, 10); } #[should_fail] #[test] fn test_range_bad_limits_flipped() { - Range::new(10i, 5i); + Range::new(10, 5); } #[test] diff --git a/src/librand/lib.rs b/src/librand/lib.rs index 76258151850..3ff40038872 100644 --- a/src/librand/lib.rs +++ b/src/librand/lib.rs @@ -22,7 +22,7 @@ html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_root_url = "http://doc.rust-lang.org/nightly/", html_playground_url = "http://play.rust-lang.org/")] -#![allow(unknown_features)] #![feature(int_uint)] +#![feature(int_uint)] #![no_std] #![unstable(feature = "rand")] #![feature(staged_api)] @@ -152,7 +152,7 @@ pub trait Rng : Sized { // (3) adds more `unsafe` that needs to be checked, (4) // probably doesn't give much performance gain if // optimisations are on. - let mut count = 0i; + let mut count = 0; let mut num = 0; for byte in dest.iter_mut() { if count == 0 { @@ -269,7 +269,7 @@ pub trait Rng : Sized { /// ``` /// use std::rand::{thread_rng, Rng}; /// - /// let choices = [1i, 2, 4, 8, 16, 32]; + /// let choices = [1, 2, 4, 8, 16, 32]; /// let mut rng = thread_rng(); /// println!("{:?}", rng.choose(&choices)); /// assert_eq!(rng.choose(&choices[..0]), None); @@ -290,7 +290,7 @@ pub trait Rng : Sized { /// use std::rand::{thread_rng, Rng}; /// /// let mut rng = thread_rng(); - /// let mut y = [1i, 2, 3]; + /// let mut y = [1, 2, 3]; /// rng.shuffle(&mut y); /// println!("{:?}", y.as_slice()); /// rng.shuffle(&mut y); @@ -498,6 +498,8 @@ mod std { pub use core::{option, fmt}; // panic!() pub use core::clone; // derive Clone pub use core::marker; + // for-loops + pub use core::iter; } #[cfg(test)] diff --git a/src/librbml/lib.rs b/src/librbml/lib.rs index f7fd8889fae..acc21cbf060 100644 --- a/src/librbml/lib.rs +++ b/src/librbml/lib.rs @@ -17,7 +17,6 @@ #![crate_name = "rbml"] #![unstable(feature = "rustc_private")] -#![feature(staged_api)] #![staged_api] #![crate_type = "rlib"] #![crate_type = "dylib"] @@ -25,13 +24,14 @@ html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_root_url = "http://doc.rust-lang.org/nightly/", html_playground_url = "http://play.rust-lang.org/")] -#![allow(unknown_features)] -#![feature(slicing_syntax)] -#![allow(unknown_features)] #![feature(int_uint)] + #![feature(collections)] #![feature(core)] +#![feature(int_uint)] #![feature(io)] #![feature(rustc_private)] +#![feature(slicing_syntax)] +#![feature(staged_api)] extern crate serialize; #[macro_use] extern crate log; diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index 580e55f78a9..6ae861fcb04 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -16,7 +16,6 @@ #![crate_name = "rustc"] #![unstable(feature = "rustc_private")] -#![feature(staged_api)] #![staged_api] #![crate_type = "dylib"] #![crate_type = "rlib"] @@ -24,22 +23,24 @@ html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_root_url = "http://doc.rust-lang.org/nightly/")] -#![allow(unknown_features)] -#![feature(quote)] -#![feature(slicing_syntax, unsafe_destructor)] +#![cfg_attr(not(stage0), allow(unused_mut))] // NOTE: remove after stage0 snap + #![feature(box_syntax)] -#![allow(unknown_features)] #![feature(int_uint)] -#![feature(rustc_diagnostic_macros)] #![feature(collections)] #![feature(core)] +#![feature(hash)] +#![feature(int_uint)] #![feature(io)] #![feature(libc)] #![feature(os)] #![feature(path)] +#![feature(quote)] +#![feature(rustc_diagnostic_macros)] #![feature(rustc_private)] +#![feature(slicing_syntax, unsafe_destructor)] +#![feature(staged_api)] #![feature(std_misc)] #![feature(unicode)] -#![feature(hash)] #![cfg_attr(test, feature(test))] extern crate arena; diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index ae537e557e7..e8e8d35fe07 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -254,7 +254,7 @@ impl LintPass for TypeLimits { let lit_val: f64 = match lit.node { ast::LitFloat(ref v, _) | ast::LitFloatUnsuffixed(ref v) => { - match v.parse() { + match v.parse().ok() { Some(f) => f, None => return } @@ -493,7 +493,7 @@ pub struct BoxPointers; impl BoxPointers { fn check_heap_type<'a, 'tcx>(&self, cx: &Context<'a, 'tcx>, span: Span, ty: Ty<'tcx>) { - let mut n_uniq = 0i; + let mut n_uniq = 0u; ty::fold_ty(cx.tcx, ty, |t| { match t.sty { ty::ty_uniq(_) => { @@ -938,6 +938,34 @@ declare_lint! { pub struct NonSnakeCase; impl NonSnakeCase { + fn to_snake_case(mut str: &str) -> String { + let mut words = vec![]; + // Preserve leading underscores + str = str.trim_left_matches(|&mut: c: char| { + if c == '_' { + words.push(String::new()); + true + } else { false } + }); + for s in str.split('_') { + let mut last_upper = false; + let mut buf = String::new(); + if s.is_empty() { continue; } + for ch in s.chars() { + if !buf.is_empty() && buf != "'" + && ch.is_uppercase() + && !last_upper { + words.push(buf); + buf = String::new(); + } + last_upper = ch.is_uppercase(); + buf.push(ch.to_lowercase()); + } + words.push(buf); + } + words.connect("_") + } + fn check_snake_case(&self, cx: &Context, sort: &str, ident: ast::Ident, span: Span) { fn is_snake_case(ident: ast::Ident) -> bool { let ident = token::get_ident(ident); @@ -948,41 +976,28 @@ impl NonSnakeCase { let mut allow_underscore = true; ident.chars().all(|c| { allow_underscore = match c { - c if c.is_lowercase() || c.is_numeric() => true, - '_' if allow_underscore => false, + '_' if !allow_underscore => return false, + '_' => false, + c if !c.is_uppercase() => true, _ => return false, }; true }) } - fn to_snake_case(str: &str) -> String { - let mut words = vec![]; - for s in str.split('_') { - let mut last_upper = false; - let mut buf = String::new(); - if s.is_empty() { continue; } - for ch in s.chars() { - if !buf.is_empty() && buf != "'" - && ch.is_uppercase() - && !last_upper { - words.push(buf); - buf = String::new(); - } - last_upper = ch.is_uppercase(); - buf.push(ch.to_lowercase()); - } - words.push(buf); - } - words.connect("_") - } - let s = token::get_ident(ident); if !is_snake_case(ident) { - cx.span_lint(NON_SNAKE_CASE, span, - &format!("{} `{}` should have a snake case name such as `{}`", - sort, s, to_snake_case(s.get()))[]); + let sc = NonSnakeCase::to_snake_case(s.get()); + if sc != s.get() { + cx.span_lint(NON_SNAKE_CASE, span, + &*format!("{} `{}` should have a snake case name such as `{}`", + sort, s, sc)); + } else { + cx.span_lint(NON_SNAKE_CASE, span, + &*format!("{} `{}` should have a snake case name", + sort, s)); + } } } } @@ -1050,6 +1065,26 @@ declare_lint! { #[derive(Copy)] pub struct NonUpperCaseGlobals; +impl NonUpperCaseGlobals { + fn check_upper_case(cx: &Context, sort: &str, ident: ast::Ident, span: Span) { + let s = token::get_ident(ident); + + if s.get().chars().any(|c| c.is_lowercase()) { + let uc: String = NonSnakeCase::to_snake_case(s.get()).chars() + .map(|c| c.to_uppercase()).collect(); + if uc != s.get() { + cx.span_lint(NON_UPPER_CASE_GLOBALS, span, + format!("{} `{}` should have an upper case name such as `{}`", + sort, s, uc).as_slice()); + } else { + cx.span_lint(NON_UPPER_CASE_GLOBALS, span, + format!("{} `{}` should have an upper case name", + sort, s).as_slice()); + } + } + } +} + impl LintPass for NonUpperCaseGlobals { fn get_lints(&self) -> LintArray { lint_array!(NON_UPPER_CASE_GLOBALS) @@ -1058,19 +1093,11 @@ impl LintPass for NonUpperCaseGlobals { fn check_item(&mut self, cx: &Context, it: &ast::Item) { match it.node { // only check static constants - ast::ItemStatic(_, ast::MutImmutable, _) | + ast::ItemStatic(_, ast::MutImmutable, _) => { + NonUpperCaseGlobals::check_upper_case(cx, "static constant", it.ident, it.span); + } ast::ItemConst(..) => { - let s = token::get_ident(it.ident); - // check for lowercase letters rather than non-uppercase - // ones (some scripts don't have a concept of - // upper/lowercase) - if s.get().chars().any(|c| c.is_lowercase()) { - cx.span_lint(NON_UPPER_CASE_GLOBALS, it.span, - &format!("static constant `{}` should have an uppercase name \ - such as `{}`", - s.get(), &s.get().chars().map(|c| c.to_uppercase()) - .collect::<String>()[])[]); - } + NonUpperCaseGlobals::check_upper_case(cx, "constant", it.ident, it.span); } _ => {} } @@ -1080,14 +1107,8 @@ impl LintPass for NonUpperCaseGlobals { // Lint for constants that look like binding identifiers (#7526) match (&p.node, cx.tcx.def_map.borrow().get(&p.id)) { (&ast::PatIdent(_, ref path1, _), Some(&def::DefConst(..))) => { - let s = token::get_ident(path1.node); - if s.get().chars().any(|c| c.is_lowercase()) { - cx.span_lint(NON_UPPER_CASE_GLOBALS, path1.span, - &format!("static constant in pattern `{}` should have an uppercase \ - name such as `{}`", - s.get(), &s.get().chars().map(|c| c.to_uppercase()) - .collect::<String>()[])[]); - } + NonUpperCaseGlobals::check_upper_case(cx, "constant in pattern", + path1.node, p.span); } _ => {} } @@ -1164,6 +1185,7 @@ impl LintPass for UnusedParens { ast::MatchSource::Normal => (head, "`match` head expression", true), ast::MatchSource::IfLetDesugar { .. } => (head, "`if let` head expression", true), ast::MatchSource::WhileLetDesugar => (head, "`while let` head expression", true), + ast::MatchSource::ForLoopDesugar => (head, "`for` head expression", true), }, ast::ExprRet(Some(ref value)) => (value, "`return` value", false), ast::ExprAssign(_, ref value) => (value, "assigned value", false), diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index 93ca42e9a28..322abe79ed2 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -223,7 +223,7 @@ fn each_reexport<F>(d: rbml::Doc, f: F) -> bool where fn variant_disr_val(d: rbml::Doc) -> Option<ty::Disr> { reader::maybe_get_doc(d, tag_disr_val).and_then(|val_doc| { reader::with_doc_data(val_doc, |data| { - str::from_utf8(data).ok().and_then(|s| s.parse()) + str::from_utf8(data).ok().and_then(|s| s.parse().ok()) }) }) } diff --git a/src/librustc/metadata/tydecode.rs b/src/librustc/metadata/tydecode.rs index 943479ff35e..6d19107096a 100644 --- a/src/librustc/metadata/tydecode.rs +++ b/src/librustc/metadata/tydecode.rs @@ -717,12 +717,16 @@ pub fn parse_def_id(buf: &[u8]) -> ast::DefId { let crate_part = &buf[0u..colon_idx]; let def_part = &buf[colon_idx + 1u..len]; - let crate_num = match str::from_utf8(crate_part).ok().and_then(|s| s.parse::<uint>()) { + let crate_num = match str::from_utf8(crate_part).ok().and_then(|s| { + s.parse::<uint>().ok() + }) { Some(cn) => cn as ast::CrateNum, None => panic!("internal error: parse_def_id: crate number expected, found {:?}", crate_part) }; - let def_num = match str::from_utf8(def_part).ok().and_then(|s| s.parse::<uint>()) { + let def_num = match str::from_utf8(def_part).ok().and_then(|s| { + s.parse::<uint>().ok() + }) { Some(dn) => dn as ast::NodeId, None => panic!("internal error: parse_def_id: id expected, found {:?}", def_part) diff --git a/src/librustc/middle/cfg/construct.rs b/src/librustc/middle/cfg/construct.rs index 6162f61fde1..0a575a31ead 100644 --- a/src/librustc/middle/cfg/construct.rs +++ b/src/librustc/middle/cfg/construct.rs @@ -263,43 +263,8 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { self.tcx.sess.span_bug(expr.span, "non-desugared ExprWhileLet"); } - ast::ExprForLoop(ref pat, ref head, ref body, _) => { - // - // [pred] - // | - // v 1 - // [head] - // | - // v 2 - // [loopback] <--+ 7 - // | | - // v 3 | - // +------[cond] | - // | | | - // | v 5 | - // | [pat] | - // | | | - // | v 6 | - // v 4 [body] -----+ - // [expr] - // - // Note that `break` and `continue` statements - // may cause additional edges. - - let head = self.expr(&**head, pred); // 1 - let loopback = self.add_dummy_node(&[head]); // 2 - let cond = self.add_dummy_node(&[loopback]); // 3 - let expr_exit = self.add_node(expr.id, &[cond]); // 4 - self.loop_scopes.push(LoopScope { - loop_id: expr.id, - continue_index: loopback, - break_index: expr_exit, - }); - let pat = self.pat(&**pat, cond); // 5 - let body = self.block(&**body, pat); // 6 - self.add_contained_edge(body, loopback); // 7 - self.loop_scopes.pop(); - expr_exit + ast::ExprForLoop(..) => { + self.tcx.sess.span_bug(expr.span, "non-desugared ExprForLoop"); } ast::ExprLoop(ref body, _) => { diff --git a/src/librustc/middle/cfg/graphviz.rs b/src/librustc/middle/cfg/graphviz.rs index 3d8348e8f5a..1f0fe4f1aca 100644 --- a/src/librustc/middle/cfg/graphviz.rs +++ b/src/librustc/middle/cfg/graphviz.rs @@ -54,10 +54,10 @@ fn replace_newline_with_backslash_l(s: String) -> String { } impl<'a, 'ast> dot::Labeller<'a, Node<'a>, Edge<'a>> for LabelledCFG<'a, 'ast> { - fn graph_id(&'a self) -> dot::Id<'a> { dot::Id::new(&self.name[]).unwrap() } + fn graph_id(&'a self) -> dot::Id<'a> { dot::Id::new(&self.name[]).ok().unwrap() } fn node_id(&'a self, &(i,_): &Node<'a>) -> dot::Id<'a> { - dot::Id::new(format!("N{}", i.node_id())).unwrap() + dot::Id::new(format!("N{}", i.node_id())).ok().unwrap() } fn node_label(&'a self, &(i, n): &Node<'a>) -> dot::LabelText<'a> { diff --git a/src/librustc/middle/check_loop.rs b/src/librustc/middle/check_loop.rs index 623f3525d4a..41ef55933cd 100644 --- a/src/librustc/middle/check_loop.rs +++ b/src/librustc/middle/check_loop.rs @@ -45,10 +45,6 @@ impl<'a, 'v> Visitor<'v> for CheckLoopVisitor<'a> { ast::ExprLoop(ref b, _) => { self.with_context(Loop, |v| v.visit_block(&**b)); } - ast::ExprForLoop(_, ref e, ref b, _) => { - self.visit_expr(&**e); - self.with_context(Loop, |v| v.visit_block(&**b)); - } ast::ExprClosure(_, _, _, ref b) => { self.with_context(Closure, |v| v.visit_block(&**b)); } diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index fec7b51157d..aded63336dc 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -221,21 +221,8 @@ fn check_expr(cx: &mut MatchCheckCtxt, ex: &ast::Expr) { .flat_map(|arm| arm.0.iter()) .map(|pat| vec![&**pat]) .collect(); - check_exhaustive(cx, ex.span, &matrix); + check_exhaustive(cx, ex.span, &matrix, source); }, - ast::ExprForLoop(ref pat, _, _, _) => { - let mut static_inliner = StaticInliner::new(cx.tcx); - is_refutable(cx, &*static_inliner.fold_pat((*pat).clone()), |uncovered_pat| { - span_err!(cx.tcx.sess, pat.span, E0297, - "refutable pattern in `for` loop binding: \ - `{}` not covered", - pat_to_string(uncovered_pat)); - }); - - // Check legality of move bindings. - check_legality_of_move_bindings(cx, false, slice::ref_slice(pat)); - check_legality_of_bindings_in_at_patterns(cx, &**pat); - } _ => () } } @@ -327,6 +314,14 @@ fn check_arms(cx: &MatchCheckCtxt, span_err!(cx.tcx.sess, span, E0165, "irrefutable while-let pattern"); }, + ast::MatchSource::ForLoopDesugar => { + // this is a bug, because on `match iter.next()` we cover + // `Some(<head>)` and `None`. It's impossible to have an unreachable + // pattern + // (see libsyntax/ext/expand.rs for the full expansion of a for loop) + cx.tcx.sess.span_bug(pat.span, "unreachable for-loop pattern") + }, + ast::MatchSource::Normal => { span_err!(cx.tcx.sess, pat.span, E0001, "unreachable pattern") }, @@ -351,7 +346,7 @@ fn raw_pat<'a>(p: &'a Pat) -> &'a Pat { } } -fn check_exhaustive(cx: &MatchCheckCtxt, sp: Span, matrix: &Matrix) { +fn check_exhaustive(cx: &MatchCheckCtxt, sp: Span, matrix: &Matrix, source: ast::MatchSource) { match is_useful(cx, matrix, &[DUMMY_WILD_PAT], ConstructWitness) { UsefulWithWitness(pats) => { let witness = match &pats[] { @@ -359,10 +354,29 @@ fn check_exhaustive(cx: &MatchCheckCtxt, sp: Span, matrix: &Matrix) { [] => DUMMY_WILD_PAT, _ => unreachable!() }; - span_err!(cx.tcx.sess, sp, E0004, - "non-exhaustive patterns: `{}` not covered", - pat_to_string(witness) - ); + match source { + ast::MatchSource::ForLoopDesugar => { + // `witness` has the form `Some(<head>)`, peel off the `Some` + let witness = match witness.node { + ast::PatEnum(_, Some(ref pats)) => match &pats[] { + [ref pat] => &**pat, + _ => unreachable!(), + }, + _ => unreachable!(), + }; + + span_err!(cx.tcx.sess, sp, E0297, + "refutable pattern in `for` loop binding: \ + `{}` not covered", + pat_to_string(witness)); + }, + _ => { + span_err!(cx.tcx.sess, sp, E0004, + "non-exhaustive patterns: `{}` not covered", + pat_to_string(witness) + ); + }, + } } NotUseful => { // This is good, wildcard pattern isn't reachable diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index 9457a1a99f6..188a56135ec 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -540,22 +540,8 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> { self.tcx().sess.span_bug(expr.span, "non-desugared ExprWhileLet"); } - ast::ExprForLoop(ref pat, ref head, ref blk, _) => { - // The pattern lives as long as the block. - debug!("walk_expr for loop case: blk id={}", blk.id); - self.consume_expr(&**head); - - // Fetch the type of the value that the iteration yields to - // produce the pattern's categorized mutable type. - let pattern_type = return_if_err!(self.typer.node_ty(pat.id)); - let blk_scope = region::CodeExtent::from_node_id(blk.id); - let pat_cmt = self.mc.cat_rvalue(pat.id, - pat.span, - ty::ReScope(blk_scope), - pattern_type); - self.walk_irrefutable_pat(pat_cmt, &**pat); - - self.walk_block(&**blk); + ast::ExprForLoop(..) => { + self.tcx().sess.span_bug(expr.span, "non-desugared ExprForLoop"); } ast::ExprUnary(op, ref lhs) => { diff --git a/src/librustc/middle/infer/combine.rs b/src/librustc/middle/infer/combine.rs index e286855c285..8b29ef9b880 100644 --- a/src/librustc/middle/infer/combine.rs +++ b/src/librustc/middle/infer/combine.rs @@ -263,7 +263,13 @@ pub trait Combine<'tcx> : Sized { Err(ty::terr_projection_name_mismatched( expected_found(self, a.item_name, b.item_name))) } else { - let trait_ref = try!(self.trait_refs(&*a.trait_ref, &*b.trait_ref)); + // Note that the trait refs for the projection must be + // *equal*. This is because there is no inherent + // relationship between `<T as Foo>::Bar` and `<U as + // Foo>::Bar` that we can derive based on how `T` relates + // to `U`. Issue #21726 contains further discussion and + // in-depth examples. + let trait_ref = try!(self.equate().trait_refs(&*a.trait_ref, &*b.trait_ref)); Ok(ty::ProjectionTy { trait_ref: Rc::new(trait_ref), item_name: a.item_name }) } } diff --git a/src/librustc/middle/infer/region_inference/graphviz.rs b/src/librustc/middle/infer/region_inference/graphviz.rs index 215c4945ea9..460687629e7 100644 --- a/src/librustc/middle/infer/region_inference/graphviz.rs +++ b/src/librustc/middle/infer/region_inference/graphviz.rs @@ -59,7 +59,7 @@ pub fn maybe_print_constraints_for<'a, 'tcx>(region_vars: &RegionVarBindings<'a, } let requested_node : Option<ast::NodeId> = - os::getenv("RUST_REGION_GRAPH_NODE").and_then(|s| s.parse()); + os::getenv("RUST_REGION_GRAPH_NODE").and_then(|s| s.parse().ok()); if requested_node.is_some() && requested_node != Some(subject_node) { return; @@ -157,10 +157,10 @@ impl<'a, 'tcx> ConstraintGraph<'a, 'tcx> { impl<'a, 'tcx> dot::Labeller<'a, Node, Edge> for ConstraintGraph<'a, 'tcx> { fn graph_id(&self) -> dot::Id { - dot::Id::new(self.graph_name.as_slice()).unwrap() + dot::Id::new(self.graph_name.as_slice()).ok().unwrap() } fn node_id(&self, n: &Node) -> dot::Id { - dot::Id::new(format!("node_{}", self.node_ids.get(n).unwrap())).unwrap() + dot::Id::new(format!("node_{}", self.node_ids.get(n).unwrap())).ok().unwrap() } fn node_label(&self, n: &Node) -> dot::LabelText { match *n { diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index 16d2c68ad60..29a615f2b40 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -325,8 +325,6 @@ lets_do_this! { NonZeroItem, "non_zero", non_zero; - IteratorItem, "iterator", iterator; - StackExhaustedLangItem, "stack_exhausted", stack_exhausted; DebugTraitLangItem, "debug_trait", debug_trait; diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index f6a51004eb6..982bc41f06a 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -135,8 +135,6 @@ enum LoopKind<'a> { LoopLoop, /// A `while` loop, with the given expression as condition. WhileLoop(&'a Expr), - /// A `for` loop, with the given pattern to bind. - ForLoop(&'a ast::Pat), } #[derive(Copy, PartialEq)] @@ -490,19 +488,8 @@ fn visit_expr(ir: &mut IrMaps, expr: &Expr) { ast::ExprWhileLet(..) => { ir.tcx.sess.span_bug(expr.span, "non-desugared ExprWhileLet"); } - ast::ExprForLoop(ref pat, _, _, _) => { - pat_util::pat_bindings(&ir.tcx.def_map, &**pat, |bm, p_id, sp, path1| { - debug!("adding local variable {} from for loop with bm {:?}", - p_id, bm); - let name = path1.node; - ir.add_live_node_for_node(p_id, VarDefNode(sp)); - ir.add_variable(Local(LocalInfo { - id: p_id, - ident: name - })); - }); - ir.add_live_node_for_node(expr.id, ExprNode(expr.span)); - visit::walk_expr(ir, expr); + ast::ExprForLoop(..) => { + ir.tcx.sess.span_bug(expr.span, "non-desugared ExprForLoop"); } ast::ExprBinary(op, _, _) if ast_util::lazy_binop(op.node) => { ir.add_live_node_for_node(expr.id, ExprNode(expr.span)); @@ -1034,9 +1021,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { self.ir.tcx.sess.span_bug(expr.span, "non-desugared ExprWhileLet"); } - ast::ExprForLoop(ref pat, ref head, ref blk, _) => { - let ln = self.propagate_through_loop(expr, ForLoop(&**pat), &**blk, succ); - self.propagate_through_expr(&**head, ln) + ast::ExprForLoop(..) => { + self.ir.tcx.sess.span_bug(expr.span, "non-desugared ExprForLoop"); } // Note that labels have been resolved, so we don't need to look @@ -1373,7 +1359,6 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { let cond_ln = match kind { LoopLoop => ln, - ForLoop(ref pat) => self.define_bindings_in_pat(*pat, ln), WhileLoop(ref cond) => self.propagate_through_expr(&**cond, ln), }; let body_ln = self.with_loop_nodes(expr.id, succ, ln, |this| { @@ -1386,9 +1371,6 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { let new_cond_ln = match kind { LoopLoop => ln, - ForLoop(ref pat) => { - self.define_bindings_in_pat(*pat, ln) - } WhileLoop(ref cond) => { self.propagate_through_expr(&**cond, ln) } @@ -1476,14 +1458,6 @@ fn check_expr(this: &mut Liveness, expr: &Expr) { visit::walk_expr(this, expr); } - ast::ExprForLoop(ref pat, _, _, _) => { - this.pat_bindings(&**pat, |this, ln, var, sp, id| { - this.warn_about_unused(sp, id, ln, var); - }); - - visit::walk_expr(this, expr); - } - // no correctness conditions related to liveness ast::ExprCall(..) | ast::ExprMethodCall(..) | ast::ExprIf(..) | ast::ExprMatch(..) | ast::ExprWhile(..) | ast::ExprLoop(..) | @@ -1503,6 +1477,9 @@ fn check_expr(this: &mut Liveness, expr: &Expr) { ast::ExprWhileLet(..) => { this.ir.tcx.sess.span_bug(expr.span, "non-desugared ExprWhileLet"); } + ast::ExprForLoop(..) => { + this.ir.tcx.sess.span_bug(expr.span, "non-desugared ExprForLoop"); + } } } diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 5fe5a4c7eb2..0d86dbeadf4 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -534,8 +534,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { ast::ExprBlock(..) | ast::ExprLoop(..) | ast::ExprMatch(..) | ast::ExprLit(..) | ast::ExprBreak(..) | ast::ExprMac(..) | ast::ExprAgain(..) | ast::ExprStruct(..) | ast::ExprRepeat(..) | - ast::ExprInlineAsm(..) | ast::ExprBox(..) | - ast::ExprForLoop(..) => { + ast::ExprInlineAsm(..) | ast::ExprBox(..) => { Ok(self.cat_rvalue_node(expr.id(), expr.span(), expr_ty)) } @@ -545,6 +544,9 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { ast::ExprWhileLet(..) => { self.tcx().sess.span_bug(expr.span, "non-desugared ExprWhileLet"); } + ast::ExprForLoop(..) => { + self.tcx().sess.span_bug(expr.span, "non-desugared ExprForLoop"); + } } } diff --git a/src/librustc/middle/recursion_limit.rs b/src/librustc/middle/recursion_limit.rs index 81cbdf13c51..da83833fba3 100644 --- a/src/librustc/middle/recursion_limit.rs +++ b/src/librustc/middle/recursion_limit.rs @@ -18,7 +18,6 @@ use session::Session; use syntax::ast; use syntax::attr::AttrMetaMethods; -use std::str::FromStr; pub fn update_recursion_limit(sess: &Session, krate: &ast::Crate) { for attr in krate.attrs.iter() { @@ -27,7 +26,7 @@ pub fn update_recursion_limit(sess: &Session, krate: &ast::Crate) { } if let Some(s) = attr.value_str() { - if let Some(n) = FromStr::from_str(s.get()) { + if let Some(n) = s.parse().ok() { sess.recursion_limit.set(n); return; } diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 4e29e9b75e8..c70532dbb30 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -701,14 +701,6 @@ fn resolve_expr(visitor: &mut RegionResolutionVisitor, expr: &ast::Expr) { terminating(body.id); } - ast::ExprForLoop(ref _pat, ref _head, ref body, _) => { - terminating(body.id); - - // The variable parent of everything inside (most importantly, the - // pattern) is the body. - visitor.cx.var_parent = InnermostDeclaringBlock::Block(body.id); - } - ast::ExprMatch(..) => { visitor.cx.var_parent = InnermostDeclaringBlock::Match(expr.id); } diff --git a/src/librustc/middle/traits/project.rs b/src/librustc/middle/traits/project.rs index d1dd086a5a3..ce66f4d5b35 100644 --- a/src/librustc/middle/traits/project.rs +++ b/src/librustc/middle/traits/project.rs @@ -430,6 +430,11 @@ fn project_type<'cx,'tcx>( &obligation_trait_ref, &mut candidates); + assemble_candidates_from_trait_def(selcx, + obligation, + &obligation_trait_ref, + &mut candidates); + if let Err(e) = assemble_candidates_from_impls(selcx, obligation, &obligation_trait_ref, @@ -474,6 +479,41 @@ fn assemble_candidates_from_param_env<'cx,'tcx>( candidate_set, env_predicates); } +/// In the case of a nested projection like <<A as Foo>::FooT as Bar>::BarT, we may find +/// that the definition of `Foo` has some clues: +/// +/// ```rust +/// trait Foo { +/// type FooT : Bar<BarT=i32> +/// } +/// ``` +/// +/// Here, for example, we could conclude that the result is `i32`. +fn assemble_candidates_from_trait_def<'cx,'tcx>( + selcx: &mut SelectionContext<'cx,'tcx>, + obligation: &ProjectionTyObligation<'tcx>, + obligation_trait_ref: &Rc<ty::TraitRef<'tcx>>, + candidate_set: &mut ProjectionTyCandidateSet<'tcx>) +{ + // Check whether the self-type is itself a projection. + let trait_ref = match obligation_trait_ref.self_ty().sty { + ty::ty_projection(ref data) => data.trait_ref.clone(), + ty::ty_infer(ty::TyVar(_)) => { + // If the self-type is an inference variable, then it MAY wind up + // being a projected type, so induce an ambiguity. + candidate_set.ambiguous = true; + return; + } + _ => { return; } + }; + + // If so, extract what we know from the trait and try to come up with a good answer. + let trait_def = ty::lookup_trait_def(selcx.tcx(), trait_ref.def_id); + let bounds = trait_def.generics.to_bounds(selcx.tcx(), trait_ref.substs); + assemble_candidates_from_predicates(selcx, obligation, obligation_trait_ref, + candidate_set, bounds.predicates.into_vec()); +} + fn assemble_candidates_from_predicates<'cx,'tcx>( selcx: &mut SelectionContext<'cx,'tcx>, obligation: &ProjectionTyObligation<'tcx>, diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 425acbae483..8e88e4338cd 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -4465,9 +4465,6 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind { // the index method invoked for `a[i]` always yields an `&T` ast::ExprIndex(..) => LvalueExpr, - // `for` loops are statements - ast::ExprForLoop(..) => RvalueStmtExpr, - // in the general case, result could be any type, use DPS _ => RvalueDpsExpr }; @@ -4554,6 +4551,10 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind { tcx.sess.span_bug(expr.span, "non-desugared ExprWhileLet"); } + ast::ExprForLoop(..) => { + tcx.sess.span_bug(expr.span, "non-desugared ExprForLoop"); + } + ast::ExprLit(ref lit) if lit_is_str(&**lit) => { RvalueDpsExpr } @@ -4591,8 +4592,7 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind { ast::ExprLoop(..) | ast::ExprAssign(..) | ast::ExprInlineAsm(..) | - ast::ExprAssignOp(..) | - ast::ExprForLoop(..) => { + ast::ExprAssignOp(..) => { RvalueStmtExpr } diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 2fc68e6244a..ab182dd2256 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -333,8 +333,8 @@ macro_rules! options { break; } if !found { - early_error(&format!("unknown codegen option: `{}`", - key)[]); + early_error(&format!("unknown {} option: `{}`", + $outputname, key)[]); } } return op; @@ -424,7 +424,7 @@ macro_rules! options { } fn parse_uint(slot: &mut uint, v: Option<&str>) -> bool { - match v.and_then(|s| s.parse()) { + match v.and_then(|s| s.parse().ok()) { Some(i) => { *slot = i; true }, None => false } @@ -432,7 +432,7 @@ macro_rules! options { fn parse_opt_uint(slot: &mut Option<uint>, v: Option<&str>) -> bool { match v { - Some(s) => { *slot = s.parse(); slot.is_some() } + Some(s) => { *slot = s.parse().ok(); slot.is_some() } None => { *slot = None; true } } } diff --git a/src/librustc/util/common.rs b/src/librustc/util/common.rs index cdaca497b90..a433161d659 100644 --- a/src/librustc/util/common.rs +++ b/src/librustc/util/common.rs @@ -96,7 +96,7 @@ impl<'v, P> Visitor<'v> for LoopQueryVisitor<P> where P: FnMut(&ast::Expr_) -> b match e.node { // Skip inner loops, since a break in the inner loop isn't a // break inside the outer loop - ast::ExprLoop(..) | ast::ExprWhile(..) | ast::ExprForLoop(..) => {} + ast::ExprLoop(..) | ast::ExprWhile(..) => {} _ => visit::walk_expr(self, e) } } diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 15a91fd0f8d..6c723a58380 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -100,6 +100,7 @@ pub fn explain_region_and_span(cx: &ctxt, region: ty::Region) ast::ExprMethodCall(..) => "method call", ast::ExprMatch(_, _, ast::MatchSource::IfLetDesugar { .. }) => "if let", ast::ExprMatch(_, _, ast::MatchSource::WhileLetDesugar) => "while let", + ast::ExprMatch(_, _, ast::MatchSource::ForLoopDesugar) => "for", ast::ExprMatch(..) => "match", _ => "expression", }, diff --git a/src/librustc_back/lib.rs b/src/librustc_back/lib.rs index 13dec65d13e..2c6b5797f57 100644 --- a/src/librustc_back/lib.rs +++ b/src/librustc_back/lib.rs @@ -23,23 +23,23 @@ #![crate_name = "rustc_back"] #![unstable(feature = "rustc_private")] -#![feature(staged_api)] #![staged_api] #![crate_type = "dylib"] #![crate_type = "rlib"] #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_root_url = "http://doc.rust-lang.org/nightly/")] -#![allow(unknown_features)] -#![feature(slicing_syntax, box_syntax)] -#![allow(unknown_features)] #![feature(int_uint)] + +#![feature(box_syntax)] #![feature(collections)] #![feature(core)] #![feature(hash)] +#![feature(int_uint)] #![feature(io)] #![feature(os)] #![feature(path)] #![feature(rustc_private)] +#![feature(staged_api)] extern crate syntax; extern crate serialize; diff --git a/src/librustc_back/svh.rs b/src/librustc_back/svh.rs index aef4f7a896b..3d7adc9934f 100644 --- a/src/librustc_back/svh.rs +++ b/src/librustc_back/svh.rs @@ -252,7 +252,6 @@ mod svh_visitor { SawExprStruct, SawExprRepeat, SawExprParen, - SawExprForLoop, } fn saw_expr<'a>(node: &'a Expr_) -> SawExprComponent<'a> { @@ -288,9 +287,9 @@ mod svh_visitor { ExprStruct(..) => SawExprStruct, ExprRepeat(..) => SawExprRepeat, ExprParen(..) => SawExprParen, - ExprForLoop(..) => SawExprForLoop, // just syntactic artifacts, expanded away by time of SVH. + ExprForLoop(..) => unreachable!(), ExprIfLet(..) => unreachable!(), ExprWhileLet(..) => unreachable!(), ExprMac(..) => unreachable!(), diff --git a/src/librustc_bitflags/lib.rs b/src/librustc_bitflags/lib.rs index 487de3a6bb5..03160772879 100644 --- a/src/librustc_bitflags/lib.rs +++ b/src/librustc_bitflags/lib.rs @@ -9,7 +9,6 @@ // except according to those terms. #![crate_name = "rustc_bitflags"] -#![allow(unknown_features)] #![feature(staged_api)] #![staged_api] #![crate_type = "rlib"] diff --git a/src/librustc_borrowck/lib.rs b/src/librustc_borrowck/lib.rs index d525c22f0ab..c2677cc3fd0 100644 --- a/src/librustc_borrowck/lib.rs +++ b/src/librustc_borrowck/lib.rs @@ -10,7 +10,6 @@ #![crate_name = "rustc_borrowck"] #![unstable(feature = "rustc_private")] -#![feature(staged_api)] #![staged_api] #![crate_type = "dylib"] #![crate_type = "rlib"] @@ -18,16 +17,16 @@ html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_root_url = "http://doc.rust-lang.org/nightly/")] -#![allow(unknown_features)] -#![feature(quote)] -#![feature(slicing_syntax, unsafe_destructor)] -#![feature(rustc_diagnostic_macros)] -#![allow(unknown_features)] #![feature(int_uint)] #![allow(non_camel_case_types)] -#![feature(collections)] + #![feature(core)] -#![feature(rustc_private)] #![feature(hash)] +#![feature(int_uint)] +#![feature(quote)] +#![feature(rustc_diagnostic_macros)] +#![feature(rustc_private)] +#![feature(staged_api)] +#![feature(unsafe_destructor)] #[macro_use] extern crate log; #[macro_use] extern crate syntax; diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index fc64cf9470a..9e00844b7ee 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -880,7 +880,7 @@ pub fn collect_crate_types(session: &Session, let res = !link::invalid_output_for_target(session, *crate_type); if !res { - session.warn(&format!("dropping unsupported crate type `{:?}` \ + session.warn(&format!("dropping unsupported crate type `{}` \ for target `{}`", *crate_type, session.opts.target_triple)[]); } diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 727638c29c3..2eada1ff174 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -16,7 +16,6 @@ #![crate_name = "rustc_driver"] #![unstable(feature = "rustc_private")] -#![feature(staged_api)] #![staged_api] #![crate_type = "dylib"] #![crate_type = "rlib"] @@ -24,19 +23,19 @@ html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_root_url = "http://doc.rust-lang.org/nightly/")] -#![allow(unknown_features)] -#![feature(quote)] -#![feature(slicing_syntax, unsafe_destructor)] #![feature(box_syntax)] -#![feature(rustc_diagnostic_macros)] -#![allow(unknown_features)] #![feature(int_uint)] #![feature(collections)] #![feature(core)] +#![feature(int_uint)] #![feature(io)] #![feature(libc)] #![feature(os)] #![feature(path)] +#![feature(quote)] +#![feature(rustc_diagnostic_macros)] #![feature(rustc_private)] +#![feature(slicing_syntax, unsafe_destructor)] +#![feature(staged_api)] #![feature(std_misc)] #![feature(unicode)] diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index 4ee13f5a542..bd7ad51de37 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -99,7 +99,7 @@ pub fn parse_pretty(sess: &Session, } } }; - let opt_second = opt_second.and_then(|s| s.parse::<UserIdentifiedItem>()); + let opt_second = opt_second.and_then(|s| s.parse::<UserIdentifiedItem>().ok()); (first, opt_second) } @@ -345,13 +345,11 @@ pub enum UserIdentifiedItem { } impl FromStr for UserIdentifiedItem { - fn from_str(s: &str) -> Option<UserIdentifiedItem> { - s.parse().map(ItemViaNode).or_else(|| { - let v : Vec<_> = s.split_str("::") - .map(|x|x.to_string()) - .collect(); - Some(ItemViaPath(v)) - }) + type Err = (); + fn from_str(s: &str) -> Result<UserIdentifiedItem, ()> { + Ok(s.parse().map(ItemViaNode).unwrap_or_else(|_| { + ItemViaPath(s.split_str("::").map(|s| s.to_string()).collect()) + })) } } diff --git a/src/librustc_llvm/lib.rs b/src/librustc_llvm/lib.rs index 5ce916f5360..a24bc6eaec3 100644 --- a/src/librustc_llvm/lib.rs +++ b/src/librustc_llvm/lib.rs @@ -15,7 +15,6 @@ #![crate_name = "rustc_llvm"] #![unstable(feature = "rustc_private")] -#![feature(staged_api)] #![staged_api] #![crate_type = "dylib"] #![crate_type = "rlib"] @@ -23,16 +22,16 @@ html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_root_url = "http://doc.rust-lang.org/nightly/")] -#![allow(unknown_features)] -#![feature(link_args)] #![feature(box_syntax)] -#![allow(unknown_features)] #![feature(int_uint)] #![feature(collections)] #![feature(core)] +#![feature(hash)] +#![feature(int_uint)] #![feature(libc)] +#![feature(link_args)] #![feature(path)] +#![feature(staged_api)] #![feature(std_misc)] -#![feature(hash)] extern crate libc; #[macro_use] #[no_link] extern crate rustc_bitflags; diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index dbac2358047..14e80c6c8ef 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -10,7 +10,6 @@ #![crate_name = "rustc_privacy"] #![unstable(feature = "rustc_private")] -#![feature(staged_api)] #![staged_api] #![crate_type = "dylib"] #![crate_type = "rlib"] @@ -18,11 +17,11 @@ html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_root_url = "http://doc.rust-lang.org/nightly/")] -#![feature(rustc_diagnostic_macros)] -#![allow(unknown_features)] #![feature(int_uint)] -#![feature(collections)] #![feature(core)] +#![feature(int_uint)] +#![feature(rustc_diagnostic_macros)] #![feature(rustc_private)] +#![feature(staged_api)] #[macro_use] extern crate log; #[macro_use] extern crate syntax; diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index c099762036a..f0711903579 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -10,7 +10,6 @@ #![crate_name = "rustc_resolve"] #![unstable(feature = "rustc_private")] -#![feature(staged_api)] #![staged_api] #![crate_type = "dylib"] #![crate_type = "rlib"] @@ -18,15 +17,16 @@ html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_root_url = "http://doc.rust-lang.org/nightly/")] -#![feature(slicing_syntax)] -#![feature(rustc_diagnostic_macros)] -#![allow(unknown_features)] #![feature(int_uint)] #![feature(alloc)] #![feature(collections)] #![feature(core)] +#![feature(hash)] +#![feature(int_uint)] +#![feature(rustc_diagnostic_macros)] #![feature(rustc_private)] +#![feature(slicing_syntax)] +#![feature(staged_api)] #![feature(std_misc)] -#![feature(hash)] #[macro_use] extern crate log; #[macro_use] extern crate syntax; @@ -68,7 +68,7 @@ use rustc::util::lev_distance::lev_distance; use syntax::ast::{Arm, BindByRef, BindByValue, BindingMode, Block, Crate, CrateNum}; use syntax::ast::{DefId, Expr, ExprAgain, ExprBreak, ExprField}; -use syntax::ast::{ExprClosure, ExprForLoop, ExprLoop, ExprWhile, ExprMethodCall}; +use syntax::ast::{ExprClosure, ExprLoop, ExprWhile, ExprMethodCall}; use syntax::ast::{ExprPath, ExprQPath, ExprStruct, FnDecl}; use syntax::ast::{ForeignItemFn, ForeignItemStatic, Generics}; use syntax::ast::{Ident, ImplItem, Item, ItemConst, ItemEnum, ItemExternCrate}; @@ -4559,39 +4559,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { }) } - ExprForLoop(ref pattern, ref head, ref body, optional_label) => { - self.resolve_expr(&**head); - - self.value_ribs.push(Rib::new(NormalRibKind)); - - self.resolve_pattern(&**pattern, - LocalIrrefutableMode, - &mut HashMap::new()); - - match optional_label { - None => {} - Some(label) => { - self.label_ribs - .push(Rib::new(NormalRibKind)); - let def_like = DlDef(DefLabel(expr.id)); - - { - let rib = self.label_ribs.last_mut().unwrap(); - let renamed = mtwt::resolve(label); - rib.bindings.insert(renamed, def_like); - } - } - } - - self.resolve_block(&**body); - - if optional_label.is_some() { - drop(self.label_ribs.pop()) - } - - self.value_ribs.pop(); - } - ExprBreak(Some(label)) | ExprAgain(Some(label)) => { let renamed = mtwt::resolve(label); match self.search_label(renamed) { diff --git a/src/librustc_trans/lib.rs b/src/librustc_trans/lib.rs index bb026e237df..c46c2b7e6dd 100644 --- a/src/librustc_trans/lib.rs +++ b/src/librustc_trans/lib.rs @@ -16,7 +16,6 @@ #![crate_name = "rustc_trans"] #![unstable(feature = "rustc_private")] -#![feature(staged_api)] #![staged_api] #![crate_type = "dylib"] #![crate_type = "rlib"] @@ -24,23 +23,25 @@ html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_root_url = "http://doc.rust-lang.org/nightly/")] -#![allow(unknown_features)] -#![feature(quote)] -#![feature(slicing_syntax, unsafe_destructor)] -#![feature(box_syntax)] -#![feature(rustc_diagnostic_macros)] -#![allow(unknown_features)] #![feature(int_uint)] +#![cfg_attr(not(stage0), allow(unused_mut))] // NOTE: remove after stage0 snap + #![feature(alloc)] +#![feature(box_syntax)] #![feature(collections)] #![feature(core)] +#![feature(hash)] +#![feature(int_uint)] #![feature(io)] #![feature(libc)] #![feature(os)] #![feature(path)] +#![feature(quote)] +#![feature(rustc_diagnostic_macros)] #![feature(rustc_private)] +#![feature(slicing_syntax, unsafe_destructor)] +#![feature(staged_api)] #![feature(std_misc)] #![feature(unicode)] -#![feature(hash)] extern crate arena; extern crate flate; diff --git a/src/librustc_trans/save/mod.rs b/src/librustc_trans/save/mod.rs index 7e7176d661c..fbeaae1d1df 100644 --- a/src/librustc_trans/save/mod.rs +++ b/src/librustc_trans/save/mod.rs @@ -44,7 +44,7 @@ use syntax::codemap::*; use syntax::parse::token::{self, get_ident, keywords}; use syntax::owned_slice::OwnedSlice; use syntax::visit::{self, Visitor}; -use syntax::print::pprust::{path_to_string,ty_to_string}; +use syntax::print::pprust::{path_to_string, ty_to_string}; use syntax::ptr::P; use self::span_utils::SpanUtils; @@ -123,14 +123,17 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { let mut result: Vec<(Span, String)> = vec!(); - let mut segs = vec!(); - for (seg, span) in path.segments.iter().zip(spans.iter()) { + for (i, (seg, span)) in path.segments.iter().zip(spans.iter()).enumerate() { segs.push(seg.clone()); let sub_path = ast::Path{span: *span, // span for the last segment global: path.global, segments: segs}; - let qualname = path_to_string(&sub_path); + let qualname = if i == 0 && path.global { + format!("::{}", path_to_string(&sub_path)) + } else { + path_to_string(&sub_path) + }; result.push((*span, qualname)); segs = sub_path.segments; } @@ -138,9 +141,18 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { result } - fn write_sub_paths(&mut self, path: &ast::Path) { + // The global arg allows us to override the global-ness of the path (which + // actually means 'does the path start with `::`', rather than 'is the path + // semantically global). We use the override for `use` imports (etc.) where + // the syntax is non-global, but the semantics are global. + fn write_sub_paths(&mut self, path: &ast::Path, global: bool) { let sub_paths = self.process_path_prefixes(path); - for &(ref span, ref qualname) in sub_paths.iter() { + for (i, &(ref span, ref qualname)) in sub_paths.iter().enumerate() { + let qualname = if i == 0 && global && !path.global { + format!("::{}", qualname) + } else { + qualname.clone() + }; self.fmt.sub_mod_ref_str(path.span, *span, &qualname[], @@ -149,16 +161,21 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { } // As write_sub_paths, but does not process the last ident in the path (assuming it - // will be processed elsewhere). - fn write_sub_paths_truncated(&mut self, path: &ast::Path) { + // will be processed elsewhere). See note on write_sub_paths about global. + fn write_sub_paths_truncated(&mut self, path: &ast::Path, global: bool) { let sub_paths = self.process_path_prefixes(path); let len = sub_paths.len(); if len <= 1 { return; } - let sub_paths = &sub_paths[.. (len-1)]; - for &(ref span, ref qualname) in sub_paths.iter() { + let sub_paths = &sub_paths[..len-1]; + for (i, &(ref span, ref qualname)) in sub_paths.iter().enumerate() { + let qualname = if i == 0 && global && !path.global { + format!("::{}", qualname) + } else { + qualname.clone() + }; self.fmt.sub_mod_ref_str(path.span, *span, &qualname[], @@ -276,9 +293,9 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { let mut scope_id; // The qualname for a method is the trait name or name of the struct in an impl in - // which the method is declared in followed by the method's name. - let mut qualname = match ty::impl_of_method(&self.analysis.ty_cx, - ast_util::local_def(method.id)) { + // which the method is declared in, followed by the method's name. + let qualname = match ty::impl_of_method(&self.analysis.ty_cx, + ast_util::local_def(method.id)) { Some(impl_id) => match self.analysis.ty_cx.map.get(impl_id.node) { NodeItem(item) => { scope_id = item.id; @@ -296,7 +313,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { }, None => {} } - result.push_str(">::"); + result.push_str(">"); result } _ => { @@ -321,9 +338,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { scope_id = def_id.node; match self.analysis.ty_cx.map.get(def_id.node) { NodeItem(_) => { - let mut result = ty::item_path_str(&self.analysis.ty_cx, def_id); - result.push_str("::"); - result + format!("::{}", ty::item_path_str(&self.analysis.ty_cx, def_id)) } _ => { self.sess.span_bug(method.span, @@ -340,7 +355,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { }, }; - qualname.push_str(get_ident(method.pe_ident()).get()); + let qualname = format!("{}::{}", qualname, get_ident(method.pe_ident()).get()); let qualname = &qualname[]; // record the decl for this def (if it has one) @@ -435,7 +450,8 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { } // Dump generic params bindings, then visit_generics - fn process_generic_params(&mut self, generics:&ast::Generics, + fn process_generic_params(&mut self, + generics:&ast::Generics, full_span: Span, prefix: &str, id: NodeId) { @@ -465,7 +481,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { decl: &ast::FnDecl, ty_params: &ast::Generics, body: &ast::Block) { - let qualname = self.analysis.ty_cx.map.path_to_string(item.id); + let qualname = format!("::{}", self.analysis.ty_cx.map.path_to_string(item.id)); let sub_span = self.span.sub_span_after_keyword(item.span, keywords::Fn); self.fmt.fn_str(item.span, @@ -497,7 +513,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { mt: ast::Mutability, expr: &ast::Expr) { - let qualname = self.analysis.ty_cx.map.path_to_string(item.id); + let qualname = format!("::{}", self.analysis.ty_cx.map.path_to_string(item.id)); // If the variable is immutable, save the initialising expression. let value = match mt { @@ -525,7 +541,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { typ: &ast::Ty, expr: &ast::Expr) { - let qualname = self.analysis.ty_cx.map.path_to_string(item.id); + let qualname = format!("::{}", self.analysis.ty_cx.map.path_to_string(item.id)); let sub_span = self.span.sub_span_after_keyword(item.span, keywords::Const); @@ -547,7 +563,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { item: &ast::Item, def: &ast::StructDef, ty_params: &ast::Generics) { - let qualname = self.analysis.ty_cx.map.path_to_string(item.id); + let qualname = format!("::{}", self.analysis.ty_cx.map.path_to_string(item.id)); let ctor_id = match def.ctor_id { Some(node_id) => node_id, @@ -576,7 +592,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { item: &ast::Item, enum_definition: &ast::EnumDef, ty_params: &ast::Generics) { - let enum_name = self.analysis.ty_cx.map.path_to_string(item.id); + let enum_name = format!("::{}", self.analysis.ty_cx.map.path_to_string(item.id)); let val = self.span.snippet(item.span); match self.span.sub_span_after_keyword(item.span, keywords::Enum) { Some(sub_span) => self.fmt.enum_str(item.span, @@ -702,7 +718,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { generics: &ast::Generics, trait_refs: &OwnedSlice<ast::TyParamBound>, methods: &Vec<ast::TraitItem>) { - let qualname = self.analysis.ty_cx.map.path_to_string(item.id); + let qualname = format!("::{}", self.analysis.ty_cx.map.path_to_string(item.id)); let val = self.span.snippet(item.span); let sub_span = self.span.sub_span_after_keyword(item.span, keywords::Trait); self.fmt.trait_str(item.span, @@ -751,7 +767,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { fn process_mod(&mut self, item: &ast::Item, // The module in question, represented as an item. m: &ast::Mod) { - let qualname = self.analysis.ty_cx.map.path_to_string(item.id); + let qualname = format!("::{}", self.analysis.ty_cx.map.path_to_string(item.id)); let cm = self.sess.codemap(); let filename = cm.span_to_filename(m.inner); @@ -798,7 +814,13 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { sub_span, def_id, self.cur_scope), - def::DefStaticMethod(declid, provenence) => { + def::DefTy(def_id, _) => self.fmt.ref_str(recorder::TypeRef, + span, + sub_span, + def_id, + self.cur_scope), + def::DefStaticMethod(declid, provenence) | + def::DefMethod(declid, _, provenence) => { let sub_span = self.span.sub_span_for_meth_name(span); let defid = if declid.krate == ast::LOCAL_CRATE { let ti = ty::impl_or_trait_item(&self.analysis.ty_cx, @@ -840,13 +862,17 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { Some(declid), self.cur_scope); }, - def::DefFn(def_id, _) => self.fmt.fn_call_str(span, - sub_span, - def_id, - self.cur_scope), + def::DefFn(def_id, _) => { + self.fmt.fn_call_str(span, + sub_span, + def_id, + self.cur_scope) + } _ => self.sess.span_bug(span, - &format!("Unexpected def kind while looking up path in '{}'", - self.span.snippet(span))[]), + &format!("Unexpected def kind while looking \ + up path in `{}`: `{:?}`", + self.span.snippet(span), + *def)[]), } // modules or types in the path prefix match *def { @@ -856,7 +882,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { def::DefConst(..) | def::DefStruct(_) | def::DefVariant(..) | - def::DefFn(..) => self.write_sub_paths_truncated(path), + def::DefFn(..) => self.write_sub_paths_truncated(path, false), _ => {}, } } @@ -870,21 +896,21 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { return } - let mut struct_def: Option<DefId> = None; - match self.lookup_type_ref(ex.id) { - Some(id) => { - struct_def = Some(id); + self.write_sub_paths_truncated(path, false); + + let ty = &ty::expr_ty_adjusted(&self.analysis.ty_cx, ex).sty; + let struct_def = match *ty { + ty::ty_struct(def_id, _) => { let sub_span = self.span.span_for_last_ident(path.span); self.fmt.ref_str(recorder::StructRef, path.span, sub_span, - id, + def_id, self.cur_scope); - }, - None => () - } - - self.write_sub_paths_truncated(path); + Some(def_id) + } + _ => None + }; for field in fields.iter() { match struct_def { @@ -1070,7 +1096,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> { mod_id, get_ident(ident).get(), self.cur_scope); - self.write_sub_paths_truncated(path); + self.write_sub_paths_truncated(path, true); } ast::ViewPathGlob(ref path) => { // Make a comma-separated list of names of imported modules. @@ -1093,7 +1119,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> { item.id, name_string.as_slice(), self.cur_scope); - self.write_sub_paths(path); + self.write_sub_paths(path, true); } ast::ViewPathList(ref path, ref list) => { for plid in list.iter() { @@ -1117,28 +1143,28 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> { } } - self.write_sub_paths(path); + self.write_sub_paths(path, true); } } } ast::ItemExternCrate(ref s) => { let name = get_ident(item.ident); let name = name.get(); - let s = match *s { + let location = match *s { Some((ref s, _)) => s.get().to_string(), None => name.to_string(), }; - let sub_span = self.span.sub_span_after_keyword(item.span, keywords::Crate); + let alias_span = self.span.span_for_last_ident(item.span); let cnum = match self.sess.cstore.find_extern_mod_stmt_cnum(item.id) { Some(cnum) => cnum, None => 0, }; self.fmt.extern_crate_str(item.span, - sub_span, + alias_span, item.id, cnum, name, - &s[], + &location[], self.cur_scope); } ast::ItemFn(ref decl, _, _, ref ty_params, ref body) => @@ -1164,7 +1190,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> { self.process_trait(item, generics, trait_refs, methods), ast::ItemMod(ref m) => self.process_mod(item, m), ast::ItemTy(ref ty, ref ty_params) => { - let qualname = self.analysis.ty_cx.map.path_to_string(item.id); + let qualname = format!("::{}", self.analysis.ty_cx.map.path_to_string(item.id)); let value = ty_to_string(&**ty); let sub_span = self.span.sub_span_after_keyword(item.span, keywords::Type); self.fmt.typedef_str(item.span, @@ -1224,9 +1250,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> { ast_util::local_def(method_type.id)) { Some(def_id) => { scope_id = def_id.node; - let mut s = ty::item_path_str(&self.analysis.ty_cx, def_id); - s.push_str("::"); - s + format!("::{}::", ty::item_path_str(&self.analysis.ty_cx, def_id)) }, None => { self.sess.span_bug(method_type.span, @@ -1283,7 +1307,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> { None => () } - self.write_sub_paths_truncated(path); + self.write_sub_paths_truncated(path, false); visit::walk_path(self, path); }, @@ -1321,8 +1345,8 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> { } self.visit_expr(&**sub_ex); - - match ty::expr_ty_adjusted(&self.analysis.ty_cx, &**sub_ex).sty { + let ty = &ty::expr_ty_adjusted(&self.analysis.ty_cx, &**sub_ex).sty; + match *ty { ty::ty_struct(def_id, _) => { let fields = ty::lookup_struct_fields(&self.analysis.ty_cx, def_id); for f in fields.iter() { @@ -1336,9 +1360,9 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> { break; } } - }, + } _ => self.sess.span_bug(ex.span, - "Expected struct type, but not ty_struct"), + &format!("Expected struct type, found {:?}", ty)[]), } }, ast::ExprTupField(ref sub_ex, idx) => { @@ -1348,12 +1372,13 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> { self.visit_expr(&**sub_ex); - match ty::expr_ty_adjusted(&self.analysis.ty_cx, &**sub_ex).sty { + let ty = &ty::expr_ty_adjusted(&self.analysis.ty_cx, &**sub_ex).sty; + match *ty { ty::ty_struct(def_id, _) => { let fields = ty::lookup_struct_fields(&self.analysis.ty_cx, def_id); for (i, f) in fields.iter().enumerate() { if i == idx.node { - let sub_span = self.span.span_for_last_ident(ex.span); + let sub_span = self.span.sub_span_after_token(ex.span, token::Dot); self.fmt.ref_str(recorder::VarRef, ex.span, sub_span, @@ -1362,9 +1387,11 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> { break; } } - }, + } + ty::ty_tup(_) => {} _ => self.sess.span_bug(ex.span, - "Expected struct type, but not ty_struct"), + &format!("Expected struct or tuple \ + type, found {:?}", ty)[]), } }, ast::ExprClosure(_, _, ref decl, ref body) => { @@ -1440,7 +1467,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> { &value[], "") } - def::DefVariant(..) => { + def::DefVariant(..) | def::DefTy(..) | def::DefStruct(..) => { paths_to_process.push((id, p.clone(), Some(ref_kind))) } // FIXME(nrc) what are these doing here? @@ -1568,8 +1595,7 @@ pub fn process_crate(sess: &Session, SpanUtils { sess: sess, err_count: Cell::new(0) - }, - cratename.clone()), + }), span: SpanUtils { sess: sess, err_count: Cell::new(0) diff --git a/src/librustc_trans/save/recorder.rs b/src/librustc_trans/save/recorder.rs index ef1eb3cb804..1378d409208 100644 --- a/src/librustc_trans/save/recorder.rs +++ b/src/librustc_trans/save/recorder.rs @@ -50,7 +50,6 @@ impl Recorder { pub struct FmtStrs<'a> { pub recorder: Box<Recorder>, span: SpanUtils<'a>, - krate: String, } macro_rules! s { ($e:expr) => { format!("{}", $e) }} @@ -63,7 +62,7 @@ macro_rules! svec { }) } -#[derive(Copy,Debug)] +#[derive(Copy, Debug, Eq, PartialEq)] pub enum Row { Variable, Enum, @@ -92,11 +91,10 @@ pub enum Row { } impl<'a> FmtStrs<'a> { - pub fn new(rec: Box<Recorder>, span: SpanUtils<'a>, krate: String) -> FmtStrs<'a> { + pub fn new(rec: Box<Recorder>, span: SpanUtils<'a>) -> FmtStrs<'a> { FmtStrs { recorder: rec, span: span, - krate: krate, } } @@ -177,16 +175,7 @@ impl<'a> FmtStrs<'a> { }); let pairs = fields.iter().zip(values); - let strs = pairs.map(|(f, v)| format!(",{},\"{}\"", f, escape( - if *f == "qualname" && v.len() > 0 { - let mut n = self.krate.clone(); - n.push_str("::"); - n.push_str(v); - n - } else { - String::from_str(v) - } - ))); + let strs = pairs.map(|(f, v)| format!(",{},\"{}\"", f, escape(String::from_str(v)))); Some(strs.fold(String::new(), |mut s, ss| { s.push_str(&ss[]); s @@ -507,13 +496,13 @@ impl<'a> FmtStrs<'a> { } pub fn extern_crate_str(&mut self, - span: Span, - sub_span: Option<Span>, - id: NodeId, - cnum: ast::CrateNum, - name: &str, - loc: &str, - parent: NodeId) { + span: Span, + sub_span: Option<Span>, + id: NodeId, + cnum: ast::CrateNum, + name: &str, + loc: &str, + parent: NodeId) { self.check_and_record(ExternCrate, span, sub_span, diff --git a/src/librustc_trans/save/span_utils.rs b/src/librustc_trans/save/span_utils.rs index 97b3cda006b..419ccfa312e 100644 --- a/src/librustc_trans/save/span_utils.rs +++ b/src/librustc_trans/save/span_utils.rs @@ -37,7 +37,7 @@ impl<'a> SpanUtils<'a> { let lo_pos_byte = self.sess.codemap().lookup_byte_offset(span.lo).pos; let hi_pos_byte = self.sess.codemap().lookup_byte_offset(span.hi).pos; - format!("file_name,{},file_line,{},file_col,{},extent_start,{},extent_start_bytes,{},\ + format!("file_name,\"{}\",file_line,{},file_col,{},extent_start,{},extent_start_bytes,{},\ file_line_end,{},file_col_end,{},extent_end,{},extent_end_bytes,{}", lo_loc.file.name, lo_loc.line, lo_loc.col.to_usize(), lo_pos.to_usize(), lo_pos_byte.to_usize(), @@ -205,6 +205,7 @@ impl<'a> SpanUtils<'a> { bracket_count += match prev.tok { token::Lt => 1, token::Gt => -1, + token::BinOp(token::Shl) => 2, token::BinOp(token::Shr) => -2, _ => 0 }; @@ -236,7 +237,7 @@ impl<'a> SpanUtils<'a> { let mut toks = self.retokenise_span(span); // We keep track of how many brackets we're nested in - let mut bracket_count = 0i; + let mut bracket_count = 0; loop { let ts = toks.real_token(); if ts.tok == token::Eof { @@ -296,13 +297,25 @@ impl<'a> SpanUtils<'a> { pub fn sub_span_after_keyword(&self, span: Span, keyword: keywords::Keyword) -> Option<Span> { + self.sub_span_after(span, |t| t.is_keyword(keyword)) + } + + pub fn sub_span_after_token(&self, + span: Span, + tok: Token) -> Option<Span> { + self.sub_span_after(span, |t| t == tok) + } + + fn sub_span_after<F: Fn(Token) -> bool>(&self, + span: Span, + f: F) -> Option<Span> { let mut toks = self.retokenise_span(span); loop { let ts = toks.real_token(); if ts.tok == token::Eof { return None; } - if ts.tok.is_keyword(keyword) { + if f(ts.tok) { let ts = toks.real_token(); if ts.tok == token::Eof { return None @@ -313,6 +326,7 @@ impl<'a> SpanUtils<'a> { } } + // Returns a list of the spans of idents in a patch. // E.g., For foo::bar<x,t>::baz, we return [foo, bar, baz] (well, their spans) pub fn spans_for_path_segments(&self, path: &ast::Path) -> Vec<Span> { diff --git a/src/librustc_trans/trans/_match.rs b/src/librustc_trans/trans/_match.rs index 8d7eb5816c2..50dfbff0034 100644 --- a/src/librustc_trans/trans/_match.rs +++ b/src/librustc_trans/trans/_match.rs @@ -1078,7 +1078,7 @@ fn compile_submatch_continue<'a, 'p, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, let sw = if kind == Switch { build::Switch(bcx, test_val, else_cx.llbb, opts.len()) } else { - C_int(ccx, 0i) // Placeholder for when not using a switch + C_int(ccx, 0) // Placeholder for when not using a switch }; let defaults = enter_default(else_cx, dm, m, col, val); @@ -1537,31 +1537,6 @@ pub fn store_arg<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, } } -/// Generates code for the pattern binding in a `for` loop like -/// `for <pat> in <expr> { ... }`. -pub fn store_for_loop_binding<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, - pat: &ast::Pat, - llvalue: ValueRef, - body_scope: cleanup::ScopeId) - -> Block<'blk, 'tcx> { - let _icx = push_ctxt("match::store_for_loop_binding"); - - if simple_identifier(&*pat).is_some() && - bcx.sess().opts.debuginfo != FullDebugInfo { - // Generate nicer LLVM for the common case of a `for` loop pattern - // like `for x in blahblah { ... }`. - let binding_type = node_id_type(bcx, pat.id); - bcx.fcx.lllocals.borrow_mut().insert(pat.id, - Datum::new(llvalue, - binding_type, - Lvalue)); - return bcx - } - - // General path. Copy out the values that are used in the pattern. - bind_irrefutable_pat(bcx, pat, llvalue, body_scope) -} - fn mk_binding_alloca<'blk, 'tcx, A, F>(bcx: Block<'blk, 'tcx>, p_id: ast::NodeId, ident: &ast::Ident, diff --git a/src/librustc_trans/trans/base.rs b/src/librustc_trans/trans/base.rs index 7b4acfac4b3..1b212aca330 100644 --- a/src/librustc_trans/trans/base.rs +++ b/src/librustc_trans/trans/base.rs @@ -623,7 +623,7 @@ pub fn compare_simd_types<'blk, 'tcx>( size: uint, op: ast::BinOp) -> ValueRef { - match t.sty { + let cmp = match t.sty { ty::ty_float(_) => { // The comparison operators for floating point vectors are challenging. // LLVM outputs a `< size x i1 >`, but if we perform a sign extension @@ -632,25 +632,32 @@ pub fn compare_simd_types<'blk, 'tcx>( cx.sess().bug("compare_simd_types: comparison operators \ not supported for floating point SIMD types") }, - ty::ty_uint(_) | ty::ty_int(_) => { - let cmp = match op.node { - ast::BiEq => llvm::IntEQ, - ast::BiNe => llvm::IntNE, - ast::BiLt => llvm::IntSLT, - ast::BiLe => llvm::IntSLE, - ast::BiGt => llvm::IntSGT, - ast::BiGe => llvm::IntSGE, - _ => cx.sess().bug("compare_simd_types: must be a comparison operator"), - }; - let return_ty = Type::vector(&type_of(cx.ccx(), t), size as u64); - // LLVM outputs an `< size x i1 >`, so we need to perform a sign extension - // to get the correctly sized type. This will compile to a single instruction - // once the IR is converted to assembly if the SIMD instruction is supported - // by the target architecture. - SExt(cx, ICmp(cx, cmp, lhs, rhs), return_ty) + ty::ty_uint(_) => match op.node { + ast::BiEq => llvm::IntEQ, + ast::BiNe => llvm::IntNE, + ast::BiLt => llvm::IntULT, + ast::BiLe => llvm::IntULE, + ast::BiGt => llvm::IntUGT, + ast::BiGe => llvm::IntUGE, + _ => cx.sess().bug("compare_simd_types: must be a comparison operator"), + }, + ty::ty_int(_) => match op.node { + ast::BiEq => llvm::IntEQ, + ast::BiNe => llvm::IntNE, + ast::BiLt => llvm::IntSLT, + ast::BiLe => llvm::IntSLE, + ast::BiGt => llvm::IntSGT, + ast::BiGe => llvm::IntSGE, + _ => cx.sess().bug("compare_simd_types: must be a comparison operator"), }, _ => cx.sess().bug("compare_simd_types: invalid SIMD type"), - } + }; + let return_ty = Type::vector(&type_of(cx.ccx(), t), size as u64); + // LLVM outputs an `< size x i1 >`, so we need to perform a sign extension + // to get the correctly sized type. This will compile to a single instruction + // once the IR is converted to assembly if the SIMD instruction is supported + // by the target architecture. + SExt(cx, ICmp(cx, cmp, lhs, rhs), return_ty) } // Iterates through the elements of a structural type. diff --git a/src/librustc_trans/trans/controlflow.rs b/src/librustc_trans/trans/controlflow.rs index bea8a759971..c4388603145 100644 --- a/src/librustc_trans/trans/controlflow.rs +++ b/src/librustc_trans/trans/controlflow.rs @@ -11,8 +11,6 @@ use llvm::ValueRef; use middle::def; use middle::lang_items::{PanicFnLangItem, PanicBoundsCheckFnLangItem}; -use trans::_match; -use trans::adt; use trans::base::*; use trans::build::*; use trans::callee; @@ -20,17 +18,12 @@ use trans::cleanup::CleanupMethods; use trans::cleanup; use trans::common::*; use trans::consts; -use trans::datum; use trans::debuginfo; use trans::debuginfo::{DebugLoc, ToDebugLoc}; use trans::expr; -use trans::meth; -use trans::type_::Type; use trans; use middle::ty; -use middle::ty::MethodCall; use util::ppaux::Repr; -use util::ppaux; use syntax::ast; use syntax::ast::Ident; @@ -259,135 +252,6 @@ pub fn trans_while<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, return next_bcx_in; } -/// Translates a `for` loop. -pub fn trans_for<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, - loop_info: NodeIdAndSpan, - pat: &ast::Pat, - head: &ast::Expr, - body: &ast::Block) - -> Block<'blk, 'tcx> -{ - let _icx = push_ctxt("trans_for"); - - // bcx - // | - // loopback_bcx_in <-------+ - // | | - // loopback_bcx_out | - // | | | - // | body_bcx_in | - // cleanup_blk | | - // | body_bcx_out --+ - // next_bcx_in - - // Codegen the head to create the iterator value. - let iterator_datum = - unpack_datum!(bcx, expr::trans_to_lvalue(bcx, head, "for_head")); - let iterator_type = node_id_type(bcx, head.id); - debug!("iterator type is {}, datum type is {}", - ppaux::ty_to_string(bcx.tcx(), iterator_type), - ppaux::ty_to_string(bcx.tcx(), iterator_datum.ty)); - - let lliterator = load_ty(bcx, iterator_datum.val, iterator_datum.ty); - - // Create our basic blocks and set up our loop cleanups. - let next_bcx_in = bcx.fcx.new_id_block("for_exit", loop_info.id); - let loopback_bcx_in = bcx.fcx.new_id_block("for_loopback", head.id); - let body_bcx_in = bcx.fcx.new_id_block("for_body", body.id); - bcx.fcx.push_loop_cleanup_scope(loop_info.id, - [next_bcx_in, loopback_bcx_in]); - Br(bcx, loopback_bcx_in.llbb, DebugLoc::None); - let cleanup_llbb = bcx.fcx.normal_exit_block(loop_info.id, - cleanup::EXIT_BREAK); - - // Set up the method call (to `.next()`). - let method_call = MethodCall::expr(loop_info.id); - let method_type = (*loopback_bcx_in.tcx() - .method_map - .borrow())[method_call] - .ty; - let method_type = monomorphize_type(loopback_bcx_in, method_type); - let method_result_type = - ty::assert_no_late_bound_regions( // LB regions are instantiated in invoked methods - loopback_bcx_in.tcx(), &ty::ty_fn_ret(method_type)).unwrap(); - let option_cleanup_scope = body_bcx_in.fcx.push_custom_cleanup_scope(); - let option_cleanup_scope_id = cleanup::CustomScope(option_cleanup_scope); - - // Compile the method call (to `.next()`). - let mut loopback_bcx_out = loopback_bcx_in; - let option_datum = - unpack_datum!(loopback_bcx_out, - datum::lvalue_scratch_datum(loopback_bcx_out, - method_result_type, - "loop_option", - false, - option_cleanup_scope_id, - (), - |(), bcx, lloption| { - let Result { - bcx, - val: _ - } = callee::trans_call_inner(bcx, - Some(loop_info), - method_type, - |bcx, arg_cleanup_scope| { - meth::trans_method_callee( - bcx, - method_call, - None, - arg_cleanup_scope) - }, - callee::ArgVals(&[lliterator]), - Some(expr::SaveIn(lloption))); - bcx - })); - - // Check the discriminant; if the `None` case, exit the loop. - let option_representation = adt::represent_type(loopback_bcx_out.ccx(), - method_result_type); - let lldiscriminant = adt::trans_get_discr(loopback_bcx_out, - &*option_representation, - option_datum.val, - None); - let i1_type = Type::i1(loopback_bcx_out.ccx()); - let llcondition = Trunc(loopback_bcx_out, lldiscriminant, i1_type); - CondBr(loopback_bcx_out, llcondition, body_bcx_in.llbb, cleanup_llbb, DebugLoc::None); - - // Now we're in the body. Unpack the `Option` value into the programmer- - // supplied pattern. - let llpayload = adt::trans_field_ptr(body_bcx_in, - &*option_representation, - option_datum.val, - 1, - 0); - let binding_cleanup_scope = body_bcx_in.fcx.push_custom_cleanup_scope(); - let binding_cleanup_scope_id = - cleanup::CustomScope(binding_cleanup_scope); - let mut body_bcx_out = - _match::store_for_loop_binding(body_bcx_in, - pat, - llpayload, - binding_cleanup_scope_id); - - debuginfo::create_for_loop_var_metadata(body_bcx_in, pat); - - // Codegen the body. - body_bcx_out = trans_block(body_bcx_out, body, expr::Ignore); - body_bcx_out = - body_bcx_out.fcx - .pop_and_trans_custom_cleanup_scope(body_bcx_out, - binding_cleanup_scope); - body_bcx_out = - body_bcx_out.fcx - .pop_and_trans_custom_cleanup_scope(body_bcx_out, - option_cleanup_scope); - Br(body_bcx_out, loopback_bcx_in.llbb, DebugLoc::None); - - // Codegen cleanups and leave. - next_bcx_in.fcx.pop_loop_cleanup_scope(loop_info.id); - next_bcx_in -} - pub fn trans_loop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, loop_expr: &ast::Expr, body: &ast::Block) diff --git a/src/librustc_trans/trans/debuginfo.rs b/src/librustc_trans/trans/debuginfo.rs index ce9af3162a0..4f9c97795e1 100644 --- a/src/librustc_trans/trans/debuginfo.rs +++ b/src/librustc_trans/trans/debuginfo.rs @@ -1053,48 +1053,6 @@ pub fn create_argument_metadata(bcx: Block, arg: &ast::Arg) { }) } -/// Creates debug information for the given for-loop variable. -/// -/// This function assumes that there's a datum for each pattern component of the -/// loop variable in `bcx.fcx.lllocals`. -/// Adds the created metadata nodes directly to the crate's IR. -pub fn create_for_loop_var_metadata(bcx: Block, pat: &ast::Pat) { - if bcx.unreachable.get() || - fn_should_be_ignored(bcx.fcx) || - bcx.sess().opts.debuginfo != FullDebugInfo { - return; - } - - let def_map = &bcx.tcx().def_map; - let locals = bcx.fcx.lllocals.borrow(); - - pat_util::pat_bindings(def_map, pat, |_, node_id, span, var_ident| { - let datum = match locals.get(&node_id) { - Some(datum) => datum, - None => { - bcx.sess().span_bug(span, - format!("no entry in lllocals table for {}", - node_id).as_slice()); - } - }; - - if unsafe { llvm::LLVMIsAAllocaInst(datum.val) } == ptr::null_mut() { - bcx.sess().span_bug(span, "debuginfo::create_for_loop_var_metadata() - \ - Referenced variable location is not an alloca!"); - } - - let scope_metadata = scope_metadata(bcx.fcx, node_id, span); - - declare_local(bcx, - var_ident.node, - datum.ty, - scope_metadata, - DirectVariable { alloca: datum.val }, - LocalVariable, - span); - }) -} - pub fn get_cleanup_debug_loc_for_ast_node<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, node_id: ast::NodeId, node_span: Span, @@ -3627,24 +3585,9 @@ fn create_scope_map(cx: &CrateContext, Found unexpanded while-let."); } - ast::ExprForLoop(ref pattern, ref head, ref body, _) => { - walk_expr(cx, &**head, scope_stack, scope_map); - - with_new_scope(cx, - exp.span, - scope_stack, - scope_map, - |cx, scope_stack, scope_map| { - scope_map.insert(exp.id, - scope_stack.last() - .unwrap() - .scope_metadata); - walk_pattern(cx, - &**pattern, - scope_stack, - scope_map); - walk_block(cx, &**body, scope_stack, scope_map); - }) + ast::ExprForLoop(..) => { + cx.sess().span_bug(exp.span, "debuginfo::create_scope_map() - \ + Found unexpanded for loop."); } ast::ExprMac(_) => { diff --git a/src/librustc_trans/trans/expr.rs b/src/librustc_trans/trans/expr.rs index 2b97e7b7964..46726f78d04 100644 --- a/src/librustc_trans/trans/expr.rs +++ b/src/librustc_trans/trans/expr.rs @@ -927,13 +927,6 @@ fn trans_rvalue_stmt_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, ast::ExprWhile(ref cond, ref body, _) => { controlflow::trans_while(bcx, expr, &**cond, &**body) } - ast::ExprForLoop(ref pat, ref head, ref body, _) => { - controlflow::trans_for(bcx, - expr_info(expr), - &**pat, - &**head, - &**body) - } ast::ExprLoop(ref body, _) => { controlflow::trans_loop(bcx, expr, &**body) } diff --git a/src/librustc_trans/trans/foreign.rs b/src/librustc_trans/trans/foreign.rs index 5965d396e87..6c017866ef0 100644 --- a/src/librustc_trans/trans/foreign.rs +++ b/src/librustc_trans/trans/foreign.rs @@ -973,9 +973,9 @@ pub fn lltype_for_foreign_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn add_argument_attributes(tys: &ForeignTypes, llfn: ValueRef) { let mut i = if tys.fn_ty.ret_ty.is_indirect() { - 1i + 1 } else { - 0i + 0 }; match tys.fn_ty.ret_ty.attr { diff --git a/src/librustc_trans/trans/tvec.rs b/src/librustc_trans/trans/tvec.rs index 06bc19f45a4..358e38a671d 100644 --- a/src/librustc_trans/trans/tvec.rs +++ b/src/librustc_trans/trans/tvec.rs @@ -499,7 +499,7 @@ pub fn iter_vec_raw<'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>, CondBr(header_bcx, not_yet_at_end, body_bcx.llbb, next_bcx.llbb, DebugLoc::None); let body_bcx = f(body_bcx, data_ptr, vt.unit_ty); AddIncomingToPhi(data_ptr, InBoundsGEP(body_bcx, data_ptr, - &[C_int(bcx.ccx(), 1i)]), + &[C_int(bcx.ccx(), 1)]), body_bcx.llbb); Br(body_bcx, header_bcx.llbb, DebugLoc::None); next_bcx diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 640c8d8d4be..9dcde1c2a0a 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -87,7 +87,6 @@ use check::_match::pat_ctxt; use fmt_macros::{Parser, Piece, Position}; use middle::{const_eval, def}; use middle::infer; -use middle::lang_items::IteratorItem; use middle::mem_categorization as mc; use middle::mem_categorization::McResult; use middle::pat_util::{self, pat_id_map}; @@ -1862,7 +1861,7 @@ pub enum LvaluePreference { } /// Whether `autoderef` requires types to resolve. -#[derive(Copy, Show, PartialEq, Eq)] +#[derive(Copy, Debug, PartialEq, Eq)] pub enum UnresolvedTypeAction { /// Produce an error and return `ty_err` whenever a type cannot /// be resolved (i.e. it is `ty_infer`). @@ -2136,92 +2135,6 @@ fn try_index_step<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, }) } -/// Given the head of a `for` expression, looks up the `next` method in the -/// `Iterator` trait. Panics if the expression does not implement `next`. -/// -/// The return type of this function represents the concrete element type -/// `A` in the type `Iterator<A>` that the method returns. -fn lookup_method_for_for_loop<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, - iterator_expr: &ast::Expr, - loop_id: ast::NodeId) - -> Ty<'tcx> { - let trait_did = match fcx.tcx().lang_items.require(IteratorItem) { - Ok(trait_did) => trait_did, - Err(ref err_string) => { - span_err!(fcx.tcx().sess, iterator_expr.span, E0233, - "{}", &err_string[]); - return fcx.tcx().types.err - } - }; - - let expr_type = fcx.expr_ty(&*iterator_expr); - let method = method::lookup_in_trait(fcx, - iterator_expr.span, - Some(&*iterator_expr), - token::intern("next"), - trait_did, - expr_type, - None); - - // Regardless of whether the lookup succeeds, check the method arguments - // so that we have *some* type for each argument. - let method_type = match method { - Some(ref method) => method.ty, - None => { - let true_expr_type = fcx.infcx().resolve_type_vars_if_possible(&expr_type); - - if !ty::type_is_error(true_expr_type) { - let ty_string = fcx.infcx().ty_to_string(true_expr_type); - span_err!(fcx.tcx().sess, iterator_expr.span, E0234, - "`for` loop expression has type `{}` which does \ - not implement the `Iterator` trait; \ - maybe try .iter()", ty_string); - } - fcx.tcx().types.err - } - }; - let return_type = check_method_argument_types(fcx, - iterator_expr.span, - method_type, - iterator_expr, - &[], - AutorefArgs::No, - DontTupleArguments, - NoExpectation); - - match method { - Some(method) => { - fcx.inh.method_map.borrow_mut().insert(MethodCall::expr(loop_id), - method); - - // We expect the return type to be `Option` or something like it. - // Grab the first parameter of its type substitution. - let return_type = match return_type { - ty::FnConverging(return_type) => - structurally_resolved_type(fcx, iterator_expr.span, return_type), - ty::FnDiverging => fcx.tcx().types.err - }; - match return_type.sty { - ty::ty_enum(_, ref substs) - if !substs.types.is_empty_in(subst::TypeSpace) => { - *substs.types.get(subst::TypeSpace, 0) - } - ty::ty_err => { - fcx.tcx().types.err - } - _ => { - span_err!(fcx.tcx().sess, iterator_expr.span, E0239, - "`next` method of the `Iterator` \ - trait has an unexpected type `{}`", - fcx.infcx().ty_to_string(return_type)); - fcx.tcx().types.err - } - } - } - None => fcx.tcx().types.err - } -} - fn check_method_argument_types<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, sp: Span, method_fn_ty: Ty<'tcx>, @@ -3758,22 +3671,8 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>, ast::ExprWhileLet(..) => { tcx.sess.span_bug(expr.span, "non-desugared ExprWhileLet"); } - ast::ExprForLoop(ref pat, ref head, ref block, _) => { - check_expr(fcx, &**head); - let typ = lookup_method_for_for_loop(fcx, &**head, expr.id); - vtable::select_new_fcx_obligations(fcx); - - debug!("ExprForLoop each item has type {}", - fcx.infcx().resolve_type_vars_if_possible(&typ).repr(fcx.tcx())); - - let pcx = pat_ctxt { - fcx: fcx, - map: pat_id_map(&tcx.def_map, &**pat), - }; - _match::check_pat(&pcx, &**pat, typ); - - check_block_no_value(fcx, &**block); - fcx.write_nil(id); + ast::ExprForLoop(..) => { + tcx.sess.span_bug(expr.span, "non-desugared ExprForLoop"); } ast::ExprLoop(ref body, _) => { check_block_no_value(fcx, &**body); diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index d1fee578218..f8c7055a003 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -658,30 +658,6 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) { rcx.set_repeating_scope(repeating_scope); } - ast::ExprForLoop(ref pat, ref head, ref body, _) => { - constrain_bindings_in_pat(&**pat, rcx); - - { - let mc = mc::MemCategorizationContext::new(rcx.fcx); - let pat_ty = rcx.resolve_node_type(pat.id); - let pat_cmt = mc.cat_rvalue(pat.id, - pat.span, - ty::ReScope(CodeExtent::from_node_id(body.id)), - pat_ty); - link_pattern(rcx, mc, pat_cmt, &**pat); - } - - rcx.visit_expr(&**head); - type_of_node_must_outlive(rcx, - infer::AddrOf(expr.span), - head.id, - ty::ReScope(CodeExtent::from_node_id(expr.id))); - - let repeating_scope = rcx.set_repeating_scope(body.id); - rcx.visit_block(&**body); - rcx.set_repeating_scope(repeating_scope); - } - _ => { visit::walk_expr(rcx, expr); } diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 31c9f996126..68f5ec9c8c2 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -65,7 +65,6 @@ This API is completely unstable and subject to change. #![crate_name = "rustc_typeck"] #![unstable(feature = "rustc_private")] -#![feature(staged_api)] #![staged_api] #![crate_type = "dylib"] #![crate_type = "rlib"] @@ -73,16 +72,18 @@ This API is completely unstable and subject to change. html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_root_url = "http://doc.rust-lang.org/nightly/")] -#![allow(unknown_features)] -#![feature(quote)] -#![feature(slicing_syntax, unsafe_destructor)] -#![feature(box_syntax)] -#![feature(rustc_diagnostic_macros)] -#![allow(unknown_features)] #![feature(int_uint)] #![allow(non_camel_case_types)] +#![cfg_attr(not(stage0), allow(unused_mut))] // NOTE: remove after stage0 snap + +#![feature(box_syntax)] #![feature(collections)] #![feature(core)] +#![feature(int_uint)] +#![feature(quote)] +#![feature(rustc_diagnostic_macros)] #![feature(rustc_private)] +#![feature(slicing_syntax, unsafe_destructor)] +#![feature(staged_api)] #![feature(std_misc)] #[macro_use] extern crate log; diff --git a/src/librustc_typeck/variance.rs b/src/librustc_typeck/variance.rs index dd42c667956..6c5950e4df5 100644 --- a/src/librustc_typeck/variance.rs +++ b/src/librustc_typeck/variance.rs @@ -793,7 +793,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { trait_def.generics.types.as_slice(), trait_def.generics.regions.as_slice(), trait_ref.substs, - variance); + self.invariant); } ty::ty_trait(ref data) => { diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 9cb29cb14b8..fe502922ffd 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -2249,7 +2249,7 @@ impl Clean<ViewListIdent> for ast::PathListItem { source: resolve_def(cx, id) }, ast::PathListMod { id } => ViewListIdent { - name: "mod".to_string(), + name: "self".to_string(), source: resolve_def(cx, id) } } diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index 1c916ad817c..7e08226019f 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -420,7 +420,7 @@ impl LangString { let mut seen_other_tags = false; let mut data = LangString::all_false(); - let mut tokens = string.split(|&: c: char| + let tokens = string.split(|&: c: char| !(c == '_' || c == '-' || c.is_alphanumeric()) ); diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index b8ebbf8ff36..8a007fb035e 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1942,7 +1942,7 @@ fn item_enum(w: &mut fmt::Formatter, it: &clean::Item, clean::VariantItem(ref var) => { match var.kind { clean::StructVariant(ref s) => { - let mut fields = s.fields.iter().filter(|f| { + let fields = s.fields.iter().filter(|f| { match f.inner { clean::StructFieldItem(ref t) => match *t { clean::HiddenStructField => false, diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index f8ba2dc2a74..29e52d627cd 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -10,7 +10,6 @@ #![crate_name = "rustdoc"] #![unstable(feature = "rustdoc")] -#![feature(staged_api)] #![staged_api] #![crate_type = "dylib"] #![crate_type = "rlib"] @@ -18,20 +17,22 @@ html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_root_url = "http://doc.rust-lang.org/nightly/", html_playground_url = "http://play.rust-lang.org/")] -#![feature(slicing_syntax)] + #![feature(box_syntax)] -#![allow(unknown_features)] #![feature(int_uint)] #![feature(collections)] #![feature(core)] +#![feature(hash)] +#![feature(int_uint)] #![feature(io)] #![feature(libc)] #![feature(os)] #![feature(path)] #![feature(rustc_private)] +#![feature(slicing_syntax)] +#![feature(staged_api)] #![feature(std_misc)] #![feature(test)] #![feature(unicode)] -#![feature(hash)] extern crate arena; extern crate getopts; diff --git a/src/libserialize/hex.rs b/src/libserialize/hex.rs index d3c2ffa9544..c9b6af26ce0 100644 --- a/src/libserialize/hex.rs +++ b/src/libserialize/hex.rs @@ -116,7 +116,7 @@ impl FromHex for str { fn from_hex(&self) -> Result<Vec<u8>, FromHexError> { // This may be an overestimate if there is any whitespace let mut b = Vec::with_capacity(self.len() / 2); - let mut modulus = 0i; + let mut modulus = 0; let mut buf = 0u8; for (idx, byte) in self.bytes().enumerate() { diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index 2e7a6fd4923..8d8bd32ba77 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -2127,7 +2127,7 @@ macro_rules! read_primitive { Json::F64(f) => Err(ExpectedError("Integer".to_string(), format!("{}", f))), // re: #12967.. a type w/ numeric keys (ie HashMap<uint, V> etc) // is going to have a string here, as per JSON spec. - Json::String(s) => match s.parse() { + Json::String(s) => match s.parse().ok() { Some(f) => Ok(f), None => Err(ExpectedError("Number".to_string(), s)), }, @@ -2165,7 +2165,7 @@ impl ::Decoder for Decoder { Json::String(s) => { // re: #12967.. a type w/ numeric keys (ie HashMap<uint, V> etc) // is going to have a string here, as per JSON spec. - match s.parse() { + match s.parse().ok() { Some(f) => Ok(f), None => Err(ExpectedError("Number".to_string(), s)), } @@ -2597,8 +2597,9 @@ impl<'a, T: Encodable> fmt::Display for AsPrettyJson<'a, T> { } impl FromStr for Json { - fn from_str(s: &str) -> Option<Json> { - from_str(s).ok() + type Err = BuilderError; + fn from_str(s: &str) -> Result<Json, BuilderError> { + from_str(s) } } @@ -3937,7 +3938,7 @@ mod tests { hash_map.insert("a".to_string(), 1u); hash_map.insert("b".to_string(), 2); assert_eq!(hash_map.to_json(), object); - assert_eq!(Some(15i).to_json(), I64(15)); + assert_eq!(Some(15).to_json(), I64(15)); assert_eq!(Some(15u).to_json(), U64(15)); assert_eq!(None::<int>.to_json(), Null); } @@ -3951,8 +3952,8 @@ mod tests { struct ArbitraryType(uint); let mut hm: HashMap<ArbitraryType, bool> = HashMap::new(); hm.insert(ArbitraryType(1), true); - let mut mem_buf = Vec::new(); - let mut encoder = Encoder::new(&mut mem_buf as &mut fmt::Writer); + let mut mem_buf = string::String::new(); + let mut encoder = Encoder::new(&mut mem_buf); let result = hm.encode(&mut encoder); match result.err().unwrap() { EncoderError::BadHashmapKey => (), @@ -3997,7 +3998,7 @@ mod tests { fn big_json() -> string::String { let mut src = "[\n".to_string(); - for _ in 0i..500 { + for _ in 0..500 { src.push_str(r#"{ "a": true, "b": null, "c":3.1415, "d": "Hello world", "e": \ [1,2,3]},"#); } diff --git a/src/libserialize/lib.rs b/src/libserialize/lib.rs index d51bb3af627..e86ee4a73ce 100644 --- a/src/libserialize/lib.rs +++ b/src/libserialize/lib.rs @@ -17,7 +17,6 @@ Core encoding and decoding interfaces. #![crate_name = "serialize"] #![unstable(feature = "rustc_private", reason = "deprecated in favor of rustc-serialize on crates.io")] -#![feature(staged_api)] #![staged_api] #![crate_type = "rlib"] #![crate_type = "dylib"] @@ -25,16 +24,16 @@ Core encoding and decoding interfaces. html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_root_url = "http://doc.rust-lang.org/nightly/", html_playground_url = "http://play.rust-lang.org/")] -#![allow(unknown_features)] + #![feature(box_syntax)] -#![feature(old_impl_check)] -#![feature(slicing_syntax)] -#![allow(unknown_features)] #![feature(int_uint)] #![feature(collections)] #![feature(core)] +#![feature(int_uint)] #![feature(io)] #![feature(path)] #![feature(rustc_private)] +#![feature(slicing_syntax)] +#![feature(staged_api)] #![feature(std_misc)] #![feature(unicode)] #![cfg_attr(test, feature(test))] diff --git a/src/libstd/collections/hash/bench.rs b/src/libstd/collections/hash/bench.rs index 28689767cb0..ce02648b8f2 100644 --- a/src/libstd/collections/hash/bench.rs +++ b/src/libstd/collections/hash/bench.rs @@ -32,7 +32,7 @@ fn new_insert_drop(b : &mut Bencher) { b.iter(|| { let mut m = HashMap::new(); - m.insert(0i, 0i); + m.insert(0, 0); assert_eq!(m.len(), 1); }) } @@ -43,7 +43,7 @@ fn grow_by_insertion(b: &mut Bencher) { let mut m = HashMap::new(); - for i in range_inclusive(1i, 1000) { + for i in range_inclusive(1, 1000) { m.insert(i, i); } @@ -61,12 +61,12 @@ fn find_existing(b: &mut Bencher) { let mut m = HashMap::new(); - for i in range_inclusive(1i, 1000) { + for i in range_inclusive(1, 1000) { m.insert(i, i); } b.iter(|| { - for i in range_inclusive(1i, 1000) { + for i in range_inclusive(1, 1000) { m.contains_key(&i); } }); @@ -78,12 +78,12 @@ fn find_nonexisting(b: &mut Bencher) { let mut m = HashMap::new(); - for i in range_inclusive(1i, 1000) { + for i in range_inclusive(1, 1000) { m.insert(i, i); } b.iter(|| { - for i in range_inclusive(1001i, 2000) { + for i in range_inclusive(1001, 2000) { m.contains_key(&i); } }); @@ -95,11 +95,11 @@ fn hashmap_as_queue(b: &mut Bencher) { let mut m = HashMap::new(); - for i in range_inclusive(1i, 1000) { + for i in range_inclusive(1, 1000) { m.insert(i, i); } - let mut k = 1i; + let mut k = 1; b.iter(|| { m.remove(&k); @@ -114,11 +114,11 @@ fn get_remove_insert(b: &mut Bencher) { let mut m = HashMap::new(); - for i in range_inclusive(1i, 1000) { + for i in range_inclusive(1, 1000) { m.insert(i, i); } - let mut k = 1i; + let mut k = 1; b.iter(|| { m.get(&(k + 400)); diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index a291ec16a62..3e2c7627dbe 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -536,7 +536,7 @@ impl<K, V, S, H> HashMap<K, V, S> /// /// let s = RandomState::new(); /// let mut map = HashMap::with_hash_state(s); - /// map.insert(1i, 2u); + /// map.insert(1, 2u); /// ``` #[inline] #[unstable(feature = "std_misc", reason = "hasher stuff is unclear")] @@ -564,7 +564,7 @@ impl<K, V, S, H> HashMap<K, V, S> /// /// let s = RandomState::new(); /// let mut map = HashMap::with_capacity_and_hash_state(10, s); - /// map.insert(1i, 2u); + /// map.insert(1, 2u); /// ``` #[inline] #[unstable(feature = "std_misc", reason = "hasher stuff is unclear")] @@ -809,7 +809,7 @@ impl<K, V, S, H> HashMap<K, V, S> /// use std::collections::HashMap; /// /// let mut map = HashMap::new(); - /// map.insert("a", 1i); + /// map.insert("a", 1); /// map.insert("b", 2); /// map.insert("c", 3); /// @@ -834,7 +834,7 @@ impl<K, V, S, H> HashMap<K, V, S> /// use std::collections::HashMap; /// /// let mut map = HashMap::new(); - /// map.insert("a", 1i); + /// map.insert("a", 1); /// map.insert("b", 2); /// map.insert("c", 3); /// @@ -859,7 +859,7 @@ impl<K, V, S, H> HashMap<K, V, S> /// use std::collections::HashMap; /// /// let mut map = HashMap::new(); - /// map.insert("a", 1i); + /// map.insert("a", 1); /// map.insert("b", 2); /// map.insert("c", 3); /// @@ -882,7 +882,7 @@ impl<K, V, S, H> HashMap<K, V, S> /// use std::collections::HashMap; /// /// let mut map = HashMap::new(); - /// map.insert("a", 1i); + /// map.insert("a", 1); /// map.insert("b", 2); /// map.insert("c", 3); /// @@ -910,7 +910,7 @@ impl<K, V, S, H> HashMap<K, V, S> /// use std::collections::HashMap; /// /// let mut map = HashMap::new(); - /// map.insert("a", 1i); + /// map.insert("a", 1); /// map.insert("b", 2); /// map.insert("c", 3); /// @@ -1622,7 +1622,7 @@ mod test_map { fn test_create_capacity_zero() { let mut m = HashMap::with_capacity(0); - assert!(m.insert(1i, 1i).is_none()); + assert!(m.insert(1, 1).is_none()); assert!(m.contains_key(&1)); assert!(!m.contains_key(&0)); @@ -1632,9 +1632,9 @@ mod test_map { fn test_insert() { let mut m = HashMap::new(); assert_eq!(m.len(), 0); - assert!(m.insert(1i, 2i).is_none()); + assert!(m.insert(1, 2).is_none()); assert_eq!(m.len(), 1); - assert!(m.insert(2i, 4i).is_none()); + assert!(m.insert(2, 4).is_none()); assert_eq!(m.len(), 2); assert_eq!(*m.get(&1).unwrap(), 2); assert_eq!(*m.get(&2).unwrap(), 4); @@ -1674,7 +1674,7 @@ mod test_map { #[test] fn test_drops() { DROP_VECTOR.with(|slot| { - *slot.borrow_mut() = repeat(0i).take(200).collect(); + *slot.borrow_mut() = repeat(0).take(200).collect(); }); { @@ -1772,7 +1772,7 @@ mod test_map { } }); - for _ in half {} + for _ in half.by_ref() {} DROP_VECTOR.with(|v| { let nk = (0u..100).filter(|&i| { @@ -1807,10 +1807,10 @@ mod test_map { // Try this a few times to make sure we never screw up the hashmap's // internal state. - for _ in 0i..10 { + for _ in 0..10 { assert!(m.is_empty()); - for i in range_inclusive(1i, 1000) { + for i in range_inclusive(1, 1000) { assert!(m.insert(i, i).is_none()); for j in range_inclusive(1, i) { @@ -1824,12 +1824,12 @@ mod test_map { } } - for i in range_inclusive(1001i, 2000) { + for i in range_inclusive(1001, 2000) { assert!(!m.contains_key(&i)); } // remove forwards - for i in range_inclusive(1i, 1000) { + for i in range_inclusive(1, 1000) { assert!(m.remove(&i).is_some()); for j in range_inclusive(1, i) { @@ -1841,16 +1841,16 @@ mod test_map { } } - for i in range_inclusive(1i, 1000) { + for i in range_inclusive(1, 1000) { assert!(!m.contains_key(&i)); } - for i in range_inclusive(1i, 1000) { + for i in range_inclusive(1, 1000) { assert!(m.insert(i, i).is_none()); } // remove backwards - for i in range_step_inclusive(1000i, 1, -1) { + for i in range_step_inclusive(1000, 1, -1) { assert!(m.remove(&i).is_some()); for j in range_inclusive(i, 1000) { @@ -1867,9 +1867,9 @@ mod test_map { #[test] fn test_find_mut() { let mut m = HashMap::new(); - assert!(m.insert(1i, 12i).is_none()); - assert!(m.insert(2i, 8i).is_none()); - assert!(m.insert(5i, 14i).is_none()); + assert!(m.insert(1, 12).is_none()); + assert!(m.insert(2, 8).is_none()); + assert!(m.insert(5, 14).is_none()); let new = 100; match m.get_mut(&5) { None => panic!(), Some(x) => *x = new @@ -1880,18 +1880,18 @@ mod test_map { #[test] fn test_insert_overwrite() { let mut m = HashMap::new(); - assert!(m.insert(1i, 2i).is_none()); + assert!(m.insert(1, 2).is_none()); assert_eq!(*m.get(&1).unwrap(), 2); - assert!(!m.insert(1i, 3i).is_none()); + assert!(!m.insert(1, 3).is_none()); assert_eq!(*m.get(&1).unwrap(), 3); } #[test] fn test_insert_conflicts() { let mut m = HashMap::with_capacity(4); - assert!(m.insert(1i, 2i).is_none()); - assert!(m.insert(5i, 3i).is_none()); - assert!(m.insert(9i, 4i).is_none()); + assert!(m.insert(1, 2).is_none()); + assert!(m.insert(5, 3).is_none()); + assert!(m.insert(9, 4).is_none()); assert_eq!(*m.get(&9).unwrap(), 4); assert_eq!(*m.get(&5).unwrap(), 3); assert_eq!(*m.get(&1).unwrap(), 2); @@ -1900,7 +1900,7 @@ mod test_map { #[test] fn test_conflict_remove() { let mut m = HashMap::with_capacity(4); - assert!(m.insert(1i, 2i).is_none()); + assert!(m.insert(1, 2).is_none()); assert_eq!(*m.get(&1).unwrap(), 2); assert!(m.insert(5, 3).is_none()); assert_eq!(*m.get(&1).unwrap(), 2); @@ -1917,7 +1917,7 @@ mod test_map { #[test] fn test_is_empty() { let mut m = HashMap::with_capacity(4); - assert!(m.insert(1i, 2i).is_none()); + assert!(m.insert(1, 2).is_none()); assert!(!m.is_empty()); assert!(m.remove(&1).is_some()); assert!(m.is_empty()); @@ -1926,7 +1926,7 @@ mod test_map { #[test] fn test_pop() { let mut m = HashMap::new(); - m.insert(1i, 2i); + m.insert(1, 2); assert_eq!(m.remove(&1), Some(2)); assert_eq!(m.remove(&1), None); } @@ -1950,7 +1950,7 @@ mod test_map { #[test] fn test_keys() { - let vec = vec![(1i, 'a'), (2i, 'b'), (3i, 'c')]; + let vec = vec![(1, 'a'), (2, 'b'), (3, 'c')]; let map = vec.into_iter().collect::<HashMap<int, char>>(); let keys = map.keys().map(|&k| k).collect::<Vec<int>>(); assert_eq!(keys.len(), 3); @@ -1961,7 +1961,7 @@ mod test_map { #[test] fn test_values() { - let vec = vec![(1i, 'a'), (2i, 'b'), (3i, 'c')]; + let vec = vec![(1, 'a'), (2, 'b'), (3, 'c')]; let map = vec.into_iter().collect::<HashMap<int, char>>(); let values = map.values().map(|&v| v).collect::<Vec<char>>(); assert_eq!(values.len(), 3); @@ -1973,8 +1973,8 @@ mod test_map { #[test] fn test_find() { let mut m = HashMap::new(); - assert!(m.get(&1i).is_none()); - m.insert(1i, 2i); + assert!(m.get(&1).is_none()); + m.insert(1, 2); match m.get(&1) { None => panic!(), Some(v) => assert_eq!(*v, 2) @@ -1984,17 +1984,17 @@ mod test_map { #[test] fn test_eq() { let mut m1 = HashMap::new(); - m1.insert(1i, 2i); - m1.insert(2i, 3i); - m1.insert(3i, 4i); + m1.insert(1, 2); + m1.insert(2, 3); + m1.insert(3, 4); let mut m2 = HashMap::new(); - m2.insert(1i, 2i); - m2.insert(2i, 3i); + m2.insert(1, 2); + m2.insert(2, 3); assert!(m1 != m2); - m2.insert(3i, 4i); + m2.insert(3, 4); assert_eq!(m1, m2); } @@ -2004,8 +2004,8 @@ mod test_map { let mut map: HashMap<int, int> = HashMap::new(); let empty: HashMap<int, int> = HashMap::new(); - map.insert(1i, 2i); - map.insert(3i, 4i); + map.insert(1, 2); + map.insert(3, 4); let map_str = format!("{:?}", map); @@ -2127,7 +2127,7 @@ mod test_map { #[test] fn test_from_iter() { - let xs = [(1i, 1i), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)]; + let xs = [(1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)]; let map: HashMap<int, int> = xs.iter().map(|&x| x).collect(); @@ -2138,7 +2138,7 @@ mod test_map { #[test] fn test_size_hint() { - let xs = [(1i, 1i), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)]; + let xs = [(1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)]; let map: HashMap<int, int> = xs.iter().map(|&x| x).collect(); @@ -2151,7 +2151,7 @@ mod test_map { #[test] fn test_iter_len() { - let xs = [(1i, 1i), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)]; + let xs = [(1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)]; let map: HashMap<int, int> = xs.iter().map(|&x| x).collect(); @@ -2164,7 +2164,7 @@ mod test_map { #[test] fn test_mut_size_hint() { - let xs = [(1i, 1i), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)]; + let xs = [(1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)]; let mut map: HashMap<int, int> = xs.iter().map(|&x| x).collect(); @@ -2177,7 +2177,7 @@ mod test_map { #[test] fn test_iter_mut_len() { - let xs = [(1i, 1i), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)]; + let xs = [(1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)]; let mut map: HashMap<int, int> = xs.iter().map(|&x| x).collect(); @@ -2213,7 +2213,7 @@ mod test_map { #[test] fn test_entry(){ - let xs = [(1i, 10i), (2, 20), (3, 30), (4, 40), (5, 50), (6, 60)]; + let xs = [(1, 10), (2, 20), (3, 30), (4, 40), (5, 50), (6, 60)]; let mut map: HashMap<int, int> = xs.iter().map(|&x| x).collect(); diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index 2b15e50c6fa..3095c2c0e41 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -168,7 +168,7 @@ impl<T, S, H> HashSet<T, S> /// /// let s = RandomState::new(); /// let mut set = HashSet::with_capacity_and_hash_state(10u, s); - /// set.insert(1i); + /// set.insert(1); /// ``` #[inline] #[unstable(feature = "std_misc", reason = "hasher stuff is unclear")] @@ -290,8 +290,8 @@ impl<T, S, H> HashSet<T, S> /// /// ``` /// use std::collections::HashSet; - /// let a: HashSet<int> = [1i, 2, 3].iter().map(|&x| x).collect(); - /// let b: HashSet<int> = [4i, 2, 3, 4].iter().map(|&x| x).collect(); + /// let a: HashSet<int> = [1, 2, 3].iter().map(|&x| x).collect(); + /// let b: HashSet<int> = [4, 2, 3, 4].iter().map(|&x| x).collect(); /// /// // Can be seen as `a - b`. /// for x in a.difference(&b) { @@ -299,12 +299,12 @@ impl<T, S, H> HashSet<T, S> /// } /// /// let diff: HashSet<int> = a.difference(&b).map(|&x| x).collect(); - /// assert_eq!(diff, [1i].iter().map(|&x| x).collect()); + /// assert_eq!(diff, [1].iter().map(|&x| x).collect()); /// /// // Note that difference is not symmetric, /// // and `b - a` means something else: /// let diff: HashSet<int> = b.difference(&a).map(|&x| x).collect(); - /// assert_eq!(diff, [4i].iter().map(|&x| x).collect()); + /// assert_eq!(diff, [4].iter().map(|&x| x).collect()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn difference<'a>(&'a self, other: &'a HashSet<T, S>) -> Difference<'a, T, S> { @@ -320,8 +320,8 @@ impl<T, S, H> HashSet<T, S> /// /// ``` /// use std::collections::HashSet; - /// let a: HashSet<int> = [1i, 2, 3].iter().map(|&x| x).collect(); - /// let b: HashSet<int> = [4i, 2, 3, 4].iter().map(|&x| x).collect(); + /// let a: HashSet<int> = [1, 2, 3].iter().map(|&x| x).collect(); + /// let b: HashSet<int> = [4, 2, 3, 4].iter().map(|&x| x).collect(); /// /// // Print 1, 4 in arbitrary order. /// for x in a.symmetric_difference(&b) { @@ -332,7 +332,7 @@ impl<T, S, H> HashSet<T, S> /// let diff2: HashSet<int> = b.symmetric_difference(&a).map(|&x| x).collect(); /// /// assert_eq!(diff1, diff2); - /// assert_eq!(diff1, [1i, 4].iter().map(|&x| x).collect()); + /// assert_eq!(diff1, [1, 4].iter().map(|&x| x).collect()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn symmetric_difference<'a>(&'a self, other: &'a HashSet<T, S>) @@ -346,8 +346,8 @@ impl<T, S, H> HashSet<T, S> /// /// ``` /// use std::collections::HashSet; - /// let a: HashSet<int> = [1i, 2, 3].iter().map(|&x| x).collect(); - /// let b: HashSet<int> = [4i, 2, 3, 4].iter().map(|&x| x).collect(); + /// let a: HashSet<int> = [1, 2, 3].iter().map(|&x| x).collect(); + /// let b: HashSet<int> = [4, 2, 3, 4].iter().map(|&x| x).collect(); /// /// // Print 2, 3 in arbitrary order. /// for x in a.intersection(&b) { @@ -355,7 +355,7 @@ impl<T, S, H> HashSet<T, S> /// } /// /// let diff: HashSet<int> = a.intersection(&b).map(|&x| x).collect(); - /// assert_eq!(diff, [2i, 3].iter().map(|&x| x).collect()); + /// assert_eq!(diff, [2, 3].iter().map(|&x| x).collect()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn intersection<'a>(&'a self, other: &'a HashSet<T, S>) -> Intersection<'a, T, S> { @@ -371,8 +371,8 @@ impl<T, S, H> HashSet<T, S> /// /// ``` /// use std::collections::HashSet; - /// let a: HashSet<int> = [1i, 2, 3].iter().map(|&x| x).collect(); - /// let b: HashSet<int> = [4i, 2, 3, 4].iter().map(|&x| x).collect(); + /// let a: HashSet<int> = [1, 2, 3].iter().map(|&x| x).collect(); + /// let b: HashSet<int> = [4, 2, 3, 4].iter().map(|&x| x).collect(); /// /// // Print 1, 2, 3, 4 in arbitrary order. /// for x in a.union(&b) { @@ -380,7 +380,7 @@ impl<T, S, H> HashSet<T, S> /// } /// /// let diff: HashSet<int> = a.union(&b).map(|&x| x).collect(); - /// assert_eq!(diff, [1i, 2, 3, 4].iter().map(|&x| x).collect()); + /// assert_eq!(diff, [1, 2, 3, 4].iter().map(|&x| x).collect()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn union<'a>(&'a self, other: &'a HashSet<T, S>) -> Union<'a, T, S> { @@ -955,8 +955,8 @@ mod test_set { let mut ys = HashSet::new(); assert!(xs.is_disjoint(&ys)); assert!(ys.is_disjoint(&xs)); - assert!(xs.insert(5i)); - assert!(ys.insert(11i)); + assert!(xs.insert(5)); + assert!(ys.insert(11)); assert!(xs.is_disjoint(&ys)); assert!(ys.is_disjoint(&xs)); assert!(xs.insert(7)); @@ -974,13 +974,13 @@ mod test_set { #[test] fn test_subset_and_superset() { let mut a = HashSet::new(); - assert!(a.insert(0i)); + assert!(a.insert(0)); assert!(a.insert(5)); assert!(a.insert(11)); assert!(a.insert(7)); let mut b = HashSet::new(); - assert!(b.insert(0i)); + assert!(b.insert(0)); assert!(b.insert(7)); assert!(b.insert(19)); assert!(b.insert(250)); @@ -1018,7 +1018,7 @@ mod test_set { let mut a = HashSet::new(); let mut b = HashSet::new(); - assert!(a.insert(11i)); + assert!(a.insert(11)); assert!(a.insert(1)); assert!(a.insert(3)); assert!(a.insert(77)); @@ -1026,7 +1026,7 @@ mod test_set { assert!(a.insert(5)); assert!(a.insert(-5)); - assert!(b.insert(2i)); + assert!(b.insert(2)); assert!(b.insert(11)); assert!(b.insert(77)); assert!(b.insert(-9)); @@ -1048,13 +1048,13 @@ mod test_set { let mut a = HashSet::new(); let mut b = HashSet::new(); - assert!(a.insert(1i)); + assert!(a.insert(1)); assert!(a.insert(3)); assert!(a.insert(5)); assert!(a.insert(9)); assert!(a.insert(11)); - assert!(b.insert(3i)); + assert!(b.insert(3)); assert!(b.insert(9)); let mut i = 0; @@ -1071,13 +1071,13 @@ mod test_set { let mut a = HashSet::new(); let mut b = HashSet::new(); - assert!(a.insert(1i)); + assert!(a.insert(1)); assert!(a.insert(3)); assert!(a.insert(5)); assert!(a.insert(9)); assert!(a.insert(11)); - assert!(b.insert(-2i)); + assert!(b.insert(-2)); assert!(b.insert(3)); assert!(b.insert(9)); assert!(b.insert(14)); @@ -1097,7 +1097,7 @@ mod test_set { let mut a = HashSet::new(); let mut b = HashSet::new(); - assert!(a.insert(1i)); + assert!(a.insert(1)); assert!(a.insert(3)); assert!(a.insert(5)); assert!(a.insert(9)); @@ -1106,7 +1106,7 @@ mod test_set { assert!(a.insert(19)); assert!(a.insert(24)); - assert!(b.insert(-2i)); + assert!(b.insert(-2)); assert!(b.insert(1)); assert!(b.insert(5)); assert!(b.insert(9)); @@ -1124,7 +1124,7 @@ mod test_set { #[test] fn test_from_iter() { - let xs = [1i, 2, 3, 4, 5, 6, 7, 8, 9]; + let xs = [1, 2, 3, 4, 5, 6, 7, 8, 9]; let set: HashSet<int> = xs.iter().map(|&x| x).collect(); @@ -1154,13 +1154,13 @@ mod test_set { // I'm keeping them around to prevent a regression. let mut s1 = HashSet::new(); - s1.insert(1i); + s1.insert(1); s1.insert(2); s1.insert(3); let mut s2 = HashSet::new(); - s2.insert(1i); + s2.insert(1); s2.insert(2); assert!(s1 != s2); @@ -1175,7 +1175,7 @@ mod test_set { let mut set: HashSet<int> = HashSet::new(); let empty: HashSet<int> = HashSet::new(); - set.insert(1i); + set.insert(1); set.insert(2); let set_str = format!("{:?}", set); @@ -1201,7 +1201,7 @@ mod test_set { let mut s: HashSet<int> = (1is..100).collect(); // try this a bunch of times to make sure we don't screw up internal state. - for _ in 0i..20 { + for _ in 0..20 { assert_eq!(s.len(), 99); { diff --git a/src/libstd/collections/hash/table.rs b/src/libstd/collections/hash/table.rs index 9e6a45d8bf0..8016a343d67 100644 --- a/src/libstd/collections/hash/table.rs +++ b/src/libstd/collections/hash/table.rs @@ -15,7 +15,7 @@ use self::BucketState::*; use clone::Clone; use cmp; use hash::{Hash, Hasher}; -use iter::{Iterator, ExactSizeIterator, count}; +use iter::{Iterator, IteratorExt, ExactSizeIterator, count}; use marker::{Copy, Sized, self}; use mem::{min_align_of, size_of}; use mem; @@ -274,7 +274,7 @@ impl<K, V, M: Deref<Target=RawTable<K, V>>> Bucket<K, V, M> { // ... and it's zero at all other times. let maybe_wraparound_dist = (self.idx ^ (self.idx + 1)) & self.table.capacity(); // Finally, we obtain the offset 1 or the offset -cap + 1. - let dist = 1i - (maybe_wraparound_dist as int); + let dist = 1 - (maybe_wraparound_dist as int); self.idx += 1; @@ -921,7 +921,7 @@ impl<'a, K, V> ExactSizeIterator for Drain<'a, K, V> { #[unsafe_destructor] impl<'a, K: 'a, V: 'a> Drop for Drain<'a, K, V> { fn drop(&mut self) { - for _ in *self {} + for _ in self.by_ref() {} } } diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index fdd7aa216d3..2e55c007b55 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -122,7 +122,7 @@ impl Deref for CString { #[stable(feature = "rust1", since = "1.0.0")] impl fmt::Debug for CString { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - String::from_utf8_lossy(self.as_bytes()).fmt(f) + fmt::Debug::fmt(&String::from_utf8_lossy(self.as_bytes()), f) } } diff --git a/src/libstd/fmt.rs b/src/libstd/fmt.rs index 4ab43e875cd..8e86aa65196 100644 --- a/src/libstd/fmt.rs +++ b/src/libstd/fmt.rs @@ -29,10 +29,10 @@ //! ``` //! format!("Hello"); // => "Hello" //! format!("Hello, {}!", "world"); // => "Hello, world!" -//! format!("The number is {}", 1i); // => "The number is 1" -//! format!("{:?}", (3i, 4i)); // => "(3i, 4i)" -//! format!("{value}", value=4i); // => "4" -//! format!("{} {}", 1i, 2u); // => "1 2" +//! format!("The number is {}", 1); // => "The number is 1" +//! format!("{:?}", (3, 4)); // => "(3, 4)" +//! format!("{value}", value=4); // => "4" +//! format!("{} {}", 1, 2u); // => "1 2" //! ``` //! //! From these, you can see that the first argument is a format string. It is @@ -55,7 +55,7 @@ //! the iterator advances. This leads to behavior like this: //! //! ```rust -//! format!("{1} {} {0} {}", 1i, 2i); // => "2 1 1 2" +//! format!("{1} {} {0} {}", 1, 2); // => "2 1 1 2" //! ``` //! //! The internal iterator over the argument has not been advanced by the time @@ -83,8 +83,8 @@ //! //! ``` //! format!("{argument}", argument = "test"); // => "test" -//! format!("{name} {}", 1i, name = 2i); // => "2 1" -//! format!("{a} {c} {b}", a="a", b='b', c=3i); // => "a 3 b" +//! format!("{name} {}", 1, name = 2); // => "2 1" +//! format!("{a} {c} {b}", a="a", b='b', c=3); // => "a 3 b" //! ``` //! //! It is illegal to put positional parameters (those without names) after @@ -206,7 +206,7 @@ //! let myvector = Vector2D { x: 3, y: 4 }; //! //! println!("{}", myvector); // => "(3, 4)" -//! println!("{:?}", myvector); // => "Vector2D {x: 3i, y:4i}" +//! println!("{:?}", myvector); // => "Vector2D {x: 3, y:4}" //! println!("{:10.3b}", myvector); // => " 5.000" //! } //! ``` @@ -411,9 +411,10 @@ pub use core::fmt::{Display, Debug}; pub use core::fmt::{LowerHex, UpperHex, Pointer}; pub use core::fmt::{LowerExp, UpperExp}; pub use core::fmt::Error; -pub use core::fmt::{Argument, Arguments, write, radix, Radix, RadixFmt}; +pub use core::fmt::{ArgumentV1, Arguments, write, radix, Radix, RadixFmt}; #[doc(hidden)] +#[cfg(stage0)] pub use core::fmt::{argument, argumentuint}; /// The format function takes a precompiled format string and a list of @@ -431,9 +432,7 @@ pub use core::fmt::{argument, argumentuint}; /// let s = fmt::format(format_args!("Hello, {}!", "world")); /// assert_eq!(s, "Hello, world!".to_string()); /// ``` -#[unstable(feature = "std_misc", - reason = "this is an implementation detail of format! and should not \ - be called directly")] +#[stable(feature = "rust1", since = "1.0.0")] pub fn format(args: Arguments) -> string::String { let mut output = string::String::new(); let _ = write!(&mut output, "{}", args); diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index a016ba8fb0c..96aebb735ef 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -97,7 +97,6 @@ #![crate_name = "std"] #![stable(feature = "rust1", since = "1.0.0")] -#![feature(staged_api)] #![staged_api] #![crate_type = "rlib"] #![crate_type = "dylib"] @@ -106,28 +105,29 @@ html_root_url = "http://doc.rust-lang.org/nightly/", html_playground_url = "http://play.rust-lang.org/")] -#![allow(unknown_features)] -#![feature(linkage, thread_local, asm)] -#![feature(lang_items, unsafe_destructor)] -#![feature(slicing_syntax, unboxed_closures)] +#![feature(alloc)] #![feature(box_syntax)] -#![feature(old_impl_check)] -#![feature(optin_builtin_traits)] -#![feature(int_uint)] -#![feature(int_uint)] +#![feature(collections)] #![feature(core)] +#![feature(hash)] +#![feature(int_uint)] +#![feature(lang_items, unsafe_destructor)] #![feature(libc)] -#![feature(alloc)] -#![feature(unicode)] -#![feature(collections)] +#![feature(linkage, thread_local, asm)] +#![feature(old_impl_check)] +#![feature(optin_builtin_traits)] #![feature(rand)] -#![feature(hash)] +#![feature(staged_api)] +#![feature(unboxed_closures)] +#![feature(unicode)] +#![cfg_attr(not(stage0), feature(macro_reexport))] #![cfg_attr(test, feature(test))] // Don't link to std. We are std. #![no_std] #![deny(missing_docs)] +#![cfg_attr(not(stage0), allow(unused_mut))] // NOTE: remove after stage0 snap #[cfg(test)] #[macro_use] @@ -310,4 +310,6 @@ mod std { pub use slice; pub use boxed; // used for vec![] + // for-loops + pub use iter; } diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index 9c3285a9d08..e91e8241a55 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -32,7 +32,7 @@ /// # #![allow(unreachable_code)] /// panic!(); /// panic!("this is a terrible mistake!"); -/// panic!(4i); // panic with the value of 4 to be collected elsewhere +/// panic!(4); // panic with the value of 4 to be collected elsewhere /// panic!("this is a {} {message}", "fancy", message = "message"); /// ``` #[macro_export] @@ -68,7 +68,7 @@ macro_rules! panic { /// ``` /// format!("test"); /// format!("hello {}", "world!"); -/// format!("x = {}, y = {y}", 10i, y = 30i); +/// format!("x = {}, y = {y}", 10, y = 30); /// ``` #[macro_export] #[stable(feature = "rust1", since = "1.0.0")] @@ -282,7 +282,7 @@ pub mod builtin { /// # Example /// /// ``` - /// let s = concat!("test", 10i, 'b', true); + /// let s = concat!("test", 10, 'b', true); /// assert_eq!(s, "test10btrue"); /// ``` #[macro_export] diff --git a/src/libstd/num/mod.rs b/src/libstd/num/mod.rs index d010a5de622..a996ad1f5b3 100644 --- a/src/libstd/num/mod.rs +++ b/src/libstd/num/mod.rs @@ -356,11 +356,11 @@ pub fn test_num<T>(ten: T, two: T) where + Rem<Output=T> + Debug + Copy { - assert_eq!(ten.add(two), cast(12i).unwrap()); - assert_eq!(ten.sub(two), cast(8i).unwrap()); - assert_eq!(ten.mul(two), cast(20i).unwrap()); - assert_eq!(ten.div(two), cast(5i).unwrap()); - assert_eq!(ten.rem(two), cast(0i).unwrap()); + assert_eq!(ten.add(two), cast(12).unwrap()); + assert_eq!(ten.sub(two), cast(8).unwrap()); + assert_eq!(ten.mul(two), cast(20).unwrap()); + assert_eq!(ten.div(two), cast(5).unwrap()); + assert_eq!(ten.rem(two), cast(0).unwrap()); assert_eq!(ten.add(two), ten + two); assert_eq!(ten.sub(two), ten - two); @@ -393,7 +393,7 @@ mod tests { assert_eq!(20u16, _20.to_u16().unwrap()); assert_eq!(20u32, _20.to_u32().unwrap()); assert_eq!(20u64, _20.to_u64().unwrap()); - assert_eq!(20i, _20.to_int().unwrap()); + assert_eq!(20, _20.to_int().unwrap()); assert_eq!(20i8, _20.to_i8().unwrap()); assert_eq!(20i16, _20.to_i16().unwrap()); assert_eq!(20i32, _20.to_i32().unwrap()); @@ -406,7 +406,7 @@ mod tests { assert_eq!(_20, NumCast::from(20u16).unwrap()); assert_eq!(_20, NumCast::from(20u32).unwrap()); assert_eq!(_20, NumCast::from(20u64).unwrap()); - assert_eq!(_20, NumCast::from(20i).unwrap()); + assert_eq!(_20, NumCast::from(20).unwrap()); assert_eq!(_20, NumCast::from(20i8).unwrap()); assert_eq!(_20, NumCast::from(20i16).unwrap()); assert_eq!(_20, NumCast::from(20i32).unwrap()); @@ -419,7 +419,7 @@ mod tests { assert_eq!(_20, cast(20u16).unwrap()); assert_eq!(_20, cast(20u32).unwrap()); assert_eq!(_20, cast(20u64).unwrap()); - assert_eq!(_20, cast(20i).unwrap()); + assert_eq!(_20, cast(20).unwrap()); assert_eq!(_20, cast(20i8).unwrap()); assert_eq!(_20, cast(20i16).unwrap()); assert_eq!(_20, cast(20i32).unwrap()); @@ -438,7 +438,7 @@ mod tests { #[test] fn test_i16_cast() { test_cast_20!(20i16) } #[test] fn test_i32_cast() { test_cast_20!(20i32) } #[test] fn test_i64_cast() { test_cast_20!(20i64) } - #[test] fn test_int_cast() { test_cast_20!(20i) } + #[test] fn test_int_cast() { test_cast_20!(20) } #[test] fn test_f32_cast() { test_cast_20!(20f32) } #[test] fn test_f64_cast() { test_cast_20!(20f64) } @@ -831,23 +831,23 @@ mod tests { #[test] fn test_saturating_add_int() { use int::{MIN,MAX}; - assert_eq!(3i.saturating_add(5i), 8i); - assert_eq!(3i.saturating_add(MAX-1), MAX); + assert_eq!(3.saturating_add(5), 8); + assert_eq!(3.saturating_add(MAX-1), MAX); assert_eq!(MAX.saturating_add(MAX), MAX); assert_eq!((MAX-2).saturating_add(1), MAX-1); - assert_eq!(3i.saturating_add(-5i), -2i); - assert_eq!(MIN.saturating_add(-1i), MIN); - assert_eq!((-2i).saturating_add(-MAX), MIN); + assert_eq!(3.saturating_add(-5), -2); + assert_eq!(MIN.saturating_add(-1), MIN); + assert_eq!((-2).saturating_add(-MAX), MIN); } #[test] fn test_saturating_sub_int() { use int::{MIN,MAX}; - assert_eq!(3i.saturating_sub(5i), -2i); - assert_eq!(MIN.saturating_sub(1i), MIN); - assert_eq!((-2i).saturating_sub(MAX), MIN); - assert_eq!(3i.saturating_sub(-5i), 8i); - assert_eq!(3i.saturating_sub(-(MAX-1)), MAX); + assert_eq!(3.saturating_sub(5), -2); + assert_eq!(MIN.saturating_sub(1), MIN); + assert_eq!((-2).saturating_sub(MAX), MIN); + assert_eq!(3.saturating_sub(-5), 8); + assert_eq!(3.saturating_sub(-(MAX-1)), MAX); assert_eq!(MAX.saturating_sub(-MAX), MAX); assert_eq!((MAX-2).saturating_sub(-1), MAX-1); } @@ -1010,10 +1010,10 @@ mod tests { assert_eq!(result, naive_pow($num, $exp)); }} } - assert_pow!((3i, 0 ) => 1); - assert_pow!((5i, 1 ) => 5); - assert_pow!((-4i, 2 ) => 16); - assert_pow!((8i, 3 ) => 512); + assert_pow!((3, 0 ) => 1); + assert_pow!((5, 1 ) => 5); + assert_pow!((-4, 2 ) => 16); + assert_pow!((8, 3 ) => 512); assert_pow!((2u64, 50) => 1125899906842624); } } diff --git a/src/libstd/num/uint_macros.rs b/src/libstd/num/uint_macros.rs index 82c55d7b5b8..4cd6391318f 100644 --- a/src/libstd/num/uint_macros.rs +++ b/src/libstd/num/uint_macros.rs @@ -20,7 +20,7 @@ mod tests { use num::FromStrRadix; fn from_str<T: ::str::FromStr>(t: &str) -> Option<T> { - ::str::FromStr::from_str(t) + ::str::FromStr::from_str(t).ok() } #[test] @@ -38,15 +38,15 @@ mod tests { #[test] pub fn test_parse_bytes() { - assert_eq!(FromStrRadix::from_str_radix("123", 10), Some(123u as $T)); - assert_eq!(FromStrRadix::from_str_radix("1001", 2), Some(9u as $T)); - assert_eq!(FromStrRadix::from_str_radix("123", 8), Some(83u as $T)); - assert_eq!(FromStrRadix::from_str_radix("123", 16), Some(291u as u16)); - assert_eq!(FromStrRadix::from_str_radix("ffff", 16), Some(65535u as u16)); - assert_eq!(FromStrRadix::from_str_radix("z", 36), Some(35u as $T)); - - assert_eq!(FromStrRadix::from_str_radix("Z", 10), None::<$T>); - assert_eq!(FromStrRadix::from_str_radix("_", 2), None::<$T>); + assert_eq!(FromStrRadix::from_str_radix("123", 10), Ok(123u as $T)); + assert_eq!(FromStrRadix::from_str_radix("1001", 2), Ok(9u as $T)); + assert_eq!(FromStrRadix::from_str_radix("123", 8), Ok(83u as $T)); + assert_eq!(FromStrRadix::from_str_radix("123", 16), Ok(291u as u16)); + assert_eq!(FromStrRadix::from_str_radix("ffff", 16), Ok(65535u as u16)); + assert_eq!(FromStrRadix::from_str_radix("z", 36), Ok(35u as $T)); + + assert_eq!(FromStrRadix::from_str_radix("Z", 10).ok(), None::<$T>); + assert_eq!(FromStrRadix::from_str_radix("_", 2).ok(), None::<$T>); } #[test] diff --git a/src/libstd/old_io/buffered.rs b/src/libstd/old_io/buffered.rs index 1590598c0b8..586cc1477f8 100644 --- a/src/libstd/old_io/buffered.rs +++ b/src/libstd/old_io/buffered.rs @@ -111,7 +111,7 @@ impl<R: Reader> Buffer for BufferedReader<R> { impl<R: Reader> Reader for BufferedReader<R> { fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> { - if self.pos == self.cap && buf.len() >= self.buf.capacity() { + if self.pos == self.cap && buf.len() >= self.buf.len() { return self.inner.read(buf); } let nread = { diff --git a/src/libstd/old_io/fs.rs b/src/libstd/old_io/fs.rs index 99c7e399b1c..1337675544d 100644 --- a/src/libstd/old_io/fs.rs +++ b/src/libstd/old_io/fs.rs @@ -981,7 +981,7 @@ mod test { let initial_msg = "food-is-yummy"; let overwrite_msg = "-the-bar!!"; let final_msg = "foo-the-bar!!"; - let seek_idx = 3i; + let seek_idx = 3; let mut read_mem = [0; 13]; let tmpdir = tmpdir(); let filename = &tmpdir.join("file_rt_io_file_test_seek_and_write.txt"); @@ -1101,10 +1101,10 @@ mod test { let dir = &tmpdir.join("di_readdir"); check!(mkdir(dir, old_io::USER_RWX)); let prefix = "foo"; - for n in 0i..3 { + for n in 0is..3 { let f = dir.join(format!("{}.txt", n)); let mut w = check!(File::create(&f)); - let msg_str = format!("{}{}", prefix, n.to_string()); + let msg_str = format!("{}{}", prefix, n); let msg = msg_str.as_bytes(); check!(w.write(msg)); } diff --git a/src/libstd/old_io/net/ip.rs b/src/libstd/old_io/net/ip.rs index f0b73bd37f2..565f9d83818 100644 --- a/src/libstd/old_io/net/ip.rs +++ b/src/libstd/old_io/net/ip.rs @@ -25,7 +25,7 @@ use iter::{Iterator, IteratorExt}; use ops::{FnOnce, FnMut}; use option::Option; use option::Option::{None, Some}; -use result::Result::{Ok, Err}; +use result::Result::{self, Ok, Err}; use slice::SliceExt; use str::{FromStr, StrExt}; use vec::Vec; @@ -350,17 +350,28 @@ impl<'a> Parser<'a> { } impl FromStr for IpAddr { - fn from_str(s: &str) -> Option<IpAddr> { - Parser::new(s).read_till_eof(|p| p.read_ip_addr()) + type Err = ParseError; + fn from_str(s: &str) -> Result<IpAddr, ParseError> { + match Parser::new(s).read_till_eof(|p| p.read_ip_addr()) { + Some(s) => Ok(s), + None => Err(ParseError), + } } } impl FromStr for SocketAddr { - fn from_str(s: &str) -> Option<SocketAddr> { - Parser::new(s).read_till_eof(|p| p.read_socket_addr()) + type Err = ParseError; + fn from_str(s: &str) -> Result<SocketAddr, ParseError> { + match Parser::new(s).read_till_eof(|p| p.read_socket_addr()) { + Some(s) => Ok(s), + None => Err(ParseError), + } } } +#[derive(Debug, Clone, PartialEq, Copy)] +pub struct ParseError; + /// A trait for objects which can be converted or resolved to one or more `SocketAddr` values. /// /// Implementing types minimally have to implement either `to_socket_addr` or `to_socket_addr_all` @@ -493,7 +504,7 @@ fn parse_and_resolve_socket_addr(s: &str) -> IoResult<Vec<SocketAddr>> { let mut parts_iter = s.rsplitn(2, ':'); let port_str = try_opt!(parts_iter.next(), "invalid socket address"); let host = try_opt!(parts_iter.next(), "invalid socket address"); - let port: u16 = try_opt!(FromStr::from_str(port_str), "invalid port value"); + let port: u16 = try_opt!(port_str.parse().ok(), "invalid port value"); resolve_socket_addr(host, port) } @@ -502,7 +513,7 @@ impl<'a> ToSocketAddr for (&'a str, u16) { let (host, port) = *self; // try to parse the host as a regular IpAddr first - match FromStr::from_str(host) { + match host.parse().ok() { Some(addr) => return Ok(vec![SocketAddr { ip: addr, port: port @@ -518,7 +529,7 @@ impl<'a> ToSocketAddr for (&'a str, u16) { impl<'a> ToSocketAddr for &'a str { fn to_socket_addr(&self) -> IoResult<SocketAddr> { // try to parse as a regular SocketAddr first - match FromStr::from_str(*self) { + match self.parse().ok() { Some(addr) => return Ok(addr), None => {} } @@ -535,7 +546,7 @@ impl<'a> ToSocketAddr for &'a str { fn to_socket_addr_all(&self) -> IoResult<Vec<SocketAddr>> { // try to parse as a regular SocketAddr first - match FromStr::from_str(*self) { + match self.parse().ok() { Some(addr) => return Ok(vec![addr]), None => {} } @@ -553,95 +564,94 @@ mod test { #[test] fn test_from_str_ipv4() { - assert_eq!(Some(Ipv4Addr(127, 0, 0, 1)), FromStr::from_str("127.0.0.1")); - assert_eq!(Some(Ipv4Addr(255, 255, 255, 255)), FromStr::from_str("255.255.255.255")); - assert_eq!(Some(Ipv4Addr(0, 0, 0, 0)), FromStr::from_str("0.0.0.0")); + assert_eq!(Ok(Ipv4Addr(127, 0, 0, 1)), "127.0.0.1".parse()); + assert_eq!(Ok(Ipv4Addr(255, 255, 255, 255)), "255.255.255.255".parse()); + assert_eq!(Ok(Ipv4Addr(0, 0, 0, 0)), "0.0.0.0".parse()); // out of range - let none: Option<IpAddr> = FromStr::from_str("256.0.0.1"); + let none: Option<IpAddr> = "256.0.0.1".parse().ok(); assert_eq!(None, none); // too short - let none: Option<IpAddr> = FromStr::from_str("255.0.0"); + let none: Option<IpAddr> = "255.0.0".parse().ok(); assert_eq!(None, none); // too long - let none: Option<IpAddr> = FromStr::from_str("255.0.0.1.2"); + let none: Option<IpAddr> = "255.0.0.1.2".parse().ok(); assert_eq!(None, none); // no number between dots - let none: Option<IpAddr> = FromStr::from_str("255.0..1"); + let none: Option<IpAddr> = "255.0..1".parse().ok(); assert_eq!(None, none); } #[test] fn test_from_str_ipv6() { - assert_eq!(Some(Ipv6Addr(0, 0, 0, 0, 0, 0, 0, 0)), FromStr::from_str("0:0:0:0:0:0:0:0")); - assert_eq!(Some(Ipv6Addr(0, 0, 0, 0, 0, 0, 0, 1)), FromStr::from_str("0:0:0:0:0:0:0:1")); + assert_eq!(Ok(Ipv6Addr(0, 0, 0, 0, 0, 0, 0, 0)), "0:0:0:0:0:0:0:0".parse()); + assert_eq!(Ok(Ipv6Addr(0, 0, 0, 0, 0, 0, 0, 1)), "0:0:0:0:0:0:0:1".parse()); - assert_eq!(Some(Ipv6Addr(0, 0, 0, 0, 0, 0, 0, 1)), FromStr::from_str("::1")); - assert_eq!(Some(Ipv6Addr(0, 0, 0, 0, 0, 0, 0, 0)), FromStr::from_str("::")); + assert_eq!(Ok(Ipv6Addr(0, 0, 0, 0, 0, 0, 0, 1)), "::1".parse()); + assert_eq!(Ok(Ipv6Addr(0, 0, 0, 0, 0, 0, 0, 0)), "::".parse()); - assert_eq!(Some(Ipv6Addr(0x2a02, 0x6b8, 0, 0, 0, 0, 0x11, 0x11)), - FromStr::from_str("2a02:6b8::11:11")); + assert_eq!(Ok(Ipv6Addr(0x2a02, 0x6b8, 0, 0, 0, 0, 0x11, 0x11)), + "2a02:6b8::11:11".parse()); // too long group - let none: Option<IpAddr> = FromStr::from_str("::00000"); + let none: Option<IpAddr> = "::00000".parse().ok(); assert_eq!(None, none); // too short - let none: Option<IpAddr> = FromStr::from_str("1:2:3:4:5:6:7"); + let none: Option<IpAddr> = "1:2:3:4:5:6:7".parse().ok(); assert_eq!(None, none); // too long - let none: Option<IpAddr> = FromStr::from_str("1:2:3:4:5:6:7:8:9"); + let none: Option<IpAddr> = "1:2:3:4:5:6:7:8:9".parse().ok(); assert_eq!(None, none); // triple colon - let none: Option<IpAddr> = FromStr::from_str("1:2:::6:7:8"); + let none: Option<IpAddr> = "1:2:::6:7:8".parse().ok(); assert_eq!(None, none); // two double colons - let none: Option<IpAddr> = FromStr::from_str("1:2::6::8"); + let none: Option<IpAddr> = "1:2::6::8".parse().ok(); assert_eq!(None, none); } #[test] fn test_from_str_ipv4_in_ipv6() { - assert_eq!(Some(Ipv6Addr(0, 0, 0, 0, 0, 0, 49152, 545)), - FromStr::from_str("::192.0.2.33")); - assert_eq!(Some(Ipv6Addr(0, 0, 0, 0, 0, 0xFFFF, 49152, 545)), - FromStr::from_str("::FFFF:192.0.2.33")); - assert_eq!(Some(Ipv6Addr(0x64, 0xff9b, 0, 0, 0, 0, 49152, 545)), - FromStr::from_str("64:ff9b::192.0.2.33")); - assert_eq!(Some(Ipv6Addr(0x2001, 0xdb8, 0x122, 0xc000, 0x2, 0x2100, 49152, 545)), - FromStr::from_str("2001:db8:122:c000:2:2100:192.0.2.33")); + assert_eq!(Ok(Ipv6Addr(0, 0, 0, 0, 0, 0, 49152, 545)), + "::192.0.2.33".parse()); + assert_eq!(Ok(Ipv6Addr(0, 0, 0, 0, 0, 0xFFFF, 49152, 545)), + "::FFFF:192.0.2.33".parse()); + assert_eq!(Ok(Ipv6Addr(0x64, 0xff9b, 0, 0, 0, 0, 49152, 545)), + "64:ff9b::192.0.2.33".parse()); + assert_eq!(Ok(Ipv6Addr(0x2001, 0xdb8, 0x122, 0xc000, 0x2, 0x2100, 49152, 545)), + "2001:db8:122:c000:2:2100:192.0.2.33".parse()); // colon after v4 - let none: Option<IpAddr> = FromStr::from_str("::127.0.0.1:"); + let none: Option<IpAddr> = "::127.0.0.1:".parse().ok(); assert_eq!(None, none); // not enough groups - let none: Option<IpAddr> = FromStr::from_str("1.2.3.4.5:127.0.0.1"); + let none: Option<IpAddr> = "1.2.3.4.5:127.0.0.1".parse().ok(); assert_eq!(None, none); // too many groups - let none: Option<IpAddr> = - FromStr::from_str("1.2.3.4.5:6:7:127.0.0.1"); + let none: Option<IpAddr> = "1.2.3.4.5:6:7:127.0.0.1".parse().ok(); assert_eq!(None, none); } #[test] fn test_from_str_socket_addr() { - assert_eq!(Some(SocketAddr { ip: Ipv4Addr(77, 88, 21, 11), port: 80 }), - FromStr::from_str("77.88.21.11:80")); - assert_eq!(Some(SocketAddr { ip: Ipv6Addr(0x2a02, 0x6b8, 0, 1, 0, 0, 0, 1), port: 53 }), - FromStr::from_str("[2a02:6b8:0:1::1]:53")); - assert_eq!(Some(SocketAddr { ip: Ipv6Addr(0, 0, 0, 0, 0, 0, 0x7F00, 1), port: 22 }), - FromStr::from_str("[::127.0.0.1]:22")); + assert_eq!(Ok(SocketAddr { ip: Ipv4Addr(77, 88, 21, 11), port: 80 }), + "77.88.21.11:80".parse()); + assert_eq!(Ok(SocketAddr { ip: Ipv6Addr(0x2a02, 0x6b8, 0, 1, 0, 0, 0, 1), port: 53 }), + "[2a02:6b8:0:1::1]:53".parse()); + assert_eq!(Ok(SocketAddr { ip: Ipv6Addr(0, 0, 0, 0, 0, 0, 0x7F00, 1), port: 22 }), + "[::127.0.0.1]:22".parse()); // without port - let none: Option<SocketAddr> = FromStr::from_str("127.0.0.1"); + let none: Option<SocketAddr> = "127.0.0.1".parse().ok(); assert_eq!(None, none); // without port - let none: Option<SocketAddr> = FromStr::from_str("127.0.0.1:"); + let none: Option<SocketAddr> = "127.0.0.1:".parse().ok(); assert_eq!(None, none); // wrong brackets around v4 - let none: Option<SocketAddr> = FromStr::from_str("[127.0.0.1]:22"); + let none: Option<SocketAddr> = "[127.0.0.1]:22".parse().ok(); assert_eq!(None, none); // port out of range - let none: Option<SocketAddr> = FromStr::from_str("127.0.0.1:123456"); + let none: Option<SocketAddr> = "127.0.0.1:123456".parse().ok(); assert_eq!(None, none); } diff --git a/src/libstd/old_io/net/tcp.rs b/src/libstd/old_io/net/tcp.rs index e0feaa4e558..122ac4c3445 100644 --- a/src/libstd/old_io/net/tcp.rs +++ b/src/libstd/old_io/net/tcp.rs @@ -1160,7 +1160,7 @@ mod test { tx.send(TcpStream::connect(addr).unwrap()).unwrap(); }); let _l = rx.recv().unwrap(); - for i in 0i..1001 { + for i in 0is..1001 { match a.accept() { Ok(..) => break, Err(ref e) if e.kind == TimedOut => {} @@ -1260,7 +1260,7 @@ mod test { assert_eq!(s.read(&mut [0]).err().unwrap().kind, TimedOut); s.set_timeout(Some(20)); - for i in 0i..1001 { + for i in 0is..1001 { match s.write(&[0; 128 * 1024]) { Ok(()) | Err(IoError { kind: ShortWrite(..), .. }) => {}, Err(IoError { kind: TimedOut, .. }) => break, @@ -1299,7 +1299,7 @@ mod test { assert_eq!(s.read(&mut [0]).err().unwrap().kind, TimedOut); tx.send(()).unwrap(); - for _ in 0i..100 { + for _ in 0..100 { assert!(s.write(&[0;128 * 1024]).is_ok()); } } @@ -1318,7 +1318,7 @@ mod test { let mut s = a.accept().unwrap(); s.set_write_timeout(Some(20)); - for i in 0i..1001 { + for i in 0is..1001 { match s.write(&[0; 128 * 1024]) { Ok(()) | Err(IoError { kind: ShortWrite(..), .. }) => {}, Err(IoError { kind: TimedOut, .. }) => break, @@ -1388,7 +1388,7 @@ mod test { }); // Try to ensure that the reading clone is indeed reading - for _ in 0i..50 { + for _ in 0..50 { ::thread::Thread::yield_now(); } diff --git a/src/libstd/old_io/process.rs b/src/libstd/old_io/process.rs index d3e60de2780..f253f9799e9 100644 --- a/src/libstd/old_io/process.rs +++ b/src/libstd/old_io/process.rs @@ -393,14 +393,15 @@ impl Command { } } +#[stable(feature = "rust1", since = "1.0.0")] impl fmt::Debug for Command { /// Format the program and arguments of a Command for display. Any /// non-utf8 data is lossily converted using the utf8 replacement /// character. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - try!(write!(f, "{}", String::from_utf8_lossy(self.program.as_bytes()))); + try!(write!(f, "{:?}", self.program)); for arg in self.args.iter() { - try!(write!(f, " '{}'", String::from_utf8_lossy(arg.as_bytes()))); + try!(write!(f, " '{:?}'", arg)); } Ok(()) } @@ -1142,7 +1143,7 @@ mod tests { fn test_zero() { let mut p = sleeper(); p.signal_kill().unwrap(); - for _ in 0i..20 { + for _ in 0..20 { if p.signal(0).is_err() { assert!(!p.wait().unwrap().success()); return diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 38c0a7b8f9b..600ca60349a 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -1484,7 +1484,7 @@ mod tests { #[ignore] fn test_getenv_big() { let mut s = "".to_string(); - let mut i = 0i; + let mut i = 0; while i < 100 { s.push_str("aaaaaaaaaa"); i += 1; diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index 588f724134e..6a0c8a93010 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -19,6 +19,7 @@ use iter::{AdditiveIterator, Extend}; use iter::{Iterator, IteratorExt, Map}; use marker::Sized; use option::Option::{self, Some, None}; +use result::Result::{self, Ok, Err}; use slice::{AsSlice, Split, SliceExt, SliceConcatExt}; use str::{self, FromStr, StrExt}; use vec::Vec; @@ -86,11 +87,19 @@ impl Ord for Path { } impl FromStr for Path { - fn from_str(s: &str) -> Option<Path> { - Path::new_opt(s) + type Err = ParsePathError; + fn from_str(s: &str) -> Result<Path, ParsePathError> { + match Path::new_opt(s) { + Some(p) => Ok(p), + None => Err(ParsePathError), + } } } +/// Valuelue indicating that a path could not be parsed from a string. +#[derive(Debug, Clone, PartialEq, Copy)] +pub struct ParsePathError; + impl<S: hash::Writer + hash::Hasher> hash::Hash<S> for Path { #[inline] fn hash(&self, state: &mut S) { diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index 88db27013ac..b524b89ef9f 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -27,6 +27,7 @@ use mem; use option::Option::{self, Some, None}; #[cfg(stage0)] use ops::FullRange; +use result::Result::{self, Ok, Err}; use slice::{SliceExt, SliceConcatExt}; use str::{SplitTerminator, FromStr, StrExt}; use string::{String, ToString}; @@ -115,11 +116,19 @@ impl Ord for Path { } impl FromStr for Path { - fn from_str(s: &str) -> Option<Path> { - Path::new_opt(s) + type Err = ParsePathError; + fn from_str(s: &str) -> Result<Path, ParsePathError> { + match Path::new_opt(s) { + Some(p) => Ok(p), + None => Err(ParsePathError), + } } } +/// Value indicating that a path could not be parsed from a string. +#[derive(Debug, Clone, PartialEq, Copy)] +pub struct ParsePathError; + impl<S: hash::Writer + hash::Hasher> hash::Hash<S> for Path { #[cfg(not(test))] #[inline] @@ -557,7 +566,7 @@ impl GenericPath for Path { } (Some(a), Some(_)) => { comps.push(".."); - for _ in itb { + for _ in itb.by_ref() { comps.push(".."); } comps.push(a); diff --git a/src/libstd/rand/mod.rs b/src/libstd/rand/mod.rs index 2969eec4737..211abc2fc83 100644 --- a/src/libstd/rand/mod.rs +++ b/src/libstd/rand/mod.rs @@ -427,7 +427,7 @@ pub fn random<T: Rand>() -> T { /// use std::rand::{thread_rng, sample}; /// /// let mut rng = thread_rng(); -/// let sample = sample(&mut rng, 1i..100, 5); +/// let sample = sample(&mut rng, 1..100, 5); /// println!("{:?}", sample); /// ``` pub fn sample<T, I: Iterator<Item=T>, R: Rng>(rng: &mut R, @@ -481,16 +481,16 @@ mod test { fn test_gen_range() { let mut r = thread_rng(); for _ in 0u..1000 { - let a = r.gen_range(-3i, 42); + let a = r.gen_range(-3, 42); assert!(a >= -3 && a < 42); - assert_eq!(r.gen_range(0i, 1), 0); - assert_eq!(r.gen_range(-12i, -11), -12); + assert_eq!(r.gen_range(0, 1), 0); + assert_eq!(r.gen_range(-12, -11), -12); } for _ in 0u..1000 { - let a = r.gen_range(10i, 42); + let a = r.gen_range(10, 42); assert!(a >= 10 && a < 42); - assert_eq!(r.gen_range(0i, 1), 0); + assert_eq!(r.gen_range(0, 1), 0); assert_eq!(r.gen_range(3_000_000, 3_000_001), 3_000_000); } @@ -500,7 +500,7 @@ mod test { #[should_fail] fn test_gen_range_panic_int() { let mut r = thread_rng(); - r.gen_range(5i, -2); + r.gen_range(5, -2); } #[test] @@ -544,7 +544,7 @@ mod test { #[test] fn test_choose() { let mut r = thread_rng(); - assert_eq!(r.choose(&[1i, 1, 1]).map(|&x|x), Some(1)); + assert_eq!(r.choose(&[1, 1, 1]).map(|&x|x), Some(1)); let v: &[int] = &[]; assert_eq!(r.choose(v), None); @@ -555,16 +555,16 @@ mod test { let mut r = thread_rng(); let empty: &mut [int] = &mut []; r.shuffle(empty); - let mut one = [1i]; + let mut one = [1]; r.shuffle(&mut one); let b: &[_] = &[1]; assert_eq!(one, b); - let mut two = [1i, 2]; + let mut two = [1, 2]; r.shuffle(&mut two); assert!(two == [1, 2] || two == [2, 1]); - let mut x = [1i, 1, 1]; + let mut x = [1, 1, 1]; r.shuffle(&mut x); let b: &[_] = &[1, 1, 1]; assert_eq!(x, b); @@ -574,7 +574,7 @@ mod test { fn test_thread_rng() { let mut r = thread_rng(); r.gen::<int>(); - let mut v = [1i, 1, 1]; + let mut v = [1, 1, 1]; r.shuffle(&mut v); let b: &[_] = &[1, 1, 1]; assert_eq!(v, b); @@ -597,8 +597,8 @@ mod test { #[test] fn test_sample() { - let min_val = 1i; - let max_val = 100i; + let min_val = 1; + let max_val = 100; let mut r = thread_rng(); let vals = (min_val..max_val).collect::<Vec<int>>(); diff --git a/src/libstd/rt/unwind.rs b/src/libstd/rt/unwind.rs index 757aecaaaff..fb40a6c8f60 100644 --- a/src/libstd/rt/unwind.rs +++ b/src/libstd/rt/unwind.rs @@ -160,7 +160,7 @@ pub fn panicking() -> bool { // An uninlined, unmangled function upon which to slap yer breakpoints #[inline(never)] #[no_mangle] -#[allow(private_no_mangle_fns)] +#[cfg_attr(not(stage0), allow(private_no_mangle_fns))] fn rust_panic(cause: Box<Any + Send>) -> ! { rtdebug!("begin_unwind()"); @@ -238,7 +238,7 @@ pub mod eabi { #[lang="eh_personality"] #[no_mangle] // referenced from rust_try.ll - #[allow(private_no_mangle_fns)] + #[cfg_attr(not(stage0), allow(private_no_mangle_fns))] extern fn rust_eh_personality( version: c_int, actions: uw::_Unwind_Action, diff --git a/src/libstd/rt/util.rs b/src/libstd/rt/util.rs index 4023a0a4c10..f5727a38b69 100644 --- a/src/libstd/rt/util.rs +++ b/src/libstd/rt/util.rs @@ -51,7 +51,7 @@ pub fn min_stack() -> uint { 0 => {} n => return n - 1, } - let amt = os::getenv("RUST_MIN_STACK").and_then(|s| s.parse()); + let amt = os::getenv("RUST_MIN_STACK").and_then(|s| s.parse().ok()); let amt = amt.unwrap_or(2 * 1024 * 1024); // 0 is our sentinel value, so ensure that we'll never see 0 after // initialization has run @@ -64,7 +64,7 @@ pub fn min_stack() -> uint { pub fn default_sched_threads() -> uint { match os::getenv("RUST_THREADS") { Some(nstr) => { - let opt_n: Option<uint> = nstr.parse(); + let opt_n: Option<uint> = nstr.parse().ok(); match opt_n { Some(n) if n > 0 => n, _ => panic!("`RUST_THREADS` is `{}`, should be a positive integer", nstr) diff --git a/src/libstd/sync/future.rs b/src/libstd/sync/future.rs index a79fb684f47..8340652d19a 100644 --- a/src/libstd/sync/future.rs +++ b/src/libstd/sync/future.rs @@ -193,7 +193,7 @@ mod test { #[test] fn test_get_ref_method() { - let mut f = Future::from_value(22i); + let mut f = Future::from_value(22); assert_eq!(*f.get_ref(), 22); } diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index 6a43eccbaba..39c57a21d75 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -59,9 +59,9 @@ //! // Create a simple streaming channel //! let (tx, rx) = channel(); //! Thread::spawn(move|| { -//! tx.send(10i).unwrap(); +//! tx.send(10).unwrap(); //! }); -//! assert_eq!(rx.recv().unwrap(), 10i); +//! assert_eq!(rx.recv().unwrap(), 10); //! ``` //! //! Shared usage: @@ -74,14 +74,14 @@ //! // where tx is the sending half (tx for transmission), and rx is the receiving //! // half (rx for receiving). //! let (tx, rx) = channel(); -//! for i in 0i..10i { +//! for i in 0..10 { //! let tx = tx.clone(); //! Thread::spawn(move|| { //! tx.send(i).unwrap(); //! }); //! } //! -//! for _ in 0i..10i { +//! for _ in 0..10 { //! let j = rx.recv().unwrap(); //! assert!(0 <= j && j < 10); //! } @@ -382,8 +382,8 @@ impl<T> !Sync for SyncSender<T> {} /// A `send` operation can only fail if the receiving end of a channel is /// disconnected, implying that the data could never be received. The error /// contains the data being sent as a payload so it can be recovered. -#[derive(PartialEq, Eq)] #[stable(feature = "rust1", since = "1.0.0")] +#[derive(PartialEq, Eq, Clone, Copy)] pub struct SendError<T>(pub T); /// An error returned from the `recv` function on a `Receiver`. @@ -396,7 +396,7 @@ pub struct RecvError; /// This enumeration is the list of the possible reasons that try_recv could not /// return data when called. -#[derive(PartialEq, Clone, Copy, Debug)] +#[derive(PartialEq, Eq, Clone, Copy, Debug)] #[stable(feature = "rust1", since = "1.0.0")] pub enum TryRecvError { /// This channel is currently empty, but the sender(s) have not yet @@ -412,8 +412,8 @@ pub enum TryRecvError { /// This enumeration is the list of the possible error outcomes for the /// `SyncSender::try_send` method. -#[derive(PartialEq, Clone)] #[stable(feature = "rust1", since = "1.0.0")] +#[derive(PartialEq, Eq, Clone, Copy)] pub enum TrySendError<T> { /// The data could not be sent on the channel because it would require that /// the callee block to send the data. @@ -514,15 +514,15 @@ pub fn channel<T: Send>() -> (Sender<T>, Receiver<T>) { /// let (tx, rx) = sync_channel(1); /// /// // this returns immediately -/// tx.send(1i).unwrap(); +/// tx.send(1).unwrap(); /// /// Thread::spawn(move|| { /// // this will block until the previous message has been received -/// tx.send(2i).unwrap(); +/// tx.send(2).unwrap(); /// }); /// -/// assert_eq!(rx.recv().unwrap(), 1i); -/// assert_eq!(rx.recv().unwrap(), 2i); +/// assert_eq!(rx.recv().unwrap(), 1); +/// assert_eq!(rx.recv().unwrap(), 2); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn sync_channel<T: Send>(bound: uint) -> (SyncSender<T>, Receiver<T>) { @@ -562,11 +562,11 @@ impl<T: Send> Sender<T> { /// let (tx, rx) = channel(); /// /// // This send is always successful - /// tx.send(1i).unwrap(); + /// tx.send(1).unwrap(); /// /// // This send will fail because the receiver is gone /// drop(rx); - /// assert_eq!(tx.send(1i).err().unwrap().0, 1); + /// assert_eq!(tx.send(1).err().unwrap().0, 1); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn send(&self, t: T) -> Result<(), SendError<T>> { @@ -1045,7 +1045,7 @@ mod test { #[test] fn drop_full() { let (tx, _rx) = channel(); - tx.send(box 1i).unwrap(); + tx.send(box 1).unwrap(); } #[test] @@ -1053,7 +1053,7 @@ mod test { let (tx, _rx) = channel(); drop(tx.clone()); drop(tx.clone()); - tx.send(box 1i).unwrap(); + tx.send(box 1).unwrap(); } #[test] @@ -1147,7 +1147,7 @@ mod test { fn stress() { let (tx, rx) = channel::<int>(); let t = Thread::scoped(move|| { - for _ in 0u..10000 { tx.send(1i).unwrap(); } + for _ in 0u..10000 { tx.send(1).unwrap(); } }); for _ in 0u..10000 { assert_eq!(rx.recv().unwrap(), 1); @@ -1187,13 +1187,13 @@ mod test { let (tx2, rx2) = channel::<int>(); let t1 = Thread::scoped(move|| { tx1.send(()).unwrap(); - for _ in 0i..40 { + for _ in 0..40 { assert_eq!(rx2.recv().unwrap(), 1); } }); rx1.recv().unwrap(); let t2 = Thread::scoped(move|| { - for _ in 0i..40 { + for _ in 0..40 { tx2.send(1).unwrap(); } }); @@ -1205,7 +1205,7 @@ mod test { fn recv_from_outside_runtime() { let (tx, rx) = channel::<int>(); let t = Thread::scoped(move|| { - for _ in 0i..40 { + for _ in 0..40 { assert_eq!(rx.recv().unwrap(), 1); } }); @@ -1391,9 +1391,9 @@ mod test { for _ in 0..stress_factor() { let (tx, rx) = channel(); let _t = Thread::spawn(move|| { - tx.send(box 10i).unwrap(); + tx.send(box 10).unwrap(); }); - assert!(rx.recv().unwrap() == box 10i); + assert!(rx.recv().unwrap() == box 10); } } @@ -1429,8 +1429,8 @@ mod test { fn recv_a_lot() { // Regression test that we don't run out of stack in scheduler context let (tx, rx) = channel(); - for _ in 0i..10000 { tx.send(()).unwrap(); } - for _ in 0i..10000 { rx.recv().unwrap(); } + for _ in 0..10000 { tx.send(()).unwrap(); } + for _ in 0..10000 { rx.recv().unwrap(); } } #[test] @@ -1567,7 +1567,7 @@ mod sync_tests { #[test] fn drop_full() { let (tx, _rx) = sync_channel(1); - tx.send(box 1i).unwrap(); + tx.send(box 1).unwrap(); } #[test] @@ -1855,9 +1855,9 @@ mod sync_tests { for _ in 0..stress_factor() { let (tx, rx) = sync_channel::<Box<int>>(0); let _t = Thread::spawn(move|| { - tx.send(box 10i).unwrap(); + tx.send(box 10).unwrap(); }); - assert!(rx.recv().unwrap() == box 10i); + assert!(rx.recv().unwrap() == box 10); } } diff --git a/src/libstd/sync/mpsc/mpsc_queue.rs b/src/libstd/sync/mpsc/mpsc_queue.rs index 53eba131674..3980d2a1fef 100644 --- a/src/libstd/sync/mpsc/mpsc_queue.rs +++ b/src/libstd/sync/mpsc/mpsc_queue.rs @@ -165,8 +165,8 @@ mod tests { #[test] fn test_full() { let q = Queue::new(); - q.push(box 1i); - q.push(box 2i); + q.push(box 1); + q.push(box 2); } #[test] diff --git a/src/libstd/sync/mpsc/select.rs b/src/libstd/sync/mpsc/select.rs index f70e2dee8ee..85c7572404b 100644 --- a/src/libstd/sync/mpsc/select.rs +++ b/src/libstd/sync/mpsc/select.rs @@ -32,15 +32,15 @@ //! let (tx1, rx1) = channel(); //! let (tx2, rx2) = channel(); //! -//! tx1.send(1i).unwrap(); -//! tx2.send(2i).unwrap(); +//! tx1.send(1).unwrap(); +//! tx2.send(2).unwrap(); //! //! select! { //! val = rx1.recv() => { -//! assert_eq!(val.unwrap(), 1i); +//! assert_eq!(val.unwrap(), 1); //! }, //! val = rx2.recv() => { -//! assert_eq!(val.unwrap(), 2i); +//! assert_eq!(val.unwrap(), 2); //! } //! } //! ``` diff --git a/src/libstd/sync/mpsc/spsc_queue.rs b/src/libstd/sync/mpsc/spsc_queue.rs index 45503f0b58e..c80aa567173 100644 --- a/src/libstd/sync/mpsc/spsc_queue.rs +++ b/src/libstd/sync/mpsc/spsc_queue.rs @@ -253,9 +253,9 @@ mod test { fn smoke() { unsafe { let queue = Queue::new(0); - queue.push(1i); + queue.push(1); queue.push(2); - assert_eq!(queue.pop(), Some(1i)); + assert_eq!(queue.pop(), Some(1)); assert_eq!(queue.pop(), Some(2)); assert_eq!(queue.pop(), None); queue.push(3); @@ -270,7 +270,7 @@ mod test { fn peek() { unsafe { let queue = Queue::new(0); - queue.push(vec![1i]); + queue.push(vec![1]); // Ensure the borrowchecker works match queue.peek() { @@ -290,8 +290,8 @@ mod test { fn drop_full() { unsafe { let q = Queue::new(0); - q.push(box 1i); - q.push(box 2i); + q.push(box 1); + q.push(box 2); } } @@ -299,7 +299,7 @@ mod test { fn smoke_bound() { unsafe { let q = Queue::new(0); - q.push(1i); + q.push(1); q.push(2); assert_eq!(q.pop(), Some(1)); assert_eq!(q.pop(), Some(2)); @@ -328,7 +328,7 @@ mod test { for _ in 0u..100000 { loop { match q2.pop() { - Some(1i) => break, + Some(1) => break, Some(_) => panic!(), None => {} } @@ -336,7 +336,7 @@ mod test { } tx.send(()).unwrap(); }); - for _ in 0i..100000 { + for _ in 0..100000 { q.push(1); } rx.recv().unwrap(); diff --git a/src/libstd/sync/mutex.rs b/src/libstd/sync/mutex.rs index c31010c170d..7531d5b058d 100644 --- a/src/libstd/sync/mutex.rs +++ b/src/libstd/sync/mutex.rs @@ -428,7 +428,7 @@ mod test { #[test] fn test_arc_condvar_poison() { - let packet = Packet(Arc::new((Mutex::new(1i), Condvar::new()))); + let packet = Packet(Arc::new((Mutex::new(1), Condvar::new()))); let packet2 = Packet(packet.0.clone()); let (tx, rx) = channel(); @@ -457,7 +457,7 @@ mod test { #[test] fn test_mutex_arc_poison() { - let arc = Arc::new(Mutex::new(1i)); + let arc = Arc::new(Mutex::new(1)); let arc2 = arc.clone(); let _ = Thread::scoped(move|| { let lock = arc2.lock().unwrap(); @@ -470,7 +470,7 @@ mod test { fn test_mutex_arc_nested() { // Tests nested mutexes and access // to underlying data. - let arc = Arc::new(Mutex::new(1i)); + let arc = Arc::new(Mutex::new(1)); let arc2 = Arc::new(Mutex::new(arc)); let (tx, rx) = channel(); let _t = Thread::spawn(move|| { @@ -484,7 +484,7 @@ mod test { #[test] fn test_mutex_arc_access_in_unwind() { - let arc = Arc::new(Mutex::new(1i)); + let arc = Arc::new(Mutex::new(1)); let arc2 = arc.clone(); let _ = Thread::scoped(move|| -> () { struct Unwinder { diff --git a/src/libstd/sync/once.rs b/src/libstd/sync/once.rs index 0604003cecd..2df211f3768 100644 --- a/src/libstd/sync/once.rs +++ b/src/libstd/sync/once.rs @@ -134,7 +134,7 @@ mod test { #[test] fn smoke_once() { static O: Once = ONCE_INIT; - let mut a = 0i; + let mut a = 0; O.call_once(|| a += 1); assert_eq!(a, 1); O.call_once(|| a += 1); diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs index b5817ad64f6..95b570dd9c8 100644 --- a/src/libstd/sync/rwlock.rs +++ b/src/libstd/sync/rwlock.rs @@ -41,7 +41,7 @@ use sys_common::rwlock as sys; /// ``` /// use std::sync::RwLock; /// -/// let lock = RwLock::new(5i); +/// let lock = RwLock::new(5); /// /// // many reader locks can be held at once /// { @@ -437,7 +437,7 @@ mod tests { #[test] fn test_rw_arc_poison_wr() { - let arc = Arc::new(RwLock::new(1i)); + let arc = Arc::new(RwLock::new(1)); let arc2 = arc.clone(); let _: Result<uint, _> = Thread::scoped(move|| { let _lock = arc2.write().unwrap(); @@ -448,7 +448,7 @@ mod tests { #[test] fn test_rw_arc_poison_ww() { - let arc = Arc::new(RwLock::new(1i)); + let arc = Arc::new(RwLock::new(1)); let arc2 = arc.clone(); let _: Result<uint, _> = Thread::scoped(move|| { let _lock = arc2.write().unwrap(); @@ -459,7 +459,7 @@ mod tests { #[test] fn test_rw_arc_no_poison_rr() { - let arc = Arc::new(RwLock::new(1i)); + let arc = Arc::new(RwLock::new(1)); let arc2 = arc.clone(); let _: Result<uint, _> = Thread::scoped(move|| { let _lock = arc2.read().unwrap(); @@ -470,7 +470,7 @@ mod tests { } #[test] fn test_rw_arc_no_poison_rw() { - let arc = Arc::new(RwLock::new(1i)); + let arc = Arc::new(RwLock::new(1)); let arc2 = arc.clone(); let _: Result<uint, _> = Thread::scoped(move|| { let _lock = arc2.read().unwrap(); @@ -482,7 +482,7 @@ mod tests { #[test] fn test_rw_arc() { - let arc = Arc::new(RwLock::new(0i)); + let arc = Arc::new(RwLock::new(0)); let arc2 = arc.clone(); let (tx, rx) = channel(); @@ -520,7 +520,7 @@ mod tests { #[test] fn test_rw_arc_access_in_unwind() { - let arc = Arc::new(RwLock::new(1i)); + let arc = Arc::new(RwLock::new(1)); let arc2 = arc.clone(); let _ = Thread::scoped(move|| -> () { struct Unwinder { diff --git a/src/libstd/sys/common/backtrace.rs b/src/libstd/sys/common/backtrace.rs index c3e12586829..a71676c6bf2 100644 --- a/src/libstd/sys/common/backtrace.rs +++ b/src/libstd/sys/common/backtrace.rs @@ -54,7 +54,7 @@ pub fn demangle(writer: &mut Writer, s: &str) -> IoResult<()> { let mut chars = inner.chars(); while valid { let mut i = 0; - for c in chars { + for c in chars.by_ref() { if c.is_numeric() { i = i * 10 + c as uint - '0' as uint; } else { diff --git a/src/libstd/sys/common/thread_info.rs b/src/libstd/sys/common/thread_info.rs index 92b936e74f6..7c9758ca924 100644 --- a/src/libstd/sys/common/thread_info.rs +++ b/src/libstd/sys/common/thread_info.rs @@ -56,6 +56,10 @@ pub fn stack_guard() -> uint { pub fn set(stack_bounds: (uint, uint), stack_guard: uint, thread: Thread) { THREAD_INFO.with(|c| assert!(c.borrow().is_none())); + match thread.name() { + Some(name) => unsafe { ::sys::thread::set_name(name.as_slice()); }, + None => {} + } THREAD_INFO.with(move |c| *c.borrow_mut() = Some(ThreadInfo{ stack_bounds: stack_bounds, stack_guard: stack_guard, diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index 5d5cda03f01..dd343baa7c9 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -196,7 +196,7 @@ pub fn load_self() -> Option<Vec<u8>> { #[cfg(target_os = "dragonfly")] pub fn load_self() -> Option<Vec<u8>> { - use std::io; + use old_io; match old_io::fs::readlink(&Path::new("/proc/curproc/file")) { Ok(path) => Some(path.into_vec()), diff --git a/src/libstd/sys/unix/process.rs b/src/libstd/sys/unix/process.rs index 3fcca2f35e1..b004a47f8a3 100644 --- a/src/libstd/sys/unix/process.rs +++ b/src/libstd/sys/unix/process.rs @@ -509,7 +509,7 @@ impl Process { // which will wake up the other end at some point, so we just allow this // signal to be coalesced with the pending signals on the pipe. extern fn sigchld_handler(_signum: libc::c_int) { - let msg = 1i; + let msg = 1; match unsafe { libc::write(WRITE_FD, &msg as *const _ as *const libc::c_void, 1) } { diff --git a/src/libstd/sys/unix/stack_overflow.rs b/src/libstd/sys/unix/stack_overflow.rs index 2b5ced5085b..a526f3393f2 100644 --- a/src/libstd/sys/unix/stack_overflow.rs +++ b/src/libstd/sys/unix/stack_overflow.rs @@ -162,7 +162,7 @@ mod imp { pub static SIGSTKSZ: libc::size_t = 8192; - pub const SIG_DFL: sighandler_t = 0i as sighandler_t; + pub const SIG_DFL: sighandler_t = 0 as sighandler_t; // This definition is not as accurate as it could be, {si_addr} is // actually a giant union. Currently we're only interested in that field, @@ -214,7 +214,7 @@ mod imp { pub const SIGSTKSZ: libc::size_t = 131072; - pub const SIG_DFL: sighandler_t = 0i as sighandler_t; + pub const SIG_DFL: sighandler_t = 0 as sighandler_t; pub type sigset_t = u32; @@ -271,7 +271,7 @@ mod imp { } pub unsafe fn make_handler() -> super::Handler { - super::Handler { _data: 0i as *mut libc::c_void } + super::Handler { _data: 0 as *mut libc::c_void } } pub unsafe fn drop_handler(_handler: &mut super::Handler) { diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs index ac51b68795f..26a450b8599 100644 --- a/src/libstd/sys/unix/thread.rs +++ b/src/libstd/sys/unix/thread.rs @@ -17,6 +17,7 @@ use ptr; use libc::consts::os::posix01::{PTHREAD_CREATE_JOINABLE, PTHREAD_STACK_MIN}; use libc; use thunk::Thunk; +use ffi::CString; use sys_common::stack::RED_ZONE; use sys_common::thread::*; @@ -206,6 +207,37 @@ pub unsafe fn create(stack: uint, p: Thunk) -> rust_thread { native } +#[cfg(any(target_os = "linux", target_os = "android"))] +pub unsafe fn set_name(name: &str) { + // pthread_setname_np() since glibc 2.12 + // availability autodetected via weak linkage + let cname = CString::from_slice(name.as_bytes()); + type F = unsafe extern "C" fn(libc::pthread_t, *const libc::c_char) -> libc::c_int; + extern { + #[linkage = "extern_weak"] + static pthread_setname_np: *const (); + } + if !pthread_setname_np.is_null() { + unsafe { + mem::transmute::<*const (), F>(pthread_setname_np)(pthread_self(), cname.as_ptr()); + } + } +} + +#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))] +pub unsafe fn set_name(name: &str) { + // pthread_set_name_np() since almost forever on all BSDs + let cname = CString::from_slice(name.as_bytes()); + pthread_set_name_np(pthread_self(), cname.as_ptr()); +} + +#[cfg(any(target_os = "macos", target_os = "ios"))] +pub unsafe fn set_name(name: &str) { + // pthread_setname_np() since OS X 10.6 and iOS 3.2 + let cname = CString::from_slice(name.as_bytes()); + pthread_setname_np(cname.as_ptr()); +} + pub unsafe fn join(native: rust_thread) { assert_eq!(pthread_join(native, ptr::null_mut()), 0); } @@ -246,7 +278,7 @@ fn min_stack_size(_: *const libc::pthread_attr_t) -> libc::size_t { PTHREAD_STACK_MIN } -#[cfg(any(target_os = "linux"))] +#[cfg(any(target_os = "linux", target_os = "android"))] extern { pub fn pthread_self() -> libc::pthread_t; pub fn pthread_getattr_np(native: libc::pthread_t, @@ -258,11 +290,18 @@ extern { stacksize: *mut libc::size_t) -> libc::c_int; } -#[cfg(target_os = "macos")] +#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))] +extern { + pub fn pthread_self() -> libc::pthread_t; + fn pthread_set_name_np(tid: libc::pthread_t, name: *const libc::c_char); +} + +#[cfg(any(target_os = "macos", target_os = "ios"))] extern { pub fn pthread_self() -> libc::pthread_t; pub fn pthread_get_stackaddr_np(thread: libc::pthread_t) -> *mut libc::c_void; pub fn pthread_get_stacksize_np(thread: libc::pthread_t) -> libc::size_t; + fn pthread_setname_np(name: *const libc::c_char) -> libc::c_int; } extern { diff --git a/src/libstd/sys/windows/backtrace.rs b/src/libstd/sys/windows/backtrace.rs index a186465f234..1be1a412ffa 100644 --- a/src/libstd/sys/windows/backtrace.rs +++ b/src/libstd/sys/windows/backtrace.rs @@ -333,7 +333,7 @@ pub fn write(w: &mut Writer) -> IoResult<()> { let _c = Cleanup { handle: process, SymCleanup: SymCleanup }; // And now that we're done with all the setup, do the stack walking! - let mut i = 0i; + let mut i = 0; try!(write!(w, "stack backtrace:\n")); while StackWalk64(image, process, thread, &mut frame, &mut context, ptr::null_mut(), diff --git a/src/libstd/sys/windows/stack_overflow.rs b/src/libstd/sys/windows/stack_overflow.rs index e8b447022cb..0cb4c573ae3 100644 --- a/src/libstd/sys/windows/stack_overflow.rs +++ b/src/libstd/sys/windows/stack_overflow.rs @@ -81,7 +81,7 @@ pub unsafe fn make_handler() -> Handler { panic!("failed to reserve stack space for exception handling"); } - Handler { _data: 0i as *mut libc::c_void } + Handler { _data: 0 as *mut libc::c_void } } pub struct EXCEPTION_RECORD { diff --git a/src/libstd/sys/windows/thread.rs b/src/libstd/sys/windows/thread.rs index 30707488b30..a94adcb3bc7 100644 --- a/src/libstd/sys/windows/thread.rs +++ b/src/libstd/sys/windows/thread.rs @@ -67,6 +67,13 @@ pub unsafe fn create(stack: uint, p: Thunk) -> rust_thread { return ret; } +pub unsafe fn set_name(_name: &str) { + // Windows threads are nameless + // The names in MSVC debugger are obtained using a "magic" exception, + // which requires a use of MS C++ extensions. + // See https://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx +} + pub unsafe fn join(native: rust_thread) { use libc::consts::os::extra::INFINITE; WaitForSingleObject(native, INFINITE); diff --git a/src/libstd/sys/windows/thread_local.rs b/src/libstd/sys/windows/thread_local.rs index 655195a3c28..0f8ceed39a6 100644 --- a/src/libstd/sys/windows/thread_local.rs +++ b/src/libstd/sys/windows/thread_local.rs @@ -235,7 +235,7 @@ unsafe extern "system" fn on_tls_callback(h: LPVOID, unsafe fn run_dtors() { let mut any_run = true; - for _ in 0..5i { + for _ in 0..5 { if !any_run { break } any_run = false; let dtors = { diff --git a/src/libstd/tuple.rs b/src/libstd/tuple.rs index 2a911557765..988b13cd160 100644 --- a/src/libstd/tuple.rs +++ b/src/libstd/tuple.rs @@ -35,9 +35,9 @@ //! let x = ("colorless", "green", "ideas", "sleep", "furiously"); //! assert_eq!(x.3, "sleep"); //! -//! let v = (3i, 3i); -//! let u = (1i, -5i); -//! assert_eq!(v.0 * u.0 + v.1 * u.1, -12i); +//! let v = (3, 3); +//! let u = (1, -5); +//! assert_eq!(v.0 * u.0 + v.1 * u.1, -12); //! ``` //! //! Using traits implemented for tuples: @@ -45,8 +45,8 @@ //! ``` //! use std::default::Default; //! -//! let a = (1i, 2i); -//! let b = (3i, 4i); +//! let a = (1, 2); +//! let b = (3, 4); //! assert!(a != b); //! //! let c = b.clone(); diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 11068880b0e..d7283db25a5 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -788,6 +788,7 @@ pub enum MatchSource { Normal, IfLetDesugar { contains_else_clause: bool }, WhileLetDesugar, + ForLoopDesugar, } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index acf0fe7f6cd..5736400313e 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -225,11 +225,101 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> { fld.cx.expr(span, ast::ExprLoop(loop_block, opt_ident)) } + // Desugar ExprForLoop + // From: `[opt_ident]: for <pat> in <head> <body>` ast::ExprForLoop(pat, head, body, opt_ident) => { - let pat = fld.fold_pat(pat); + // to: + // + // match ::std::iter::IntoIterator::into_iter(<head>) { + // mut iter => { + // [opt_ident]: loop { + // match ::std::iter::Iterator::next(&mut iter) { + // ::std::option::Option::Some(<pat>) => <body>, + // ::std::option::Option::None => break + // } + // } + // } + // } + + // expand <head> let head = fld.fold_expr(head); - let (body, opt_ident) = expand_loop_block(body, opt_ident, fld); - fld.cx.expr(span, ast::ExprForLoop(pat, head, body, opt_ident)) + + // create an hygienic ident + let iter = { + let ident = fld.cx.ident_of("iter"); + let new_ident = fresh_name(&ident); + let rename = (ident, new_ident); + let mut rename_list = vec![rename]; + let mut rename_fld = IdentRenamer{ renames: &mut rename_list }; + + rename_fld.fold_ident(ident) + }; + + let pat_span = pat.span; + // `:;std::option::Option::Some(<pat>) => <body>` + let pat_arm = { + let body_expr = fld.cx.expr_block(body); + let some_pat = fld.cx.pat_some(pat_span, pat); + + fld.cx.arm(pat_span, vec![some_pat], body_expr) + }; + + // `::std::option::Option::None => break` + let break_arm = { + let break_expr = fld.cx.expr_break(span); + + fld.cx.arm(span, vec![fld.cx.pat_none(span)], break_expr) + }; + + // `match ::std::iter::Iterator::next(&mut iter) { ... }` + let match_expr = { + let next_path = { + let strs = vec![ + fld.cx.ident_of("std"), + fld.cx.ident_of("iter"), + fld.cx.ident_of("Iterator"), + fld.cx.ident_of("next"), + ]; + + fld.cx.path_global(span, strs) + }; + let ref_mut_iter = fld.cx.expr_mut_addr_of(span, fld.cx.expr_ident(span, iter)); + let next_expr = + fld.cx.expr_call(span, fld.cx.expr_path(next_path), vec![ref_mut_iter]); + let arms = vec![pat_arm, break_arm]; + + fld.cx.expr(pat_span, + ast::ExprMatch(next_expr, arms, ast::MatchSource::ForLoopDesugar)) + }; + + // `[opt_ident]: loop { ... }` + let loop_block = fld.cx.block_expr(match_expr); + let (loop_block, opt_ident) = expand_loop_block(loop_block, opt_ident, fld); + let loop_expr = fld.cx.expr(span, ast::ExprLoop(loop_block, opt_ident)); + + // `mut iter => { ... }` + let iter_arm = { + let iter_pat = + fld.cx.pat_ident_binding_mode(span, iter, ast::BindByValue(ast::MutMutable)); + fld.cx.arm(span, vec![iter_pat], loop_expr) + }; + + // `match ::std::iter::IntoIterator::into_iter(<head>) { ... }` + let into_iter_expr = { + let into_iter_path = { + let strs = vec![ + fld.cx.ident_of("std"), + fld.cx.ident_of("iter"), + fld.cx.ident_of("IntoIterator"), + fld.cx.ident_of("into_iter"), + ]; + + fld.cx.path_global(span, strs) + }; + + fld.cx.expr_call(span, fld.cx.expr_path(into_iter_path), vec![head]) + }; + fld.cx.expr_match(span, into_iter_expr, vec![iter_arm]) } ast::ExprClosure(capture_clause, opt_kind, fn_decl, block) => { diff --git a/src/libsyntax/ext/format.rs b/src/libsyntax/ext/format.rs index 2a0a352f128..36dbf117604 100644 --- a/src/libsyntax/ext/format.rs +++ b/src/libsyntax/ext/format.rs @@ -17,7 +17,7 @@ use ext::base::*; use ext::base; use ext::build::AstBuilder; use fmt_macros as parse; -use parse::token::{InternedString, special_idents}; +use parse::token::special_idents; use parse::token; use ptr::P; @@ -300,56 +300,35 @@ impl<'a, 'b> Context<'a, 'b> { } } - /// These attributes are applied to all statics that this syntax extension - /// will generate. - fn static_attrs(ecx: &ExtCtxt, fmtsp: Span) -> Vec<ast::Attribute> { - // Flag statics as `inline` so LLVM can merge duplicate globals as much - // as possible (which we're generating a whole lot of). - let unnamed = ecx.meta_word(fmtsp, InternedString::new("inline")); - let unnamed = ecx.attribute(fmtsp, unnamed); - - // Do not warn format string as dead code - let dead_code = ecx.meta_word(fmtsp, InternedString::new("dead_code")); - let allow_dead_code = ecx.meta_list(fmtsp, - InternedString::new("allow"), - vec![dead_code]); - let allow_dead_code = ecx.attribute(fmtsp, allow_dead_code); - vec![unnamed, allow_dead_code] - } - fn rtpath(ecx: &ExtCtxt, s: &str) -> Vec<ast::Ident> { - vec![ecx.ident_of("std"), ecx.ident_of("fmt"), ecx.ident_of("rt"), ecx.ident_of(s)] + vec![ecx.ident_of("std"), ecx.ident_of("fmt"), ecx.ident_of("rt"), + ecx.ident_of("v1"), ecx.ident_of(s)] } fn trans_count(&self, c: parse::Count) -> P<ast::Expr> { let sp = self.fmtsp; - match c { - parse::CountIs(i) => { - self.ecx.expr_call_global(sp, Context::rtpath(self.ecx, "CountIs"), - vec!(self.ecx.expr_usize(sp, i))) + let count = |: c, arg| { + let mut path = Context::rtpath(self.ecx, "Count"); + path.push(self.ecx.ident_of(c)); + match arg { + Some(arg) => self.ecx.expr_call_global(sp, path, vec![arg]), + None => self.ecx.expr_path(self.ecx.path_global(sp, path)), } + }; + match c { + parse::CountIs(i) => count("Is", Some(self.ecx.expr_usize(sp, i))), parse::CountIsParam(i) => { - self.ecx.expr_call_global(sp, Context::rtpath(self.ecx, "CountIsParam"), - vec!(self.ecx.expr_usize(sp, i))) - } - parse::CountImplied => { - let path = self.ecx.path_global(sp, Context::rtpath(self.ecx, - "CountImplied")); - self.ecx.expr_path(path) - } - parse::CountIsNextParam => { - let path = self.ecx.path_global(sp, Context::rtpath(self.ecx, - "CountIsNextParam")); - self.ecx.expr_path(path) + count("Param", Some(self.ecx.expr_usize(sp, i))) } + parse::CountImplied => count("Implied", None), + parse::CountIsNextParam => count("NextParam", None), parse::CountIsName(n) => { let i = match self.name_positions.get(n) { Some(&i) => i, None => 0, // error already emitted elsewhere }; let i = i + self.args.len(); - self.ecx.expr_call_global(sp, Context::rtpath(self.ecx, "CountIsParam"), - vec!(self.ecx.expr_usize(sp, i))) + count("Param", Some(self.ecx.expr_usize(sp, i))) } } } @@ -373,27 +352,35 @@ impl<'a, 'b> Context<'a, 'b> { } parse::NextArgument(ref arg) => { // Translate the position - let pos = match arg.position { - // These two have a direct mapping - parse::ArgumentNext => { - let path = self.ecx.path_global(sp, Context::rtpath(self.ecx, - "ArgumentNext")); - self.ecx.expr_path(path) - } - parse::ArgumentIs(i) => { - self.ecx.expr_call_global(sp, Context::rtpath(self.ecx, "ArgumentIs"), - vec!(self.ecx.expr_usize(sp, i))) - } - // Named arguments are converted to positional arguments at - // the end of the list of arguments - parse::ArgumentNamed(n) => { - let i = match self.name_positions.get(n) { - Some(&i) => i, - None => 0, // error already emitted elsewhere - }; - let i = i + self.args.len(); - self.ecx.expr_call_global(sp, Context::rtpath(self.ecx, "ArgumentIs"), - vec!(self.ecx.expr_usize(sp, i))) + let pos = { + let pos = |: c, arg| { + let mut path = Context::rtpath(self.ecx, "Position"); + path.push(self.ecx.ident_of(c)); + match arg { + Some(i) => { + let arg = self.ecx.expr_usize(sp, i); + self.ecx.expr_call_global(sp, path, vec![arg]) + } + None => { + self.ecx.expr_path(self.ecx.path_global(sp, path)) + } + } + }; + match arg.position { + // These two have a direct mapping + parse::ArgumentNext => pos("Next", None), + parse::ArgumentIs(i) => pos("At", Some(i)), + + // Named arguments are converted to positional arguments + // at the end of the list of arguments + parse::ArgumentNamed(n) => { + let i = match self.name_positions.get(n) { + Some(&i) => i, + None => 0, // error already emitted elsewhere + }; + let i = i + self.args.len(); + pos("At", Some(i)) + } } }; @@ -417,19 +404,16 @@ impl<'a, 'b> Context<'a, 'b> { // Translate the format let fill = self.ecx.expr_lit(sp, ast::LitChar(fill)); + let align = |:name| { + let mut p = Context::rtpath(self.ecx, "Alignment"); + p.push(self.ecx.ident_of(name)); + self.ecx.path_global(sp, p) + }; let align = match arg.format.align { - parse::AlignLeft => { - self.ecx.path_global(sp, Context::rtpath(self.ecx, "AlignLeft")) - } - parse::AlignRight => { - self.ecx.path_global(sp, Context::rtpath(self.ecx, "AlignRight")) - } - parse::AlignCenter => { - self.ecx.path_global(sp, Context::rtpath(self.ecx, "AlignCenter")) - } - parse::AlignUnknown => { - self.ecx.path_global(sp, Context::rtpath(self.ecx, "AlignUnknown")) - } + parse::AlignLeft => align("Left"), + parse::AlignRight => align("Right"), + parse::AlignCenter => align("Center"), + parse::AlignUnknown => align("Unknown"), }; let align = self.ecx.expr_path(align); let flags = self.ecx.expr_usize(sp, arg.format.flags); @@ -465,7 +449,7 @@ impl<'a, 'b> Context<'a, 'b> { let st = ast::ItemStatic(ty, ast::MutImmutable, slice); let name = ecx.ident_of(name); - let item = ecx.item(fmtsp, name, Context::static_attrs(ecx, fmtsp), st); + let item = ecx.item(fmtsp, name, vec![], st); let decl = respan(fmtsp, ast::DeclItem(item)); // Wrap the declaration in a block so that it forms a single expression. @@ -575,7 +559,7 @@ impl<'a, 'b> Context<'a, 'b> { // Now create the fmt::Arguments struct with all our locals we created. let (fn_name, fn_args) = if self.all_pieces_simple { - ("new", vec![pieces, args_slice]) + ("new_v1", vec![pieces, args_slice]) } else { // Build up the static array which will store our precompiled // nonstandard placeholders, if there are any. @@ -587,7 +571,7 @@ impl<'a, 'b> Context<'a, 'b> { piece_ty, self.pieces); - ("with_placeholders", vec![pieces, fmt, args_slice]) + ("new_v1_formatted", vec![pieces, args_slice, fmt]) }; self.ecx.expr_call_global(self.fmtsp, vec!( @@ -624,7 +608,8 @@ impl<'a, 'b> Context<'a, 'b> { return ecx.expr_call_global(sp, vec![ ecx.ident_of("std"), ecx.ident_of("fmt"), - ecx.ident_of("argumentuint")], vec![arg]) + ecx.ident_of("ArgumentV1"), + ecx.ident_of("from_uint")], vec![arg]) } }; @@ -636,7 +621,8 @@ impl<'a, 'b> Context<'a, 'b> { ecx.expr_call_global(sp, vec![ ecx.ident_of("std"), ecx.ident_of("fmt"), - ecx.ident_of("argument")], vec![ecx.expr_path(format_fn), arg]) + ecx.ident_of("ArgumentV1"), + ecx.ident_of("new")], vec![arg, ecx.expr_path(format_fn)]) } } diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 6e797844c18..775cfede70d 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -109,6 +109,9 @@ static KNOWN_FEATURES: &'static [(&'static str, &'static str, Status)] = &[ // int and uint are now deprecated ("int_uint", "1.0.0", Active), + // macro reexport needs more discusion and stabilization + ("macro_reexport", "1.0.0", Active), + // These are used to test this portion of the compiler, they don't actually // mean anything ("test_accepted_feature", "1.0.0", Accepted), @@ -272,6 +275,10 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> { self.gate_feature("plugin", i.span, "compiler plugins are experimental \ and possibly buggy"); + } else if attr::contains_name(&i.attrs[], "macro_reexport") { + self.gate_feature("macro_reexport", i.span, + "macros reexports are experimental \ + and possibly buggy"); } } diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index ff4c7b565cb..73424136cfb 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -16,7 +16,6 @@ #![crate_name = "syntax"] #![unstable(feature = "rustc_private")] -#![feature(staged_api)] #![staged_api] #![crate_type = "dylib"] #![crate_type = "rlib"] @@ -24,19 +23,21 @@ html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_root_url = "http://doc.rust-lang.org/nightly/")] -#![allow(unknown_features)] -#![feature(slicing_syntax)] +#![cfg_attr(not(stage0), allow(unused_mut))] // NOTE: remove after stage0 snap + #![feature(box_syntax)] -#![feature(quote, unsafe_destructor)] -#![allow(unknown_features)] #![feature(int_uint)] #![feature(collections)] #![feature(core)] #![feature(hash)] +#![feature(int_uint)] #![feature(io)] #![feature(libc)] #![feature(os)] #![feature(path)] +#![feature(quote, unsafe_destructor)] #![feature(rustc_private)] +#![feature(slicing_syntax)] +#![feature(staged_api)] #![feature(std_misc)] #![feature(unicode)] diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index 493a97c24cf..2cf6058a433 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -613,7 +613,7 @@ impl<'a> StringReader<'a> { // find the integer representing the name self.scan_digits(base); let encoded_name : u32 = self.with_str_from(start_bpos, |s| { - num::from_str_radix(s, 10).unwrap_or_else(|| { + num::from_str_radix(s, 10).ok().unwrap_or_else(|| { panic!("expected digits representing a name, got {:?}, {}, range [{:?},{:?}]", s, whence, start_bpos, self.last_pos); }) @@ -631,7 +631,7 @@ impl<'a> StringReader<'a> { let start_bpos = self.last_pos; self.scan_digits(base); let encoded_ctxt : ast::SyntaxContext = self.with_str_from(start_bpos, |s| { - num::from_str_radix(s, 10).unwrap_or_else(|| { + num::from_str_radix(s, 10).ok().unwrap_or_else(|| { panic!("expected digits representing a ctxt, got {:?}, {}", s, whence); }) }); diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 1c146968fd5..e7be876edbb 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -401,7 +401,7 @@ pub fn char_lit(lit: &str) -> (char, isize) { let msg2 = &msg[]; fn esc(len: usize, lit: &str) -> Option<(char, isize)> { - num::from_str_radix(&lit[2..len], 16) + num::from_str_radix(&lit[2..len], 16).ok() .and_then(char::from_u32) .map(|x| (x, len as isize)) } @@ -410,7 +410,7 @@ pub fn char_lit(lit: &str) -> (char, isize) { if lit.as_bytes()[2] == b'{' { let idx = lit.find('}').expect(msg2); let subslice = &lit[3..idx]; - num::from_str_radix(subslice, 16) + num::from_str_radix(subslice, 16).ok() .and_then(char::from_u32) .map(|x| (x, subslice.chars().count() as isize + 4)) } else { @@ -583,7 +583,7 @@ pub fn byte_lit(lit: &str) -> (u8, usize) { b'\'' => b'\'', b'0' => b'\0', _ => { - match ::std::num::from_str_radix::<u64>(&lit[2..4], 16) { + match ::std::num::from_str_radix::<u64>(&lit[2..4], 16).ok() { Some(c) => if c > 0xFF { panic!(err(2)) @@ -732,7 +732,7 @@ pub fn integer_lit(s: &str, suffix: Option<&str>, sd: &SpanHandler, sp: Span) -> debug!("integer_lit: the type is {:?}, base {:?}, the new string is {:?}, the original \ string was {:?}, the original suffix was {:?}", ty, base, s, orig, suffix); - let res: u64 = match ::std::num::from_str_radix(s, base) { + let res: u64 = match ::std::num::from_str_radix(s, base).ok() { Some(r) => r, None => { sd.span_err(sp, "int literal is too large"); 0 } }; diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index c4224db8e18..d99095eeba3 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2459,7 +2459,7 @@ impl<'a> Parser<'a> { hi = self.span.hi; self.bump(); - let index = n.as_str().parse::<usize>(); + let index = n.as_str().parse::<usize>().ok(); match index { Some(n) => { let id = spanned(dot, hi, n); @@ -2479,7 +2479,7 @@ impl<'a> Parser<'a> { self.span_err(last_span, &format!("unexpected token: `{}`", n.as_str())[]); if fstr.chars().all(|x| "0123456789.".contains_char(x)) { - let float = match fstr.parse::<f64>() { + let float = match fstr.parse::<f64>().ok() { Some(f) => f, None => continue, }; diff --git a/src/libsyntax/show_span.rs b/src/libsyntax/show_span.rs index 57520257fe1..6492cd4b095 100644 --- a/src/libsyntax/show_span.rs +++ b/src/libsyntax/show_span.rs @@ -27,14 +27,15 @@ enum Mode { } impl FromStr for Mode { - fn from_str(s: &str) -> Option<Mode> { + type Err = (); + fn from_str(s: &str) -> Result<Mode, ()> { let mode = match s { "expr" => Mode::Expression, "pat" => Mode::Pattern, "ty" => Mode::Type, - _ => return None + _ => return Err(()) }; - Some(mode) + Ok(mode) } } @@ -73,7 +74,7 @@ impl<'a, 'v> Visitor<'v> for ShowSpanVisitor<'a> { pub fn run(span_diagnostic: &diagnostic::SpanHandler, mode: &str, krate: &ast::Crate) { - let mode = match mode.parse() { + let mode = match mode.parse().ok() { Some(mode) => mode, None => return }; diff --git a/src/libterm/lib.rs b/src/libterm/lib.rs index aa3af76d46c..27a46fb5a68 100644 --- a/src/libterm/lib.rs +++ b/src/libterm/lib.rs @@ -41,7 +41,6 @@ #![crate_name = "term"] #![unstable(feature = "rustc_private", reason = "use the crates.io `term` library instead")] -#![feature(staged_api)] #![staged_api] #![crate_type = "rlib"] #![crate_type = "dylib"] @@ -49,18 +48,18 @@ html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_root_url = "http://doc.rust-lang.org/nightly/", html_playground_url = "http://play.rust-lang.org/")] +#![deny(missing_docs)] -#![allow(unknown_features)] -#![feature(slicing_syntax)] #![feature(box_syntax)] -#![allow(unknown_features)] #![feature(int_uint)] -#![deny(missing_docs)] #![feature(collections)] #![feature(core)] +#![feature(int_uint)] #![feature(io)] #![feature(os)] #![feature(path)] #![feature(rustc_private)] +#![feature(slicing_syntax)] +#![feature(staged_api)] #![feature(std_misc)] #![feature(unicode)] diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 8fea6bb539f..f22c58c54a6 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -25,25 +25,27 @@ #![crate_name = "test"] #![unstable(feature = "test")] -#![feature(staged_api)] #![staged_api] #![crate_type = "rlib"] #![crate_type = "dylib"] #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_root_url = "http://doc.rust-lang.org/nightly/")] -#![allow(unknown_features)] + +#![cfg_attr(not(stage0), allow(unused_mut))] // NOTE: remove after stage0 snap + #![feature(asm, slicing_syntax)] #![feature(box_syntax)] -#![allow(unknown_features)] #![feature(int_uint)] #![feature(collections)] #![feature(core)] +#![feature(hash)] +#![feature(int_uint)] #![feature(io)] #![feature(os)] #![feature(path)] #![feature(rustc_private)] +#![feature(staged_api)] #![feature(std_misc)] -#![feature(hash)] extern crate getopts; extern crate serialize; @@ -74,7 +76,6 @@ use std::old_io; use std::iter::repeat; use std::num::{Float, Int}; use std::os; -use std::str::FromStr; use std::sync::mpsc::{channel, Sender}; use std::thread::{self, Thread}; use std::thunk::{Thunk, Invoke}; @@ -818,7 +819,7 @@ fn get_concurrency() -> uint { use std::rt; match os::getenv("RUST_TEST_TASKS") { Some(s) => { - let opt_n: Option<uint> = FromStr::from_str(s.as_slice()); + let opt_n: Option<uint> = s.parse().ok(); match opt_n { Some(n) if n > 0 => n, _ => panic!("RUST_TEST_TASKS is `{}`, should be a positive integer.", s) diff --git a/src/libunicode/lib.rs b/src/libunicode/lib.rs index 02f738c9d29..822dde7eb2c 100644 --- a/src/libunicode/lib.rs +++ b/src/libunicode/lib.rs @@ -31,7 +31,7 @@ html_playground_url = "http://play.rust-lang.org/")] #![no_std] #![feature(slicing_syntax)] -#![allow(unknown_features)] #![feature(int_uint)] +#![feature(int_uint)] #![feature(core)] extern crate core; @@ -84,4 +84,7 @@ mod std { pub use core::cmp; pub use core::fmt; pub use core::marker; + // for-loops + pub use core::iter; + pub use core::option; } diff --git a/src/libunicode/u_str.rs b/src/libunicode/u_str.rs index 370f59a5b26..9a757c0c980 100644 --- a/src/libunicode/u_str.rs +++ b/src/libunicode/u_str.rs @@ -447,7 +447,7 @@ impl<'a> Iterator for Utf16Items<'a> { Some(Utf16Item::LoneSurrogate(u)) } else { // preserve state for rewinding. - let old = self.iter; + let old = self.iter.clone(); let u2 = match self.iter.next() { Some(u2) => *u2, @@ -457,7 +457,7 @@ impl<'a> Iterator for Utf16Items<'a> { if u2 < 0xDC00 || u2 > 0xDFFF { // not a trailing surrogate so we're not a valid // surrogate pair, so rewind to redecode u2 next time. - self.iter = old; + self.iter = old.clone(); return Some(Utf16Item::LoneSurrogate(u)) } diff --git a/src/rustbook/css.rs b/src/rustbook/css.rs index 7af95350c95..8b933fdd6dd 100644 --- a/src/rustbook/css.rs +++ b/src/rustbook/css.rs @@ -48,6 +48,7 @@ body { margin-left: auto; margin-right:auto; max-width: 750px; + padding-bottom: 50px; } .chapter { @@ -125,4 +126,12 @@ body { padding: 0; } +.left { + float: left; +} + +.right { + float: right; +} + "#; diff --git a/src/rustbook/javascript.rs b/src/rustbook/javascript.rs index eb4401e1835..d34887d2b08 100644 --- a/src/rustbook/javascript.rs +++ b/src/rustbook/javascript.rs @@ -38,6 +38,37 @@ document.addEventListener("DOMContentLoaded", function(event) { el.className = classes.join(' '); } } + + // The below code is used to add prev and next navigation links to the bottom + // of each of the sections. + // It works by extracting the current page based on the url and iterates over + // the menu links until it finds the menu item for the current page. We then + // create a copy of the preceeding and following menu links and add the + // correct css class and insert them into the bottom of the page. + var toc = document.getElementById('toc').getElementsByTagName('a'); + var href = document.location.pathname.split('/').pop(); + if (href === 'index.html' || href === '') { + href = 'README.html'; + } + + for (var i = 0; i < toc.length; i++) { + if (toc[i].attributes['href'].value === href) { + var nav = document.createElement('p'); + if (i > 0) { + var prevNode = toc[i-1].cloneNode(true); + prevNode.className = 'left'; + nav.appendChild(prevNode); + } + if (i < toc.length - 1) { + var nextNode = toc[i+1].cloneNode(true); + nextNode.className = 'right'; + nav.appendChild(nextNode); + } + document.getElementById('page').appendChild(nav); + break; + } + } + }); </script> "#; diff --git a/src/rustllvm/llvm-auto-clean-trigger b/src/rustllvm/llvm-auto-clean-trigger index 9dd66ac0a30..e159e9729b6 100644 --- a/src/rustllvm/llvm-auto-clean-trigger +++ b/src/rustllvm/llvm-auto-clean-trigger @@ -1,4 +1,4 @@ # If this file is modified, then llvm will be forcibly cleaned and then rebuilt. # The actual contents of this file do not matter, but to trigger a change on the # build bots then the contents should be changed so git updates the mtime. -2015-01-18 +2015-01-30 diff --git a/src/snapshots.txt b/src/snapshots.txt index 8d3ab53ef7f..3406a91e718 100644 --- a/src/snapshots.txt +++ b/src/snapshots.txt @@ -1,3 +1,12 @@ +S 2015-01-28 a45e117 + freebsd-x86_64 08a3ce7331fd1a52466acc0598cf745a009f86f6 + linux-i386 66e36a3461c12e2102a7f7f241d1b0e242c704d0 + linux-x86_64 0ae2f5da9913cfa211a367de77d5faa2ff798918 + macos-i386 d1a6776f00bf5091d73816d46c7fca8617575bd8 + macos-x86_64 cd4d7659b93e2341316cef4b7c5c9b50d23c6bbf + winnt-i386 14859dde2eb57f8c54989852ae6f807e66576338 + winnt-x86_64 693c0d1068debe5781e89e0d9efee85825eeae6c + S 2015-01-27 7774359 freebsd-x86_64 63623b632d4f9c33ad3b3cfaeebf8e2dd8395c96 linux-i386 937b0b126aade54dc2c7198cad67f40d711b64ba diff --git a/src/test/auxiliary/issue-11224.rs b/src/test/auxiliary/issue-11224.rs index d66cfe9bf63..560844332a1 100644 --- a/src/test/auxiliary/issue-11224.rs +++ b/src/test/auxiliary/issue-11224.rs @@ -21,6 +21,6 @@ mod inner { } pub fn foo() { - let a = &1i as &inner::Trait; + let a = &1 as &inner::Trait; a.f(); } diff --git a/src/test/auxiliary/issue-16643.rs b/src/test/auxiliary/issue-16643.rs index c3f7f2d1aa1..c5b3fceaf4a 100644 --- a/src/test/auxiliary/issue-16643.rs +++ b/src/test/auxiliary/issue-16643.rs @@ -15,7 +15,7 @@ pub struct TreeBuilder<H>; impl<H> TreeBuilder<H> { pub fn process_token(&mut self) { match self { - _ => for _y in *self {} + _ => for _y in self.by_ref() {} } } } diff --git a/src/test/auxiliary/issue-8044.rs b/src/test/auxiliary/issue-8044.rs index 7096146a43a..7bfd2e79641 100644 --- a/src/test/auxiliary/issue-8044.rs +++ b/src/test/auxiliary/issue-8044.rs @@ -21,5 +21,5 @@ pub fn leaf<V>(value: V) -> TreeItem<V> { } fn main() { - BTree::<int> { node: leaf(1i) }; + BTree::<int> { node: leaf(1) }; } diff --git a/src/test/auxiliary/issue-9906.rs b/src/test/auxiliary/issue-9906.rs index c0cb501735d..1e746bf39db 100644 --- a/src/test/auxiliary/issue-9906.rs +++ b/src/test/auxiliary/issue-9906.rs @@ -22,6 +22,6 @@ mod other { } pub fn foo(){ - 1i+1; + 1+1; } } diff --git a/src/test/auxiliary/macro_crate_test.rs b/src/test/auxiliary/macro_crate_test.rs index e3e91e05f55..d545a42ae19 100644 --- a/src/test/auxiliary/macro_crate_test.rs +++ b/src/test/auxiliary/macro_crate_test.rs @@ -25,9 +25,9 @@ use syntax::ptr::P; use rustc::plugin::Registry; #[macro_export] -macro_rules! exported_macro { () => (2i) } +macro_rules! exported_macro { () => (2) } -macro_rules! unexported_macro { () => (3i) } +macro_rules! unexported_macro { () => (3) } #[plugin_registrar] pub fn plugin_registrar(reg: &mut Registry) { @@ -47,7 +47,7 @@ fn expand_make_a_1(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) if !tts.is_empty() { cx.span_fatal(sp, "make_a_1 takes no arguments"); } - MacExpr::new(quote_expr!(cx, 1i)) + MacExpr::new(quote_expr!(cx, 1)) } // See Issue #15750 diff --git a/src/test/auxiliary/macro_reexport_2.rs b/src/test/auxiliary/macro_reexport_2.rs index 15d9f9cc914..3918be88d86 100644 --- a/src/test/auxiliary/macro_reexport_2.rs +++ b/src/test/auxiliary/macro_reexport_2.rs @@ -9,6 +9,7 @@ // except according to those terms. #![crate_type = "dylib"] +#![feature(macro_reexport)] #[macro_reexport(reexported)] #[macro_use] #[no_link] diff --git a/src/test/auxiliary/macro_reexport_2_no_use.rs b/src/test/auxiliary/macro_reexport_2_no_use.rs index 63142b0a699..1d3dc26b0b4 100644 --- a/src/test/auxiliary/macro_reexport_2_no_use.rs +++ b/src/test/auxiliary/macro_reexport_2_no_use.rs @@ -9,6 +9,7 @@ // except according to those terms. #![crate_type = "dylib"] +#![feature(macro_reexport)] #[macro_reexport(reexported)] #[no_link] diff --git a/src/test/auxiliary/static-methods-crate.rs b/src/test/auxiliary/static-methods-crate.rs index 1b18571cf8c..6cb16f04ce1 100644 --- a/src/test/auxiliary/static-methods-crate.rs +++ b/src/test/auxiliary/static-methods-crate.rs @@ -19,7 +19,7 @@ pub trait read { impl read for int { fn readMaybe(s: String) -> Option<int> { - s.parse() + s.parse().ok() } } diff --git a/src/test/bench/core-std.rs b/src/test/bench/core-std.rs index 6d12d84f652..388868eee70 100644 --- a/src/test/bench/core-std.rs +++ b/src/test/bench/core-std.rs @@ -62,7 +62,7 @@ fn maybe_run_test<F>(argv: &[String], name: String, test: F) where F: FnOnce() { } fn shift_push() { - let mut v1 = repeat(1i).take(30000).collect::<Vec<_>>(); + let mut v1 = repeat(1).take(30000).collect::<Vec<_>>(); let mut v2 = Vec::new(); while v1.len() > 0 { diff --git a/src/test/bench/shootout-chameneos-redux.rs b/src/test/bench/shootout-chameneos-redux.rs index 7fad2c9b4be..15a63e153b9 100644 --- a/src/test/bench/shootout-chameneos-redux.rs +++ b/src/test/bench/shootout-chameneos-redux.rs @@ -232,7 +232,7 @@ fn main() { } else { std::os::args().as_slice() .get(1) - .and_then(|arg| arg.parse()) + .and_then(|arg| arg.parse().ok()) .unwrap_or(600u) }; diff --git a/src/test/bench/shootout-fannkuch-redux.rs b/src/test/bench/shootout-fannkuch-redux.rs index e12a9e7cb16..03666c84d57 100644 --- a/src/test/bench/shootout-fannkuch-redux.rs +++ b/src/test/bench/shootout-fannkuch-redux.rs @@ -182,7 +182,7 @@ fn fannkuch(n: i32) -> (i32, i32) { fn main() { let n = std::os::args().as_slice() .get(1) - .and_then(|arg| arg.parse()) + .and_then(|arg| arg.parse().ok()) .unwrap_or(2i32); let (checksum, maxflips) = fannkuch(n); diff --git a/src/test/bench/shootout-meteor.rs b/src/test/bench/shootout-meteor.rs index e6ef58cba35..3c01697166e 100644 --- a/src/test/bench/shootout-meteor.rs +++ b/src/test/bench/shootout-meteor.rs @@ -104,8 +104,8 @@ impl<'a, T> Iterator for ListIterator<'a, T> { // corresponding mirrored piece), with, as minimum coordinates, (0, // 0). If all is false, only generate half of the possibilities (used // to break the symmetry of the board). -fn transform(piece: Vec<(int, int)> , all: bool) -> Vec<Vec<(int, int)>> { - let mut res: Vec<Vec<(int, int)>> = +fn transform(piece: Vec<(isize, isize)> , all: bool) -> Vec<Vec<(isize, isize)>> { + let mut res: Vec<Vec<(isize, isize)>> = // rotations iterate(piece, |rot| rot.iter().map(|&(y, x)| (x + y, -y)).collect()) .take(if all {6} else {3}) @@ -133,14 +133,14 @@ fn transform(piece: Vec<(int, int)> , all: bool) -> Vec<Vec<(int, int)>> { // Takes a piece with minimum coordinate (0, 0) (as generated by // transform). Returns the corresponding mask if p translated by (dy, // dx) is on the board. -fn mask(dy: int, dx: int, id: uint, p: &Vec<(int, int)>) -> Option<u64> { +fn mask(dy: isize, dx: isize, id: usize, p: &Vec<(isize, isize)>) -> Option<u64> { let mut m = 1 << (50 + id); for &(y, x) in p.iter() { let x = x + dx + (y + (dy % 2)) / 2; if x < 0 || x > 4 {return None;} let y = y + dy; if y < 0 || y > 9 {return None;} - m |= 1 << (y * 5 + x) as uint; + m |= 1 << (y * 5 + x) as usize; } Some(m) } @@ -150,26 +150,26 @@ fn mask(dy: int, dx: int, id: uint, p: &Vec<(int, int)>) -> Option<u64> { // (i/5, i%5). fn make_masks() -> Vec<Vec<Vec<u64> > > { let pieces = vec!( - vec!((0i,0i),(0,1),(0,2),(0,3),(1,3)), - vec!((0i,0i),(0,2),(0,3),(1,0),(1,1)), - vec!((0i,0i),(0,1),(0,2),(1,2),(2,1)), - vec!((0i,0i),(0,1),(0,2),(1,1),(2,1)), - vec!((0i,0i),(0,2),(1,0),(1,1),(2,1)), - vec!((0i,0i),(0,1),(0,2),(1,1),(1,2)), - vec!((0i,0i),(0,1),(1,1),(1,2),(2,1)), - vec!((0i,0i),(0,1),(0,2),(1,0),(1,2)), - vec!((0i,0i),(0,1),(0,2),(1,2),(1,3)), - vec!((0i,0i),(0,1),(0,2),(0,3),(1,2))); + vec!((0,0),(0,1),(0,2),(0,3),(1,3)), + vec!((0,0),(0,2),(0,3),(1,0),(1,1)), + vec!((0,0),(0,1),(0,2),(1,2),(2,1)), + vec!((0,0),(0,1),(0,2),(1,1),(2,1)), + vec!((0,0),(0,2),(1,0),(1,1),(2,1)), + vec!((0,0),(0,1),(0,2),(1,1),(1,2)), + vec!((0,0),(0,1),(1,1),(1,2),(2,1)), + vec!((0,0),(0,1),(0,2),(1,0),(1,2)), + vec!((0,0),(0,1),(0,2),(1,2),(1,3)), + vec!((0,0),(0,1),(0,2),(0,3),(1,2))); // To break the central symmetry of the problem, every // transformation must be taken except for one piece (piece 3 // here). - let transforms: Vec<Vec<Vec<(int, int)>>> = + let transforms: Vec<Vec<Vec<(isize, isize)>>> = pieces.into_iter().enumerate() .map(|(id, p)| transform(p, id != 3)) .collect(); - (0i..50).map(|yx| { + (0is..50).map(|yx| { transforms.iter().enumerate().map(|(id, t)| { t.iter().filter_map(|p| mask(yx / 5, yx % 5, id, p)).collect() }).collect() @@ -212,7 +212,7 @@ fn filter_masks(masks: &mut Vec<Vec<Vec<u64>>>) { // Gets the identifier of a mask. fn get_id(m: u64) -> u8 { for id in 0u8..10 { - if m & (1 << (id + 50) as uint) != 0 {return id;} + if m & (1 << (id + 50) as usize) != 0 {return id;} } panic!("{:016x} does not have a valid identifier", m); } @@ -222,7 +222,7 @@ fn to_vec(raw_sol: &List<u64>) -> Vec<u8> { let mut sol = repeat('.' as u8).take(50).collect::<Vec<_>>(); for &m in raw_sol.iter() { let id = '0' as u8 + get_id(m); - for i in 0u..50 { + for i in 0us..50 { if m & 1 << i != 0 { sol[i] = id; } @@ -244,7 +244,7 @@ fn print_sol(sol: &Vec<u8>) { // The data managed during the search struct Data { // Number of solution found. - nb: int, + nb: isize, // Lexicographically minimal solution found. min: Vec<u8>, // Lexicographically maximal solution found. @@ -286,7 +286,7 @@ fn handle_sol(raw_sol: &List<u64>, data: &mut Data) { fn search( masks: &Vec<Vec<Vec<u64>>>, board: u64, - mut i: uint, + mut i: usize, cur: List<u64>, data: &mut Data) { @@ -297,7 +297,7 @@ fn search( let masks_at = &masks[i]; // for every unused piece - for id in (0u..10).filter(|&id| board & (1 << (id + 50)) == 0) { + for id in (0us..10).filter(|&id| board & (1 << (id + 50)) == 0) { // for each mask that fits on the board for m in masks_at[id].iter().filter(|&m| board & *m == 0) { // This check is too costly. diff --git a/src/test/bench/shootout-nbody.rs b/src/test/bench/shootout-nbody.rs index 7325b8a4738..b2161000322 100644 --- a/src/test/bench/shootout-nbody.rs +++ b/src/test/bench/shootout-nbody.rs @@ -174,7 +174,7 @@ fn main() { 5000000 } else { std::os::args().get(1) - .and_then(|arg| arg.parse()) + .and_then(|arg| arg.parse().ok()) .unwrap_or(1000) }; let mut bodies = BODIES; diff --git a/src/test/bench/shootout-pfib.rs b/src/test/bench/shootout-pfib.rs index 2f68262b608..dd3ae1699a9 100644 --- a/src/test/bench/shootout-pfib.rs +++ b/src/test/bench/shootout-pfib.rs @@ -66,9 +66,9 @@ fn parse_opts(argv: Vec<String> ) -> Config { } fn stress_task(id: int) { - let mut i = 0i; + let mut i = 0; loop { - let n = 15i; + let n = 15; assert_eq!(fib(n), fib(n)); i += 1; println!("{}: Completed {} iterations", id, i); diff --git a/src/test/bench/shootout-threadring.rs b/src/test/bench/shootout-threadring.rs index 47f17997e84..ebe8a0751c3 100644 --- a/src/test/bench/shootout-threadring.rs +++ b/src/test/bench/shootout-threadring.rs @@ -68,10 +68,10 @@ fn main() { let token = if std::os::getenv("RUST_BENCH").is_some() { 2000000 } else { - args.get(1).and_then(|arg| arg.parse()).unwrap_or(1000) + args.get(1).and_then(|arg| arg.parse().ok()).unwrap_or(1000) }; let n_tasks = args.get(2) - .and_then(|arg| arg.parse()) + .and_then(|arg| arg.parse().ok()) .unwrap_or(503); start(n_tasks, token); diff --git a/src/test/compile-fail/associated-types-subtyping-1.rs b/src/test/compile-fail/associated-types-subtyping-1.rs new file mode 100644 index 00000000000..f9106ba3960 --- /dev/null +++ b/src/test/compile-fail/associated-types-subtyping-1.rs @@ -0,0 +1,55 @@ +// Copyright 2015 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![allow(unused_variables)] + +trait Trait<'a> { + type Type; + + fn method(&'a self) { } +} + +fn method1<'a,'b,T>(x: &'a T, y: &'b T) + where T : for<'z> Trait<'z>, 'a : 'b +{ + // Note that &'static T <: &'a T. + let a: <T as Trait<'a>>::Type = loop { }; + let b: <T as Trait<'b>>::Type = loop { }; + let _: <T as Trait<'a>>::Type = a; +} + +fn method2<'a,'b,T>(x: &'a T, y: &'b T) + where T : for<'z> Trait<'z>, 'a : 'b +{ + // Note that &'static T <: &'a T. + let a: <T as Trait<'a>>::Type = loop { }; + let b: <T as Trait<'b>>::Type = loop { }; + let _: <T as Trait<'b>>::Type = a; //~ ERROR mismatched types +} + +fn method3<'a,'b,T>(x: &'a T, y: &'b T) + where T : for<'z> Trait<'z>, 'a : 'b +{ + // Note that &'static T <: &'a T. + let a: <T as Trait<'a>>::Type = loop { }; + let b: <T as Trait<'b>>::Type = loop { }; + let _: <T as Trait<'a>>::Type = b; //~ ERROR mismatched types +} + +fn method4<'a,'b,T>(x: &'a T, y: &'b T) + where T : for<'z> Trait<'z>, 'a : 'b +{ + // Note that &'static T <: &'a T. + let a: <T as Trait<'a>>::Type = loop { }; + let b: <T as Trait<'b>>::Type = loop { }; + let _: <T as Trait<'b>>::Type = b; +} + +fn main() { } diff --git a/src/test/compile-fail/for-loop-bogosity.rs b/src/test/compile-fail/for-loop-bogosity.rs index fd920f92394..6bc0e74a2eb 100644 --- a/src/test/compile-fail/for-loop-bogosity.rs +++ b/src/test/compile-fail/for-loop-bogosity.rs @@ -24,7 +24,10 @@ pub fn main() { x: 1, y: 2, }; - for x in bogus { //~ ERROR has type `MyStruct` which does not implement the `Iterator` trait + for x in bogus { //~ ERROR `core::iter::Iterator` is not implemented for the type `MyStruct` + //~^ ERROR + //~^^ ERROR + // FIXME(#21528) not fulfilled obligation error should be reported once, not thrice drop(x); } } diff --git a/src/test/compile-fail/for-loop-hygiene.rs b/src/test/compile-fail/for-loop-hygiene.rs new file mode 100644 index 00000000000..ff6f848ab59 --- /dev/null +++ b/src/test/compile-fail/for-loop-hygiene.rs @@ -0,0 +1,20 @@ +// 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// for-loops are expanded in the front end, and use an `iter` ident in their expansion. Check that +// `iter` is not accessible inside the for loop. + +#![allow(unstable)] + +fn main() { + for _ in 0..10 { + iter.next(); //~ error: unresolved name `iter` + } +} diff --git a/src/test/compile-fail/for-loop-refutable-pattern-error-message.rs b/src/test/compile-fail/for-loop-refutable-pattern-error-message.rs index c381fcf3efb..fa55e7215c0 100644 --- a/src/test/compile-fail/for-loop-refutable-pattern-error-message.rs +++ b/src/test/compile-fail/for-loop-refutable-pattern-error-message.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - fn main() { for &1is //~ ERROR refutable pattern in `for` loop binding diff --git a/src/test/compile-fail/issue-13853.rs b/src/test/compile-fail/issue-13853.rs index 509ca9b80f8..251da2c6b3e 100644 --- a/src/test/compile-fail/issue-13853.rs +++ b/src/test/compile-fail/issue-13853.rs @@ -32,7 +32,7 @@ impl Node for Stuff { fn iterate<N: Node, G: Graph<N>>(graph: &G) { for node in graph.iter() { //~ ERROR does not implement any method in scope named - node.zomg(); + node.zomg(); //~ error: the type of this value must be known in this context } } diff --git a/src/test/compile-fail/issue-17718-const-naming.rs b/src/test/compile-fail/issue-17718-const-naming.rs index 15f66493f88..06719e2756b 100644 --- a/src/test/compile-fail/issue-17718-const-naming.rs +++ b/src/test/compile-fail/issue-17718-const-naming.rs @@ -11,7 +11,7 @@ #[deny(warnings)] const foo: isize = 3; -//~^ ERROR: should have an uppercase name such as +//~^ ERROR: should have an upper case name such as //~^^ ERROR: constant item is never used fn main() {} diff --git a/src/test/compile-fail/issue-17999.rs b/src/test/compile-fail/issue-17999.rs index 99cb2ec2c02..f336fdbfbed 100644 --- a/src/test/compile-fail/issue-17999.rs +++ b/src/test/compile-fail/issue-17999.rs @@ -9,6 +9,7 @@ // except according to those terms. #![deny(unused_variables)] +#![feature(core)] fn main() { for _ in 1is..101 { diff --git a/src/test/compile-fail/issue-20605.rs b/src/test/compile-fail/issue-20605.rs new file mode 100644 index 00000000000..87b7616db8e --- /dev/null +++ b/src/test/compile-fail/issue-20605.rs @@ -0,0 +1,19 @@ +// Copyright 2015 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn changer<'a>(mut things: Box<Iterator<Item=&'a mut u8>>) { + for item in *things { *item = 0 } +//~^ ERROR the trait `core::marker::Sized` is not implemented for the type `core::iter::Iterator +//~^^ ERROR +//~^^^ ERROR +// FIXME(#21528) error should be reported once, not thrice +} + +fn main() {} diff --git a/src/test/compile-fail/issue-2150.rs b/src/test/compile-fail/issue-2150.rs index f18db94acf3..68195985eec 100644 --- a/src/test/compile-fail/issue-2150.rs +++ b/src/test/compile-fail/issue-2150.rs @@ -11,6 +11,7 @@ #![deny(unreachable_code)] #![allow(unused_variables)] #![allow(dead_code)] +#![feature(core)] fn fail_len(v: Vec<isize> ) -> usize { let mut i = 3; diff --git a/src/test/compile-fail/lint-dead-code-4.rs b/src/test/compile-fail/lint-dead-code-4.rs index 22570bad616..449788459dc 100644 --- a/src/test/compile-fail/lint-dead-code-4.rs +++ b/src/test/compile-fail/lint-dead-code-4.rs @@ -13,7 +13,6 @@ #![deny(dead_code)] #![feature(libc)] #![feature(core)] -#![feature(collections)] extern crate libc; diff --git a/src/test/compile-fail/lint-group-style.rs b/src/test/compile-fail/lint-group-style.rs index 24d16bcaafc..59ab5be1572 100644 --- a/src/test/compile-fail/lint-group-style.rs +++ b/src/test/compile-fail/lint-group-style.rs @@ -24,7 +24,7 @@ mod test { mod bad { fn CamelCase() {} //~ ERROR function `CamelCase` should have a snake case name - static bad: isize = 1; //~ ERROR static constant `bad` should have an uppercase name + static bad: isize = 1; //~ ERROR static constant `bad` should have an upper case name } mod warn { diff --git a/src/test/compile-fail/lint-non-uppercase-statics.rs b/src/test/compile-fail/lint-non-uppercase-statics.rs index 10475f967d7..e1fbc73bbed 100644 --- a/src/test/compile-fail/lint-non-uppercase-statics.rs +++ b/src/test/compile-fail/lint-non-uppercase-statics.rs @@ -11,6 +11,6 @@ #![forbid(non_upper_case_globals)] #![allow(dead_code)] -static foo: isize = 1; //~ ERROR static constant `foo` should have an uppercase name such as `FOO` +static foo: isize = 1; //~ ERROR static constant `foo` should have an upper case name such as `FOO` fn main() { } diff --git a/src/test/compile-fail/liveness-unused.rs b/src/test/compile-fail/liveness-unused.rs index 6262783dd38..ebcf46f7277 100644 --- a/src/test/compile-fail/liveness-unused.rs +++ b/src/test/compile-fail/liveness-unused.rs @@ -11,6 +11,7 @@ #![deny(unused_variables)] #![deny(unused_assignments)] #![allow(dead_code, non_camel_case_types)] +#![feature(core)] #![feature(os)] fn f1(x: isize) { diff --git a/src/test/compile-fail/macro-reexport-malformed-1.rs b/src/test/compile-fail/macro-reexport-malformed-1.rs index b9f754b2778..6c85cf5c7f5 100644 --- a/src/test/compile-fail/macro-reexport-malformed-1.rs +++ b/src/test/compile-fail/macro-reexport-malformed-1.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(macro_reexport)] + #[macro_reexport] //~ ERROR bad macro reexport extern crate std; diff --git a/src/test/compile-fail/macro-reexport-malformed-2.rs b/src/test/compile-fail/macro-reexport-malformed-2.rs index 9ced5be8479..1dd0168181f 100644 --- a/src/test/compile-fail/macro-reexport-malformed-2.rs +++ b/src/test/compile-fail/macro-reexport-malformed-2.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(macro_reexport)] + #[macro_reexport="foo"] //~ ERROR bad macro reexport extern crate std; diff --git a/src/test/compile-fail/macro-reexport-malformed-3.rs b/src/test/compile-fail/macro-reexport-malformed-3.rs index c8bd0a0509c..7ae045f6e4f 100644 --- a/src/test/compile-fail/macro-reexport-malformed-3.rs +++ b/src/test/compile-fail/macro-reexport-malformed-3.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(macro_reexport)] + #[macro_reexport(foo="bar")] //~ ERROR bad macro reexport extern crate std; diff --git a/src/test/compile-fail/macro-reexport-not-locally-visible.rs b/src/test/compile-fail/macro-reexport-not-locally-visible.rs index cf0d79e0fef..6859ccfe3b7 100644 --- a/src/test/compile-fail/macro-reexport-not-locally-visible.rs +++ b/src/test/compile-fail/macro-reexport-not-locally-visible.rs @@ -11,6 +11,8 @@ // aux-build:macro_reexport_1.rs // ignore-stage1 +#![feature(macro_reexport)] + #[macro_reexport(reexported)] #[no_link] extern crate macro_reexport_1; diff --git a/src/test/compile-fail/match-static-const-lc.rs b/src/test/compile-fail/match-static-const-lc.rs index 345c4aa69a7..04b234d8db7 100644 --- a/src/test/compile-fail/match-static-const-lc.rs +++ b/src/test/compile-fail/match-static-const-lc.rs @@ -19,7 +19,7 @@ pub const a : isize = 97; fn f() { let r = match (0,0) { (0, a) => 0, - //~^ ERROR static constant in pattern `a` should have an uppercase name such as `A` + //~^ ERROR constant in pattern `a` should have an upper case name such as `A` (x, y) => 1 + x + y, }; assert!(r == 1); @@ -34,7 +34,7 @@ fn g() { use self::m::aha; let r = match (0,0) { (0, aha) => 0, - //~^ ERROR static constant in pattern `aha` should have an uppercase name such as `AHA` + //~^ ERROR constant in pattern `aha` should have an upper case name such as `AHA` (x, y) => 1 + x + y, }; assert!(r == 1); @@ -48,7 +48,7 @@ fn h() { use self::n::OKAY as not_okay; let r = match (0,0) { (0, not_okay) => 0, -//~^ ERROR static constant in pattern `not_okay` should have an uppercase name such as `NOT_OKAY` +//~^ ERROR constant in pattern `not_okay` should have an upper case name such as `NOT_OKAY` (x, y) => 1 + x + y, }; assert!(r == 1); diff --git a/src/test/compile-fail/missing_debug_impls.rs b/src/test/compile-fail/missing_debug_impls.rs index 5b781a40fe5..bc4bfef4d48 100644 --- a/src/test/compile-fail/missing_debug_impls.rs +++ b/src/test/compile-fail/missing_debug_impls.rs @@ -11,7 +11,6 @@ // compile-flags: --crate-type lib #![deny(missing_debug_implementations)] #![allow(unused, missing_copy_implementations)] -#![feature(core)] use std::fmt; diff --git a/src/test/compile-fail/range-1.rs b/src/test/compile-fail/range-1.rs index fdae5f79546..fbc9ad99b72 100644 --- a/src/test/compile-fail/range-1.rs +++ b/src/test/compile-fail/range-1.rs @@ -17,7 +17,10 @@ pub fn main() { // Float => does not implement iterator. for i in 0f32..42f32 {} - //~^ ERROR `for` loop expression has type `core::ops::Range<f32>` which does not implement + //~^ ERROR `core::iter::Iterator` is not implemented for the type `core::ops::Range<f32>` + //~^^ ERROR + //~^^^ ERROR + // FIXME(#21528) not fulfilled obligation error should be reported once, not thrice // Unsized type. let arr: &[_] = &[1us, 2, 3]; diff --git a/src/test/compile-fail/regions-infer-not-param.rs b/src/test/compile-fail/regions-infer-not-param.rs index 5d7a218ca8a..83b9d4633dc 100644 --- a/src/test/compile-fail/regions-infer-not-param.rs +++ b/src/test/compile-fail/regions-infer-not-param.rs @@ -27,5 +27,10 @@ fn take_direct<'a,'b>(p: direct<'a>) -> direct<'b> { p } //~ ERROR mismatched ty fn take_indirect1(p: indirect1) -> indirect1 { p } fn take_indirect2<'a,'b>(p: indirect2<'a>) -> indirect2<'b> { p } //~ ERROR mismatched types +//~| expected `indirect2<'b>` +//~| found `indirect2<'a>` +//~| ERROR mismatched types +//~| expected `indirect2<'b>` +//~| found `indirect2<'a>` fn main() {} diff --git a/src/test/compile-fail/variance-associated-types.rs b/src/test/compile-fail/variance-associated-types.rs new file mode 100644 index 00000000000..ecb2287769b --- /dev/null +++ b/src/test/compile-fail/variance-associated-types.rs @@ -0,0 +1,30 @@ +// Copyright 2015 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that the variance computation considers types/regions that +// appear in projections to be invariant. + +trait Trait<'a> { + type Type; + + fn method(&'a self) { } +} + +#[rustc_variance] +struct Foo<'a, T : Trait<'a>> { //~ ERROR ItemVariances(types=[[+];[];[]], regions=[[-];[];[]]) + field: (T, &'a ()) +} + +#[rustc_variance] +struct Bar<'a, T : Trait<'a>> { //~ ERROR ItemVariances(types=[[o];[];[]], regions=[[o];[];[]]) + field: <T as Trait<'a>>::Type +} + +fn main() { } diff --git a/src/test/debuginfo/basic-types-metadata.rs b/src/test/debuginfo/basic-types-metadata.rs index 5e2497043da..3b016f287fb 100644 --- a/src/test/debuginfo/basic-types-metadata.rs +++ b/src/test/debuginfo/basic-types-metadata.rs @@ -67,7 +67,7 @@ fn main() { let f32: f32 = 2.5; let f64: f64 = 3.5; _zzz(); // #break - if 1i == 1 { _yyy(); } + if 1 == 1 { _yyy(); } } fn _zzz() {()} diff --git a/src/test/debuginfo/box.rs b/src/test/debuginfo/box.rs index 0439e3dc34d..6db3dce4668 100644 --- a/src/test/debuginfo/box.rs +++ b/src/test/debuginfo/box.rs @@ -36,8 +36,8 @@ #![omit_gdb_pretty_printer_section] fn main() { - let a = box 1i; - let b = box() (2i, 3.5f64); + let a = box 1; + let b = box() (2, 3.5f64); zzz(); // #break } diff --git a/src/test/debuginfo/closure-in-generic-function.rs b/src/test/debuginfo/closure-in-generic-function.rs index f8b12569400..59428a2c06f 100644 --- a/src/test/debuginfo/closure-in-generic-function.rs +++ b/src/test/debuginfo/closure-in-generic-function.rs @@ -60,8 +60,8 @@ fn some_generic_fun<T1, T2>(a: T1, b: T2) -> (T2, T1) { } fn main() { - some_generic_fun(0.5f64, 10i); - some_generic_fun(&29i, box 110i); + some_generic_fun(0.5f64, 10); + some_generic_fun(&29, box 110); } fn zzz() { () } diff --git a/src/test/debuginfo/destructured-for-loop-variable.rs b/src/test/debuginfo/destructured-for-loop-variable.rs index 38f8f859d39..08062ce8966 100644 --- a/src/test/debuginfo/destructured-for-loop-variable.rs +++ b/src/test/debuginfo/destructured-for-loop-variable.rs @@ -202,7 +202,7 @@ fn main() { zzz(); // #break } - for i in 1234..1235i { + for i in 1234..1235 { zzz(); // #break } diff --git a/src/test/debuginfo/destructured-local.rs b/src/test/debuginfo/destructured-local.rs index 1fd598e18c1..22cc779aeca 100644 --- a/src/test/debuginfo/destructured-local.rs +++ b/src/test/debuginfo/destructured-local.rs @@ -278,7 +278,7 @@ fn main() { let Struct { a: k, b: l } = Struct { a: 12, b: 13 }; // ignored tuple element - let (m, _, n) = (14i, 15i, 16i); + let (m, _, n) = (14, 15, 16); // ignored struct field let Struct { b: o, .. } = Struct { a: 17, b: 18 }; @@ -291,25 +291,25 @@ fn main() { // complex nesting let ((u, v), ((w, (x, Struct { a: y, b: z})), Struct { a: ae, b: oe }), ue) = - ((25i, 26i), ((27i, (28i, Struct { a: 29, b: 30})), Struct { a: 31, b: 32 }), 33i); + ((25, 26), ((27, (28, Struct { a: 29, b: 30})), Struct { a: 31, b: 32 }), 33); // reference - let &aa = &(34i, 35i); + let &aa = &(34, 35); // reference - let &bb = &(36i, 37i); + let &bb = &(36, 37); // contained reference - let (&cc, _) = (&38i, 39i); + let (&cc, _) = (&38, 39); // unique pointer - let box dd = box() (40i, 41i, 42i); + let box dd = box() (40, 41, 42); // ref binding - let ref ee = (43i, 44i, 45i); + let ref ee = (43, 44, 45); // ref binding in tuple - let (ref ff, gg) = (46i, (47i, 48i)); + let (ref ff, gg) = (46, (47, 48)); // ref binding in struct let Struct { b: ref hh, .. } = Struct { a: 49, b: 50 }; diff --git a/src/test/debuginfo/function-arg-initialization.rs b/src/test/debuginfo/function-arg-initialization.rs index 38875c7656e..f9a2b2fef34 100644 --- a/src/test/debuginfo/function-arg-initialization.rs +++ b/src/test/debuginfo/function-arg-initialization.rs @@ -245,7 +245,7 @@ fn non_immediate_args(a: BigStruct, b: BigStruct) { } fn binding(a: i64, b: u64, c: f64) { - let x = 0i; // #break + let x = 0; // #break ::std::old_io::print("") } diff --git a/src/test/debuginfo/function-prologue-stepping-no-stack-check.rs b/src/test/debuginfo/function-prologue-stepping-no-stack-check.rs index 4692318b98f..8d456f33432 100644 --- a/src/test/debuginfo/function-prologue-stepping-no-stack-check.rs +++ b/src/test/debuginfo/function-prologue-stepping-no-stack-check.rs @@ -270,7 +270,7 @@ fn non_immediate_args(a: BigStruct, b: BigStruct) { #[no_stack_check] fn binding(a: i64, b: u64, c: f64) { - let x = 0i; + let x = 0; ::std::old_io::print(""); } diff --git a/src/test/debuginfo/function-prologue-stepping-regular.rs b/src/test/debuginfo/function-prologue-stepping-regular.rs index 799352911f6..14433fbcd23 100644 --- a/src/test/debuginfo/function-prologue-stepping-regular.rs +++ b/src/test/debuginfo/function-prologue-stepping-regular.rs @@ -148,7 +148,7 @@ fn non_immediate_args(a: BigStruct, b: BigStruct) { } fn binding(a: i64, b: u64, c: f64) { - let x = 0i; + let x = 0; } fn assignment(mut a: u64, b: u64, c: f64) { diff --git a/src/test/debuginfo/generic-function.rs b/src/test/debuginfo/generic-function.rs index b2fdb708db5..b9a09867a00 100644 --- a/src/test/debuginfo/generic-function.rs +++ b/src/test/debuginfo/generic-function.rs @@ -86,9 +86,9 @@ fn dup_tup<T0: Clone, T1: Clone>(t0: &T0, t1: &T1) -> ((T0, T1), (T1, T0)) { fn main() { - let _ = dup_tup(&1i, &2.5f64); + let _ = dup_tup(&1, &2.5f64); let _ = dup_tup(&3.5f64, &4_u16); - let _ = dup_tup(&5i, &Struct { a: 6, b: 7.5 }); + let _ = dup_tup(&5, &Struct { a: 6, b: 7.5 }); } fn zzz() {()} diff --git a/src/test/debuginfo/generic-functions-nested.rs b/src/test/debuginfo/generic-functions-nested.rs index 0f3fd556f18..9f6d8a45a99 100644 --- a/src/test/debuginfo/generic-functions-nested.rs +++ b/src/test/debuginfo/generic-functions-nested.rs @@ -74,7 +74,7 @@ #![omit_gdb_pretty_printer_section] fn outer<TA: Clone>(a: TA) { - inner(a.clone(), 1i); + inner(a.clone(), 1); inner(a.clone(), 2.5f64); fn inner<TX, TY>(x: TX, y: TY) { @@ -83,7 +83,7 @@ fn outer<TA: Clone>(a: TA) { } fn main() { - outer(-1i); + outer(-1); outer(-2.5f64); } diff --git a/src/test/debuginfo/generic-static-method-on-struct-and-enum.rs b/src/test/debuginfo/generic-static-method-on-struct-and-enum.rs index bf755d379a6..61843a20d05 100644 --- a/src/test/debuginfo/generic-static-method-on-struct-and-enum.rs +++ b/src/test/debuginfo/generic-static-method-on-struct-and-enum.rs @@ -61,8 +61,8 @@ impl Enum { } fn main() { - Struct::static_method(1i, 2i); - Enum::static_method(-3i, 4.5f64, 5i); + Struct::static_method(1, 2); + Enum::static_method(-3, 4.5f64, 5); } fn zzz() {()} diff --git a/src/test/debuginfo/generic-struct-style-enum.rs b/src/test/debuginfo/generic-struct-style-enum.rs index 992e7417913..2faafbd7634 100644 --- a/src/test/debuginfo/generic-struct-style-enum.rs +++ b/src/test/debuginfo/generic-struct-style-enum.rs @@ -76,7 +76,7 @@ fn main() { // 0b01011001 = 89 let case3: Regular<u16, i32, u64> = Case3 { a: 0, b: 6438275382588823897 }; - let univariant = TheOnlyCase { a: -1i }; + let univariant = TheOnlyCase { a: -1 }; zzz(); // #break } diff --git a/src/test/debuginfo/generic-struct.rs b/src/test/debuginfo/generic-struct.rs index a81230599fa..696d2703bde 100644 --- a/src/test/debuginfo/generic-struct.rs +++ b/src/test/debuginfo/generic-struct.rs @@ -32,14 +32,14 @@ // lldb-command:run // lldb-command:print int_int -// lldb-check:[...]$0 = AGenericStruct<isize, isize> { key: 0, value: 1 } +// lldb-check:[...]$0 = AGenericStruct<i32, i32> { key: 0, value: 1 } // lldb-command:print int_float -// lldb-check:[...]$1 = AGenericStruct<isize, f64> { key: 2, value: 3.5 } +// lldb-check:[...]$1 = AGenericStruct<i32, f64> { key: 2, value: 3.5 } // lldb-command:print float_int -// lldb-check:[...]$2 = AGenericStruct<f64, isize> { key: 4.5, value: 5 } +// lldb-check:[...]$2 = AGenericStruct<f64, i32> { key: 4.5, value: 5 } // lldb-command:print float_int_float -// lldb-check:[...]$3 = AGenericStruct<f64, generic-struct::AGenericStruct<isize, f64>> { key: 6.5, value: AGenericStruct<isize, f64> { key: 7, value: 8.5 } } +// lldb-check:[...]$3 = AGenericStruct<f64, generic-struct::AGenericStruct<i32, f64>> { key: 6.5, value: AGenericStruct<i32, f64> { key: 7, value: 8.5 } } #![omit_gdb_pretty_printer_section] @@ -51,12 +51,12 @@ struct AGenericStruct<TKey, TValue> { fn main() { - let int_int = AGenericStruct { key: 0i, value: 1i }; - let int_float = AGenericStruct { key: 2i, value: 3.5f64 }; - let float_int = AGenericStruct { key: 4.5f64, value: 5i }; + let int_int = AGenericStruct { key: 0, value: 1 }; + let int_float = AGenericStruct { key: 2, value: 3.5f64 }; + let float_int = AGenericStruct { key: 4.5f64, value: 5 }; let float_int_float = AGenericStruct { key: 6.5f64, - value: AGenericStruct { key: 7i, value: 8.5f64 }, + value: AGenericStruct { key: 7, value: 8.5f64 }, }; zzz(); // #break diff --git a/src/test/debuginfo/lexical-scope-in-for-loop.rs b/src/test/debuginfo/lexical-scope-in-for-loop.rs index 3309ae13c9d..1fa54e47163 100644 --- a/src/test/debuginfo/lexical-scope-in-for-loop.rs +++ b/src/test/debuginfo/lexical-scope-in-for-loop.rs @@ -90,15 +90,15 @@ fn main() { - let range = [1i, 2, 3]; + let range = [1, 2, 3]; - let x = 1000000i; // wan meeeljen doollaars! + let x = 1000000; // wan meeeljen doollaars! for &x in range.iter() { zzz(); // #break sentinel(); - let x = -1i * x; + let x = -1 * x; zzz(); // #break sentinel(); diff --git a/src/test/debuginfo/lexical-scope-in-if.rs b/src/test/debuginfo/lexical-scope-in-if.rs index bc3a6945243..c885bfce216 100644 --- a/src/test/debuginfo/lexical-scope-in-if.rs +++ b/src/test/debuginfo/lexical-scope-in-if.rs @@ -138,8 +138,8 @@ fn main() { - let x = 999i; - let y = -1i; + let x = 999; + let y = -1; zzz(); // #break sentinel(); @@ -148,13 +148,13 @@ fn main() { zzz(); // #break sentinel(); - let x = 1001i; + let x = 1001; zzz(); // #break sentinel(); - let x = 1002i; - let y = 1003i; + let x = 1002; + let y = 1003; zzz(); // #break sentinel(); } else { @@ -170,8 +170,8 @@ fn main() { zzz(); // #break sentinel(); - let x = 1004i; - let y = 1005i; + let x = 1004; + let y = 1005; zzz(); // #break sentinel(); } diff --git a/src/test/debuginfo/lexical-scope-in-match.rs b/src/test/debuginfo/lexical-scope-in-match.rs index 37976ab3996..c596253560e 100644 --- a/src/test/debuginfo/lexical-scope-in-match.rs +++ b/src/test/debuginfo/lexical-scope-in-match.rs @@ -135,13 +135,13 @@ struct Struct { fn main() { - let shadowed = 231i; - let not_shadowed = 232i; + let shadowed = 231; + let not_shadowed = 232; zzz(); // #break sentinel(); - match (233i, 234i) { + match (233, 234) { (shadowed, local_to_arm) => { zzz(); // #break @@ -149,7 +149,7 @@ fn main() { } } - match (235i, 236i) { + match (235, 236) { // with literal (235, shadowed) => { @@ -186,7 +186,7 @@ fn main() { _ => {} } - match (243i, 244i) { + match (243, 244) { (shadowed, ref local_to_arm) => { zzz(); // #break diff --git a/src/test/debuginfo/lexical-scope-in-parameterless-closure.rs b/src/test/debuginfo/lexical-scope-in-parameterless-closure.rs index 107c5cb9782..5e04c81cefd 100644 --- a/src/test/debuginfo/lexical-scope-in-parameterless-closure.rs +++ b/src/test/debuginfo/lexical-scope-in-parameterless-closure.rs @@ -19,6 +19,6 @@ // Nothing to do here really, just make sure it compiles. See issue #8513. fn main() { let _ = |&:|(); - let _ = (1u..3).map(|_| 5i); + let _ = (1u..3).map(|_| 5); } diff --git a/src/test/debuginfo/lexical-scope-in-unconditional-loop.rs b/src/test/debuginfo/lexical-scope-in-unconditional-loop.rs index b295c6f37a7..6826bca695b 100644 --- a/src/test/debuginfo/lexical-scope-in-unconditional-loop.rs +++ b/src/test/debuginfo/lexical-scope-in-unconditional-loop.rs @@ -136,7 +136,7 @@ fn main() { - let mut x = 0i; + let mut x = 0; loop { if x >= 2 { @@ -160,7 +160,7 @@ fn main() { zzz(); // #break sentinel(); - let x = -987i; + let x = -987; zzz(); // #break sentinel(); diff --git a/src/test/debuginfo/lexical-scope-in-while.rs b/src/test/debuginfo/lexical-scope-in-while.rs index c7a36ef9b82..40280b469f7 100644 --- a/src/test/debuginfo/lexical-scope-in-while.rs +++ b/src/test/debuginfo/lexical-scope-in-while.rs @@ -136,7 +136,7 @@ fn main() { - let mut x = 0i; + let mut x = 0; while x < 2 { zzz(); // #break @@ -156,7 +156,7 @@ fn main() { zzz(); // #break sentinel(); - let x = -987i; + let x = -987; zzz(); // #break sentinel(); diff --git a/src/test/debuginfo/lexical-scope-with-macro.rs b/src/test/debuginfo/lexical-scope-with-macro.rs index 2aa31969a46..da941979fb6 100644 --- a/src/test/debuginfo/lexical-scope-with-macro.rs +++ b/src/test/debuginfo/lexical-scope-with-macro.rs @@ -123,7 +123,7 @@ macro_rules! no_new_scope { macro_rules! new_scope { () => ({ - let a = 890242i; + let a = 890242; zzz(); // #break sentinel(); }) @@ -151,8 +151,8 @@ macro_rules! dup_expr { fn main() { - let a = trivial!(10i); - let b = no_new_scope!(33i); + let a = trivial!(10); + let b = no_new_scope!(33); zzz(); // #break sentinel(); @@ -162,12 +162,12 @@ fn main() { zzz(); // #break sentinel(); - shadow_within_macro!(100i); + shadow_within_macro!(100); zzz(); // #break sentinel(); - let c = dup_expr!(10i * 20); + let c = dup_expr!(10 * 20); zzz(); // #break sentinel(); diff --git a/src/test/debuginfo/lexical-scopes-in-block-expression.rs b/src/test/debuginfo/lexical-scopes-in-block-expression.rs index 2f8b11ac283..118d096d31b 100644 --- a/src/test/debuginfo/lexical-scopes-in-block-expression.rs +++ b/src/test/debuginfo/lexical-scopes-in-block-expression.rs @@ -364,8 +364,8 @@ fn a_function(x: int) -> int { fn main() { - let val = -1i; - let ten = 10i; + let val = -1; + let ten = 10; // surrounded by struct expression let point = Point { @@ -417,7 +417,7 @@ fn main() { sentinel(); val - }, 0i); + }, 0); zzz(); // #break sentinel(); @@ -492,7 +492,7 @@ fn main() { sentinel(); // index expression - let a_vector = [10i; 20]; + let a_vector = [10; 20]; let _ = a_vector[{ zzz(); // #break sentinel(); diff --git a/src/test/debuginfo/limited-debuginfo.rs b/src/test/debuginfo/limited-debuginfo.rs index e1aec83714d..c8fe76fdbe5 100644 --- a/src/test/debuginfo/limited-debuginfo.rs +++ b/src/test/debuginfo/limited-debuginfo.rs @@ -47,7 +47,7 @@ fn zzz() {()} fn some_function(a: int, b: int) { let some_variable = Struct { a: 11, b: 22 }; - let some_other_variable = 23i; + let some_other_variable = 23; for x in 0..1 { zzz(); // #break diff --git a/src/test/debuginfo/multiple-functions-equal-var-names.rs b/src/test/debuginfo/multiple-functions-equal-var-names.rs index cb21c13426a..0b2f8ef8181 100644 --- a/src/test/debuginfo/multiple-functions-equal-var-names.rs +++ b/src/test/debuginfo/multiple-functions-equal-var-names.rs @@ -48,18 +48,18 @@ #![omit_gdb_pretty_printer_section] fn function_one() { - let abc = 10101i; + let abc = 10101; zzz(); // #break } fn function_two() { - let abc = 20202i; + let abc = 20202; zzz(); // #break } fn function_three() { - let abc = 30303i; + let abc = 30303; zzz(); // #break } diff --git a/src/test/debuginfo/multiple-functions.rs b/src/test/debuginfo/multiple-functions.rs index ef7c4ce2045..00698ae1dfb 100644 --- a/src/test/debuginfo/multiple-functions.rs +++ b/src/test/debuginfo/multiple-functions.rs @@ -48,18 +48,18 @@ #![omit_gdb_pretty_printer_section] fn function_one() { - let a = 10101i; + let a = 10101; zzz(); // #break } fn function_two() { - let b = 20202i; + let b = 20202; zzz(); // #break } fn function_three() { - let c = 30303i; + let c = 30303; zzz(); // #break } diff --git a/src/test/debuginfo/name-shadowing-and-scope-nesting.rs b/src/test/debuginfo/name-shadowing-and-scope-nesting.rs index d248c7e9819..8c1a5376dba 100644 --- a/src/test/debuginfo/name-shadowing-and-scope-nesting.rs +++ b/src/test/debuginfo/name-shadowing-and-scope-nesting.rs @@ -103,20 +103,20 @@ fn main() { zzz(); // #break sentinel(); - let x = 10i; + let x = 10; zzz(); // #break sentinel(); let x = 10.5f64; - let y = 20i; + let y = 20; zzz(); // #break sentinel(); { let x = true; - let y = 2220i; + let y = 2220; zzz(); // #break sentinel(); diff --git a/src/test/debuginfo/shadowed-argument.rs b/src/test/debuginfo/shadowed-argument.rs index c5c3664b07a..5b36d32e49f 100644 --- a/src/test/debuginfo/shadowed-argument.rs +++ b/src/test/debuginfo/shadowed-argument.rs @@ -65,13 +65,13 @@ fn a_function(x: bool, y: bool) { zzz(); // #break sentinel(); - let x = 10i; + let x = 10; zzz(); // #break sentinel(); let x = 10.5f64; - let y = 20i; + let y = 20; zzz(); // #break sentinel(); diff --git a/src/test/debuginfo/shadowed-variable.rs b/src/test/debuginfo/shadowed-variable.rs index f384b756da6..66fd656eaac 100644 --- a/src/test/debuginfo/shadowed-variable.rs +++ b/src/test/debuginfo/shadowed-variable.rs @@ -67,13 +67,13 @@ fn main() { zzz(); // #break sentinel(); - let x = 10i; + let x = 10; zzz(); // #break sentinel(); let x = 10.5f64; - let y = 20i; + let y = 20; zzz(); // #break sentinel(); diff --git a/src/test/debuginfo/simple-lexical-scope.rs b/src/test/debuginfo/simple-lexical-scope.rs index 5981c18494d..31441db20f1 100644 --- a/src/test/debuginfo/simple-lexical-scope.rs +++ b/src/test/debuginfo/simple-lexical-scope.rs @@ -91,7 +91,7 @@ fn main() { zzz(); // #break sentinel(); - let x = 10i; + let x = 10; zzz(); // #break sentinel(); diff --git a/src/test/debuginfo/type-names.rs b/src/test/debuginfo/type-names.rs index 156e5f12ad5..24b6df4e8f1 100644 --- a/src/test/debuginfo/type-names.rs +++ b/src/test/debuginfo/type-names.rs @@ -288,15 +288,15 @@ fn main() { let slice2 = vec2.as_slice(); // Trait Objects - let box_trait = (box 0i) as Box<Trait1>; - let ref_trait = &0i as &Trait1; - let mut mut_int1 = 0i; + let box_trait = (box 0) as Box<Trait1>; + let ref_trait = &0 as &Trait1; + let mut mut_int1 = 0; let mut_ref_trait = (&mut mut_int1) as &mut Trait1; - let generic_box_trait = (box 0i) as Box<Trait2<i32, Mod1::Struct2>>; - let generic_ref_trait = (&0i) as &Trait2<Struct1, Struct1>; + let generic_box_trait = (box 0) as Box<Trait2<i32, Mod1::Struct2>>; + let generic_ref_trait = (&0) as &Trait2<Struct1, Struct1>; - let mut generic_mut_ref_trait_impl = 0i; + let mut generic_mut_ref_trait_impl = 0; let generic_mut_ref_trait = (&mut generic_mut_ref_trait_impl) as &mut Trait2<Mod1::Mod2::Struct3, GenericStruct<usize, isize>>; diff --git a/src/test/debuginfo/vec.rs b/src/test/debuginfo/vec.rs index 92a490206b6..9ee18c0d77b 100644 --- a/src/test/debuginfo/vec.rs +++ b/src/test/debuginfo/vec.rs @@ -34,7 +34,7 @@ static mut VECT: [i32; 3] = [1, 2, 3]; fn main() { - let a = [1i, 2, 3]; + let a = [1, 2, 3]; unsafe { VECT[0] = 4; diff --git a/src/test/pretty/block-disambig.rs b/src/test/pretty/block-disambig.rs index 1e286c236a5..c9cb72d8af7 100644 --- a/src/test/pretty/block-disambig.rs +++ b/src/test/pretty/block-disambig.rs @@ -15,9 +15,9 @@ use std::cell::Cell; -fn test1() { let val = &0i; { } *val; } +fn test1() { let val = &0; { } *val; } -fn test2() -> int { let val = &0i; { } *val } +fn test2() -> int { let val = &0; { } *val } #[derive(Copy)] struct S { eax: int } @@ -35,13 +35,13 @@ fn test5() -> (int, int) { { } (0, 1) } fn test6() -> bool { { } (true || false) && true } fn test7() -> uint { - let regs = &0i; + let regs = &0; match true { true => { } _ => { } } (*regs < 2) as uint } fn test8() -> int { - let val = &0i; + let val = &0; match true { true => { } _ => { } @@ -54,12 +54,12 @@ fn test8() -> int { } fn test9() { - let regs = &Cell::new(0i); + let regs = &Cell::new(0); match true { true => { } _ => { } } regs.set(regs.get() + 1); } fn test10() -> int { - let regs = vec!(0i); + let regs = vec!(0); match true { true => { } _ => { } } regs[0] } diff --git a/src/test/pretty/issue-4264.pp b/src/test/pretty/issue-4264.pp index c18d076c0d3..b1d38f5dc9b 100644 --- a/src/test/pretty/issue-4264.pp +++ b/src/test/pretty/issue-4264.pp @@ -41,41 +41,39 @@ pub fn bar() { ((::std::fmt::format as - fn(core::fmt::Arguments<'_>) -> collections::string::String {std::fmt::format})(((::std::fmt::Arguments::new + fn(core::fmt::Arguments<'_>) -> collections::string::String {std::fmt::format})(((::std::fmt::Arguments::new_v1 as - fn(&[&str], &[core::fmt::Argument<'_>]) -> core::fmt::Arguments<'_> {core::fmt::Arguments<'a>::new})(({ - #[inline] - #[allow(dead_code)] - static __STATIC_FMTSTR: - &'static [&'static str] - = - (&([("test" - as - &'static str)] - as - [&'static str; 1]) - as - &'static [&'static str; 1]); - (__STATIC_FMTSTR + fn(&[&str], &[core::fmt::ArgumentV1<'_>]) -> core::fmt::Arguments<'_> {core::fmt::Arguments<'a>::new_v1})(({ + static __STATIC_FMTSTR: + &'static [&'static str] + = + (&([("test" + as + &'static str)] + as + [&'static str; 1]) + as + &'static [&'static str; 1]); + (__STATIC_FMTSTR + as + &'static [&'static str]) + } as - &'static [&'static str]) - } - as - &[&str]), - (&(match (() - as - ()) - { - () - => - ([] + &[&str]), + (&(match (() + as + ()) + { + () + => + ([] + as + [core::fmt::ArgumentV1<'_>; 0]), + } as - [core::fmt::Argument<'_>; 0]), - } - as - [core::fmt::Argument<'_>; 0]) - as - &[core::fmt::Argument<'_>; 0])) + [core::fmt::ArgumentV1<'_>; 0]) + as + &[core::fmt::ArgumentV1<'_>; 0])) as core::fmt::Arguments<'_>)) as collections::string::String); diff --git a/src/test/pretty/issue-929.rs b/src/test/pretty/issue-929.rs index 377f4669ffc..75a6b919342 100644 --- a/src/test/pretty/issue-929.rs +++ b/src/test/pretty/issue-929.rs @@ -8,6 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn f() { if (1i == panic!()) { } else { } } +fn f() { if (1 == panic!()) { } else { } } fn main() { } diff --git a/src/test/pretty/match-block-expr.rs b/src/test/pretty/match-block-expr.rs index 44771a29bb4..7751f155da4 100644 --- a/src/test/pretty/match-block-expr.rs +++ b/src/test/pretty/match-block-expr.rs @@ -11,6 +11,6 @@ // pp-exact fn main() { - let x = match { 5i } { 1 => 5i, 2 => 6, _ => 7, }; + let x = match { 5 } { 1 => 5, 2 => 6, _ => 7, }; assert_eq!(x , 7); } diff --git a/src/test/pretty/match-naked-expr-medium.rs b/src/test/pretty/match-naked-expr-medium.rs index d2f8157ef62..39af19dbf6f 100644 --- a/src/test/pretty/match-naked-expr-medium.rs +++ b/src/test/pretty/match-naked-expr-medium.rs @@ -11,7 +11,7 @@ // pp-exact fn main() { - let x = Some(3i); + let x = Some(3); let _y = match x { Some(_) => diff --git a/src/test/pretty/match-naked-expr.rs b/src/test/pretty/match-naked-expr.rs index 6b4f579f9c5..02bbf667d96 100644 --- a/src/test/pretty/match-naked-expr.rs +++ b/src/test/pretty/match-naked-expr.rs @@ -11,7 +11,7 @@ // pp-exact fn main() { - let x = Some(3i); + let x = Some(3); let _y = match x { Some(_) => "some(_)".to_string(), diff --git a/src/test/pretty/path-type-bounds.rs b/src/test/pretty/path-type-bounds.rs index 382394b1407..e27a3365a41 100644 --- a/src/test/pretty/path-type-bounds.rs +++ b/src/test/pretty/path-type-bounds.rs @@ -19,6 +19,6 @@ fn foo<'a>(x: Box<Tr+ Sync + 'a>) -> Box<Tr+ Sync + 'a> { x } fn main() { let x: Box<Tr+ Sync>; - Box::new(1i) as Box<Tr+ Sync>; + Box::new(1) as Box<Tr+ Sync>; } diff --git a/src/test/pretty/unary-op-disambig.rs b/src/test/pretty/unary-op-disambig.rs index 850904fe53e..1592e010aaf 100644 --- a/src/test/pretty/unary-op-disambig.rs +++ b/src/test/pretty/unary-op-disambig.rs @@ -18,10 +18,10 @@ fn block_nosemi() -> int { ({ 0 }) - 1 } fn if_semi() -> int { if true { f() } else { f() }; -1 } -fn if_nosemi() -> int { (if true { 0i } else { 0i }) - 1 } +fn if_nosemi() -> int { (if true { 0 } else { 0 }) - 1 } fn alt_semi() -> int { match true { true => { f() } _ => { } }; -1 } fn alt_no_semi() -> int { (match true { true => { 0 } _ => { 1 } }) - 1 } -fn stmt() { { f() }; -1i; } +fn stmt() { { f() }; -1; } diff --git a/src/test/pretty/vec-comments.pp b/src/test/pretty/vec-comments.pp index 401c63efbc4..dc2dae1044d 100644 --- a/src/test/pretty/vec-comments.pp +++ b/src/test/pretty/vec-comments.pp @@ -15,25 +15,25 @@ fn main() { let _v1 = [ // Comment - 0i, + 0, // Comment - 1i, + 1, // Comment - 2i]; + 2]; let _v2 = - [0i, // Comment - 1i, // Comment - 2i]; // Comment + [0, // Comment + 1, // Comment + 2]; // Comment let _v3 = [ /* Comment */ - 0i, + 0, /* Comment */ - 1i, + 1, /* Comment */ - 2i]; + 2]; let _v4 = - [0i, /* Comment */ - 1i, /* Comment */ - 2i]; /* Comment */ + [0, /* Comment */ + 1, /* Comment */ + 2]; /* Comment */ } diff --git a/src/test/pretty/vec-comments.rs b/src/test/pretty/vec-comments.rs index 401c63efbc4..dc2dae1044d 100644 --- a/src/test/pretty/vec-comments.rs +++ b/src/test/pretty/vec-comments.rs @@ -15,25 +15,25 @@ fn main() { let _v1 = [ // Comment - 0i, + 0, // Comment - 1i, + 1, // Comment - 2i]; + 2]; let _v2 = - [0i, // Comment - 1i, // Comment - 2i]; // Comment + [0, // Comment + 1, // Comment + 2]; // Comment let _v3 = [ /* Comment */ - 0i, + 0, /* Comment */ - 1i, + 1, /* Comment */ - 2i]; + 2]; let _v4 = - [0i, /* Comment */ - 1i, /* Comment */ - 2i]; /* Comment */ + [0, /* Comment */ + 1, /* Comment */ + 2]; /* Comment */ } diff --git a/src/test/run-fail/assert-eq-macro-panic.rs b/src/test/run-fail/assert-eq-macro-panic.rs index 69ed025070b..fd6d69efb4f 100644 --- a/src/test/run-fail/assert-eq-macro-panic.rs +++ b/src/test/run-fail/assert-eq-macro-panic.rs @@ -11,5 +11,5 @@ // error-pattern:assertion failed: `(left == right) && (right == left)` (left: `14`, right: `15`) fn main() { - assert_eq!(14i,15i); + assert_eq!(14,15); } diff --git a/src/test/run-fail/assert-macro-fmt.rs b/src/test/run-fail/assert-macro-fmt.rs index 223c60d6ae4..78239a2217e 100644 --- a/src/test/run-fail/assert-macro-fmt.rs +++ b/src/test/run-fail/assert-macro-fmt.rs @@ -11,5 +11,5 @@ // error-pattern:panicked at 'test-assert-fmt 42 rust' fn main() { - assert!(false, "test-assert-fmt {} {}", 42i, "rust"); + assert!(false, "test-assert-fmt {} {}", 42, "rust"); } diff --git a/src/test/run-fail/bounds-check-no-overflow.rs b/src/test/run-fail/bounds-check-no-overflow.rs index df9050e2186..be4ad0781f2 100644 --- a/src/test/run-fail/bounds-check-no-overflow.rs +++ b/src/test/run-fail/bounds-check-no-overflow.rs @@ -14,6 +14,6 @@ use std::uint; use std::mem::size_of; fn main() { - let xs = [1i, 2, 3]; + let xs = [1, 2, 3]; xs[uint::MAX / size_of::<int>() + 1]; } diff --git a/src/test/run-fail/divide-by-zero.rs b/src/test/run-fail/divide-by-zero.rs index c58d30f2729..de69b7b9fa6 100644 --- a/src/test/run-fail/divide-by-zero.rs +++ b/src/test/run-fail/divide-by-zero.rs @@ -10,6 +10,6 @@ // error-pattern:attempted to divide by zero fn main() { - let y = 0i; - let _z = 1i / y; + let y = 0; + let _z = 1 / y; } diff --git a/src/test/run-fail/dst-raw-slice.rs b/src/test/run-fail/dst-raw-slice.rs index 39bf899a023..77cec8b6327 100644 --- a/src/test/run-fail/dst-raw-slice.rs +++ b/src/test/run-fail/dst-raw-slice.rs @@ -12,7 +12,7 @@ // error-pattern:index out of bounds fn main() { - let a: *const [_] = &[1i, 2, 3]; + let a: *const [_] = &[1, 2, 3]; unsafe { let _b = (*a)[3]; } diff --git a/src/test/run-fail/explicit-panic-msg.rs b/src/test/run-fail/explicit-panic-msg.rs index ae6e72bdd4f..c9c04e5f2da 100644 --- a/src/test/run-fail/explicit-panic-msg.rs +++ b/src/test/run-fail/explicit-panic-msg.rs @@ -13,7 +13,7 @@ // error-pattern:wooooo fn main() { - let mut a = 1i; - if 1i == 1 { a = 2; } + let mut a = 1; + if 1 == 1 { a = 2; } panic!(format!("woooo{}", "o")); } diff --git a/src/test/run-fail/expr-if-panic.rs b/src/test/run-fail/expr-if-panic.rs index f04c94a3bf4..b6791271a11 100644 --- a/src/test/run-fail/expr-if-panic.rs +++ b/src/test/run-fail/expr-if-panic.rs @@ -10,4 +10,4 @@ // error-pattern:explicit panic -fn main() { let _x = if false { 0i } else if true { panic!() } else { 10i }; } +fn main() { let _x = if false { 0 } else if true { panic!() } else { 10 }; } diff --git a/src/test/run-fail/expr-match-panic.rs b/src/test/run-fail/expr-match-panic.rs index d5c005b7029..3a6bd59b3ac 100644 --- a/src/test/run-fail/expr-match-panic.rs +++ b/src/test/run-fail/expr-match-panic.rs @@ -10,4 +10,4 @@ // error-pattern:explicit panic -fn main() { let _x = match true { false => { 0i } true => { panic!() } }; } +fn main() { let _x = match true { false => { 0 } true => { panic!() } }; } diff --git a/src/test/run-fail/issue-12920.rs b/src/test/run-fail/issue-12920.rs index 8dbfc06152a..cbc92c640d2 100644 --- a/src/test/run-fail/issue-12920.rs +++ b/src/test/run-fail/issue-12920.rs @@ -11,5 +11,5 @@ // error-pattern:explicit panic pub fn main() { - panic!(); println!("{}", 1i); + panic!(); println!("{}", 1); } diff --git a/src/test/run-fail/issue-3029.rs b/src/test/run-fail/issue-3029.rs index 0846ba2e71a..4d048fe0fcf 100644 --- a/src/test/run-fail/issue-3029.rs +++ b/src/test/run-fail/issue-3029.rs @@ -16,7 +16,7 @@ // error-pattern:so long fn main() { let mut x = Vec::new(); - let y = vec!(3i); + let y = vec!(3); panic!("so long"); x.extend(y.into_iter()); } diff --git a/src/test/run-fail/mod-zero.rs b/src/test/run-fail/mod-zero.rs index 54415051708..76d4de7ecb0 100644 --- a/src/test/run-fail/mod-zero.rs +++ b/src/test/run-fail/mod-zero.rs @@ -10,6 +10,6 @@ // error-pattern:attempted remainder with a divisor of zero fn main() { - let y = 0i; - let _z = 1i % y; + let y = 0; + let _z = 1 % y; } diff --git a/src/test/run-fail/panic-macro-any.rs b/src/test/run-fail/panic-macro-any.rs index 231c57390b3..ce6a5d46cc7 100644 --- a/src/test/run-fail/panic-macro-any.rs +++ b/src/test/run-fail/panic-macro-any.rs @@ -14,5 +14,5 @@ #![feature(box_syntax)] fn main() { - panic!(box 413i as Box<::std::any::Any+Send>); + panic!(box 413 as Box<::std::any::Any+Send>); } diff --git a/src/test/run-fail/panic-macro-fmt.rs b/src/test/run-fail/panic-macro-fmt.rs index ac50f02cf33..50ad99c6747 100644 --- a/src/test/run-fail/panic-macro-fmt.rs +++ b/src/test/run-fail/panic-macro-fmt.rs @@ -11,5 +11,5 @@ // error-pattern:panicked at 'test-fail-fmt 42 rust' fn main() { - panic!("test-fail-fmt {} {}", 42i, "rust"); + panic!("test-fail-fmt {} {}", 42, "rust"); } diff --git a/src/test/run-fail/panic-task-name-none.rs b/src/test/run-fail/panic-task-name-none.rs index 9beee3b1843..816ee84a841 100644 --- a/src/test/run-fail/panic-task-name-none.rs +++ b/src/test/run-fail/panic-task-name-none.rs @@ -15,7 +15,7 @@ use std::thread::Thread; fn main() { let r: Result<int,_> = Thread::scoped(move|| { panic!("test"); - 1i + 1 }).join(); assert!(r.is_ok()); } diff --git a/src/test/run-fail/panic-task-name-owned.rs b/src/test/run-fail/panic-task-name-owned.rs index 714cec6fb3d..d48d282c9eb 100644 --- a/src/test/run-fail/panic-task-name-owned.rs +++ b/src/test/run-fail/panic-task-name-owned.rs @@ -15,7 +15,7 @@ use std::thread::Builder; fn main() { let r: Result<int,_> = Builder::new().name("owned name".to_string()).scoped(move|| { panic!("test"); - 1i + 1 }).join(); assert!(r.is_ok()); } diff --git a/src/test/run-fail/unwind-interleaved.rs b/src/test/run-fail/unwind-interleaved.rs index 5012ded28b5..91a33329a4f 100644 --- a/src/test/run-fail/unwind-interleaved.rs +++ b/src/test/run-fail/unwind-interleaved.rs @@ -15,8 +15,8 @@ fn a() { } fn b() { panic!(); } fn main() { - let _x = vec!(0i); + let _x = vec!(0); a(); - let _y = vec!(0i); + let _y = vec!(0); b(); } diff --git a/src/test/run-fail/unwind-unique.rs b/src/test/run-fail/unwind-unique.rs index f39ded8f98e..e1176b1bcdb 100644 --- a/src/test/run-fail/unwind-unique.rs +++ b/src/test/run-fail/unwind-unique.rs @@ -18,6 +18,6 @@ fn failfn() { } fn main() { - box 0i; + box 0; failfn(); } diff --git a/src/test/run-make/cannot-read-embedded-idents/create_and_compile.rs b/src/test/run-make/cannot-read-embedded-idents/create_and_compile.rs index f9dffdf8928..f7c581172e2 100644 --- a/src/test/run-make/cannot-read-embedded-idents/create_and_compile.rs +++ b/src/test/run-make/cannot-read-embedded-idents/create_and_compile.rs @@ -23,7 +23,7 @@ fn main() { let main_file = tmpdir.join("broken.rs"); let _ = File::create(&main_file).unwrap() .write_str("pub fn main() { - let \x00name_0,ctxt_0\x00 = 3i; + let \x00name_0,ctxt_0\x00 = 3; println!(\"{}\", \x00name_0,ctxt_0\x00); }"); diff --git a/src/test/run-make/rustdoc-viewpath-self/Makefile b/src/test/run-make/rustdoc-viewpath-self/Makefile new file mode 100644 index 00000000000..1316ee256e1 --- /dev/null +++ b/src/test/run-make/rustdoc-viewpath-self/Makefile @@ -0,0 +1,6 @@ +-include ../tools.mk + +all: foo.rs + $(HOST_RPATH_ENV) $(RUSTDOC) -w html -o $(TMPDIR)/doc foo.rs + $(HTMLDOCCK) $(TMPDIR)/doc foo.rs + diff --git a/src/test/run-make/rustdoc-viewpath-self/foo.rs b/src/test/run-make/rustdoc-viewpath-self/foo.rs new file mode 100644 index 00000000000..da8f7393023 --- /dev/null +++ b/src/test/run-make/rustdoc-viewpath-self/foo.rs @@ -0,0 +1,26 @@ +// Copyright 2015 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +pub mod io { + pub trait Reader { } +} + +pub enum Maybe<A> { + Just(A), + Nothing +} + +// @has foo/prelude/index.html +pub mod prelude { + // @has foo/prelude/index.html '//code' 'pub use io::{self, Reader}' + #[doc(no_inline)] pub use io::{self, Reader}; + // @has foo/prelude/index.html '//code' 'pub use Maybe::{self, Just, Nothing}' + #[doc(no_inline)] pub use Maybe::{self, Just, Nothing}; +} diff --git a/src/test/run-make/save-analysis/SameDir.rs b/src/test/run-make/save-analysis/SameDir.rs new file mode 100644 index 00000000000..fe70ac1edef --- /dev/null +++ b/src/test/run-make/save-analysis/SameDir.rs @@ -0,0 +1,15 @@ +// Copyright 2015 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// sub-module in the same directory as the main crate file + +pub struct SameStruct { + pub name: String +} diff --git a/src/test/run-make/save-analysis/SameDir3.rs b/src/test/run-make/save-analysis/SameDir3.rs new file mode 100644 index 00000000000..315f900868b --- /dev/null +++ b/src/test/run-make/save-analysis/SameDir3.rs @@ -0,0 +1,13 @@ +// Copyright 2015 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +pub fn hello(x: isize) { + println!("macro {} :-(", x); +} diff --git a/src/test/run-make/save-analysis/SubDir/mod.rs b/src/test/run-make/save-analysis/SubDir/mod.rs new file mode 100644 index 00000000000..f2879cfc6ba --- /dev/null +++ b/src/test/run-make/save-analysis/SubDir/mod.rs @@ -0,0 +1,40 @@ +// Copyright 2015 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// sub-module in a sub-directory + +use sub::sub2 as msalias; +use sub::sub2; +use std::old_io::stdio::println; + +static yy: usize = 25us; + +mod sub { + pub mod sub2 { + use std::old_io::stdio::println; + pub mod sub3 { + use std::old_io::stdio::println; + pub fn hello() { + println("hello from module 3"); + } + } + pub fn hello() { + println("hello from a module"); + } + + pub struct nested_struct { + pub field2: u32, + } + } +} + +pub struct SubStruct { + pub name: String +} diff --git a/src/test/run-make/save-analysis/foo.rs b/src/test/run-make/save-analysis/foo.rs index c72d685b311..690f40b4f5b 100644 --- a/src/test/run-make/save-analysis/foo.rs +++ b/src/test/run-make/save-analysis/foo.rs @@ -1,4 +1,4 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -8,53 +8,332 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![ crate_name = "test" ] +#![allow(unstable)] #![feature(box_syntax)] -struct Foo { - f: int +extern crate graphviz; +// A simple rust project + +extern crate "flate" as myflate; + +use graphviz::maybe_owned_vec::MaybeOwnedVector; +use std::collections::{HashMap,HashSet}; +use std::cell::RefCell; +use std::old_io::stdio::println; + + +use sub::sub2 as msalias; +use sub::sub2; +use sub::sub2::nested_struct as sub_struct; +use std::num::Float; +use std::num::cast; +use std::num::{from_int,from_i8,from_i32}; + +use std::mem::size_of; + +static uni: &'static str = "Les Miséééééééérables"; +static yy: usize = 25us; + +static bob: Option<graphviz::maybe_owned_vec::MaybeOwnedVector<'static, isize>> = None; + +// buglink test - see issue #1337. + +fn test_alias<I: Iterator>(i: Option<<I as Iterator>::Item>) { + let s = sub_struct{ field2: 45u32, }; + + // import tests + fn foo(x: &Float) {} + let _: Option<u8> = from_i32(45); + + let x = 42us; + + myflate::deflate_bytes(&[]); + + let x = (3is, 4us); + let y = x.1; +} + +struct TupStruct(int, int, Box<str>); + +fn test_tup_struct(x: TupStruct) -> int { + x.1 +} + +mod sub { + pub mod sub2 { + use std::old_io::stdio::println; + pub mod sub3 { + use std::old_io::stdio::println; + pub fn hello() { + println("hello from module 3"); + } + } + pub fn hello() { + println("hello from a module"); + } + + pub struct nested_struct { + pub field2: u32, + } + + pub enum nested_enum { + Nest2 = 2, + Nest3 = 3 + } + } +} + +pub mod SameDir; +pub mod SubDir; + +#[path = "SameDir3.rs"] +pub mod SameDir2; + +struct nofields; + +#[derive(Clone)] +struct some_fields { + field1: u32, +} + +type SF = some_fields; + +trait SuperTrait { +} + +trait SomeTrait: SuperTrait { + fn Method(&self, x: u32) -> u32; + + fn prov(&self, x: u32) -> u32 { + println(x.to_string().as_slice()); + 42 + } + fn provided_method(&self) -> u32 { + 42 + } +} + +trait SubTrait: SomeTrait { + fn stat2(x: &Self) -> u32 { + 32 + } +} + +impl SomeTrait for some_fields { + fn Method(&self, x: u32) -> u32 { + println(x.to_string().as_slice()); + self.field1 + } +} + +impl SuperTrait for some_fields { +} + +impl SubTrait for some_fields {} + +impl some_fields { + fn stat(x: u32) -> u32 { + println(x.to_string().as_slice()); + 42 + } + fn stat2(x: &some_fields) -> u32 { + 42 + } + + fn align_to<T>(&mut self) { + } + + fn test(&mut self) { + self.align_to::<bool>(); + } } -impl Foo { - fn bar(&self) -> int { - println!("f is {}", self.f); - self.f +impl SuperTrait for nofields { +} +impl SomeTrait for nofields { + fn Method(&self, x: u32) -> u32 { + self.Method(x); + 43 + } + + fn provided_method(&self) -> u32 { + 21 } } -trait Tr { - fn tar(&self, x: Box<Foo>) -> Foo; +impl SubTrait for nofields {} + +impl SuperTrait for (Box<nofields>, Box<some_fields>) {} + +fn f_with_params<T: SomeTrait>(x: &T) { + x.Method(41); } -impl Tr for Foo { - fn tar(&self, x: Box<Foo>) -> Foo { - Foo{ f: self.f + x.f } +type MyType = Box<some_fields>; + +enum SomeEnum<'a> { + Ints(isize, isize), + Floats(f64, f64), + Strings(&'a str, &'a str, &'a str), + MyTypes(MyType, MyType) +} + +#[derive(Copy)] +enum SomeOtherEnum { + SomeConst1, + SomeConst2, + SomeConst3 +} + +enum SomeStructEnum { + EnumStruct{a:isize, b:isize}, + EnumStruct2{f1:MyType, f2:MyType}, + EnumStruct3{f1:MyType, f2:MyType, f3:SomeEnum<'static>} +} + +fn matchSomeEnum(val: SomeEnum) { + match val { + SomeEnum::Ints(int1, int2) => { println((int1+int2).to_string().as_slice()); } + SomeEnum::Floats(float1, float2) => { println((float2*float1).to_string().as_slice()); } + SomeEnum::Strings(_, _, s3) => { println(s3); } + SomeEnum::MyTypes(mt1, mt2) => { + println((mt1.field1 - mt2.field1).to_string().as_slice()); + } } } -trait Tr2<X, Y: Tr> { - fn squid(&self, y: &Y, z: Self) -> Box<X>; +fn matchSomeStructEnum(se: SomeStructEnum) { + match se { + SomeStructEnum::EnumStruct{a:a, ..} => println(a.to_string().as_slice()), + SomeStructEnum::EnumStruct2{f1:f1, f2:f_2} => println(f_2.field1.to_string().as_slice()), + SomeStructEnum::EnumStruct3{f1, ..} => println(f1.field1.to_string().as_slice()), + } } -impl Tr2<Foo, Foo> for Foo { - fn squid(&self, y: &Foo, z: Foo) -> Box<Foo> { - box Foo { f: y.f + z.f + self.f } + +fn matchSomeStructEnum2(se: SomeStructEnum) { + use SomeStructEnum::*; + match se { + EnumStruct{a: ref aaa, ..} => println(aaa.to_string().as_slice()), + EnumStruct2{f1, f2: f2} => println(f1.field1.to_string().as_slice()), + EnumStruct3{f1, f3: SomeEnum::Ints(_, _), f2} => println(f1.field1.to_string().as_slice()), + _ => {}, } } -enum En { - Var1, - Var2, - Var3(int, int, Foo) +fn matchSomeOtherEnum(val: SomeOtherEnum) { + use SomeOtherEnum::{SomeConst2, SomeConst3}; + match val { + SomeOtherEnum::SomeConst1 => { println("I'm const1."); } + SomeConst2 | SomeConst3 => { println("I'm const2 or const3."); } + } } -fn main() { - let x = Foo { f: 237 }; - let _f = x.bar(); - let en = En::Var2; +fn hello<X: SomeTrait>((z, a) : (u32, String), ex: X) { + SameDir2::hello(43); + + println(yy.to_string().as_slice()); + let (x, y): (u32, u32) = (5, 3); + println(x.to_string().as_slice()); + println(z.to_string().as_slice()); + let x: u32 = x; + println(x.to_string().as_slice()); + let x = "hello"; + println(x); + + let x = 32.0f32; + let _ = (x + ((x * x) + 1.0).sqrt()).ln(); - let _ = match en { - En::Var1 => x.bar(), - En::Var2 => 34, - En::Var3(x, y, f) => f.bar() + let s: Box<SomeTrait> = box some_fields {field1: 43}; + let s2: Box<some_fields> = box some_fields {field1: 43}; + let s3 = box nofields; + + s.Method(43); + s3.Method(43); + s2.Method(43); + + ex.prov(43); + + let y: u32 = 56; + // static method on struct + let r = some_fields::stat(y); + // trait static method, calls override + let r = SubTrait::stat2(&*s2); + // trait static method, calls default + let r = SubTrait::stat2(&*s3); + + let s4 = s3 as Box<SomeTrait>; + s4.Method(43); + + s4.provided_method(); + s2.prov(45); + + let closure = |&: x: u32, s: &SomeTrait| { + s.Method(23); + return x + y; + }; + + let z = closure(10, &*s); +} + +pub struct blah { + used_link_args: RefCell<[&'static str; 0]>, +} + +fn main() { // foo + let s = box some_fields {field1: 43}; + hello((43, "a".to_string()), *s); + sub::sub2::hello(); + sub2::sub3::hello(); + + let h = sub2::sub3::hello; + h(); + + // utf8 chars + let ut = "Les Miséééééééérables"; + + // For some reason, this pattern of macro_rules foiled our generated code + // avoiding strategy. + macro_rules! variable_str(($name:expr) => ( + some_fields { + field1: $name, + } + )); + let vs = variable_str!(32); + + let mut candidates: RefCell<HashMap<&'static str, &'static str>> = RefCell::new(HashMap::new()); + let _ = blah { + used_link_args: RefCell::new([]), }; + let s1 = nofields; + let s2 = SF { field1: 55}; + let s3: some_fields = some_fields{ field1: 55}; + let s4: msalias::nested_struct = sub::sub2::nested_struct{ field2: 55}; + let s4: msalias::nested_struct = sub2::nested_struct{ field2: 55}; + println(s2.field1.to_string().as_slice()); + let s5: MyType = box some_fields{ field1: 55}; + let s = SameDir::SameStruct{name: "Bob".to_string()}; + let s = SubDir::SubStruct{name:"Bob".to_string()}; + let s6: SomeEnum = SomeEnum::MyTypes(box s2.clone(), s5); + let s7: SomeEnum = SomeEnum::Strings("one", "two", "three"); + matchSomeEnum(s6); + matchSomeEnum(s7); + let s8: SomeOtherEnum = SomeOtherEnum::SomeConst2; + matchSomeOtherEnum(s8); + let s9: SomeStructEnum = + SomeStructEnum::EnumStruct2{f1: box some_fields{field1:10}, f2: box s2}; + matchSomeStructEnum(s9); +} + +impl Iterator for nofields { + type Item = (usize, usize); + + fn next(&mut self) -> Option<(usize, usize)> { + panic!() + } + + fn size_hint(&self) -> (usize, Option<usize>) { + panic!() + } } diff --git a/src/test/run-make/static-unwinding/main.rs b/src/test/run-make/static-unwinding/main.rs index bd88cb19aa7..6d10a247143 100644 --- a/src/test/run-make/static-unwinding/main.rs +++ b/src/test/run-make/static-unwinding/main.rs @@ -25,7 +25,7 @@ fn main() { Thread::scoped(move|| { let _a = A; lib::callback(|| panic!()); - 1i + 1 }).join().err().unwrap(); unsafe { diff --git a/src/test/run-pass-fulldeps/issue-16992.rs b/src/test/run-pass-fulldeps/issue-16992.rs index 563b8394963..9e3ad8ee283 100644 --- a/src/test/run-pass-fulldeps/issue-16992.rs +++ b/src/test/run-pass-fulldeps/issue-16992.rs @@ -19,8 +19,8 @@ use syntax::ext::base::ExtCtxt; #[allow(dead_code)] fn foobar(cx: &mut ExtCtxt) { - quote_expr!(cx, 1i); - quote_expr!(cx, 2i); + quote_expr!(cx, 1); + quote_expr!(cx, 2); } fn main() { } diff --git a/src/test/run-pass-fulldeps/macro-crate-does-hygiene-work.rs b/src/test/run-pass-fulldeps/macro-crate-does-hygiene-work.rs index a8762234ad9..497afae6189 100644 --- a/src/test/run-pass-fulldeps/macro-crate-does-hygiene-work.rs +++ b/src/test/run-pass-fulldeps/macro-crate-does-hygiene-work.rs @@ -20,9 +20,9 @@ extern crate macro_crate_test; fn main() { - let x = 3i; + let x = 3; assert_eq!(3, identity!(x)); assert_eq!(6, identity!(x+x)); - let x = 4i; + let x = 4; assert_eq!(4, identity!(x)); } diff --git a/src/test/run-pass-fulldeps/quote-unused-sp-no-warning.rs b/src/test/run-pass-fulldeps/quote-unused-sp-no-warning.rs index 2d5bbd43e82..848ea738ed7 100644 --- a/src/test/run-pass-fulldeps/quote-unused-sp-no-warning.rs +++ b/src/test/run-pass-fulldeps/quote-unused-sp-no-warning.rs @@ -19,7 +19,7 @@ extern crate syntax; use syntax::ext::base::ExtCtxt; fn test(cx: &mut ExtCtxt) { - let foo = 10i; + let foo = 10; let _e = quote_expr!(cx, $foo); } diff --git a/src/test/run-pass/assert-eq-macro-success.rs b/src/test/run-pass/assert-eq-macro-success.rs index 8771ed7a742..e55a2d39cbf 100644 --- a/src/test/run-pass/assert-eq-macro-success.rs +++ b/src/test/run-pass/assert-eq-macro-success.rs @@ -15,7 +15,7 @@ struct Point { x : int } pub fn main() { - assert_eq!(14i,14i); + assert_eq!(14,14); assert_eq!("abc".to_string(),"abc".to_string()); assert_eq!(box Point{x:34},box Point{x:34}); assert_eq!(&Point{x:34},&Point{x:34}); diff --git a/src/test/run-pass/associated-types-binding-in-trait.rs b/src/test/run-pass/associated-types-binding-in-trait.rs new file mode 100644 index 00000000000..b47b0109bdf --- /dev/null +++ b/src/test/run-pass/associated-types-binding-in-trait.rs @@ -0,0 +1,44 @@ +// Copyright 2015 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test a case where the associated type binding (to `bool`, in this +// case) is derived from the trait definition. Issue #21636. + +use std::vec; + +pub trait BitIter { + type Iter: Iterator<Item=bool>; + fn bit_iter(self) -> <Self as BitIter>::Iter; +} + +impl BitIter for Vec<bool> { + type Iter = vec::IntoIter<bool>; + fn bit_iter(self) -> <Self as BitIter>::Iter { + self.into_iter() + } +} + +fn count<T>(arg: T) -> usize + where T: BitIter +{ + let mut sum = 0; + for i in arg.bit_iter() { + if i { + sum += 1; + } + } + sum +} + +fn main() { + let v = vec![true, false, true]; + let c = count(v); + assert_eq!(c, 2); +} diff --git a/src/test/run-pass/associated-types-binding-in-where-clause.rs b/src/test/run-pass/associated-types-binding-in-where-clause.rs index caf7d31a5fd..2f9a0b328b5 100644 --- a/src/test/run-pass/associated-types-binding-in-where-clause.rs +++ b/src/test/run-pass/associated-types-binding-in-where-clause.rs @@ -37,7 +37,7 @@ fn foo_uint<I: Foo<A=uint>>(x: I) -> uint { } pub fn main() { - let a = 42i; + let a = 42; foo_uint(a); let a = 'a'; diff --git a/src/test/run-pass/associated-types-bound.rs b/src/test/run-pass/associated-types-bound.rs index c34a19e1d82..9f97d69ce3f 100644 --- a/src/test/run-pass/associated-types-bound.rs +++ b/src/test/run-pass/associated-types-bound.rs @@ -8,44 +8,44 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// Test equality constraints on associated types in a where clause. +// Test equality constrai32s on associated types in a where clause. -pub trait ToInt { - fn to_int(&self) -> int; +pub trait ToI32 { + fn to_i32(&self) -> i32; } -impl ToInt for int { - fn to_int(&self) -> int { *self } +impl ToI32 for i32 { + fn to_i32(&self) -> i32 { *self } } -impl ToInt for uint { - fn to_int(&self) -> int { *self as int } +impl ToI32 for u32 { + fn to_i32(&self) -> i32 { *self as i32 } } -pub trait GetToInt +pub trait GetToI32 { - type R : ToInt; + type R : ToI32; - fn get(&self) -> <Self as GetToInt>::R; + fn get(&self) -> <Self as GetToI32>::R; } -impl GetToInt for int { - type R = int; - fn get(&self) -> int { *self } +impl GetToI32 for i32 { + type R = i32; + fn get(&self) -> i32 { *self } } -impl GetToInt for uint { - type R = uint; - fn get(&self) -> uint { *self } +impl GetToI32 for u32 { + type R = u32; + fn get(&self) -> u32 { *self } } -fn foo<G>(g: G) -> int - where G : GetToInt +fn foo<G>(g: G) -> i32 + where G : GetToI32 { - ToInt::to_int(&g.get()) + ToI32::to_i32(&g.get()) } pub fn main() { - assert_eq!(foo(22i), 22i); - assert_eq!(foo(22u), 22i); + assert_eq!(foo(22i32), 22); + assert_eq!(foo(22u32), 22); } diff --git a/src/test/run-pass/associated-types-cc.rs b/src/test/run-pass/associated-types-cc.rs index 58aa351ba9c..948192f4fc0 100644 --- a/src/test/run-pass/associated-types-cc.rs +++ b/src/test/run-pass/associated-types-cc.rs @@ -22,5 +22,5 @@ fn foo<B:Bar>(b: B) -> <B as Bar>::T { } fn main() { - println!("{}", foo(3i)); + println!("{}", foo(3)); } diff --git a/src/test/run-pass/associated-types-nested-projections.rs b/src/test/run-pass/associated-types-nested-projections.rs index a907b9fcde5..e3227613159 100644 --- a/src/test/run-pass/associated-types-nested-projections.rs +++ b/src/test/run-pass/associated-types-nested-projections.rs @@ -45,6 +45,6 @@ fn bar<T, I, X>(x: X) where } fn main() { - foo(&[0i, 1, 2]); - bar(&[0i, 1, 2]); + foo(&[0, 1, 2]); + bar(&[0, 1, 2]); } diff --git a/src/test/run-pass/associated-types-ref-in-struct-literal.rs b/src/test/run-pass/associated-types-ref-in-struct-literal.rs index b51d44a0c24..022c8f4cd01 100644 --- a/src/test/run-pass/associated-types-ref-in-struct-literal.rs +++ b/src/test/run-pass/associated-types-ref-in-struct-literal.rs @@ -24,6 +24,6 @@ struct Thing<F: Foo> { } fn main() { - let thing = Thing{a: 1i, b: 2i}; + let thing = Thing{a: 1, b: 2}; assert_eq!(thing.a + 1, thing.b); } diff --git a/src/test/run-pass/associated-types-return.rs b/src/test/run-pass/associated-types-return.rs index b9b6d14f8a0..72290921854 100644 --- a/src/test/run-pass/associated-types-return.rs +++ b/src/test/run-pass/associated-types-return.rs @@ -42,11 +42,11 @@ fn foo2<I: Foo>(x: I) -> <I as Foo>::A { } pub fn main() { - let a = 42i; + let a = 42; assert!(foo2(a) == 42u); let a = Bar; - assert!(foo2(a) == 43i); + assert!(foo2(a) == 43); let a = 'a'; foo1(a); diff --git a/src/test/run-pass/associated-types-sugar-path.rs b/src/test/run-pass/associated-types-sugar-path.rs index 880554b61b2..ea1df6658fd 100644 --- a/src/test/run-pass/associated-types-sugar-path.rs +++ b/src/test/run-pass/associated-types-sugar-path.rs @@ -40,5 +40,5 @@ impl<T: Foo> C for B<T> { } pub fn main() { - let z: uint = bar(2i, 4u); + let z: uint = bar(2, 4u); } diff --git a/src/test/run-pass/auto-instantiate.rs b/src/test/run-pass/auto-instantiate.rs index 0e2f6ef056e..cd4c66cb321 100644 --- a/src/test/run-pass/auto-instantiate.rs +++ b/src/test/run-pass/auto-instantiate.rs @@ -15,6 +15,6 @@ struct Triple { x: int, y: int, z: int } fn f<T,U>(x: T, y: U) -> Pair<T, U> { return Pair {a: x, b: y}; } pub fn main() { - println!("{}", f(Triple {x: 3, y: 4, z: 5}, 4i).a.x); - println!("{}", f(5i, 6i).a); + println!("{}", f(Triple {x: 3, y: 4, z: 5}, 4).a.x); + println!("{}", f(5, 6).a); } diff --git a/src/test/run-pass/auto-loop.rs b/src/test/run-pass/auto-loop.rs index 88884dfeb50..e5f4d078749 100644 --- a/src/test/run-pass/auto-loop.rs +++ b/src/test/run-pass/auto-loop.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let mut sum = 0i; + let mut sum = 0; let xs = vec!(1, 2, 3, 4, 5); for x in xs.iter() { sum += *x; diff --git a/src/test/run-pass/auto-ref-sliceable.rs b/src/test/run-pass/auto-ref-sliceable.rs index fd3ede07e21..652f21c2ae3 100644 --- a/src/test/run-pass/auto-ref-sliceable.rs +++ b/src/test/run-pass/auto-ref-sliceable.rs @@ -20,7 +20,7 @@ impl<T> Pushable<T> for Vec<T> { } pub fn main() { - let mut v = vec!(1i); + let mut v = vec!(1); v.push_val(2); v.push_val(3); assert_eq!(v, vec!(1, 2, 3)); diff --git a/src/test/run-pass/backtrace.rs b/src/test/run-pass/backtrace.rs index af1cc3b1f4d..e9a3ab6be35 100644 --- a/src/test/run-pass/backtrace.rs +++ b/src/test/run-pass/backtrace.rs @@ -21,7 +21,7 @@ use std::ops::{Drop, FnMut, FnOnce}; #[inline(never)] fn foo() { - let _v = vec![1i, 2, 3]; + let _v = vec![1, 2, 3]; if os::getenv("IS_TEST").is_some() { panic!() } @@ -77,7 +77,7 @@ fn runtest(me: &str) { assert!(!out.status.success()); let s = str::from_utf8(out.error.as_slice()).unwrap(); let mut i = 0; - for _ in 0i..2 { + for _ in 0..2 { i += s[i + 10..].find_str("stack backtrace").unwrap() + 10; } assert!(s[i + 10..].find_str("stack backtrace").is_none(), diff --git a/src/test/run-pass/binary-minus-without-space.rs b/src/test/run-pass/binary-minus-without-space.rs index 8235b91273b..dc3b142f233 100644 --- a/src/test/run-pass/binary-minus-without-space.rs +++ b/src/test/run-pass/binary-minus-without-space.rs @@ -11,6 +11,6 @@ // Check that issue #954 stays fixed pub fn main() { - match -1i { -1 => {}, _ => panic!("wat") } - assert_eq!(1i-1, 0i); + match -1 { -1 => {}, _ => panic!("wat") } + assert_eq!(1-1, 0); } diff --git a/src/test/run-pass/bitv-perf-test.rs b/src/test/run-pass/bitv-perf-test.rs index 167d0ace159..b6d428924e3 100644 --- a/src/test/run-pass/bitv-perf-test.rs +++ b/src/test/run-pass/bitv-perf-test.rs @@ -22,5 +22,5 @@ fn bitv_test() { } pub fn main() { - for _ in 0i..10000 { bitv_test(); } + for _ in 0..10000 { bitv_test(); } } diff --git a/src/test/run-pass/bitwise.rs b/src/test/run-pass/bitwise.rs index 251804e214b..8a57279e866 100644 --- a/src/test/run-pass/bitwise.rs +++ b/src/test/run-pass/bitwise.rs @@ -33,7 +33,7 @@ fn general() { assert_eq!(0xf0i | 0xf, 0xff); assert_eq!(0xfi << 4, 0xf0); assert_eq!(0xf0i >> 4, 0xf); - assert_eq!(-16i >> 2, -4); + assert_eq!(-16 >> 2, -4); assert_eq!(0b1010_1010i | 0b0101_0101, 0xff); } diff --git a/src/test/run-pass/block-expr-precedence.rs b/src/test/run-pass/block-expr-precedence.rs index 31d0d52f8b4..ace372dd2d3 100644 --- a/src/test/run-pass/block-expr-precedence.rs +++ b/src/test/run-pass/block-expr-precedence.rs @@ -58,9 +58,9 @@ pub fn main() { let num = 12; - assert_eq!(if (true) { 12i } else { 12 } - num, 0); - assert_eq!(12i - if (true) { 12i } else { 12 }, 0); - if (true) { 12i; } {-num}; - if (true) { 12i; }; {-num}; - if (true) { 12i; };;; -num; + assert_eq!(if (true) { 12 } else { 12 } - num, 0); + assert_eq!(12 - if (true) { 12 } else { 12 }, 0); + if (true) { 12; } {-num}; + if (true) { 12; }; {-num}; + if (true) { 12; };;; -num; } diff --git a/src/test/run-pass/block-iter-1.rs b/src/test/run-pass/block-iter-1.rs index 972bde5f29a..b5bd4d90c2e 100644 --- a/src/test/run-pass/block-iter-1.rs +++ b/src/test/run-pass/block-iter-1.rs @@ -11,8 +11,8 @@ fn iter_vec<T, F>(v: Vec<T> , mut f: F) where F: FnMut(&T) { for x in v.iter() { f(x); } } pub fn main() { - let v = vec!(1i, 2, 3, 4, 5, 6, 7); - let mut odds = 0i; + let v = vec![1i32, 2, 3, 4, 5, 6, 7]; + let mut odds = 0i32; iter_vec(v, |i| { if *i % 2 == 1 { odds += 1; diff --git a/src/test/run-pass/block-iter-2.rs b/src/test/run-pass/block-iter-2.rs index 1032fb486a1..348d9df6e7e 100644 --- a/src/test/run-pass/block-iter-2.rs +++ b/src/test/run-pass/block-iter-2.rs @@ -11,7 +11,7 @@ fn iter_vec<T, F>(v: Vec<T>, mut f: F) where F: FnMut(&T) { for x in v.iter() { f(x); } } pub fn main() { - let v = vec!(1i, 2, 3, 4, 5); + let v = vec![1i32, 2, 3, 4, 5]; let mut sum = 0; iter_vec(v.clone(), |i| { iter_vec(v.clone(), |j| { diff --git a/src/test/run-pass/borrow-tuple-fields.rs b/src/test/run-pass/borrow-tuple-fields.rs index a151a837f77..2e5688d8b74 100644 --- a/src/test/run-pass/borrow-tuple-fields.rs +++ b/src/test/run-pass/borrow-tuple-fields.rs @@ -11,13 +11,13 @@ struct Foo(int, int); fn main() { - let x = (1i, 2i); + let x = (1, 2); let a = &x.0; let b = &x.0; assert_eq!(*a, 1); assert_eq!(*b, 1); - let mut x = (1i, 2i); + let mut x = (1, 2); { let a = &x.0; let b = &mut x.1; @@ -28,13 +28,13 @@ fn main() { assert_eq!(x.1, 5); - let x = Foo(1i, 2i); + let x = Foo(1, 2); let a = &x.0; let b = &x.0; assert_eq!(*a, 1); assert_eq!(*b, 1); - let mut x = Foo(1i, 2i); + let mut x = Foo(1, 2); { let a = &x.0; let b = &mut x.1; diff --git a/src/test/run-pass/borrowck-closures-two-imm.rs b/src/test/run-pass/borrowck-closures-two-imm.rs index 33e4294366f..df8dbdd03c7 100644 --- a/src/test/run-pass/borrowck-closures-two-imm.rs +++ b/src/test/run-pass/borrowck-closures-two-imm.rs @@ -14,28 +14,28 @@ // that the main function can read the variable too while // the closures are in scope. Issue #6801. -fn a() -> int { - let mut x = 3i; +fn a() -> i32 { + let mut x = 3i32; x += 1; let c1 = |&:| x * 4; let c2 = |&:| x * 5; c1() * c2() * x } -fn get(x: &int) -> int { +fn get(x: &i32) -> i32 { *x * 4 } -fn b() -> int { - let mut x = 3; +fn b() -> i32 { + let mut x = 3i32; x += 1; let c1 = |&:| get(&x); let c2 = |&:| get(&x); c1() * c2() * x } -fn c() -> int { - let mut x = 3; +fn c() -> i32 { + let mut x = 3i32; x += 1; let c1 = |&:| x * 5; let c2 = |&:| get(&x); diff --git a/src/test/run-pass/borrowck-fixed-length-vecs.rs b/src/test/run-pass/borrowck-fixed-length-vecs.rs index 71c8936570a..ee561fdb0be 100644 --- a/src/test/run-pass/borrowck-fixed-length-vecs.rs +++ b/src/test/run-pass/borrowck-fixed-length-vecs.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let x = [22i]; + let x = [22]; let y = &x[0]; assert_eq!(*y, 22); } diff --git a/src/test/run-pass/borrowck-freeze-frozen-mut.rs b/src/test/run-pass/borrowck-freeze-frozen-mut.rs index 21f5d0e6c14..30a921c9bd2 100644 --- a/src/test/run-pass/borrowck-freeze-frozen-mut.rs +++ b/src/test/run-pass/borrowck-freeze-frozen-mut.rs @@ -19,7 +19,7 @@ fn get<'a, T>(ms: &'a MutSlice<'a, T>, index: uint) -> &'a T { } pub fn main() { - let mut data = [1i, 2, 3]; + let mut data = [1, 2, 3]; { let slice = MutSlice { data: &mut data }; slice.data[0] += 4; diff --git a/src/test/run-pass/borrowck-pat-reassign-no-binding.rs b/src/test/run-pass/borrowck-pat-reassign-no-binding.rs index 6136bc90fd4..4ccbf6b5b0f 100644 --- a/src/test/run-pass/borrowck-pat-reassign-no-binding.rs +++ b/src/test/run-pass/borrowck-pat-reassign-no-binding.rs @@ -14,7 +14,7 @@ pub fn main() { None => { // It is ok to reassign x here, because there is in // fact no outstanding loan of x! - x = Some(0i); + x = Some(0); } Some(_) => { } } diff --git a/src/test/run-pass/borrowed-ptr-pattern-infallible.rs b/src/test/run-pass/borrowed-ptr-pattern-infallible.rs index 55ae6d3bebf..e57c001ea05 100644 --- a/src/test/run-pass/borrowed-ptr-pattern-infallible.rs +++ b/src/test/run-pass/borrowed-ptr-pattern-infallible.rs @@ -10,7 +10,7 @@ pub fn main() { - let (&x, &y) = (&3i, &'a'); + let (&x, &y) = (&3, &'a'); assert_eq!(x, 3); assert_eq!(y, 'a'); } diff --git a/src/test/run-pass/borrowed-ptr-pattern.rs b/src/test/run-pass/borrowed-ptr-pattern.rs index 3636d4d769d..7ccb40c8e7b 100644 --- a/src/test/run-pass/borrowed-ptr-pattern.rs +++ b/src/test/run-pass/borrowed-ptr-pattern.rs @@ -15,6 +15,6 @@ fn foo<T:Clone>(x: &T) -> T{ } pub fn main() { - assert_eq!(foo(&3i), 3i); + assert_eq!(foo(&3), 3); assert_eq!(foo(&'a'), 'a'); } diff --git a/src/test/run-pass/break.rs b/src/test/run-pass/break.rs index 89745bd167c..bcfb8f6f914 100644 --- a/src/test/run-pass/break.rs +++ b/src/test/run-pass/break.rs @@ -9,12 +9,12 @@ // except according to those terms. pub fn main() { - let mut i = 0i; + let mut i = 0; while i < 20 { i += 1; if i == 10 { break; } } assert_eq!(i, 10); loop { i += 1; if i == 20 { break; } } assert_eq!(i, 20); - let xs = [1i, 2, 3, 4, 5, 6]; + let xs = [1, 2, 3, 4, 5, 6]; for x in xs.iter() { if *x == 3 { break; } assert!((*x <= 3)); } @@ -25,7 +25,7 @@ pub fn main() { i += 1; if i % 2 == 0 { continue; } assert!((i % 2 != 0)); if i >= 10 { break; } } - let ys = vec!(1i, 2, 3, 4, 5, 6); + let ys = vec!(1, 2, 3, 4, 5, 6); for x in ys.iter() { if *x % 2 == 0 { continue; } assert!((*x % 2 != 0)); diff --git a/src/test/run-pass/bug-7183-generics.rs b/src/test/run-pass/bug-7183-generics.rs index bf8d303f341..a3bb02d1d00 100644 --- a/src/test/run-pass/bug-7183-generics.rs +++ b/src/test/run-pass/bug-7183-generics.rs @@ -34,11 +34,11 @@ impl<T: Speak> Speak for Option<T> { pub fn main() { - assert_eq!(3i.hi(), "hello: 3".to_string()); - assert_eq!(Some(Some(3i)).hi(), + assert_eq!(3.hi(), "hello: 3".to_string()); + assert_eq!(Some(Some(3)).hi(), "something!something!hello: 3".to_string()); assert_eq!(None::<int>.hi(), "hello - none".to_string()); assert_eq!(Some(None::<int>).hi(), "something!hello - none".to_string()); - assert_eq!(Some(3i).hi(), "something!hello: 3".to_string()); + assert_eq!(Some(3).hi(), "something!hello: 3".to_string()); } diff --git a/src/test/run-pass/builtin-superkinds-capabilities-transitive.rs b/src/test/run-pass/builtin-superkinds-capabilities-transitive.rs index 365670db6f9..3df9dd25d86 100644 --- a/src/test/run-pass/builtin-superkinds-capabilities-transitive.rs +++ b/src/test/run-pass/builtin-superkinds-capabilities-transitive.rs @@ -28,6 +28,6 @@ fn foo<T: Foo>(val: T, chan: Sender<T>) { pub fn main() { let (tx, rx) = channel(); - foo(31337i, tx); - assert!(rx.recv().unwrap() == 31337i); + foo(31337, tx); + assert!(rx.recv().unwrap() == 31337); } diff --git a/src/test/run-pass/builtin-superkinds-capabilities-xc.rs b/src/test/run-pass/builtin-superkinds-capabilities-xc.rs index 126088d7f9d..52b826393e9 100644 --- a/src/test/run-pass/builtin-superkinds-capabilities-xc.rs +++ b/src/test/run-pass/builtin-superkinds-capabilities-xc.rs @@ -31,6 +31,6 @@ fn foo<T: RequiresRequiresShareAndSend>(val: T, chan: Sender<T>) { pub fn main() { let (tx, rx): (Sender<X<int>>, Receiver<X<int>>) = channel(); - foo(X(31337i), tx); - assert!(rx.recv().unwrap() == X(31337i)); + foo(X(31337), tx); + assert!(rx.recv().unwrap() == X(31337)); } diff --git a/src/test/run-pass/builtin-superkinds-capabilities.rs b/src/test/run-pass/builtin-superkinds-capabilities.rs index 7f4a2398f54..034e5ff2d3a 100644 --- a/src/test/run-pass/builtin-superkinds-capabilities.rs +++ b/src/test/run-pass/builtin-superkinds-capabilities.rs @@ -24,6 +24,6 @@ fn foo<T: Foo>(val: T, chan: Sender<T>) { pub fn main() { let (tx, rx): (Sender<int>, Receiver<int>) = channel(); - foo(31337i, tx); - assert!(rx.recv().unwrap() == 31337i); + foo(31337, tx); + assert!(rx.recv().unwrap() == 31337); } diff --git a/src/test/run-pass/builtin-superkinds-self-type.rs b/src/test/run-pass/builtin-superkinds-self-type.rs index d0db2542ccc..1b3070ba3b0 100644 --- a/src/test/run-pass/builtin-superkinds-self-type.rs +++ b/src/test/run-pass/builtin-superkinds-self-type.rs @@ -23,6 +23,6 @@ impl <T: Send> Foo for T { } pub fn main() { let (tx, rx) = channel(); - 1193182i.foo(tx); - assert!(rx.recv().unwrap() == 1193182i); + 1193182.foo(tx); + assert!(rx.recv().unwrap() == 1193182); } diff --git a/src/test/run-pass/cci_iter_exe.rs b/src/test/run-pass/cci_iter_exe.rs index 7191d5078b8..e4b26ba74be 100644 --- a/src/test/run-pass/cci_iter_exe.rs +++ b/src/test/run-pass/cci_iter_exe.rs @@ -15,7 +15,7 @@ extern crate cci_iter_lib; pub fn main() { //let bt0 = sys::rusti::frame_address(1u32); //println!("%?", bt0); - cci_iter_lib::iter(&[1i, 2, 3], |i| { + cci_iter_lib::iter(&[1, 2, 3], |i| { println!("{}", *i); //assert!(bt0 == sys::rusti::frame_address(2u32)); }) diff --git a/src/test/run-pass/class-poly-methods.rs b/src/test/run-pass/class-poly-methods.rs index d94547a4dda..4f94673a2c0 100644 --- a/src/test/run-pass/class-poly-methods.rs +++ b/src/test/run-pass/class-poly-methods.rs @@ -36,7 +36,7 @@ pub fn main() { let mut kitty = cat(1000u, 2, vec!("tabby".to_string())); assert_eq!(nyan.how_hungry, 99); assert_eq!(kitty.how_hungry, 2); - nyan.speak(vec!(1i,2,3)); + nyan.speak(vec!(1,2,3)); assert_eq!(nyan.meow_count(), 55u); kitty.speak(vec!("meow".to_string(), "mew".to_string(), "purr".to_string(), "chirp".to_string())); assert_eq!(kitty.meow_count(), 1004u); diff --git a/src/test/run-pass/cleanup-rvalue-scopes.rs b/src/test/run-pass/cleanup-rvalue-scopes.rs index bbfe0e6a18d..b39a4d7f685 100644 --- a/src/test/run-pass/cleanup-rvalue-scopes.rs +++ b/src/test/run-pass/cleanup-rvalue-scopes.rs @@ -110,7 +110,7 @@ pub fn main() { end_of_block!(ref _x, AddFlags(1)); end_of_block!(AddFlags { bits: ref _x }, AddFlags(1)); end_of_block!(&AddFlags { bits }, &AddFlags(1)); - end_of_block!((_, ref _y), (AddFlags(1), 22i)); + end_of_block!((_, ref _y), (AddFlags(1), 22)); end_of_block!(box ref _x, box AddFlags(1)); end_of_block!(box _x, box AddFlags(1)); end_of_block!(_, { { check_flags(0); &AddFlags(1) } }); @@ -120,7 +120,7 @@ pub fn main() { // LHS does not create a ref binding, so temporary lives as long // as statement, and we do not move the AddFlags out: end_of_stmt!(_, AddFlags(1)); - end_of_stmt!((_, _), (AddFlags(1), 22i)); + end_of_stmt!((_, _), (AddFlags(1), 22)); // `&` operator appears inside an arg to a function, // so it is not prolonged: diff --git a/src/test/run-pass/closure-inference2.rs b/src/test/run-pass/closure-inference2.rs index 03b10b881f7..c0877568b72 100644 --- a/src/test/run-pass/closure-inference2.rs +++ b/src/test/run-pass/closure-inference2.rs @@ -12,6 +12,6 @@ pub fn main() { let f = {|&: i| i}; - assert_eq!(f(2i), 2i); - assert_eq!(f(5i), 5i); + assert_eq!(f(2), 2); + assert_eq!(f(5), 5); } diff --git a/src/test/run-pass/coerce-match-calls.rs b/src/test/run-pass/coerce-match-calls.rs index 0ff28b471a3..34c9875f1de 100644 --- a/src/test/run-pass/coerce-match-calls.rs +++ b/src/test/run-pass/coerce-match-calls.rs @@ -13,9 +13,9 @@ use std::boxed::Box; pub fn main() { - let _: Box<[int]> = if true { Box::new([1i, 2, 3]) } else { Box::new([1i]) }; + let _: Box<[int]> = if true { Box::new([1, 2, 3]) } else { Box::new([1]) }; - let _: Box<[int]> = match true { true => Box::new([1i, 2, 3]), false => Box::new([1i]) }; + let _: Box<[int]> = match true { true => Box::new([1, 2, 3]), false => Box::new([1]) }; // Check we don't get over-keen at propagating coercions in the case of casts. let x = if true { 42 } else { 42u8 } as u16; diff --git a/src/test/run-pass/coerce-match.rs b/src/test/run-pass/coerce-match.rs index 0992ee97d06..098a08b0787 100644 --- a/src/test/run-pass/coerce-match.rs +++ b/src/test/run-pass/coerce-match.rs @@ -14,9 +14,9 @@ #![feature(box_syntax)] pub fn main() { - let _: Box<[int]> = if true { box [1i, 2, 3] } else { box [1i] }; + let _: Box<[int]> = if true { box [1, 2, 3] } else { box [1] }; - let _: Box<[int]> = match true { true => box [1i, 2, 3], false => box [1i] }; + let _: Box<[int]> = match true { true => box [1, 2, 3], false => box [1] }; // Check we don't get over-keen at propagating coercions in the case of casts. let x = if true { 42 } else { 42u8 } as u16; diff --git a/src/test/run-pass/complex.rs b/src/test/run-pass/complex.rs index 34292453ec4..f8c8ac20d72 100644 --- a/src/test/run-pass/complex.rs +++ b/src/test/run-pass/complex.rs @@ -35,8 +35,8 @@ fn foo(x: int) -> int { } pub fn main() { - let x: int = 2i + 2; + let x: int = 2 + 2; println!("{}", x); println!("hello, world"); - println!("{}", 10i); + println!("{}", 10); } diff --git a/src/test/run-pass/concat.rs b/src/test/run-pass/concat.rs index d78f948edc5..2a8443167d0 100644 --- a/src/test/run-pass/concat.rs +++ b/src/test/run-pass/concat.rs @@ -15,12 +15,12 @@ pub fn main() { assert_eq!(concat!("qux", "quux",).to_string(), "quxquux".to_string()); assert_eq!( - concat!(1, 2i, 3u, 4f32, 4.0, 'a', true), + concat!(1, 2, 3u, 4f32, 4.0, 'a', true), "12344.0atrue" ); assert!(match "12344.0atrue" { - concat!(1, 2i, 3u, 4f32, 4.0, 'a', true) => true, + concat!(1, 2, 3u, 4f32, 4.0, 'a', true) => true, _ => false }) } diff --git a/src/test/run-pass/const-binops.rs b/src/test/run-pass/const-binops.rs index 11590ceb19d..1268fc4e435 100644 --- a/src/test/run-pass/const-binops.rs +++ b/src/test/run-pass/const-binops.rs @@ -52,27 +52,27 @@ static V: int = 1 << 3; static W: int = 1024 >> 4; static X: uint = 1024 >> 4; -static Y: bool = 1i == 1; +static Y: bool = 1 == 1; static Z: bool = 1.0f64 == 1.0; -static AA: bool = 1i <= 2; -static AB: bool = -1i <= 2; +static AA: bool = 1 <= 2; +static AB: bool = -1 <= 2; static AC: bool = 1.0f64 <= 2.0; -static AD: bool = 1i < 2; -static AE: bool = -1i < 2; +static AD: bool = 1 < 2; +static AE: bool = -1 < 2; static AF: bool = 1.0f64 < 2.0; -static AG: bool = 1i != 2; -static AH: bool = -1i != 2; +static AG: bool = 1 != 2; +static AH: bool = -1 != 2; static AI: bool = 1.0f64 != 2.0; -static AJ: bool = 2i >= 1; -static AK: bool = 2i >= -2; +static AJ: bool = 2 >= 1; +static AK: bool = 2 >= -2; static AL: bool = 1.0f64 >= -2.0; -static AM: bool = 2i > 1; -static AN: bool = 2i > -2; +static AM: bool = 2 > 1; +static AN: bool = 2 > -2; static AO: bool = 1.0f64 > -2.0; pub fn main() { diff --git a/src/test/run-pass/const-bound.rs b/src/test/run-pass/const-bound.rs index 3a6973fe61c..e6a280a91d7 100644 --- a/src/test/run-pass/const-bound.rs +++ b/src/test/run-pass/const-bound.rs @@ -25,5 +25,5 @@ pub fn main() { foo(F{field: 42}); foo((1, 2u)); foo(@1);*/ - foo(box 1i); + foo(box 1); } diff --git a/src/test/run-pass/const-expr-in-vec-repeat.rs b/src/test/run-pass/const-expr-in-vec-repeat.rs index d692f3a87e4..0b097c0b060 100644 --- a/src/test/run-pass/const-expr-in-vec-repeat.rs +++ b/src/test/run-pass/const-expr-in-vec-repeat.rs @@ -13,6 +13,6 @@ pub fn main() { const FOO: uint = 2; - let _v = [0i; FOO*3*2/2]; + let _v = [0; FOO*3*2/2]; } diff --git a/src/test/run-pass/consts-in-patterns.rs b/src/test/run-pass/consts-in-patterns.rs index 87b7fcad385..e8f4948a165 100644 --- a/src/test/run-pass/consts-in-patterns.rs +++ b/src/test/run-pass/consts-in-patterns.rs @@ -12,11 +12,11 @@ const FOO: int = 10; const BAR: int = 3; pub fn main() { - let x: int = 3i; + let x: int = 3; let y = match x { - FOO => 1i, - BAR => 2i, - _ => 3i + FOO => 1, + BAR => 2, + _ => 3 }; assert_eq!(y, 2); } diff --git a/src/test/run-pass/deref-lval.rs b/src/test/run-pass/deref-lval.rs index ead0683b870..41c74250b3b 100644 --- a/src/test/run-pass/deref-lval.rs +++ b/src/test/run-pass/deref-lval.rs @@ -14,7 +14,7 @@ use std::cell::Cell; pub fn main() { - let x = box Cell::new(5i); - x.set(1000i); + let x = box Cell::new(5); + x.set(1000); println!("{}", x.get()); } diff --git a/src/test/run-pass/deref-rc.rs b/src/test/run-pass/deref-rc.rs index 03697875d56..fbb8a3a1720 100644 --- a/src/test/run-pass/deref-rc.rs +++ b/src/test/run-pass/deref-rc.rs @@ -11,6 +11,6 @@ use std::rc::Rc; fn main() { - let x = Rc::new([1i, 2, 3, 4]); + let x = Rc::new([1, 2, 3, 4]); assert!(*x == [1, 2, 3, 4]); } diff --git a/src/test/run-pass/deriving-clone-generic-enum.rs b/src/test/run-pass/deriving-clone-generic-enum.rs index e8e65dcb8a9..e174ffae75d 100644 --- a/src/test/run-pass/deriving-clone-generic-enum.rs +++ b/src/test/run-pass/deriving-clone-generic-enum.rs @@ -16,5 +16,5 @@ enum E<T,U> { } pub fn main() { - let _ = E::A::<int, int>(1i).clone(); + let _ = E::A::<int, int>(1).clone(); } diff --git a/src/test/run-pass/deriving-clone-generic-struct.rs b/src/test/run-pass/deriving-clone-generic-struct.rs index d340fe9d3fb..329c7dab3eb 100644 --- a/src/test/run-pass/deriving-clone-generic-struct.rs +++ b/src/test/run-pass/deriving-clone-generic-struct.rs @@ -16,5 +16,5 @@ struct S<T> { } pub fn main() { - let _ = S { foo: (), bar: (), baz: 1i }.clone(); + let _ = S { foo: (), bar: (), baz: 1 }.clone(); } diff --git a/src/test/run-pass/deriving-clone-generic-tuple-struct.rs b/src/test/run-pass/deriving-clone-generic-tuple-struct.rs index ecf1fdc6e5f..bb07b08859f 100644 --- a/src/test/run-pass/deriving-clone-generic-tuple-struct.rs +++ b/src/test/run-pass/deriving-clone-generic-tuple-struct.rs @@ -12,5 +12,5 @@ struct S<T>(T, ()); pub fn main() { - let _ = S(1i, ()).clone(); + let _ = S(1, ()).clone(); } diff --git a/src/test/run-pass/deriving-cmp-generic-enum.rs b/src/test/run-pass/deriving-cmp-generic-enum.rs index 04cb3b7c076..b3194d5820a 100644 --- a/src/test/run-pass/deriving-cmp-generic-enum.rs +++ b/src/test/run-pass/deriving-cmp-generic-enum.rs @@ -19,10 +19,10 @@ enum E<T> { pub fn main() { let e0 = E::E0; - let e11 = E::E1(1i); - let e12 = E::E1(2i); - let e21 = E::E2(1i, 1i); - let e22 = E::E2(1i, 2i); + let e11 = E::E1(1); + let e12 = E::E1(2); + let e21 = E::E2(1, 1); + let e22 = E::E2(1, 2); // in order for both PartialOrd and Ord let es = [e0, e11, e12, e21, e22]; diff --git a/src/test/run-pass/deriving-cmp-generic-struct-enum.rs b/src/test/run-pass/deriving-cmp-generic-struct-enum.rs index dbac7fa5bca..8b54536f3ab 100644 --- a/src/test/run-pass/deriving-cmp-generic-struct-enum.rs +++ b/src/test/run-pass/deriving-cmp-generic-struct-enum.rs @@ -19,15 +19,15 @@ enum ES<T> { pub fn main() { let (es11, es12, es21, es22) = (ES::ES1 { - x: 1i + x: 1 }, ES::ES1 { - x: 2i + x: 2 }, ES::ES2 { - x: 1i, - y: 1i + x: 1, + y: 1 }, ES::ES2 { - x: 1i, - y: 2i + x: 1, + y: 2 }); // in order for both PartialOrd and Ord diff --git a/src/test/run-pass/deriving-cmp-generic-struct.rs b/src/test/run-pass/deriving-cmp-generic-struct.rs index cd2cbb2d0a9..86887c3411f 100644 --- a/src/test/run-pass/deriving-cmp-generic-struct.rs +++ b/src/test/run-pass/deriving-cmp-generic-struct.rs @@ -17,8 +17,8 @@ struct S<T> { } pub fn main() { - let s1 = S {x: 1i, y: 1i}; - let s2 = S {x: 1i, y: 2i}; + let s1 = S {x: 1, y: 1}; + let s2 = S {x: 1, y: 2}; // in order for both PartialOrd and Ord let ss = [s1, s2]; diff --git a/src/test/run-pass/deriving-cmp-generic-tuple-struct.rs b/src/test/run-pass/deriving-cmp-generic-tuple-struct.rs index 0a45b73755e..c7d7f8ded83 100644 --- a/src/test/run-pass/deriving-cmp-generic-tuple-struct.rs +++ b/src/test/run-pass/deriving-cmp-generic-tuple-struct.rs @@ -15,8 +15,8 @@ struct TS<T>(T,T); pub fn main() { - let ts1 = TS(1i, 1i); - let ts2 = TS(1i, 2i); + let ts1 = TS(1, 1); + let ts2 = TS(1, 2); // in order for both PartialOrd and Ord let tss = [ts1, ts2]; diff --git a/src/test/run-pass/deriving-rand.rs b/src/test/run-pass/deriving-rand.rs index 36b6b3cbeea..d6e5fedf182 100644 --- a/src/test/run-pass/deriving-rand.rs +++ b/src/test/run-pass/deriving-rand.rs @@ -31,7 +31,7 @@ enum D { pub fn main() { // check there's no segfaults - for _ in 0i..20 { + for _ in 0..20 { rand::random::<A>(); rand::random::<B>(); rand::random::<C>(); diff --git a/src/test/run-pass/drop-trait-generic.rs b/src/test/run-pass/drop-trait-generic.rs index 9a93873f538..4ba3aa70dfc 100644 --- a/src/test/run-pass/drop-trait-generic.rs +++ b/src/test/run-pass/drop-trait-generic.rs @@ -22,5 +22,5 @@ impl<T> ::std::ops::Drop for S<T> { } pub fn main() { - let _x = S { x: 1i }; + let _x = S { x: 1 }; } diff --git a/src/test/run-pass/dst-raw.rs b/src/test/run-pass/dst-raw.rs index d3d2e3581aa..226025cd80e 100644 --- a/src/test/run-pass/dst-raw.rs +++ b/src/test/run-pass/dst-raw.rs @@ -45,7 +45,7 @@ pub fn main() { assert!(r == 42); // raw slice - let a: *const [_] = &[1i, 2, 3]; + let a: *const [_] = &[1, 2, 3]; unsafe { let b = (*a)[2]; assert!(b == 3); @@ -54,7 +54,7 @@ pub fn main() { } // raw slice with explicit cast - let a = &[1i, 2, 3] as *const [_]; + let a = &[1, 2, 3] as *const [_]; unsafe { let b = (*a)[2]; assert!(b == 3); @@ -63,7 +63,7 @@ pub fn main() { } // raw DST struct with slice - let c: *const Foo<[_]> = &Foo {f: [1i, 2, 3]}; + let c: *const Foo<[_]> = &Foo {f: [1, 2, 3]}; unsafe { let b = (&*c).f[0]; assert!(b == 1); @@ -86,7 +86,7 @@ pub fn main() { }; assert!(r == 42); - let a: *mut [_] = &mut [1i, 2, 3]; + let a: *mut [_] = &mut [1, 2, 3]; unsafe { let b = (*a)[2]; assert!(b == 3); @@ -94,7 +94,7 @@ pub fn main() { assert!(len == 3); } - let a = &mut [1i, 2, 3] as *mut [_]; + let a = &mut [1, 2, 3] as *mut [_]; unsafe { let b = (*a)[2]; assert!(b == 3); @@ -102,7 +102,7 @@ pub fn main() { assert!(len == 3); } - let c: *mut Foo<[_]> = &mut Foo {f: [1i, 2, 3]}; + let c: *mut Foo<[_]> = &mut Foo {f: [1, 2, 3]}; unsafe { let b = (&*c).f[0]; assert!(b == 1); diff --git a/src/test/run-pass/dst-struct.rs b/src/test/run-pass/dst-struct.rs index fa2af29431c..ee5193adbc6 100644 --- a/src/test/run-pass/dst-struct.rs +++ b/src/test/run-pass/dst-struct.rs @@ -115,7 +115,7 @@ pub fn main() { foo3(f5); // Box. - let f1 = box [1i, 2, 3]; + let f1 = box [1, 2, 3]; assert!((*f1)[1] == 2); let f2: Box<[int]> = f1; assert!((*f2)[1] == 2); diff --git a/src/test/run-pass/early-ret-binop-add.rs b/src/test/run-pass/early-ret-binop-add.rs index b9efdeb3bed..97e873e9aff 100644 --- a/src/test/run-pass/early-ret-binop-add.rs +++ b/src/test/run-pass/early-ret-binop-add.rs @@ -8,5 +8,5 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn wsucc(n: int) -> int { 0i + { return n + 1 } } +fn wsucc(n: int) -> int { 0 + { return n + 1 } } pub fn main() { } diff --git a/src/test/run-pass/early-vtbl-resolution.rs b/src/test/run-pass/early-vtbl-resolution.rs index 70030c66ca2..89fee7358a1 100644 --- a/src/test/run-pass/early-vtbl-resolution.rs +++ b/src/test/run-pass/early-vtbl-resolution.rs @@ -19,5 +19,5 @@ fn foo_func<A, B: thing<A>>(x: B) -> Option<A> { x.foo() } struct A { a: int } pub fn main() { - let _x: Option<f64> = foo_func(0i); + let _x: Option<f64> = foo_func(0); } diff --git a/src/test/run-pass/else-if.rs b/src/test/run-pass/else-if.rs index 63f32ae702b..476d3f42d6e 100644 --- a/src/test/run-pass/else-if.rs +++ b/src/test/run-pass/else-if.rs @@ -11,20 +11,20 @@ pub fn main() { - if 1i == 2 { + if 1 == 2 { assert!((false)); - } else if 2i == 3 { + } else if 2 == 3 { assert!((false)); - } else if 3i == 4 { assert!((false)); } else { assert!((true)); } - if 1i == 2 { assert!((false)); } else if 2i == 2 { assert!((true)); } - if 1i == 2 { + } else if 3 == 4 { assert!((false)); } else { assert!((true)); } + if 1 == 2 { assert!((false)); } else if 2 == 2 { assert!((true)); } + if 1 == 2 { assert!((false)); - } else if 2i == 2 { - if 1i == 1 { + } else if 2 == 2 { + if 1 == 1 { assert!((true)); - } else { if 2i == 1 { assert!((false)); } else { assert!((false)); } } + } else { if 2 == 1 { assert!((false)); } else { assert!((false)); } } } - if 1i == 2 { + if 1 == 2 { assert!((false)); - } else { if 1i == 2 { assert!((false)); } else { assert!((true)); } } + } else { if 1 == 2 { assert!((false)); } else { assert!((true)); } } } diff --git a/src/test/run-pass/enum-nullable-simplifycfg-misopt.rs b/src/test/run-pass/enum-nullable-simplifycfg-misopt.rs index 81713657202..468e5f5f4b3 100644 --- a/src/test/run-pass/enum-nullable-simplifycfg-misopt.rs +++ b/src/test/run-pass/enum-nullable-simplifycfg-misopt.rs @@ -19,8 +19,8 @@ enum List<X> { Nil, Cons(X, Box<List<X>>) } pub fn main() { - match List::Cons(10i, box List::Nil) { - List::Cons(10i, _) => {} + match List::Cons(10, box List::Nil) { + List::Cons(10, _) => {} List::Nil => {} _ => panic!() } diff --git a/src/test/run-pass/enum-vec-initializer.rs b/src/test/run-pass/enum-vec-initializer.rs index d436916c279..86a998100b0 100644 --- a/src/test/run-pass/enum-vec-initializer.rs +++ b/src/test/run-pass/enum-vec-initializer.rs @@ -16,9 +16,9 @@ const BAR:uint = Flopsy::Bunny as uint; const BAR2:uint = BAR; pub fn main() { - let _v = [0i; Flopsy::Bunny as uint]; - let _v = [0i; BAR]; - let _v = [0i; BAR2]; + let _v = [0; Flopsy::Bunny as uint]; + let _v = [0; BAR]; + let _v = [0; BAR2]; const BAR3:uint = BAR2; - let _v = [0i; BAR3]; + let _v = [0; BAR3]; } diff --git a/src/test/run-pass/explicit-i-suffix.rs b/src/test/run-pass/explicit-i-suffix.rs index 45cfee76fb8..96c58b106f3 100644 --- a/src/test/run-pass/explicit-i-suffix.rs +++ b/src/test/run-pass/explicit-i-suffix.rs @@ -9,11 +9,11 @@ // except according to those terms. pub fn main() { - let x: int = 8i; - let y = 9i; + let x: int = 8; + let y = 9; x + y; - let q: int = -8i; - let r = -9i; + let q: int = -8; + let r = -9; q + r; } diff --git a/src/test/run-pass/expr-block-unique.rs b/src/test/run-pass/expr-block-unique.rs index d934ce677d1..d10b209965f 100644 --- a/src/test/run-pass/expr-block-unique.rs +++ b/src/test/run-pass/expr-block-unique.rs @@ -12,4 +12,4 @@ #![allow(unknown_features)] #![feature(box_syntax)] -pub fn main() { let x = { box 100i }; assert!((*x == 100)); } +pub fn main() { let x = { box 100 }; assert!((*x == 100)); } diff --git a/src/test/run-pass/expr-block.rs b/src/test/run-pass/expr-block.rs index 7af9e790504..ee1d955b0d3 100644 --- a/src/test/run-pass/expr-block.rs +++ b/src/test/run-pass/expr-block.rs @@ -20,7 +20,7 @@ struct RS { v1: int, v2: int } fn test_rec() { let rs = { RS {v1: 10, v2: 20} }; assert!((rs.v2 == 20)); } fn test_filled_with_stuff() { - let rs = { let mut a = 0i; while a < 10 { a += 1; } a }; + let rs = { let mut a = 0; while a < 10 { a += 1; } a }; assert_eq!(rs, 10); } diff --git a/src/test/run-pass/expr-empty-ret.rs b/src/test/run-pass/expr-empty-ret.rs index 7b08251967e..afc7dfaf9b4 100644 --- a/src/test/run-pass/expr-empty-ret.rs +++ b/src/test/run-pass/expr-empty-ret.rs @@ -12,7 +12,7 @@ fn f() { let _x = match true { - true => { 10i } + true => { 10 } false => { return } }; } diff --git a/src/test/run-pass/expr-fn.rs b/src/test/run-pass/expr-fn.rs index 8172c16abf2..0ea1f3fcdaf 100644 --- a/src/test/run-pass/expr-fn.rs +++ b/src/test/run-pass/expr-fn.rs @@ -22,7 +22,7 @@ fn test_vec() { fn test_generic() { fn f<T>(t: T) -> T { t } - assert_eq!(f(10i), 10); + assert_eq!(f(10), 10); } fn test_alt() { diff --git a/src/test/run-pass/expr-if-panic-all.rs b/src/test/run-pass/expr-if-panic-all.rs index 0dd7ddc3f84..52ccee05817 100644 --- a/src/test/run-pass/expr-if-panic-all.rs +++ b/src/test/run-pass/expr-if-panic-all.rs @@ -12,7 +12,7 @@ // expression results in panic. pub fn main() { let _x = if true { - 10i + 10 } else { if true { panic!() } else { panic!() } }; diff --git a/src/test/run-pass/expr-if-panic.rs b/src/test/run-pass/expr-if-panic.rs index aa4240c60f1..87c7954fa49 100644 --- a/src/test/run-pass/expr-if-panic.rs +++ b/src/test/run-pass/expr-if-panic.rs @@ -9,18 +9,18 @@ // except according to those terms. fn test_if_panic() { - let x = if false { panic!() } else { 10i }; + let x = if false { panic!() } else { 10 }; assert!((x == 10)); } fn test_else_panic() { - let x = if true { 10i } else { panic!() }; - assert_eq!(x, 10i); + let x = if true { 10 } else { panic!() }; + assert_eq!(x, 10); } fn test_elseif_panic() { - let x = if false { 0i } else if false { panic!() } else { 10i }; - assert_eq!(x, 10i); + let x = if false { 0 } else if false { panic!() } else { 10 }; + assert_eq!(x, 10); } pub fn main() { test_if_panic(); test_else_panic(); test_elseif_panic(); } diff --git a/src/test/run-pass/expr-if-unique.rs b/src/test/run-pass/expr-if-unique.rs index 5294d05401c..317e5434930 100644 --- a/src/test/run-pass/expr-if-unique.rs +++ b/src/test/run-pass/expr-if-unique.rs @@ -15,8 +15,8 @@ // Tests for if as expressions returning boxed types fn test_box() { - let rs = if true { box 100i } else { box 101i }; - assert_eq!(*rs, 100i); + let rs = if true { box 100 } else { box 101 }; + assert_eq!(*rs, 100); } pub fn main() { test_box(); } diff --git a/src/test/run-pass/expr-match-panic-all.rs b/src/test/run-pass/expr-match-panic-all.rs index 3b33c18bbbd..3a8955917d6 100644 --- a/src/test/run-pass/expr-match-panic-all.rs +++ b/src/test/run-pass/expr-match-panic-all.rs @@ -16,7 +16,7 @@ pub fn main() { let _x = match true { - true => { 10i } + true => { 10 } false => { match true { true => { panic!() } false => { panic!() } } } }; } diff --git a/src/test/run-pass/expr-match-panic.rs b/src/test/run-pass/expr-match-panic.rs index d8ee21dfdc6..da24d4c57cc 100644 --- a/src/test/run-pass/expr-match-panic.rs +++ b/src/test/run-pass/expr-match-panic.rs @@ -15,8 +15,8 @@ fn test_simple() { } fn test_box() { - let r = match true { true => { vec!(10i) } false => { panic!() } }; - assert_eq!(r[0], 10i); + let r = match true { true => { vec!(10) } false => { panic!() } }; + assert_eq!(r[0], 10); } pub fn main() { test_simple(); test_box(); } diff --git a/src/test/run-pass/expr-match-unique.rs b/src/test/run-pass/expr-match-unique.rs index 7958f4927da..57ccfe1d5e0 100644 --- a/src/test/run-pass/expr-match-unique.rs +++ b/src/test/run-pass/expr-match-unique.rs @@ -13,8 +13,8 @@ // Tests for match as expressions resulting in boxed types fn test_box() { - let res = match true { true => { box 100i }, _ => panic!() }; - assert_eq!(*res, 100i); + let res = match true { true => { box 100 }, _ => panic!() }; + assert_eq!(*res, 100); } pub fn main() { test_box(); } diff --git a/src/test/run-pass/fat-arrow-match.rs b/src/test/run-pass/fat-arrow-match.rs index 929d1c8e63d..004e6d48e37 100644 --- a/src/test/run-pass/fat-arrow-match.rs +++ b/src/test/run-pass/fat-arrow-match.rs @@ -17,8 +17,8 @@ enum color { pub fn main() { println!("{}", match color::red { - color::red => { 1i } - color::green => { 2i } - color::blue => { 3i } + color::red => { 1 } + color::green => { 2 } + color::blue => { 3 } }); } diff --git a/src/test/run-pass/fixed_length_copy.rs b/src/test/run-pass/fixed_length_copy.rs index dc34cec7fa2..bbd7b9130e7 100644 --- a/src/test/run-pass/fixed_length_copy.rs +++ b/src/test/run-pass/fixed_length_copy.rs @@ -9,8 +9,8 @@ // except according to those terms. pub fn main() { - let arr = [1i,2i,3i]; + let arr = [1,2,3]; let arr2 = arr; - assert_eq!(arr[1], 2i); - assert_eq!(arr2[2], 3i); + assert_eq!(arr[1], 2); + assert_eq!(arr2[2], 3); } diff --git a/src/test/run-pass/fn-type-infer.rs b/src/test/run-pass/fn-type-infer.rs index ae22ff5cce0..785abbe449b 100644 --- a/src/test/run-pass/fn-type-infer.rs +++ b/src/test/run-pass/fn-type-infer.rs @@ -13,6 +13,6 @@ pub fn main() { // We should be able to type infer inside of ||s. let _f = |&:| { - let i = 10i; + let i = 10; }; } diff --git a/src/test/run-pass/for-loop-goofiness.rs b/src/test/run-pass/for-loop-goofiness.rs index 73f4cdd252e..ae509dc0862 100644 --- a/src/test/run-pass/for-loop-goofiness.rs +++ b/src/test/run-pass/for-loop-goofiness.rs @@ -16,7 +16,7 @@ enum BogusOption<T> { type Iterator = int; pub fn main() { - let x = [ 3i, 3, 3 ]; + let x = [ 3, 3, 3 ]; for i in x.iter() { assert_eq!(*i, 3); } diff --git a/src/test/run-pass/for-loop-into-iterator.rs b/src/test/run-pass/for-loop-into-iterator.rs new file mode 100644 index 00000000000..7564efbd9e5 --- /dev/null +++ b/src/test/run-pass/for-loop-into-iterator.rs @@ -0,0 +1,27 @@ +// 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that for loops can do what RFC #235 claims + +fn main() { + let mut v = vec![1]; + + for x in &v { + assert_eq!(x, &1); + } + + for x in &mut v { + assert_eq!(x, &mut 1); + } + + for x in v { + assert_eq!(x, 1); + } +} diff --git a/src/test/run-pass/foreach-external-iterators-break.rs b/src/test/run-pass/foreach-external-iterators-break.rs index 5f7770e97a9..9cbb4f4107a 100644 --- a/src/test/run-pass/foreach-external-iterators-break.rs +++ b/src/test/run-pass/foreach-external-iterators-break.rs @@ -9,8 +9,8 @@ // except according to those terms. pub fn main() { - let x = [1i; 100]; - let mut y = 0i; + let x = [1; 100]; + let mut y = 0; for i in x.iter() { if y > 10 { break; diff --git a/src/test/run-pass/foreach-external-iterators-hashmap-break-restart.rs b/src/test/run-pass/foreach-external-iterators-hashmap-break-restart.rs index 4305ae95698..891cbf6696b 100644 --- a/src/test/run-pass/foreach-external-iterators-hashmap-break-restart.rs +++ b/src/test/run-pass/foreach-external-iterators-hashmap-break-restart.rs @@ -18,7 +18,7 @@ use std::collections::HashMap; pub fn main() { let mut h = HashMap::new(); - let kvs = [(1i, 10i), (2i, 20i), (3i, 30i)]; + let kvs = [(1, 10), (2, 20), (3, 30)]; for &(k,v) in kvs.iter() { h.insert(k,v); } @@ -27,7 +27,7 @@ pub fn main() { let mut i = h.iter(); - for (&k,&v) in i { + for (&k,&v) in i.by_ref() { x += k; y += v; break; diff --git a/src/test/run-pass/foreach-external-iterators-hashmap.rs b/src/test/run-pass/foreach-external-iterators-hashmap.rs index ab20f9f9778..1878997de5a 100644 --- a/src/test/run-pass/foreach-external-iterators-hashmap.rs +++ b/src/test/run-pass/foreach-external-iterators-hashmap.rs @@ -14,12 +14,12 @@ use std::collections::HashMap; pub fn main() { let mut h = HashMap::new(); - let kvs = [(1i, 10i), (2i, 20i), (3i, 30i)]; + let kvs = [(1, 10), (2, 20), (3, 30)]; for &(k,v) in kvs.iter() { h.insert(k,v); } - let mut x = 0i; - let mut y = 0i; + let mut x = 0; + let mut y = 0; for (&k,&v) in h.iter() { x += k; y += v; diff --git a/src/test/run-pass/foreach-external-iterators-loop.rs b/src/test/run-pass/foreach-external-iterators-loop.rs index d8c6dd6a93d..d9abed50123 100644 --- a/src/test/run-pass/foreach-external-iterators-loop.rs +++ b/src/test/run-pass/foreach-external-iterators-loop.rs @@ -9,8 +9,8 @@ // except according to those terms. pub fn main() { - let x = [1i; 100]; - let mut y = 0i; + let x = [1; 100]; + let mut y = 0; for (n,i) in x.iter().enumerate() { if n < 10 { continue; diff --git a/src/test/run-pass/foreach-external-iterators-nested.rs b/src/test/run-pass/foreach-external-iterators-nested.rs index 20ea9c440a1..75471991620 100644 --- a/src/test/run-pass/foreach-external-iterators-nested.rs +++ b/src/test/run-pass/foreach-external-iterators-nested.rs @@ -9,10 +9,10 @@ // except according to those terms. pub fn main() { - let x = [1i; 100]; - let y = [2i; 100]; - let mut p = 0i; - let mut q = 0i; + let x = [1; 100]; + let y = [2; 100]; + let mut p = 0; + let mut q = 0; for i in x.iter() { for j in y.iter() { p += *j; diff --git a/src/test/run-pass/foreach-external-iterators.rs b/src/test/run-pass/foreach-external-iterators.rs index 0ac642cc449..ef4692b2b51 100644 --- a/src/test/run-pass/foreach-external-iterators.rs +++ b/src/test/run-pass/foreach-external-iterators.rs @@ -9,8 +9,8 @@ // except according to those terms. pub fn main() { - let x = [1i; 100]; - let mut y = 0i; + let x = [1; 100]; + let mut y = 0; for i in x.iter() { y += *i } diff --git a/src/test/run-pass/foreign-call-no-runtime.rs b/src/test/run-pass/foreign-call-no-runtime.rs index c1df9d53ad4..f99d3eb1c7d 100644 --- a/src/test/run-pass/foreign-call-no-runtime.rs +++ b/src/test/run-pass/foreign-call-no-runtime.rs @@ -22,7 +22,7 @@ extern { pub fn main() { unsafe { Thread::scoped(move|| { - let i = &100i; + let i = &100; rust_dbg_call(callback, mem::transmute(i)); }).join(); } @@ -31,6 +31,6 @@ pub fn main() { extern fn callback(data: libc::uintptr_t) { unsafe { let data: *const int = mem::transmute(data); - assert_eq!(*data, 100i); + assert_eq!(*data, 100); } } diff --git a/src/test/run-pass/generic-alias-unique.rs b/src/test/run-pass/generic-alias-unique.rs index 34b7f15e4c6..db468ba1802 100644 --- a/src/test/run-pass/generic-alias-unique.rs +++ b/src/test/run-pass/generic-alias-unique.rs @@ -14,7 +14,7 @@ fn id<T:Send>(t: T) -> T { return t; } pub fn main() { - let expected = box 100i; + let expected = box 100; let actual = id::<Box<int>>(expected.clone()); println!("{}", *actual); assert_eq!(*expected, *actual); diff --git a/src/test/run-pass/generic-fn-unique.rs b/src/test/run-pass/generic-fn-unique.rs index be83cb04f2c..6599aa74124 100644 --- a/src/test/run-pass/generic-fn-unique.rs +++ b/src/test/run-pass/generic-fn-unique.rs @@ -13,4 +13,4 @@ fn f<T>(x: Box<T>) -> Box<T> { return x; } -pub fn main() { let x = f(box 3i); println!("{}", *x); } +pub fn main() { let x = f(box 3); println!("{}", *x); } diff --git a/src/test/run-pass/generic-ivec-leak.rs b/src/test/run-pass/generic-ivec-leak.rs index 48b61bf745d..eb0546063f7 100644 --- a/src/test/run-pass/generic-ivec-leak.rs +++ b/src/test/run-pass/generic-ivec-leak.rs @@ -10,4 +10,4 @@ enum wrapper<T> { wrapped(T), } -pub fn main() { let _w = wrapper::wrapped(vec!(1i, 2, 3, 4, 5)); } +pub fn main() { let _w = wrapper::wrapped(vec!(1, 2, 3, 4, 5)); } diff --git a/src/test/run-pass/generic-newtype-struct.rs b/src/test/run-pass/generic-newtype-struct.rs index f87e11cbb61..4e3c8204052 100644 --- a/src/test/run-pass/generic-newtype-struct.rs +++ b/src/test/run-pass/generic-newtype-struct.rs @@ -11,5 +11,5 @@ struct S<T>(T); pub fn main() { - let _s = S(2i); + let _s = S(2); } diff --git a/src/test/run-pass/generic-static-methods.rs b/src/test/run-pass/generic-static-methods.rs index f992847e4e9..90a6349385d 100644 --- a/src/test/run-pass/generic-static-methods.rs +++ b/src/test/run-pass/generic-static-methods.rs @@ -24,5 +24,5 @@ impl<T> vec_utils<T> for Vec<T> { } pub fn main() { - assert_eq!(vec_utils::map_(&vec!(1i,2i,3i), |&x| x+1), vec!(2i,3i,4i)); + assert_eq!(vec_utils::map_(&vec!(1,2,3), |&x| x+1), vec!(2,3,4)); } diff --git a/src/test/run-pass/generic-tag-local.rs b/src/test/run-pass/generic-tag-local.rs index cd8b13421c4..24c31ab4ee6 100644 --- a/src/test/run-pass/generic-tag-local.rs +++ b/src/test/run-pass/generic-tag-local.rs @@ -12,4 +12,4 @@ enum clam<T> { a(T), } -pub fn main() { let _c = clam::a(3i); } +pub fn main() { let _c = clam::a(3); } diff --git a/src/test/run-pass/generic-tup.rs b/src/test/run-pass/generic-tup.rs index dc9a90f7025..cd0e344b89c 100644 --- a/src/test/run-pass/generic-tup.rs +++ b/src/test/run-pass/generic-tup.rs @@ -11,7 +11,7 @@ fn get_third<T>(t: (T, T, T)) -> T { let (_, _, x) = t; return x; } pub fn main() { - println!("{}", get_third((1i, 2i, 3i))); - assert_eq!(get_third((1i, 2i, 3i)), 3); + println!("{}", get_third((1, 2, 3))); + assert_eq!(get_third((1, 2, 3)), 3); assert_eq!(get_third((5u8, 6u8, 7u8)), 7u8); } diff --git a/src/test/run-pass/guards.rs b/src/test/run-pass/guards.rs index e7031ae147e..188106ec107 100644 --- a/src/test/run-pass/guards.rs +++ b/src/test/run-pass/guards.rs @@ -13,14 +13,14 @@ struct Pair { x: int, y: int } pub fn main() { let a: int = - match 10i { x if x < 7 => { 1i } x if x < 11 => { 2i } 10 => { 3i } _ => { 4i } }; + match 10 { x if x < 7 => { 1 } x if x < 11 => { 2 } 10 => { 3 } _ => { 4 } }; assert_eq!(a, 2); let b: int = match (Pair {x: 10, y: 20}) { - x if x.x < 5 && x.y < 5 => { 1i } - Pair {x: x, y: y} if x == 10 && y == 20 => { 2i } - Pair {x: _x, y: _y} => { 3i } + x if x.x < 5 && x.y < 5 => { 1 } + Pair {x: x, y: y} if x == 10 && y == 20 => { 2 } + Pair {x: _x, y: _y} => { 3 } }; assert_eq!(b, 2); } diff --git a/src/test/run-pass/hygiene-dodging-1.rs b/src/test/run-pass/hygiene-dodging-1.rs index eb81f82a146..3969394a26b 100644 --- a/src/test/run-pass/hygiene-dodging-1.rs +++ b/src/test/run-pass/hygiene-dodging-1.rs @@ -14,7 +14,7 @@ mod x { pub fn main(){ // should *not* shadow the module x: - let x = 9i; + let x = 9; // use it to avoid warnings: x+3; assert_eq!(x::g(),14); diff --git a/src/test/run-pass/hygienic-labels-in-let.rs b/src/test/run-pass/hygienic-labels-in-let.rs index d8c08a0e4ef..cca0e5b163c 100644 --- a/src/test/run-pass/hygienic-labels-in-let.rs +++ b/src/test/run-pass/hygienic-labels-in-let.rs @@ -20,19 +20,19 @@ macro_rules! loop_x { macro_rules! while_true { ($e: expr) => { // $e shouldn't be able to interact with this 'x - 'x: while 1i + 1 == 2 { $e } + 'x: while 1 + 1 == 2 { $e } } } macro_rules! run_once { ($e: expr) => { // ditto - 'x: for _ in 0i..1 { $e } + 'x: for _ in 0..1 { $e } } } pub fn main() { - let mut i = 0i; + let mut i = 0; let j: int = { 'x: loop { @@ -42,35 +42,35 @@ pub fn main() { } i + 1 }; - assert_eq!(j, 1i); + assert_eq!(j, 1); let k: int = { - 'x: for _ in 0i..1 { + 'x: for _ in 0..1 { // ditto loop_x!(break 'x); i += 1; } i + 1 }; - assert_eq!(k, 1i); + assert_eq!(k, 1); let l: int = { - 'x: for _ in 0i..1 { + 'x: for _ in 0..1 { // ditto while_true!(break 'x); i += 1; } i + 1 }; - assert_eq!(l, 1i); + assert_eq!(l, 1); let n: int = { - 'x: for _ in 0i..1 { + 'x: for _ in 0..1 { // ditto run_once!(continue 'x); i += 1; } i + 1 }; - assert_eq!(n, 1i); + assert_eq!(n, 1); } diff --git a/src/test/run-pass/hygienic-labels.rs b/src/test/run-pass/hygienic-labels.rs index ff8f248a082..0d8da2a9348 100644 --- a/src/test/run-pass/hygienic-labels.rs +++ b/src/test/run-pass/hygienic-labels.rs @@ -18,19 +18,19 @@ macro_rules! loop_x { macro_rules! run_once { ($e: expr) => { // ditto - 'x: for _ in 0i..1 { $e } + 'x: for _ in 0..1 { $e } } } macro_rules! while_x { ($e: expr) => { // ditto - 'x: while 1i + 1 == 2 { $e } + 'x: while 1 + 1 == 2 { $e } } } pub fn main() { - 'x: for _ in 0i..1 { + 'x: for _ in 0..1 { // this 'x should refer to the outer loop, lexically loop_x!(break 'x); panic!("break doesn't act hygienically inside for loop"); @@ -42,12 +42,12 @@ pub fn main() { panic!("break doesn't act hygienically inside infinite loop"); } - 'x: while 1i + 1 == 2 { + 'x: while 1 + 1 == 2 { while_x!(break 'x); panic!("break doesn't act hygienically inside infinite while loop"); } - 'x: for _ in 0i..1 { + 'x: for _ in 0..1 { // ditto run_once!(continue 'x); panic!("continue doesn't act hygienically inside for loop"); diff --git a/src/test/run-pass/if-let.rs b/src/test/run-pass/if-let.rs index 4dff2ea55f1..5d97b886e8e 100644 --- a/src/test/run-pass/if-let.rs +++ b/src/test/run-pass/if-let.rs @@ -9,9 +9,9 @@ // except according to those terms. pub fn main() { - let x = Some(3i); + let x = Some(3); if let Some(y) = x { - assert_eq!(y, 3i); + assert_eq!(y, 3); } else { panic!("if-let panicked"); } @@ -32,9 +32,9 @@ pub fn main() { } assert_eq!(clause, 4u); - if 3i > 4 { + if 3 > 4 { panic!("bad math"); - } else if let 1 = 2i { + } else if let 1 = 2 { panic!("bad pattern match"); } @@ -44,7 +44,7 @@ pub fn main() { Three(String, int) } - let foo = Foo::Three("three".to_string(), 42i); + let foo = Foo::Three("three".to_string(), 42); if let Foo::One = foo { panic!("bad pattern match"); } else if let Foo::Two(_x) = foo { diff --git a/src/test/run-pass/ifmt.rs b/src/test/run-pass/ifmt.rs index 56de6726bfb..0acc70f6b5d 100644 --- a/src/test/run-pass/ifmt.rs +++ b/src/test/run-pass/ifmt.rs @@ -59,10 +59,10 @@ pub fn main() { // At least exercise all the formats t!(format!("{}", true), "true"); t!(format!("{}", '☃'), "☃"); - t!(format!("{}", 10i), "10"); + t!(format!("{}", 10), "10"); t!(format!("{}", 10u), "10"); t!(format!("{:?}", '☃'), "'\\u{2603}'"); - t!(format!("{:?}", 10i), "10"); + t!(format!("{:?}", 10), "10"); t!(format!("{:?}", 10u), "10"); t!(format!("{:?}", "true"), "\"true\""); t!(format!("{:?}", "foo\nbar"), "\"foo\\nbar\""); @@ -76,16 +76,16 @@ pub fn main() { t!(format!("{:x}", A), "aloha"); t!(format!("{:X}", B), "adios"); t!(format!("foo {} ☃☃☃☃☃☃", "bar"), "foo bar ☃☃☃☃☃☃"); - t!(format!("{1} {0}", 0i, 1i), "1 0"); - t!(format!("{foo} {bar}", foo=0i, bar=1is), "0 1"); + t!(format!("{1} {0}", 0, 1), "1 0"); + t!(format!("{foo} {bar}", foo=0, bar=1is), "0 1"); t!(format!("{foo} {1} {bar} {0}", 0is, 1is, foo=2is, bar=3is), "2 1 3 0"); t!(format!("{} {0}", "a"), "a a"); - t!(format!("{foo_bar}", foo_bar=1i), "1"); - t!(format!("{}", 5i + 5i), "10"); + t!(format!("{foo_bar}", foo_bar=1), "1"); + t!(format!("{}", 5 + 5), "10"); t!(format!("{:#4}", C), "☃123"); // FIXME(#20676) - // let a: &fmt::Debug = &1i; + // let a: &fmt::Debug = &1; // t!(format!("{:?}", a), "1"); @@ -146,7 +146,7 @@ pub fn main() { test_order(); // make sure that format! doesn't move out of local variables - let a = box 3i; + let a = box 3; format!("{}", a); format!("{}", a); @@ -169,10 +169,10 @@ pub fn main() { fn test_write() { use std::fmt::Writer; let mut buf = String::new(); - write!(&mut buf, "{}", 3i); + write!(&mut buf, "{}", 3); { let w = &mut buf; - write!(w, "{foo}", foo=4i); + write!(w, "{foo}", foo=4); write!(w, "{}", "hello"); writeln!(w, "{}", "line"); writeln!(w, "{foo}", foo="bar"); @@ -198,9 +198,9 @@ fn test_format_args() { let mut buf = String::new(); { let w = &mut buf; - write!(w, "{}", format_args!("{}", 1i)); + write!(w, "{}", format_args!("{}", 1)); write!(w, "{}", format_args!("test")); - write!(w, "{}", format_args!("{test}", test=3i)); + write!(w, "{}", format_args!("{test}", test=3)); } let s = buf; t!(s, "1test3"); diff --git a/src/test/run-pass/ignore-all-the-things.rs b/src/test/run-pass/ignore-all-the-things.rs index 1c87b6dad89..65fc24ae746 100644 --- a/src/test/run-pass/ignore-all-the-things.rs +++ b/src/test/run-pass/ignore-all-the-things.rs @@ -23,28 +23,28 @@ pub fn main() { //let (a, b, ..) = (5, 5, 5, 5); //let (.., c, d) = (5, 5, 5, 5); let Bar{b: b, ..} = Bar{a: 5, b: 5, c: 5, d: 5}; - match [5i, 5, 5, 5] { + match [5, 5, 5, 5] { [..] => { } } - match [5i, 5, 5, 5] { + match [5, 5, 5, 5] { [a, ..] => { } } - match [5i, 5, 5, 5] { + match [5, 5, 5, 5] { [.., b] => { } } - match [5i, 5, 5, 5] { + match [5, 5, 5, 5] { [a, .., b] => { } } - match [5i, 5, 5] { + match [5, 5, 5] { [..] => { } } - match [5i, 5, 5] { + match [5, 5, 5] { [a, ..] => { } } - match [5i, 5, 5] { + match [5, 5, 5] { [.., a] => { } } - match [5i, 5, 5] { + match [5, 5, 5] { [a, .., b] => { } } } diff --git a/src/test/run-pass/import-glob-crate.rs b/src/test/run-pass/import-glob-crate.rs index 24d90741bbc..f7874cc56fc 100644 --- a/src/test/run-pass/import-glob-crate.rs +++ b/src/test/run-pass/import-glob-crate.rs @@ -14,7 +14,7 @@ use std::mem::*; pub fn main() { assert_eq!(size_of::<u8>(), 1); - let (mut x, mut y) = (1i, 2i); + let (mut x, mut y) = (1, 2); swap(&mut x, &mut y); assert_eq!(x, 2); assert_eq!(y, 1); diff --git a/src/test/run-pass/import-in-block.rs b/src/test/run-pass/import-in-block.rs index 3c28354dedc..4567651e892 100644 --- a/src/test/run-pass/import-in-block.rs +++ b/src/test/run-pass/import-in-block.rs @@ -10,11 +10,11 @@ pub fn main() { use std::mem::replace; - let mut x = 5i; + let mut x = 5; replace(&mut x, 6); { use std::mem::*; - let mut y = 6i; + let mut y = 6; swap(&mut x, &mut y); } } diff --git a/src/test/run-pass/import4.rs b/src/test/run-pass/import4.rs index 0639d732089..44f6b6140fb 100644 --- a/src/test/run-pass/import4.rs +++ b/src/test/run-pass/import4.rs @@ -16,4 +16,4 @@ mod zed { pub fn bar() { println!("bar"); } } -pub fn main() { let _zed = 42i; bar(); } +pub fn main() { let _zed = 42; bar(); } diff --git a/src/test/run-pass/inferred-suffix-in-pattern-range.rs b/src/test/run-pass/inferred-suffix-in-pattern-range.rs index a104ee6baaa..be561dfffa6 100644 --- a/src/test/run-pass/inferred-suffix-in-pattern-range.rs +++ b/src/test/run-pass/inferred-suffix-in-pattern-range.rs @@ -9,14 +9,14 @@ // except according to those terms. pub fn main() { - let x = 2i; + let x = 2; let x_message = match x { 0 ... 1 => { "not many".to_string() } _ => { "lots".to_string() } }; assert_eq!(x_message, "lots".to_string()); - let y = 2i; + let y = 2; let y_message = match y { 0 ... 1 => { "not many".to_string() } _ => { "lots".to_string() } diff --git a/src/test/run-pass/init-res-into-things.rs b/src/test/run-pass/init-res-into-things.rs index eeae3f35cfc..ee793359fbc 100644 --- a/src/test/run-pass/init-res-into-things.rs +++ b/src/test/run-pass/init-res-into-things.rs @@ -37,7 +37,7 @@ fn r(i: &Cell<int>) -> r { } fn test_rec() { - let i = &Cell::new(0i); + let i = &Cell::new(0); { let _a = BoxR {x: r(i)}; } @@ -49,7 +49,7 @@ fn test_tag() { t0(r<'a>), } - let i = &Cell::new(0i); + let i = &Cell::new(0); { let _a = t::t0(r(i)); } @@ -57,15 +57,15 @@ fn test_tag() { } fn test_tup() { - let i = &Cell::new(0i); + let i = &Cell::new(0); { - let _a = (r(i), 0i); + let _a = (r(i), 0); } assert_eq!(i.get(), 1); } fn test_unique() { - let i = &Cell::new(0i); + let i = &Cell::new(0); { let _a = box r(i); } @@ -73,7 +73,7 @@ fn test_unique() { } fn test_unique_rec() { - let i = &Cell::new(0i); + let i = &Cell::new(0); { let _a = box BoxR { x: r(i) diff --git a/src/test/run-pass/intrinsic-atomics.rs b/src/test/run-pass/intrinsic-atomics.rs index 0644fbbc99f..d3f62f9d04a 100644 --- a/src/test/run-pass/intrinsic-atomics.rs +++ b/src/test/run-pass/intrinsic-atomics.rs @@ -40,7 +40,7 @@ mod rusti { pub fn main() { unsafe { - let mut x = box 1i; + let mut x = box 1; assert_eq!(rusti::atomic_load(&*x), 1); *x = 5; diff --git a/src/test/run-pass/intrinsic-move-val.rs b/src/test/run-pass/intrinsic-move-val.rs index fb04f67e380..0daf661c2f6 100644 --- a/src/test/run-pass/intrinsic-move-val.rs +++ b/src/test/run-pass/intrinsic-move-val.rs @@ -23,7 +23,7 @@ mod rusti { pub fn main() { unsafe { - let x = box 1i; + let x = box 1; let mut y = rusti::init(); let mut z: *const uint = transmute(&x); rusti::move_val_init(&mut y, x); diff --git a/src/test/run-pass/issue-10626.rs b/src/test/run-pass/issue-10626.rs index 880a8b4d2e0..79a0a54f834 100644 --- a/src/test/run-pass/issue-10626.rs +++ b/src/test/run-pass/issue-10626.rs @@ -19,10 +19,10 @@ pub fn main () { let args = os::args(); let args = args.as_slice(); if args.len() > 1 && args[1].as_slice() == "child" { - for _ in 0i..1000i { + for _ in 0..1000 { println!("hello?"); } - for _ in 0i..1000i { + for _ in 0..1000 { println!("hello?"); } return; diff --git a/src/test/run-pass/issue-10638.rs b/src/test/run-pass/issue-10638.rs index a4ef77df311..bc77b4c5343 100644 --- a/src/test/run-pass/issue-10638.rs +++ b/src/test/run-pass/issue-10638.rs @@ -13,6 +13,6 @@ pub fn main() { ////////////////// still not a doc comment /////**** nope, me neither */ /*** And neither am I! */ - 5i; + 5; /*****! certainly not I */ } diff --git a/src/test/run-pass/issue-11205.rs b/src/test/run-pass/issue-11205.rs index 194208620a8..d7c6c1b1bb2 100644 --- a/src/test/run-pass/issue-11205.rs +++ b/src/test/run-pass/issue-11205.rs @@ -22,45 +22,45 @@ fn bar(_: [Box<Foo>; 2]) {} fn bars(_: &[Box<Foo>]) {} fn main() { - let x: [&Foo; 2] = [&1i, &2i]; + let x: [&Foo; 2] = [&1, &2]; foo(x); - foo([&1i, &2i]); + foo([&1, &2]); - let r = &1i; + let r = &1; let x: [&Foo; 2] = [r; 2]; foo(x); - foo([&1i; 2]); + foo([&1; 2]); - let x: &[&Foo] = &[&1i, &2i]; + let x: &[&Foo] = &[&1, &2]; foos(x); - foos(&[&1i, &2i]); + foos(&[&1, &2]); - let x: &[&Foo] = &[&1i, &2i]; - let r = &1i; + let x: &[&Foo] = &[&1, &2]; + let r = &1; foog(x, &[r]); - let x: [Box<Foo>; 2] = [box 1i, box 2i]; + let x: [Box<Foo>; 2] = [box 1, box 2]; bar(x); - bar([box 1i, box 2i]); + bar([box 1, box 2]); - let x: &[Box<Foo>] = &[box 1i, box 2i]; + let x: &[Box<Foo>] = &[box 1, box 2]; bars(x); - bars(&[box 1i, box 2i]); + bars(&[box 1, box 2]); - let x: &[Box<Foo>] = &[box 1i, box 2i]; - foog(x, &[box 1i]); + let x: &[Box<Foo>] = &[box 1, box 2]; + foog(x, &[box 1]); struct T<'a> { t: [&'a (Foo+'a); 2] } let _n = T { - t: [&1i, &2i] + t: [&1, &2] }; - let r = &1i; + let r = &1; let _n = T { t: [r; 2] }; - let x: [&Foo; 2] = [&1i, &2i]; + let x: [&Foo; 2] = [&1, &2]; let _n = T { t: x }; @@ -69,14 +69,14 @@ fn main() { t: &'b [&'b (Foo+'b)] } let _n = F { - t: &[&1i, &2i] + t: &[&1, &2] }; - let r = &1i; + let r = &1; let r: [&Foo; 2] = [r; 2]; let _n = F { t: &r }; - let x: [&Foo; 2] = [&1i, &2i]; + let x: [&Foo; 2] = [&1, &2]; let _n = F { t: &x }; @@ -85,9 +85,9 @@ fn main() { t: &'a [Box<Foo+'static>] } let _n = M { - t: &[box 1i, box 2i] + t: &[box 1, box 2] }; - let x: [Box<Foo>; 2] = [box 1i, box 2i]; + let x: [Box<Foo>; 2] = [box 1, box 2]; let _n = M { t: &x }; diff --git a/src/test/run-pass/issue-11225-1.rs b/src/test/run-pass/issue-11225-1.rs index 7d1c93fe9a4..a45d129ade2 100644 --- a/src/test/run-pass/issue-11225-1.rs +++ b/src/test/run-pass/issue-11225-1.rs @@ -13,5 +13,5 @@ extern crate "issue-11225-1" as foo; pub fn main() { - foo::foo(1i); + foo::foo(1); } diff --git a/src/test/run-pass/issue-11225-2.rs b/src/test/run-pass/issue-11225-2.rs index 7f36c38283b..f07957b30ec 100644 --- a/src/test/run-pass/issue-11225-2.rs +++ b/src/test/run-pass/issue-11225-2.rs @@ -13,5 +13,5 @@ extern crate "issue-11225-2" as foo; pub fn main() { - foo::foo(1i); + foo::foo(1); } diff --git a/src/test/run-pass/issue-11958.rs b/src/test/run-pass/issue-11958.rs index 13177880c5a..00613f35f17 100644 --- a/src/test/run-pass/issue-11958.rs +++ b/src/test/run-pass/issue-11958.rs @@ -19,6 +19,6 @@ use std::thunk::Thunk; pub fn main() { - let mut x = 1i; + let mut x = 1i32; let _thunk = Thunk::new(move|| { x = 2; }); } diff --git a/src/test/run-pass/issue-1257.rs b/src/test/run-pass/issue-1257.rs index ad3a050dde9..7d5bd9d6a74 100644 --- a/src/test/run-pass/issue-1257.rs +++ b/src/test/run-pass/issue-1257.rs @@ -10,7 +10,7 @@ pub fn main () { let mut line = "".to_string(); - let mut i = 0i; + let mut i = 0; while line != "exit".to_string() { line = if i == 9 { "exit".to_string() } else { "notexit".to_string() }; i += 1; diff --git a/src/test/run-pass/issue-12582.rs b/src/test/run-pass/issue-12582.rs index ab2abc094f4..4009d17139d 100644 --- a/src/test/run-pass/issue-12582.rs +++ b/src/test/run-pass/issue-12582.rs @@ -11,10 +11,10 @@ // ignore-lexer-test FIXME #15877 pub fn main() { - let x = 1i; - let y = 2i; + let x = 1; + let y = 2; - assert_eq!(3i, match (x, y) { + assert_eq!(3, match (x, y) { (1, 1) => 1, (2, 2) => 2, (1...2, 2) => 3, @@ -22,7 +22,7 @@ pub fn main() { }); // nested tuple - assert_eq!(3i, match ((x, y),) { + assert_eq!(3, match ((x, y),) { ((1, 1),) => 1, ((2, 2),) => 2, ((1...2, 2),) => 3, diff --git a/src/test/run-pass/issue-12744.rs b/src/test/run-pass/issue-12744.rs index ec929a9c792..2f7ba315aa1 100644 --- a/src/test/run-pass/issue-12744.rs +++ b/src/test/run-pass/issue-12744.rs @@ -12,6 +12,6 @@ #![feature(box_syntax)] fn main() { - fn test() -> Box<std::any::Any + 'static> { box 1i } + fn test() -> Box<std::any::Any + 'static> { box 1 } println!("{:?}", test()) } diff --git a/src/test/run-pass/issue-12909.rs b/src/test/run-pass/issue-12909.rs index dfdf979fcec..3075bae44fe 100644 --- a/src/test/run-pass/issue-12909.rs +++ b/src/test/run-pass/issue-12909.rs @@ -15,7 +15,7 @@ fn copy<T: Copy>(&x: &T) -> T { } fn main() { - let arr = [(1i, 1u), (2, 2), (3, 3)]; + let arr = [(1, 1u), (2, 2), (3, 3)]; let v1: Vec<&_> = arr.iter().collect(); let v2: Vec<_> = arr.iter().map(copy).collect(); diff --git a/src/test/run-pass/issue-13027.rs b/src/test/run-pass/issue-13027.rs index 1f61da2f424..649cf63e84a 100644 --- a/src/test/run-pass/issue-13027.rs +++ b/src/test/run-pass/issue-13027.rs @@ -29,99 +29,99 @@ pub fn main() { } fn lit_shadow_range() { - assert_eq!(2i, match 1i { - 1 if false => 1i, + assert_eq!(2, match 1 { + 1 if false => 1, 1...2 => 2, _ => 3 }); - let x = 0i; - assert_eq!(2i, match x+1 { - 0 => 0i, + let x = 0; + assert_eq!(2, match x+1 { + 0 => 0, 1 if false => 1, 1...2 => 2, _ => 3 }); - assert_eq!(2i, match val() { - 1 if false => 1i, + assert_eq!(2, match val() { + 1 if false => 1, 1...2 => 2, _ => 3 }); - assert_eq!(2i, match CONST { - 0 => 0i, + assert_eq!(2, match CONST { + 0 => 0, 1 if false => 1, 1...2 => 2, _ => 3 }); // value is out of the range of second arm, should match wildcard pattern - assert_eq!(3i, match 3i { - 1 if false => 1i, + assert_eq!(3, match 3 { + 1 if false => 1, 1...2 => 2, _ => 3 }); } fn range_shadow_lit() { - assert_eq!(2i, match 1i { - 1...2 if false => 1i, + assert_eq!(2, match 1 { + 1...2 if false => 1, 1 => 2, _ => 3 }); - let x = 0i; - assert_eq!(2i, match x+1 { - 0 => 0i, + let x = 0; + assert_eq!(2, match x+1 { + 0 => 0, 1...2 if false => 1, 1 => 2, _ => 3 }); - assert_eq!(2i, match val() { - 1...2 if false => 1i, + assert_eq!(2, match val() { + 1...2 if false => 1, 1 => 2, _ => 3 }); - assert_eq!(2i, match CONST { - 0 => 0i, + assert_eq!(2, match CONST { + 0 => 0, 1...2 if false => 1, 1 => 2, _ => 3 }); // ditto - assert_eq!(3i, match 3i { - 1...2 if false => 1i, + assert_eq!(3, match 3 { + 1...2 if false => 1, 1 => 2, _ => 3 }); } fn range_shadow_range() { - assert_eq!(2i, match 1i { - 0...2 if false => 1i, + assert_eq!(2, match 1 { + 0...2 if false => 1, 1...3 => 2, _ => 3, }); - let x = 0i; - assert_eq!(2i, match x+1 { + let x = 0; + assert_eq!(2, match x+1 { 100 => 0, 0...2 if false => 1, 1...3 => 2, _ => 3, }); - assert_eq!(2i, match val() { + assert_eq!(2, match val() { 0...2 if false => 1, 1...3 => 2, _ => 3, }); - assert_eq!(2i, match CONST { + assert_eq!(2, match CONST { 100 => 0, 0...2 if false => 1, 1...3 => 2, @@ -129,16 +129,16 @@ fn range_shadow_range() { }); // ditto - assert_eq!(3i, match 5i { - 0...2 if false => 1i, + assert_eq!(3, match 5 { + 0...2 if false => 1, 1...3 => 2, _ => 3, }); } fn multi_pats_shadow_lit() { - assert_eq!(2i, match 1i { - 100 => 0i, + assert_eq!(2, match 1 { + 100 => 0, 0 | 1...10 if false => 1, 1 => 2, _ => 3, @@ -146,8 +146,8 @@ fn multi_pats_shadow_lit() { } fn multi_pats_shadow_range() { - assert_eq!(2i, match 1i { - 100 => 0i, + assert_eq!(2, match 1 { + 100 => 0, 0 | 1...10 if false => 1, 1...3 => 2, _ => 3, @@ -155,8 +155,8 @@ fn multi_pats_shadow_range() { } fn lit_shadow_multi_pats() { - assert_eq!(2i, match 1i { - 100 => 0i, + assert_eq!(2, match 1 { + 100 => 0, 1 if false => 1, 0 | 1...10 => 2, _ => 3, @@ -164,8 +164,8 @@ fn lit_shadow_multi_pats() { } fn range_shadow_multi_pats() { - assert_eq!(2i, match 1i { - 100 => 0i, + assert_eq!(2, match 1 { + 100 => 0, 1...3 if false => 1, 0 | 1...10 => 2, _ => 3, @@ -180,9 +180,9 @@ fn misc() { // which is a rare combination of vector patterns, multiple wild-card // patterns and guard functions. let r = match [Foo::Bar(0, false)].as_slice() { - [Foo::Bar(_, pred)] if pred => 1i, - [Foo::Bar(_, pred)] if !pred => 2i, - _ => 0i, + [Foo::Bar(_, pred)] if pred => 1, + [Foo::Bar(_, pred)] if !pred => 2, + _ => 0, }; - assert_eq!(2i, r); + assert_eq!(2, r); } diff --git a/src/test/run-pass/issue-13494.rs b/src/test/run-pass/issue-13494.rs index c10fd7328a1..5025d403468 100644 --- a/src/test/run-pass/issue-13494.rs +++ b/src/test/run-pass/issue-13494.rs @@ -24,7 +24,7 @@ fn main() { let (tx, rx) = channel(); let _t = Thread::spawn(move|| { helper(rx) }); let (snd, rcv) = channel::<int>(); - for _ in 1i..100000i { + for _ in 1..100000 { snd.send(1i).unwrap(); let (tx2, rx2) = channel(); tx.send(tx2).unwrap(); diff --git a/src/test/run-pass/issue-13867.rs b/src/test/run-pass/issue-13867.rs index 00ff837b981..960884c4aa5 100644 --- a/src/test/run-pass/issue-13867.rs +++ b/src/test/run-pass/issue-13867.rs @@ -18,39 +18,39 @@ enum Foo { fn main() { let r = match (Foo::FooNullary, 'a') { - (Foo::FooUint(..), 'a'...'z') => 1i, - (Foo::FooNullary, 'x') => 2i, + (Foo::FooUint(..), 'a'...'z') => 1, + (Foo::FooNullary, 'x') => 2, _ => 0 }; assert_eq!(r, 0); let r = match (Foo::FooUint(0), 'a') { - (Foo::FooUint(1), 'a'...'z') => 1i, - (Foo::FooUint(..), 'x') => 2i, - (Foo::FooNullary, 'a') => 3i, + (Foo::FooUint(1), 'a'...'z') => 1, + (Foo::FooUint(..), 'x') => 2, + (Foo::FooNullary, 'a') => 3, _ => 0 }; assert_eq!(r, 0); let r = match ('a', Foo::FooUint(0)) { - ('a'...'z', Foo::FooUint(1)) => 1i, - ('x', Foo::FooUint(..)) => 2i, - ('a', Foo::FooNullary) => 3i, + ('a'...'z', Foo::FooUint(1)) => 1, + ('x', Foo::FooUint(..)) => 2, + ('a', Foo::FooNullary) => 3, _ => 0 }; assert_eq!(r, 0); let r = match ('a', 'a') { - ('a'...'z', 'b') => 1i, - ('x', 'a'...'z') => 2i, + ('a'...'z', 'b') => 1, + ('x', 'a'...'z') => 2, _ => 0 }; assert_eq!(r, 0); let r = match ('a', 'a') { - ('a'...'z', 'b') => 1i, - ('x', 'a'...'z') => 2i, - ('a', 'a') => 3i, + ('a'...'z', 'b') => 1, + ('x', 'a'...'z') => 2, + ('a', 'a') => 3, _ => 0 }; assert_eq!(r, 3); diff --git a/src/test/run-pass/issue-14308.rs b/src/test/run-pass/issue-14308.rs index 82a1a16ba57..0e4b4a2c9cf 100644 --- a/src/test/run-pass/issue-14308.rs +++ b/src/test/run-pass/issue-14308.rs @@ -13,12 +13,12 @@ struct B; fn main() { let x = match A(3) { - A(..) => 1i + A(..) => 1 }; assert_eq!(x, 1); let x = match A(4) { - A(1) => 1i, - A(..) => 2i + A(1) => 1, + A(..) => 2 }; assert_eq!(x, 2); @@ -26,7 +26,7 @@ fn main() { // There's no particularly good reason to support this, but it's currently allowed, // and this makes sure it doesn't ICE or break LLVM. let x = match B { - B(..) => 3i + B(..) => 3 }; assert_eq!(x, 3); } diff --git a/src/test/run-pass/issue-1460.rs b/src/test/run-pass/issue-1460.rs index 2091a5437c2..e7516639db0 100644 --- a/src/test/run-pass/issue-1460.rs +++ b/src/test/run-pass/issue-1460.rs @@ -10,5 +10,5 @@ pub fn main() { - {|&: i| if 1i == i { }}; + {|&: i| if 1 == i { }}; } diff --git a/src/test/run-pass/issue-14865.rs b/src/test/run-pass/issue-14865.rs index 53af0c8635c..c322346c2a6 100644 --- a/src/test/run-pass/issue-14865.rs +++ b/src/test/run-pass/issue-14865.rs @@ -15,14 +15,14 @@ enum X { fn main() { let x = match X::Foo(42) { - X::Foo(..) => 1i, + X::Foo(..) => 1, _ if true => 0, X::Bar(..) => panic!("Oh dear") }; assert_eq!(x, 1); let x = match X::Foo(42) { - _ if true => 0i, + _ if true => 0, X::Foo(..) => 1, X::Bar(..) => panic!("Oh dear") }; diff --git a/src/test/run-pass/issue-15080.rs b/src/test/run-pass/issue-15080.rs index 76b8463a417..9752b01e52b 100644 --- a/src/test/run-pass/issue-15080.rs +++ b/src/test/run-pass/issue-15080.rs @@ -9,7 +9,7 @@ // except according to those terms. fn main() { - let mut x: &[_] = &[1i, 2, 3, 4]; + let mut x: &[_] = &[1, 2, 3, 4]; let mut result = vec!(); loop { diff --git a/src/test/run-pass/issue-15221.rs b/src/test/run-pass/issue-15221.rs index e3c102e01ec..49e5b14aff8 100644 --- a/src/test/run-pass/issue-15221.rs +++ b/src/test/run-pass/issue-15221.rs @@ -17,7 +17,7 @@ macro_rules! outer { } fn main() { - let outer!(g1) = 13i; + let outer!(g1) = 13; g1; } diff --git a/src/test/run-pass/issue-15571.rs b/src/test/run-pass/issue-15571.rs index 6b273b5786a..7d53b672951 100644 --- a/src/test/run-pass/issue-15571.rs +++ b/src/test/run-pass/issue-15571.rs @@ -12,7 +12,7 @@ #![feature(box_syntax)] fn match_on_local() { - let mut foo = Some(box 5i); + let mut foo = Some(box 5); match foo { None => {}, Some(x) => { @@ -22,7 +22,7 @@ fn match_on_local() { println!("'{}'", foo.unwrap()); } -fn match_on_arg(mut foo: Option<Box<int>>) { +fn match_on_arg(mut foo: Option<Box<i32>>) { match foo { None => {} Some(x) => { @@ -33,7 +33,7 @@ fn match_on_arg(mut foo: Option<Box<int>>) { } fn match_on_binding() { - match Some(box 7i) { + match Some(box 7) { mut foo => { match foo { None => {}, @@ -47,7 +47,7 @@ fn match_on_binding() { } fn match_on_upvar() { - let mut foo = Some(box 8i); + let mut foo = Some(box 8i32); let f = move|:| { match foo { None => {}, @@ -62,7 +62,7 @@ fn match_on_upvar() { fn main() { match_on_local(); - match_on_arg(Some(box 6i)); + match_on_arg(Some(box 6)); match_on_binding(); match_on_upvar(); } diff --git a/src/test/run-pass/issue-15763.rs b/src/test/run-pass/issue-15763.rs index f30991a1963..7bfd8e0ab71 100644 --- a/src/test/run-pass/issue-15763.rs +++ b/src/test/run-pass/issue-15763.rs @@ -87,12 +87,12 @@ fn main() { assert_eq!(cc().unwrap(), 3); assert_eq!(dd().unwrap(), 3); - let i = box 32i as Box<A>; + let i = box 32 as Box<A>; assert_eq!(i.aaa(), 3); - let i = box 32i as Box<A>; + let i = box 32 as Box<A>; assert_eq!(i.bbb(), 3); - let i = box 32i as Box<A>; + let i = box 32 as Box<A>; assert_eq!(i.ccc().unwrap(), 3); - let i = box 32i as Box<A>; + let i = box 32 as Box<A>; assert_eq!(i.ddd().unwrap(), 3); } diff --git a/src/test/run-pass/issue-15924.rs b/src/test/run-pass/issue-15924.rs index db9f1cc9df7..88b250af1c0 100644 --- a/src/test/run-pass/issue-15924.rs +++ b/src/test/run-pass/issue-15924.rs @@ -28,5 +28,5 @@ impl<T: Encodable> Drop for Foo<T> { } fn main() { - let _ = Foo { v: 10i }; + let _ = Foo { v: 10 }; } diff --git a/src/test/run-pass/issue-16648.rs b/src/test/run-pass/issue-16648.rs index 7ddb20811a3..0b58df56b6f 100644 --- a/src/test/run-pass/issue-16648.rs +++ b/src/test/run-pass/issue-16648.rs @@ -9,12 +9,12 @@ // except according to those terms. fn main() { - let x: (int, &[int]) = (2i, &[1i, 2i]); + let x: (int, &[int]) = (2, &[1, 2]); assert_eq!(match x { (0, [_, _]) => 0, (1, _) => 1, (2, [_, _]) => 2, (2, _) => 3, _ => 4 - }, 2i); + }, 2); } diff --git a/src/test/run-pass/issue-16668.rs b/src/test/run-pass/issue-16668.rs index e82add61aa3..95b7728b47f 100644 --- a/src/test/run-pass/issue-16668.rs +++ b/src/test/run-pass/issue-16668.rs @@ -18,7 +18,7 @@ struct Parser<'a, I, O> { parse: Box<FnMut(I) -> Result<O, String> + 'a> } -impl<'a, I, O: 'a> Parser<'a, I, O> { +impl<'a, I: 'a, O: 'a> Parser<'a, I, O> { fn compose<K: 'a>(mut self, mut rhs: Parser<'a, O, K>) -> Parser<'a, I, K> { Parser { parse: box move |&mut: x: I| { diff --git a/src/test/run-pass/issue-16774.rs b/src/test/run-pass/issue-16774.rs index 175e2188811..d426f82f89f 100644 --- a/src/test/run-pass/issue-16774.rs +++ b/src/test/run-pass/issue-16774.rs @@ -45,7 +45,7 @@ impl DerefMut for X { fn main() { { - let mut test = X(box 5i); + let mut test = X(box 5); { let mut change = |&mut:| { *test = 10 }; change(); diff --git a/src/test/run-pass/issue-17074.rs b/src/test/run-pass/issue-17074.rs index d35c3a587c5..d367e0e908e 100644 --- a/src/test/run-pass/issue-17074.rs +++ b/src/test/run-pass/issue-17074.rs @@ -17,6 +17,6 @@ fn main() { assert_eq!(match 1 { X => unreachable!(), Y => unreachable!(), - _ => 1i + _ => 1 }, 1); } diff --git a/src/test/run-pass/issue-19244.rs b/src/test/run-pass/issue-19244.rs index 3ee5ce9bff9..9af4d30c4f6 100644 --- a/src/test/run-pass/issue-19244.rs +++ b/src/test/run-pass/issue-19244.rs @@ -13,8 +13,8 @@ const STRUCT: MyStruct = MyStruct { field: 42 }; const TUP: (uint,) = (43,); fn main() { - let a = [0i; STRUCT.field]; - let b = [0i; TUP.0]; + let a = [0; STRUCT.field]; + let b = [0; TUP.0]; assert!(a.len() == 42); assert!(b.len() == 43); diff --git a/src/test/run-pass/issue-19358.rs b/src/test/run-pass/issue-19358.rs index 37d05453914..ff657376ecc 100644 --- a/src/test/run-pass/issue-19358.rs +++ b/src/test/run-pass/issue-19358.rs @@ -23,7 +23,7 @@ struct Bar<T> where T: Trait { impl Trait for int {} fn main() { - let a = Foo { foo: 12i }; - let b = Bar { bar: 12i }; + let a = Foo { foo: 12 }; + let b = Bar { bar: 12 }; println!("{:?} {:?}", a, b); } diff --git a/src/test/run-pass/issue-19367.rs b/src/test/run-pass/issue-19367.rs index 7db84d518ff..d5bb6ebb7de 100644 --- a/src/test/run-pass/issue-19367.rs +++ b/src/test/run-pass/issue-19367.rs @@ -16,7 +16,7 @@ struct S { // on field of struct or tuple which we reassign in the match body. fn main() { - let mut a = (0i, Some("right".to_string())); + let mut a = (0, Some("right".to_string())); let b = match a.1 { Some(v) => { a.1 = Some("wrong".to_string()); diff --git a/src/test/run-pass/issue-21655.rs b/src/test/run-pass/issue-21655.rs new file mode 100644 index 00000000000..b9b1e5f3337 --- /dev/null +++ b/src/test/run-pass/issue-21655.rs @@ -0,0 +1,20 @@ +// Copyright 2015 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn test(it: &mut Iterator<Item=i32>) { + for x in it { + assert_eq!(x, 1) + } +} + +fn main() { + let v = vec![1]; + test(&mut v.into_iter()) +} diff --git a/src/test/run-pass/issue-21726.rs b/src/test/run-pass/issue-21726.rs new file mode 100644 index 00000000000..09d1a3bca69 --- /dev/null +++ b/src/test/run-pass/issue-21726.rs @@ -0,0 +1,44 @@ +// Copyright 2015 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Regression test for #21726: an issue arose around the rules for +// subtyping of projection types that resulted in an unconstrained +// region, yielding region inference failures. + +fn main() { } + +fn foo<'a>(s: &'a str) { + let b: B<()> = B::new(s, ()); + b.get_short(); +} + +trait IntoRef<'a> { + type T: Clone; + fn into_ref(self, &'a str) -> Self::T; +} + +impl<'a> IntoRef<'a> for () { + type T = &'a str; + fn into_ref(self, s: &'a str) -> &'a str { + s + } +} + +struct B<'a, P: IntoRef<'a>>(P::T); + +impl<'a, P: IntoRef<'a>> B<'a, P> { + fn new(s: &'a str, i: P) -> B<'a, P> { + B(i.into_ref(s)) + } + + fn get_short(&self) -> P::T { + self.0.clone() + } +} diff --git a/src/test/run-pass/issue-2216.rs b/src/test/run-pass/issue-2216.rs index 98e6e051343..c2f74a9d653 100644 --- a/src/test/run-pass/issue-2216.rs +++ b/src/test/run-pass/issue-2216.rs @@ -9,12 +9,12 @@ // except according to those terms. pub fn main() { - let mut x = 0i; + let mut x = 0; 'foo: loop { 'bar: loop { 'quux: loop { - if 1i == 2 { + if 1 == 2 { break 'foo; } else { diff --git a/src/test/run-pass/issue-2383.rs b/src/test/run-pass/issue-2383.rs index 94bff890820..b8136323df6 100644 --- a/src/test/run-pass/issue-2383.rs +++ b/src/test/run-pass/issue-2383.rs @@ -14,5 +14,5 @@ use std::collections::RingBuf; pub fn main() { let mut q = RingBuf::new(); - q.push_front(10i); + q.push_front(10); } diff --git a/src/test/run-pass/issue-2428.rs b/src/test/run-pass/issue-2428.rs index afa053de243..7ed26428be0 100644 --- a/src/test/run-pass/issue-2428.rs +++ b/src/test/run-pass/issue-2428.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let _foo = 100i; + let _foo = 100; const quux: int = 5; enum Stuff { diff --git a/src/test/run-pass/issue-2633-2.rs b/src/test/run-pass/issue-2633-2.rs index c146f8a7a9a..80e9ca47025 100644 --- a/src/test/run-pass/issue-2633-2.rs +++ b/src/test/run-pass/issue-2633-2.rs @@ -17,6 +17,6 @@ fn a_val(x: Box<int>, y: Box<int>) -> int { } pub fn main() { - let z = box 22i; + let z = box 22; a_val(z.clone(), z.clone()); } diff --git a/src/test/run-pass/issue-2734.rs b/src/test/run-pass/issue-2734.rs index 3e4cffe5dfa..7ca439a1a19 100644 --- a/src/test/run-pass/issue-2734.rs +++ b/src/test/run-pass/issue-2734.rs @@ -23,5 +23,5 @@ fn deadcode() { } pub fn main() { - let _ = perform_hax(box 42i); + let _ = perform_hax(box 42); } diff --git a/src/test/run-pass/issue-2735.rs b/src/test/run-pass/issue-2735.rs index cb376d0e439..962359537bf 100644 --- a/src/test/run-pass/issue-2735.rs +++ b/src/test/run-pass/issue-2735.rs @@ -23,5 +23,5 @@ fn deadcode() { } pub fn main() { - perform_hax(box 42i); + perform_hax(box 42); } diff --git a/src/test/run-pass/issue-2935.rs b/src/test/run-pass/issue-2935.rs index 295fd538de6..31599d0caad 100644 --- a/src/test/run-pass/issue-2935.rs +++ b/src/test/run-pass/issue-2935.rs @@ -24,9 +24,9 @@ impl it for t { } pub fn main() { - // let x = ({a: 4i} as it); - // let y = box ({a: 4i}); - // let z = box ({a: 4i} as it); + // let x = ({a: 4} as it); + // let y = box ({a: 4}); + // let z = box ({a: 4} as it); // let z = box ({a: true} as it); let z = box() (box true as Box<it>); // x.f(); diff --git a/src/test/run-pass/issue-3091.rs b/src/test/run-pass/issue-3091.rs index 2e287e24e23..c4c2c2b7da8 100644 --- a/src/test/run-pass/issue-3091.rs +++ b/src/test/run-pass/issue-3091.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let x = 1i; - let y = 1i; + let x = 1; + let y = 1; assert_eq!(&x, &y); } diff --git a/src/test/run-pass/issue-3211.rs b/src/test/run-pass/issue-3211.rs index c908c073d4f..28c9bf1e83a 100644 --- a/src/test/run-pass/issue-3211.rs +++ b/src/test/run-pass/issue-3211.rs @@ -9,8 +9,8 @@ // except according to those terms. pub fn main() { - let mut x = 0i; - for _ in 0i..4096 { x += 1; } + let mut x = 0; + for _ in 0..4096 { x += 1; } assert_eq!(x, 4096); println!("x = {}", x); } diff --git a/src/test/run-pass/issue-3290.rs b/src/test/run-pass/issue-3290.rs index a72b272abaa..c8d6e69801f 100644 --- a/src/test/run-pass/issue-3290.rs +++ b/src/test/run-pass/issue-3290.rs @@ -12,7 +12,7 @@ #![feature(box_syntax)] pub fn main() { - let mut x = box 3i; + let mut x = box 3; x = x; assert_eq!(*x, 3); } diff --git a/src/test/run-pass/issue-333.rs b/src/test/run-pass/issue-333.rs index ef49d0a170f..1217f32826f 100644 --- a/src/test/run-pass/issue-333.rs +++ b/src/test/run-pass/issue-333.rs @@ -12,4 +12,4 @@ fn quux<T>(x: T) -> T { let f = id::<T>; return f(x); } fn id<T>(x: T) -> T { return x; } -pub fn main() { assert!((quux(10i) == 10i)); } +pub fn main() { assert!((quux(10) == 10)); } diff --git a/src/test/run-pass/issue-3500.rs b/src/test/run-pass/issue-3500.rs index eb422c9a8b9..99def5476f9 100644 --- a/src/test/run-pass/issue-3500.rs +++ b/src/test/run-pass/issue-3500.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let x = &Some(1i); + let x = &Some(1); match x { &Some(_) => (), &None => (), diff --git a/src/test/run-pass/issue-3559.rs b/src/test/run-pass/issue-3559.rs index 0118fce4ec3..69a148d4108 100644 --- a/src/test/run-pass/issue-3559.rs +++ b/src/test/run-pass/issue-3559.rs @@ -22,8 +22,8 @@ fn check_strs(actual: &str, expected: &str) -> bool { pub fn main() { let mut table = HashMap::new(); - table.insert("one".to_string(), 1i); - table.insert("two".to_string(), 2i); + table.insert("one".to_string(), 1); + table.insert("two".to_string(), 2); assert!(check_strs(format!("{:?}", table).as_slice(), "HashMap {\"one\": 1, \"two\": 2}") || check_strs(format!("{:?}", table).as_slice(), "HashMap {\"two\": 2, \"one\": 1}")); } diff --git a/src/test/run-pass/issue-3878.rs b/src/test/run-pass/issue-3878.rs index 5434e44c173..c1d19f228db 100644 --- a/src/test/run-pass/issue-3878.rs +++ b/src/test/run-pass/issue-3878.rs @@ -13,6 +13,6 @@ #![feature(box_syntax)] pub fn main() { - let y = box 1i; + let y = box 1; y; } diff --git a/src/test/run-pass/issue-4387.rs b/src/test/run-pass/issue-4387.rs index 43948ef4a45..02601ba2f2a 100644 --- a/src/test/run-pass/issue-4387.rs +++ b/src/test/run-pass/issue-4387.rs @@ -9,5 +9,5 @@ // except according to those terms. pub fn main() { - let _foo = [0i; 2*4]; + let _foo = [0; 2*4]; } diff --git a/src/test/run-pass/issue-4401.rs b/src/test/run-pass/issue-4401.rs index a03253b8efb..e4fea724c79 100644 --- a/src/test/run-pass/issue-4401.rs +++ b/src/test/run-pass/issue-4401.rs @@ -9,8 +9,8 @@ // except according to those terms. pub fn main() { - let mut count = 0i; - for _ in 0i..999_999 { count += 1; } + let mut count = 0; + for _ in 0..999_999 { count += 1; } assert_eq!(count, 999_999); println!("{}", count); } diff --git a/src/test/run-pass/issue-5708.rs b/src/test/run-pass/issue-5708.rs index 61ae273aef5..fd39bcc6b61 100644 --- a/src/test/run-pass/issue-5708.rs +++ b/src/test/run-pass/issue-5708.rs @@ -41,7 +41,7 @@ impl<'a> Outer<'a> { } pub fn main() { - let inner = 5i; + let inner = 5; let outer = Outer::new(&inner as &Inner); outer.inner.print(); } diff --git a/src/test/run-pass/issue-6117.rs b/src/test/run-pass/issue-6117.rs index 85de03dfe34..93edffdcb47 100644 --- a/src/test/run-pass/issue-6117.rs +++ b/src/test/run-pass/issue-6117.rs @@ -14,7 +14,7 @@ enum Either<T, U> { Left(T), Right(U) } pub fn main() { - match Either::Left(box 17i) { + match Either::Left(box 17) { Either::Right(()) => {} _ => {} } diff --git a/src/test/run-pass/issue-6318.rs b/src/test/run-pass/issue-6318.rs index b9f1a8bda7b..1d8fe8bfce8 100644 --- a/src/test/run-pass/issue-6318.rs +++ b/src/test/run-pass/issue-6318.rs @@ -23,7 +23,7 @@ impl Foo for Struct {} pub fn main() { match Thing::A(box Struct as Box<Foo+'static>) { - Thing::A(_a) => 0i, + Thing::A(_a) => 0, }; } diff --git a/src/test/run-pass/issue-7178.rs b/src/test/run-pass/issue-7178.rs index 4acb4959724..6ef740b2a50 100644 --- a/src/test/run-pass/issue-7178.rs +++ b/src/test/run-pass/issue-7178.rs @@ -13,5 +13,5 @@ extern crate "issue-7178" as cross_crate_self; pub fn main() { - let _ = cross_crate_self::Foo::new(&1i); + let _ = cross_crate_self::Foo::new(&1); } diff --git a/src/test/run-pass/issue-7575.rs b/src/test/run-pass/issue-7575.rs index d60e5caee68..225213db6a4 100644 --- a/src/test/run-pass/issue-7575.rs +++ b/src/test/run-pass/issue-7575.rs @@ -20,5 +20,5 @@ impl Bar for int {} impl Foo for int {} fn main() { - assert!(1i.new()); + assert!(1.new()); } diff --git a/src/test/run-pass/issue-7784.rs b/src/test/run-pass/issue-7784.rs index 882ca00f1df..a61ee8c2a0b 100644 --- a/src/test/run-pass/issue-7784.rs +++ b/src/test/run-pass/issue-7784.rs @@ -20,7 +20,7 @@ fn bar(a: &'static str, b: &'static str) -> [&'static str; 4] { } fn main() { - assert_eq!(foo([1i, 2i, 3i]), (1i, 3i, 6i)); + assert_eq!(foo([1, 2, 3]), (1, 3, 6)); let [a, b, c, d] = bar("foo", "bar"); assert_eq!(a, "foo"); diff --git a/src/test/run-pass/issue-8044.rs b/src/test/run-pass/issue-8044.rs index c50cf845d00..504441e3ba9 100644 --- a/src/test/run-pass/issue-8044.rs +++ b/src/test/run-pass/issue-8044.rs @@ -14,5 +14,5 @@ extern crate "issue-8044" as minimal; use minimal::{BTree, leaf}; pub fn main() { - BTree::<int> { node: leaf(1i) }; + BTree::<int> { node: leaf(1) }; } diff --git a/src/test/run-pass/issue-8391.rs b/src/test/run-pass/issue-8391.rs index 468e6563182..86c9b8c6964 100644 --- a/src/test/run-pass/issue-8391.rs +++ b/src/test/run-pass/issue-8391.rs @@ -9,9 +9,9 @@ // except according to those terms. fn main() { - let x = match Some(1i) { - ref _y @ Some(_) => 1i, - None => 2i, + let x = match Some(1) { + ref _y @ Some(_) => 1, + None => 2, }; assert_eq!(x, 1); } diff --git a/src/test/run-pass/issue-8460.rs b/src/test/run-pass/issue-8460.rs index 3ea6d5d4f2f..3944895460f 100644 --- a/src/test/run-pass/issue-8460.rs +++ b/src/test/run-pass/issue-8460.rs @@ -17,7 +17,7 @@ fn main() { assert!(Thread::scoped(move|| i16::MIN / -1).join().is_err()); assert!(Thread::scoped(move|| i32::MIN / -1).join().is_err()); assert!(Thread::scoped(move|| i64::MIN / -1).join().is_err()); - assert!(Thread::scoped(move|| 1i / 0).join().is_err()); + assert!(Thread::scoped(move|| 1 / 0).join().is_err()); assert!(Thread::scoped(move|| 1i8 / 0).join().is_err()); assert!(Thread::scoped(move|| 1i16 / 0).join().is_err()); assert!(Thread::scoped(move|| 1i32 / 0).join().is_err()); @@ -27,7 +27,7 @@ fn main() { assert!(Thread::scoped(move|| i16::MIN % -1).join().is_err()); assert!(Thread::scoped(move|| i32::MIN % -1).join().is_err()); assert!(Thread::scoped(move|| i64::MIN % -1).join().is_err()); - assert!(Thread::scoped(move|| 1i % 0).join().is_err()); + assert!(Thread::scoped(move|| 1 % 0).join().is_err()); assert!(Thread::scoped(move|| 1i8 % 0).join().is_err()); assert!(Thread::scoped(move|| 1i16 % 0).join().is_err()); assert!(Thread::scoped(move|| 1i32 % 0).join().is_err()); diff --git a/src/test/run-pass/issue-8498.rs b/src/test/run-pass/issue-8498.rs index 2a2ca4f0712..494b6217855 100644 --- a/src/test/run-pass/issue-8498.rs +++ b/src/test/run-pass/issue-8498.rs @@ -12,14 +12,14 @@ #![feature(box_syntax)] pub fn main() { - match &[(box 5i,box 7i)] { + match &[(box 5,box 7)] { ps => { let (ref y, _) = ps[0]; assert!(**y == 5); } } - match Some(&[(box 5i,)]) { + match Some(&[(box 5,)]) { Some(ps) => { let (ref y,) = ps[0]; assert!(**y == 5); @@ -27,7 +27,7 @@ pub fn main() { None => () } - match Some(&[(box 5i,box 7i)]) { + match Some(&[(box 5,box 7)]) { Some(ps) => { let (ref y, ref z) = ps[0]; assert!(**y == 5); diff --git a/src/test/run-pass/issue-868.rs b/src/test/run-pass/issue-868.rs index 72bdd1af746..b2ccc092358 100644 --- a/src/test/run-pass/issue-868.rs +++ b/src/test/run-pass/issue-868.rs @@ -11,7 +11,7 @@ fn f<T, F>(g: F) -> T where F: FnOnce() -> T { g() } pub fn main() { - let _x = f( | | { 10i }); + let _x = f( | | { 10 }); // used to be: cannot determine a type for this expression f(| | { }); // ditto diff --git a/src/test/run-pass/issue-8827.rs b/src/test/run-pass/issue-8827.rs index 80beeb7275c..d7a86749546 100644 --- a/src/test/run-pass/issue-8827.rs +++ b/src/test/run-pass/issue-8827.rs @@ -49,7 +49,7 @@ fn main() { let ints = integers(); let threes = periodical(3); let fives = periodical(5); - for _ in 1i..100i { + for _ in 1..100 { match (ints.recv().unwrap(), threes.recv().unwrap(), fives.recv().unwrap()) { (_, true, true) => println!("FizzBuzz"), (_, true, false) => println!("Fizz"), diff --git a/src/test/run-pass/issue-8860.rs b/src/test/run-pass/issue-8860.rs index 35f713c4c2c..72e2a33b43e 100644 --- a/src/test/run-pass/issue-8860.rs +++ b/src/test/run-pass/issue-8860.rs @@ -8,9 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -static mut DROP: int = 0i; -static mut DROP_S: int = 0i; -static mut DROP_T: int = 0i; +static mut DROP: int = 0; +static mut DROP_S: int = 0; +static mut DROP_T: int = 0; struct S; impl Drop for S { diff --git a/src/test/run-pass/issue-9719.rs b/src/test/run-pass/issue-9719.rs index 4c6b9a3aaa0..8fc86eb49e7 100644 --- a/src/test/run-pass/issue-9719.rs +++ b/src/test/run-pass/issue-9719.rs @@ -17,7 +17,7 @@ mod a { impl X for int {} pub struct Z<'a>(Enum<&'a (X+'a)>); - fn foo() { let x = 42i; let z = Z(Enum::A(&x as &X)); let _ = z; } + fn foo() { let x = 42; let z = Z(Enum::A(&x as &X)); let _ = z; } } mod b { @@ -28,7 +28,7 @@ mod b { } fn bar() { - let x = 42i; + let x = 42; let _y = Y { x: Some(&x as &X) }; } } @@ -37,7 +37,7 @@ mod c { pub trait X { fn f(&self); } impl X for int { fn f(&self) {} } pub struct Z<'a>(Option<&'a (X+'a)>); - fn main() { let x = 42i; let z = Z(Some(&x as &X)); let _ = z; } + fn main() { let x = 42; let z = Z(Some(&x as &X)); let _ = z; } } pub fn main() {} diff --git a/src/test/run-pass/issue-9906.rs b/src/test/run-pass/issue-9906.rs index d8e28e449ee..921965b280b 100644 --- a/src/test/run-pass/issue-9906.rs +++ b/src/test/run-pass/issue-9906.rs @@ -14,5 +14,5 @@ extern crate "issue-9906" as testmod; pub fn main() { testmod::foo(); - testmod::FooBar::new(1i); + testmod::FooBar::new(1); } diff --git a/src/test/run-pass/issue-9942.rs b/src/test/run-pass/issue-9942.rs index 321e22cd19c..c7dea719986 100644 --- a/src/test/run-pass/issue-9942.rs +++ b/src/test/run-pass/issue-9942.rs @@ -9,5 +9,5 @@ // except according to those terms. pub fn main() { - const S: uint = 23 as uint; [0i; S]; () + const S: uint = 23 as uint; [0; S]; () } diff --git a/src/test/run-pass/keyword-changes-2012-07-31.rs b/src/test/run-pass/keyword-changes-2012-07-31.rs index 885f266ca3d..ff568b77f08 100644 --- a/src/test/run-pass/keyword-changes-2012-07-31.rs +++ b/src/test/run-pass/keyword-changes-2012-07-31.rs @@ -19,7 +19,7 @@ mod foo { } fn bar() -> int { - match 0i { - _ => { 0i } + match 0 { + _ => { 0 } } } diff --git a/src/test/run-pass/kindck-owned-trait-contains-1.rs b/src/test/run-pass/kindck-owned-trait-contains-1.rs index 999fb2c4b69..f05ac11d413 100644 --- a/src/test/run-pass/kindck-owned-trait-contains-1.rs +++ b/src/test/run-pass/kindck-owned-trait-contains-1.rs @@ -24,7 +24,7 @@ fn repeater<A:Clone + 'static>(v: Box<A>) -> Box<repeat<A>+'static> { } pub fn main() { - let x = 3i; + let x = 3; let y = repeater(box x); assert_eq!(x, y.get()); } diff --git a/src/test/run-pass/labeled-break.rs b/src/test/run-pass/labeled-break.rs index ebfe1e353d8..30c2495d590 100644 --- a/src/test/run-pass/labeled-break.rs +++ b/src/test/run-pass/labeled-break.rs @@ -15,13 +15,13 @@ pub fn main() { } } - 'bar: for _ in 0i..100i { + 'bar: for _ in 0..100 { loop { break 'bar; } } - 'foobar: while 1i + 1 == 2 { + 'foobar: while 1 + 1 == 2 { loop { break 'foobar; } diff --git a/src/test/run-pass/last-use-in-cap-clause.rs b/src/test/run-pass/last-use-in-cap-clause.rs index 9be9f098264..0cdd4d3889c 100644 --- a/src/test/run-pass/last-use-in-cap-clause.rs +++ b/src/test/run-pass/last-use-in-cap-clause.rs @@ -17,7 +17,7 @@ struct A { a: Box<int> } fn foo() -> Box<FnMut() -> int + 'static> { - let k = box 22i; + let k = box 22; let _u = A {a: k.clone()}; let result = |&mut:| 22; box result diff --git a/src/test/run-pass/last-use-is-capture.rs b/src/test/run-pass/last-use-is-capture.rs index 4a7e844268f..19a780d180f 100644 --- a/src/test/run-pass/last-use-is-capture.rs +++ b/src/test/run-pass/last-use-is-capture.rs @@ -17,7 +17,7 @@ struct A { a: Box<int> } pub fn main() { fn invoke<F>(f: F) where F: FnOnce() { f(); } - let k = box 22i; + let k = box 22; let _u = A {a: k.clone()}; invoke(|| println!("{}", k.clone()) ) } diff --git a/src/test/run-pass/lazy-and-or.rs b/src/test/run-pass/lazy-and-or.rs index 043961ce599..559c9e78945 100644 --- a/src/test/run-pass/lazy-and-or.rs +++ b/src/test/run-pass/lazy-and-or.rs @@ -11,7 +11,7 @@ fn incr(x: &mut int) -> bool { *x += 1; assert!((false)); return false; } pub fn main() { - let x = 1i == 2 || 3i == 3; + let x = 1 == 2 || 3 == 3; assert!((x)); let mut y: int = 10; println!("{}", x || incr(&mut y)); diff --git a/src/test/run-pass/lazy-init.rs b/src/test/run-pass/lazy-init.rs index cd8be550d51..60f7689ecfa 100644 --- a/src/test/run-pass/lazy-init.rs +++ b/src/test/run-pass/lazy-init.rs @@ -12,4 +12,4 @@ fn foo(x: int) { println!("{}", x); } -pub fn main() { let mut x: int; if 1i > 2 { x = 12; } else { x = 10; } foo(x); } +pub fn main() { let mut x: int; if 1 > 2 { x = 12; } else { x = 10; } foo(x); } diff --git a/src/test/run-pass/let-var-hygiene.rs b/src/test/run-pass/let-var-hygiene.rs index 2287cc48b66..d6409267eb6 100644 --- a/src/test/run-pass/let-var-hygiene.rs +++ b/src/test/run-pass/let-var-hygiene.rs @@ -10,10 +10,10 @@ // shouldn't affect evaluation of $ex: macro_rules! bad_macro { - ($ex:expr) => ({let _x = 9i; $ex}) + ($ex:expr) => ({let _x = 9; $ex}) } pub fn main() { - let _x = 8i; - assert_eq!(bad_macro!(_x),8i) + let _x = 8; + assert_eq!(bad_macro!(_x),8) } diff --git a/src/test/run-pass/linear-for-loop.rs b/src/test/run-pass/linear-for-loop.rs index 6a2140d49cd..eda14222e91 100644 --- a/src/test/run-pass/linear-for-loop.rs +++ b/src/test/run-pass/linear-for-loop.rs @@ -11,8 +11,8 @@ // no-pretty-expanded FIXME #15189 pub fn main() { - let x = vec!(1i, 2i, 3i); - let mut y = 0i; + let x = vec!(1, 2, 3); + let mut y = 0; for i in x.iter() { println!("{}", *i); y += *i; } println!("{}", y); assert_eq!(y, 6); diff --git a/src/test/run-pass/liveness-loop-break.rs b/src/test/run-pass/liveness-loop-break.rs index 6ad2be68e8f..0dba1830cbd 100644 --- a/src/test/run-pass/liveness-loop-break.rs +++ b/src/test/run-pass/liveness-loop-break.rs @@ -11,7 +11,7 @@ fn test() { let v; loop { - v = 3i; + v = 3; break; } println!("{}", v); diff --git a/src/test/run-pass/log-poly.rs b/src/test/run-pass/log-poly.rs index ce598c5d382..d8a69177caf 100644 --- a/src/test/run-pass/log-poly.rs +++ b/src/test/run-pass/log-poly.rs @@ -14,8 +14,8 @@ enum Numbers { } pub fn main() { - println!("{:?}", 1i); + println!("{:?}", 1); println!("{:?}", 2.0f64); println!("{:?}", Numbers::Three); - println!("{:?}", vec!(4i)); + println!("{:?}", vec!(4)); } diff --git a/src/test/run-pass/long-while.rs b/src/test/run-pass/long-while.rs index 7d30b22867c..cbe26844708 100644 --- a/src/test/run-pass/long-while.rs +++ b/src/test/run-pass/long-while.rs @@ -14,6 +14,6 @@ pub fn main() { let mut i: int = 0; while i < 1000000 { i += 1; - let x = 3i; + let x = 3; } } diff --git a/src/test/run-pass/loop-diverges.rs b/src/test/run-pass/loop-diverges.rs index 4fe73188b45..9c46ba2cb9b 100644 --- a/src/test/run-pass/loop-diverges.rs +++ b/src/test/run-pass/loop-diverges.rs @@ -16,5 +16,5 @@ fn forever() -> ! { } pub fn main() { - if (1i == 2) { forever(); } + if (1 == 2) { forever(); } } diff --git a/src/test/run-pass/loop-label-shadowing.rs b/src/test/run-pass/loop-label-shadowing.rs index 46d4fa460fe..cfe51fe7758 100644 --- a/src/test/run-pass/loop-label-shadowing.rs +++ b/src/test/run-pass/loop-label-shadowing.rs @@ -12,7 +12,7 @@ fn main() { let mut foo = Vec::new(); - 'foo: for i in [1i, 2, 3].iter() { + 'foo: for i in [1, 2, 3].iter() { foo.push(i); } } diff --git a/src/test/run-pass/loop-no-reinit-needed-post-bot.rs b/src/test/run-pass/loop-no-reinit-needed-post-bot.rs index 0f4dd881698..2582c2e6147 100644 --- a/src/test/run-pass/loop-no-reinit-needed-post-bot.rs +++ b/src/test/run-pass/loop-no-reinit-needed-post-bot.rs @@ -17,7 +17,7 @@ fn my_panic() -> ! { loop {} } pub fn step(f: bool) { let mut g = S; - let mut i = 0i; + let mut i = 0; loop { if i > 10 { break; } else { i += 1; } diff --git a/src/test/run-pass/loop-scope.rs b/src/test/run-pass/loop-scope.rs index 4b8ccad068c..1dc3700194c 100644 --- a/src/test/run-pass/loop-scope.rs +++ b/src/test/run-pass/loop-scope.rs @@ -9,8 +9,8 @@ // except according to those terms. pub fn main() { - let x = vec!(10i, 20i, 30i); - let mut sum = 0i; + let x = vec!(10, 20, 30); + let mut sum = 0; for x in x.iter() { sum += *x; } assert_eq!(sum, 60); } diff --git a/src/test/run-pass/macro-crate-def-only.rs b/src/test/run-pass/macro-crate-def-only.rs index 7505fa6e684..efee9ba963a 100644 --- a/src/test/run-pass/macro-crate-def-only.rs +++ b/src/test/run-pass/macro-crate-def-only.rs @@ -14,5 +14,5 @@ extern crate macro_crate_def_only; pub fn main() { - assert_eq!(5i, make_a_5!()); + assert_eq!(5, make_a_5!()); } diff --git a/src/test/run-pass/macro-export-inner-module.rs b/src/test/run-pass/macro-export-inner-module.rs index ef22410751c..1c7b2530b90 100644 --- a/src/test/run-pass/macro-export-inner-module.rs +++ b/src/test/run-pass/macro-export-inner-module.rs @@ -15,5 +15,5 @@ extern crate macro_export_inner_module; pub fn main() { - assert_eq!(1i, foo!()); + assert_eq!(1, foo!()); } diff --git a/src/test/run-pass/macro-pat.rs b/src/test/run-pass/macro-pat.rs index 07b75389cf4..30a74126b49 100644 --- a/src/test/run-pass/macro-pat.rs +++ b/src/test/run-pass/macro-pat.rs @@ -51,23 +51,23 @@ pub fn main() { assert_eq!(2u, f(Some('y'))); assert_eq!(3u, f(None)); - assert_eq!(1i, match Some('x') { - Some(char_x!()) => 1i, - _ => 2i, + assert_eq!(1, match Some('x') { + Some(char_x!()) => 1, + _ => 2, }); - assert_eq!(1i, match Some('x') { - some!(char_x!()) => 1i, - _ => 2i, + assert_eq!(1, match Some('x') { + some!(char_x!()) => 1, + _ => 2, }); - assert_eq!(1i, match Some('x') { - indirect!() => 1i, - _ => 2i, + assert_eq!(1, match Some('x') { + indirect!() => 1, + _ => 2, }); - assert_eq!(3i, { - let ident_pat!(x) = 2i; - x+1i + assert_eq!(3, { + let ident_pat!(x) = 2; + x+1 }); } diff --git a/src/test/run-pass/macro-stmt.rs b/src/test/run-pass/macro-stmt.rs index cb5370c8bcb..3aa02987098 100644 --- a/src/test/run-pass/macro-stmt.rs +++ b/src/test/run-pass/macro-stmt.rs @@ -26,17 +26,17 @@ pub fn main() { ) } - mylet!(y, 8i*2); - assert_eq!(y, 16i); + mylet!(y, 8*2); + assert_eq!(y, 16); myfn!(mult, (a,b), { a*b } ); assert_eq!(mult(2, add(4,4)), 16); macro_rules! actually_an_expr_macro { - () => ( 16i ) + () => ( 16 ) } - assert_eq!({ actually_an_expr_macro!() }, 16i); + assert_eq!({ actually_an_expr_macro!() }, 16); } diff --git a/src/test/run-pass/macro-with-attrs1.rs b/src/test/run-pass/macro-with-attrs1.rs index 3f9d07466cc..f180922a052 100644 --- a/src/test/run-pass/macro-with-attrs1.rs +++ b/src/test/run-pass/macro-with-attrs1.rs @@ -11,11 +11,11 @@ // compile-flags: --cfg foo #[cfg(foo)] -macro_rules! foo { () => (1i) } +macro_rules! foo { () => (1) } #[cfg(not(foo))] -macro_rules! foo { () => (2i) } +macro_rules! foo { () => (2) } pub fn main() { - assert_eq!(foo!(), 1i); + assert_eq!(foo!(), 1); } diff --git a/src/test/run-pass/macro-with-attrs2.rs b/src/test/run-pass/macro-with-attrs2.rs index f90a0dfa6b3..d683979462b 100644 --- a/src/test/run-pass/macro-with-attrs2.rs +++ b/src/test/run-pass/macro-with-attrs2.rs @@ -9,12 +9,12 @@ // except according to those terms. #[cfg(foo)] -macro_rules! foo { () => (1i) } +macro_rules! foo { () => (1) } #[cfg(not(foo))] -macro_rules! foo { () => (2i) } +macro_rules! foo { () => (2) } pub fn main() { - assert_eq!(foo!(), 2i); + assert_eq!(foo!(), 2); } diff --git a/src/test/run-pass/match-arm-statics.rs b/src/test/run-pass/match-arm-statics.rs index 1964bf4bd7d..dfefe84518c 100644 --- a/src/test/run-pass/match-arm-statics.rs +++ b/src/test/run-pass/match-arm-statics.rs @@ -84,7 +84,7 @@ fn issue_14576() { enum C { D = 3, E = 4 } const F : C = C::D; - assert_eq!(match C::D { F => 1i, _ => 2, }, 1); + assert_eq!(match C::D { F => 1, _ => 2, }, 1); } fn issue_13731() { @@ -113,14 +113,14 @@ fn issue_15393() { fn main() { assert_eq!(match (true, false) { - TRUE_TRUE => 1i, + TRUE_TRUE => 1, (false, false) => 2, (false, true) => 3, (true, false) => 4 }, 4); assert_eq!(match Some(Some(Direction::North)) { - Some(NONE) => 1i, + Some(NONE) => 1, Some(Some(Direction::North)) => 2, Some(Some(EAST)) => 3, Some(Some(Direction::South)) => 4, @@ -129,7 +129,7 @@ fn main() { }, 2); assert_eq!(match (Foo { bar: Some(Direction::West), baz: NewBool(true) }) { - Foo { bar: None, baz: NewBool(true) } => 1i, + Foo { bar: None, baz: NewBool(true) } => 1, Foo { bar: NONE, baz: NEW_FALSE } => 2, STATIC_FOO => 3, Foo { bar: _, baz: NEW_FALSE } => 4, @@ -140,7 +140,7 @@ fn main() { }, 5); assert_eq!(match (EnumWithStructVariants::Variant2 { dir: Direction::North }) { - EnumWithStructVariants::Variant1(true) => 1i, + EnumWithStructVariants::Variant1(true) => 1, EnumWithStructVariants::Variant1(false) => 2, EnumWithStructVariants::Variant2 { dir: Direction::West } => 3, VARIANT2_NORTH => 4, diff --git a/src/test/run-pass/match-bot-2.rs b/src/test/run-pass/match-bot-2.rs index 5b48d0ff508..949fad11344 100644 --- a/src/test/run-pass/match-bot-2.rs +++ b/src/test/run-pass/match-bot-2.rs @@ -9,5 +9,5 @@ // except according to those terms. // n.b. This was only ever failing with optimization disabled. -fn a() -> int { match return 1i { 2i => 3i, _ => panic!() } } +fn a() -> int { match return 1 { 2 => 3, _ => panic!() } } pub fn main() { a(); } diff --git a/src/test/run-pass/match-naked-record-expr.rs b/src/test/run-pass/match-naked-record-expr.rs index 170a3513a1a..433cf23626b 100644 --- a/src/test/run-pass/match-naked-record-expr.rs +++ b/src/test/run-pass/match-naked-record-expr.rs @@ -11,7 +11,7 @@ struct X { x: int } pub fn main() { - let _x = match 0i { + let _x = match 0 { _ => X { x: 0 }.x diff --git a/src/test/run-pass/match-naked-record.rs b/src/test/run-pass/match-naked-record.rs index 21c31b62183..fe12b7c1585 100644 --- a/src/test/run-pass/match-naked-record.rs +++ b/src/test/run-pass/match-naked-record.rs @@ -11,7 +11,7 @@ struct X { x: int } pub fn main() { - let _x = match 0i { + let _x = match 0 { _ => X { x: 0 } diff --git a/src/test/run-pass/match-pattern-bindings.rs b/src/test/run-pass/match-pattern-bindings.rs index e6ce94ec5d4..abb78fc8310 100644 --- a/src/test/run-pass/match-pattern-bindings.rs +++ b/src/test/run-pass/match-pattern-bindings.rs @@ -9,15 +9,15 @@ // except according to those terms. fn main() { - let value = Some(1i); + let value = Some(1); assert_eq!(match value { ref a @ Some(_) => a, ref b @ None => b - }, &Some(1i)); + }, &Some(1)); assert_eq!(match value { ref c @ Some(_) => c, ref b @ None => b - }, &Some(1i)); + }, &Some(1)); assert_eq!(match "foobarbaz" { b @ _ => b }, "foobarbaz"); diff --git a/src/test/run-pass/match-pipe-binding.rs b/src/test/run-pass/match-pipe-binding.rs index ed2f7c5cb47..bdf12d22edd 100644 --- a/src/test/run-pass/match-pipe-binding.rs +++ b/src/test/run-pass/match-pipe-binding.rs @@ -10,7 +10,7 @@ fn test1() { // from issue 6338 - match ((1i, "a".to_string()), (2i, "b".to_string())) { + match ((1, "a".to_string()), (2, "b".to_string())) { ((1, a), (2, b)) | ((2, b), (1, a)) => { assert_eq!(a, "a".to_string()); assert_eq!(b, "b".to_string()); @@ -20,7 +20,7 @@ fn test1() { } fn test2() { - match (1i, 2i, 3i) { + match (1, 2, 3) { (1, a, b) | (2, b, a) => { assert_eq!(a, 2); assert_eq!(b, 3); @@ -30,7 +30,7 @@ fn test2() { } fn test3() { - match (1i, 2i, 3i) { + match (1, 2, 3) { (1, ref a, ref b) | (2, ref b, ref a) => { assert_eq!(*a, 2); assert_eq!(*b, 3); @@ -40,7 +40,7 @@ fn test3() { } fn test4() { - match (1i, 2i, 3i) { + match (1, 2, 3) { (1, a, b) | (2, b, a) if a == 2 => { assert_eq!(a, 2); assert_eq!(b, 3); @@ -50,7 +50,7 @@ fn test4() { } fn test5() { - match (1i, 2i, 3i) { + match (1, 2, 3) { (1, ref a, ref b) | (2, ref b, ref a) if *a == 2 => { assert_eq!(*a, 2); assert_eq!(*b, 3); diff --git a/src/test/run-pass/match-range.rs b/src/test/run-pass/match-range.rs index 83066c126ce..b9ab0c85ec4 100644 --- a/src/test/run-pass/match-range.rs +++ b/src/test/run-pass/match-range.rs @@ -28,7 +28,7 @@ pub fn main() { 'a'...'z' => {} _ => panic!("should suppport char ranges") } - match -3i { + match -3 { -7...5 => {} _ => panic!("should match signed range") } diff --git a/src/test/run-pass/match-ref-binding-mut-option.rs b/src/test/run-pass/match-ref-binding-mut-option.rs index c983903ac18..8d1e483bcd8 100644 --- a/src/test/run-pass/match-ref-binding-mut-option.rs +++ b/src/test/run-pass/match-ref-binding-mut-option.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let mut v = Some(22i); + let mut v = Some(22); match v { None => {} Some(ref mut p) => { *p += 1; } diff --git a/src/test/run-pass/match-str.rs b/src/test/run-pass/match-str.rs index 544751754c6..60a5904cff3 100644 --- a/src/test/run-pass/match-str.rs +++ b/src/test/run-pass/match-str.rs @@ -23,7 +23,7 @@ pub fn main() { _ => panic!() } - let x = match "a" { "a" => 1i, "b" => 2i, _ => panic!() }; + let x = match "a" { "a" => 1, "b" => 2, _ => panic!() }; assert_eq!(x, 1); match "a" { "a" => { } "b" => { }, _ => panic!() } diff --git a/src/test/run-pass/match-unique-bind.rs b/src/test/run-pass/match-unique-bind.rs index ebe01a1d1f2..63817d42ae8 100644 --- a/src/test/run-pass/match-unique-bind.rs +++ b/src/test/run-pass/match-unique-bind.rs @@ -12,7 +12,7 @@ #![feature(box_syntax)] pub fn main() { - match box 100i { + match box 100 { box x => { println!("{}", x); assert_eq!(x, 100); diff --git a/src/test/run-pass/match-vec-alternatives.rs b/src/test/run-pass/match-vec-alternatives.rs index ae4fd1f1993..98b9d11ecdd 100644 --- a/src/test/run-pass/match-vec-alternatives.rs +++ b/src/test/run-pass/match-vec-alternatives.rs @@ -55,28 +55,28 @@ fn match_nested_vecs_snoc<'a, T>(l1: Option<&'a [T]>, l2: Result<&'a [T], ()>) - } fn main() { - assert_eq!(match_vecs(&[1i, 2], &[2i, 3]), "both non-empty"); - assert_eq!(match_vecs(&[], &[1i, 2, 3, 4]), "one empty"); + assert_eq!(match_vecs(&[1, 2], &[2, 3]), "both non-empty"); + assert_eq!(match_vecs(&[], &[1, 2, 3, 4]), "one empty"); assert_eq!(match_vecs::<uint>(&[], &[]), "both empty"); - assert_eq!(match_vecs(&[1i, 2, 3], &[]), "one empty"); + assert_eq!(match_vecs(&[1, 2, 3], &[]), "one empty"); - assert_eq!(match_vecs_cons(&[1i, 2], &[2i, 3]), "both non-empty"); - assert_eq!(match_vecs_cons(&[], &[1i, 2, 3, 4]), "one empty"); + assert_eq!(match_vecs_cons(&[1, 2], &[2, 3]), "both non-empty"); + assert_eq!(match_vecs_cons(&[], &[1, 2, 3, 4]), "one empty"); assert_eq!(match_vecs_cons::<uint>(&[], &[]), "both empty"); - assert_eq!(match_vecs_cons(&[1i, 2, 3], &[]), "one empty"); + assert_eq!(match_vecs_cons(&[1, 2, 3], &[]), "one empty"); - assert_eq!(match_vecs_snoc(&[1i, 2], &[2i, 3]), "both non-empty"); - assert_eq!(match_vecs_snoc(&[], &[1i, 2, 3, 4]), "one empty"); + assert_eq!(match_vecs_snoc(&[1, 2], &[2, 3]), "both non-empty"); + assert_eq!(match_vecs_snoc(&[], &[1, 2, 3, 4]), "one empty"); assert_eq!(match_vecs_snoc::<uint>(&[], &[]), "both empty"); - assert_eq!(match_vecs_snoc(&[1i, 2, 3], &[]), "one empty"); + assert_eq!(match_vecs_snoc(&[1, 2, 3], &[]), "one empty"); assert_eq!(match_nested_vecs_cons(None, Ok::<&[_], ()>(&[4u, 2u])), "None, Ok(at least two elements)"); assert_eq!(match_nested_vecs_cons::<uint>(None, Err(())), "None, Ok(less than one element)"); assert_eq!(match_nested_vecs_cons::<bool>(Some::<&[_]>(&[]), Ok::<&[_], ()>(&[])), "Some(empty), Ok(empty)"); - assert_eq!(match_nested_vecs_cons(Some::<&[_]>(&[1i]), Err(())), "Some(non-empty), any"); - assert_eq!(match_nested_vecs_cons(Some::<&[_]>(&[(42i, ())]), Ok::<&[_], ()>(&[(1i, ())])), + assert_eq!(match_nested_vecs_cons(Some::<&[_]>(&[1]), Err(())), "Some(non-empty), any"); + assert_eq!(match_nested_vecs_cons(Some::<&[_]>(&[(42, ())]), Ok::<&[_], ()>(&[(1, ())])), "Some(non-empty), any"); assert_eq!(match_nested_vecs_snoc(None, Ok::<&[_], ()>(&[4u, 2u])), @@ -84,7 +84,7 @@ fn main() { assert_eq!(match_nested_vecs_snoc::<uint>(None, Err(())), "None, Ok(less than one element)"); assert_eq!(match_nested_vecs_snoc::<bool>(Some::<&[_]>(&[]), Ok::<&[_], ()>(&[])), "Some(empty), Ok(empty)"); - assert_eq!(match_nested_vecs_snoc(Some::<&[_]>(&[1i]), Err(())), "Some(non-empty), any"); - assert_eq!(match_nested_vecs_snoc(Some::<&[_]>(&[(42i, ())]), Ok::<&[_], ()>(&[(1i, ())])), + assert_eq!(match_nested_vecs_snoc(Some::<&[_]>(&[1]), Err(())), "Some(non-empty), any"); + assert_eq!(match_nested_vecs_snoc(Some::<&[_]>(&[(42, ())]), Ok::<&[_], ()>(&[(1, ())])), "Some(non-empty), any"); } diff --git a/src/test/run-pass/match-vec-rvalue.rs b/src/test/run-pass/match-vec-rvalue.rs index 0f058086add..04a0204d206 100644 --- a/src/test/run-pass/match-vec-rvalue.rs +++ b/src/test/run-pass/match-vec-rvalue.rs @@ -12,7 +12,7 @@ pub fn main() { - match vec!(1i, 2i, 3i) { + match vec!(1, 2, 3) { x => { assert_eq!(x.len(), 3); assert_eq!(x[0], 1); diff --git a/src/test/run-pass/match-with-ret-arm.rs b/src/test/run-pass/match-with-ret-arm.rs index a1537e63e57..05c6aac90e3 100644 --- a/src/test/run-pass/match-with-ret-arm.rs +++ b/src/test/run-pass/match-with-ret-arm.rs @@ -14,7 +14,7 @@ pub fn main() { // sometimes we have had trouble finding // the right type for f, as we unified // bot and u32 here - let f = match "1234".parse::<uint>() { + let f = match "1234".parse::<uint>().ok() { None => return (), Some(num) => num as u32 }; diff --git a/src/test/run-pass/method-two-trait-defer-resolution-1.rs b/src/test/run-pass/method-two-trait-defer-resolution-1.rs index e4ae33c1c50..414b08b4335 100644 --- a/src/test/run-pass/method-two-trait-defer-resolution-1.rs +++ b/src/test/run-pass/method-two-trait-defer-resolution-1.rs @@ -12,28 +12,28 @@ // type that is (ultimately) inferred for `x`. trait foo { - fn foo(&self) -> int; + fn foo(&self) -> i32; } -impl foo for Vec<uint> { - fn foo(&self) -> int {1} +impl foo for Vec<u32> { + fn foo(&self) -> i32 {1} } -impl foo for Vec<int> { - fn foo(&self) -> int {2} +impl foo for Vec<i32> { + fn foo(&self) -> i32 {2} } -fn call_foo_uint() -> int { +fn call_foo_uint() -> i32 { let mut x = Vec::new(); let y = x.foo(); - x.push(0u); + x.push(0u32); y } -fn call_foo_int() -> int { +fn call_foo_int() -> i32 { let mut x = Vec::new(); let y = x.foo(); - x.push(0i); + x.push(0i32); y } diff --git a/src/test/run-pass/method-two-trait-defer-resolution-2.rs b/src/test/run-pass/method-two-trait-defer-resolution-2.rs index b18c29dc3c1..7f498b2b578 100644 --- a/src/test/run-pass/method-two-trait-defer-resolution-2.rs +++ b/src/test/run-pass/method-two-trait-defer-resolution-2.rs @@ -41,7 +41,7 @@ fn call_foo_copy() -> int { fn call_foo_other() -> int { let mut x = Vec::new(); let y = x.foo(); - x.push(box 0i); + x.push(box 0); y } diff --git a/src/test/run-pass/method-where-clause.rs b/src/test/run-pass/method-where-clause.rs index 4361c22f55a..6337538a332 100644 --- a/src/test/run-pass/method-where-clause.rs +++ b/src/test/run-pass/method-where-clause.rs @@ -12,24 +12,24 @@ // where clause type, and not only type parameters. trait Foo { - fn foo(&self) -> int; + fn foo(&self) -> i32; } -impl Foo for Option<int> +impl Foo for Option<i32> { - fn foo(&self) -> int { + fn foo(&self) -> i32 { self.unwrap_or(22) } } -impl Foo for Option<uint> +impl Foo for Option<u32> { - fn foo(&self) -> int { - self.unwrap_or(22) as int + fn foo(&self) -> i32 { + self.unwrap_or(22) as i32 } } -fn check<T>(x: Option<T>) -> (int, int) +fn check<T>(x: Option<T>) -> (i32, i32) where Option<T> : Foo { let y: Option<T> = None; @@ -37,6 +37,6 @@ fn check<T>(x: Option<T>) -> (int, int) } fn main() { - assert_eq!(check(Some(23u)), (23i, 22i)); - assert_eq!(check(Some(23i)), (23i, 22i)); + assert_eq!(check(Some(23u32)), (23, 22)); + assert_eq!(check(Some(23)), (23, 22)); } diff --git a/src/test/run-pass/monomorphized-callees-with-ty-params-3314.rs b/src/test/run-pass/monomorphized-callees-with-ty-params-3314.rs index 4ebebc46018..eb17aa78bd9 100644 --- a/src/test/run-pass/monomorphized-callees-with-ty-params-3314.rs +++ b/src/test/run-pass/monomorphized-callees-with-ty-params-3314.rs @@ -32,9 +32,9 @@ impl Serializer for int { } pub fn main() { - let foo = F { a: 1i }; - foo.serialize(1i); + let foo = F { a: 1 }; + foo.serialize(1); - let bar = F { a: F {a: 1i } }; - bar.serialize(2i); + let bar = F { a: F {a: 1 } }; + bar.serialize(2); } diff --git a/src/test/run-pass/multi-let.rs b/src/test/run-pass/multi-let.rs index 201abeba073..eb1444be378 100644 --- a/src/test/run-pass/multi-let.rs +++ b/src/test/run-pass/multi-let.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let x = 10i; + let x = 10; let y = x; assert!((y == 10)); } diff --git a/src/test/run-pass/multiple-trait-bounds.rs b/src/test/run-pass/multiple-trait-bounds.rs index 10abe4ce710..7ce1afb52a2 100644 --- a/src/test/run-pass/multiple-trait-bounds.rs +++ b/src/test/run-pass/multiple-trait-bounds.rs @@ -12,5 +12,5 @@ fn f<T:PartialEq + PartialOrd>(_: T) { } pub fn main() { - f(3i); + f(3); } diff --git a/src/test/run-pass/mut-in-ident-patterns.rs b/src/test/run-pass/mut-in-ident-patterns.rs index ad9161f9bd4..8be200d3bf3 100644 --- a/src/test/run-pass/mut-in-ident-patterns.rs +++ b/src/test/run-pass/mut-in-ident-patterns.rs @@ -20,7 +20,7 @@ struct X; impl Foo for X {} pub fn main() { - let (a, mut b) = (23i, 4i); + let (a, mut b) = (23, 4); assert_eq!(a, 23); assert_eq!(b, 4); b = a + b; @@ -34,7 +34,7 @@ pub fn main() { Baz(f32, u8) } - let (x, mut y) = (32i, Bar::Foo(21)); + let (x, mut y) = (32, Bar::Foo(21)); match x { mut z @ 32 => { diff --git a/src/test/run-pass/mutability-inherits-through-fixed-length-vec.rs b/src/test/run-pass/mutability-inherits-through-fixed-length-vec.rs index bf926a6c48a..7d6bbbe4240 100644 --- a/src/test/run-pass/mutability-inherits-through-fixed-length-vec.rs +++ b/src/test/run-pass/mutability-inherits-through-fixed-length-vec.rs @@ -9,13 +9,13 @@ // except according to those terms. fn test1() { - let mut ints = [0i; 32]; + let mut ints = [0; 32]; ints[0] += 1; assert_eq!(ints[0], 1); } fn test2() { - let mut ints = [0i; 32]; + let mut ints = [0; 32]; for i in ints.iter_mut() { *i += 22; } for i in ints.iter() { assert!(*i == 22); } } diff --git a/src/test/run-pass/negative.rs b/src/test/run-pass/negative.rs index 4bf91bf7035..435382666f1 100644 --- a/src/test/run-pass/negative.rs +++ b/src/test/run-pass/negative.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - match -5i { + match -5 { -5 => {} _ => { panic!() } } diff --git a/src/test/run-pass/nested-matchs.rs b/src/test/run-pass/nested-matchs.rs index 55c1de2700f..b0ac9fb597a 100644 --- a/src/test/run-pass/nested-matchs.rs +++ b/src/test/run-pass/nested-matchs.rs @@ -14,7 +14,7 @@ fn foo() { match Some::<int>(5) { Some::<int>(_x) => { let mut bar; - match None::<int> { None::<int> => { bar = 5i; } _ => { baz(); } } + match None::<int> { None::<int> => { bar = 5; } _ => { baz(); } } println!("{}", bar); } None::<int> => { println!("hello"); } diff --git a/src/test/run-pass/new-box-syntax.rs b/src/test/run-pass/new-box-syntax.rs index 4ea51b3b409..3d4847a119a 100644 --- a/src/test/run-pass/new-box-syntax.rs +++ b/src/test/run-pass/new-box-syntax.rs @@ -24,8 +24,8 @@ struct Structure { } pub fn main() { - let x: Box<int> = box(HEAP) 2i; - let y: Box<int> = box 2i; - let b: Box<int> = box()(1i + 2); - let c = box()(3i + 4); + let x: Box<int> = box(HEAP) 2; + let y: Box<int> = box 2; + let b: Box<int> = box()(1 + 2); + let c = box()(3 + 4); } diff --git a/src/test/run-pass/newtype-polymorphic.rs b/src/test/run-pass/newtype-polymorphic.rs index 74487f5b57d..4b7dbdc9e5b 100644 --- a/src/test/run-pass/newtype-polymorphic.rs +++ b/src/test/run-pass/newtype-polymorphic.rs @@ -23,7 +23,7 @@ fn myvec_elt<X>(mv: myvec<X>) -> X { } pub fn main() { - let mv = myvec(vec!(1i, 2, 3)); + let mv = myvec(vec!(1, 2, 3)); let mv_clone = mv.clone(); let mv_clone = myvec_deref(mv_clone); assert_eq!(mv_clone[1], 2); diff --git a/src/test/run-pass/numeric-method-autoexport.rs b/src/test/run-pass/numeric-method-autoexport.rs index b4d079d79d6..140cf33cd1d 100644 --- a/src/test/run-pass/numeric-method-autoexport.rs +++ b/src/test/run-pass/numeric-method-autoexport.rs @@ -21,7 +21,7 @@ use std::num::ToPrimitive; pub fn main() { // ints // num - assert_eq!(15i.add(6), 21); + assert_eq!(15is.add(6is), 21is); assert_eq!(15i8.add(6i8), 21i8); assert_eq!(15i16.add(6i16), 21i16); assert_eq!(15i32.add(6i32), 21i32); @@ -29,7 +29,7 @@ pub fn main() { // uints // num - assert_eq!(15u.add(6u), 21u); + assert_eq!(15u.add(6us), 21us); assert_eq!(15u8.add(6u8), 21u8); assert_eq!(15u16.add(6u16), 21u16); assert_eq!(15u32.add(6u32), 21u32); diff --git a/src/test/run-pass/object-one-type-two-traits.rs b/src/test/run-pass/object-one-type-two-traits.rs index ebdf3c08a22..f8a3ce7cda0 100644 --- a/src/test/run-pass/object-one-type-two-traits.rs +++ b/src/test/run-pass/object-one-type-two-traits.rs @@ -35,7 +35,7 @@ fn is<T:'static>(x: &Any) -> bool { } fn main() { - let x = box 22i as Box<Wrap>; + let x = box 22 as Box<Wrap>; println!("x={}", x.get()); let y = x.wrap(); } diff --git a/src/test/run-pass/operator-associativity.rs b/src/test/run-pass/operator-associativity.rs index 8d45b8ecb08..bee6d23a27d 100644 --- a/src/test/run-pass/operator-associativity.rs +++ b/src/test/run-pass/operator-associativity.rs @@ -12,4 +12,4 @@ // Testcase for issue #130, operator associativity. -pub fn main() { assert!((3i * 5i / 2i == 7i)); } +pub fn main() { assert!((3 * 5 / 2 == 7)); } diff --git a/src/test/run-pass/out-of-stack-new-thread-no-split.rs b/src/test/run-pass/out-of-stack-new-thread-no-split.rs index 1ede5f546d7..c9e2f893c0f 100644 --- a/src/test/run-pass/out-of-stack-new-thread-no-split.rs +++ b/src/test/run-pass/out-of-stack-new-thread-no-split.rs @@ -28,7 +28,7 @@ pub fn black_box<T>(dummy: T) { unsafe { asm!("" : : "r"(&dummy)) } } #[no_stack_check] fn recurse() { - let buf = [0i; 10]; + let buf = [0; 10]; black_box(buf); recurse(); } diff --git a/src/test/run-pass/out-of-stack-no-split.rs b/src/test/run-pass/out-of-stack-no-split.rs index adaa472c760..846fbd477e0 100644 --- a/src/test/run-pass/out-of-stack-no-split.rs +++ b/src/test/run-pass/out-of-stack-no-split.rs @@ -28,7 +28,7 @@ pub fn black_box<T>(dummy: T) { unsafe { asm!("" : : "r"(&dummy)) } } #[no_stack_check] fn recurse() { - let buf = [0i; 10]; + let buf = [0; 10]; black_box(buf); recurse(); } diff --git a/src/test/run-pass/out-of-stack.rs b/src/test/run-pass/out-of-stack.rs index 9615cfab5c1..97539a076ff 100644 --- a/src/test/run-pass/out-of-stack.rs +++ b/src/test/run-pass/out-of-stack.rs @@ -22,7 +22,7 @@ use std::os; pub fn black_box<T>(dummy: T) { unsafe { asm!("" : : "r"(&dummy)) } } fn silent_recurse() { - let buf = [0i; 1000]; + let buf = [0; 1000]; black_box(buf); silent_recurse(); } diff --git a/src/test/run-pass/overloaded-autoderef-indexing.rs b/src/test/run-pass/overloaded-autoderef-indexing.rs index de37173810f..4cb7ece4ab8 100644 --- a/src/test/run-pass/overloaded-autoderef-indexing.rs +++ b/src/test/run-pass/overloaded-autoderef-indexing.rs @@ -23,6 +23,6 @@ impl<'a, T> Deref for DerefArray<'a, T> { } pub fn main() { - let a = &[1i, 2i, 3i]; + let a = &[1, 2, 3]; assert_eq!(DerefArray {inner: a}[1], 2); } diff --git a/src/test/run-pass/overloaded-autoderef-order.rs b/src/test/run-pass/overloaded-autoderef-order.rs index 4c48b0ba710..d023a01f4b1 100644 --- a/src/test/run-pass/overloaded-autoderef-order.rs +++ b/src/test/run-pass/overloaded-autoderef-order.rs @@ -59,7 +59,7 @@ mod priv_test { } pub fn main() { - let nested = DerefWrapper {x: true, y: DerefWrapper {x: 0i, y: 1i}}; + let nested = DerefWrapper {x: true, y: DerefWrapper {x: 0, y: 1}}; // Use the first field that you can find. assert_eq!(nested.x, true); @@ -73,7 +73,7 @@ pub fn main() { // Also go through multiple levels of indirection. assert_eq!(Rc::new(nested).x, true); - let nested_priv = priv_test::DerefWrapperHideX::new(true, DerefWrapper {x: 0i, y: 1i}); + let nested_priv = priv_test::DerefWrapperHideX::new(true, DerefWrapper {x: 0, y: 1}); // FIXME(eddyb) #12808 should skip private fields. // assert_eq!(nested_priv.x, 0); assert_eq!((*nested_priv).x, 0); diff --git a/src/test/run-pass/overloaded-autoderef-xcrate.rs b/src/test/run-pass/overloaded-autoderef-xcrate.rs index 4f449b344e3..f8dd729ec67 100644 --- a/src/test/run-pass/overloaded-autoderef-xcrate.rs +++ b/src/test/run-pass/overloaded-autoderef-xcrate.rs @@ -13,5 +13,5 @@ extern crate overloaded_autoderef_xc; fn main() { - assert!(overloaded_autoderef_xc::check(5i, 5i)); + assert!(overloaded_autoderef_xc::check(5, 5)); } diff --git a/src/test/run-pass/overloaded-autoderef.rs b/src/test/run-pass/overloaded-autoderef.rs index 59e3a807d5a..baa9709eb76 100644 --- a/src/test/run-pass/overloaded-autoderef.rs +++ b/src/test/run-pass/overloaded-autoderef.rs @@ -28,7 +28,7 @@ pub fn main() { assert_eq!(point.x, 2); assert_eq!(point.y, 4); - let i = Rc::new(RefCell::new(2i)); + let i = Rc::new(RefCell::new(2)); let i_value = *i.borrow(); *i.borrow_mut() = 5; assert_eq!((i_value, *i.borrow()), (2, 5)); @@ -47,7 +47,7 @@ pub fn main() { p.borrow_mut().y += 3; assert_eq!(*p.borrow(), Point {x: 3, y: 5}); - let v = Rc::new(RefCell::new([1i, 2, 3])); + let v = Rc::new(RefCell::new([1, 2, 3])); v.borrow_mut()[0] = 3; v.borrow_mut()[1] += 3; assert_eq!((v.borrow()[0], v.borrow()[1], v.borrow()[2]), (3, 5, 3)); diff --git a/src/test/run-pass/overloaded-deref-count.rs b/src/test/run-pass/overloaded-deref-count.rs index 5cd76879798..03fa64fb87f 100644 --- a/src/test/run-pass/overloaded-deref-count.rs +++ b/src/test/run-pass/overloaded-deref-count.rs @@ -49,7 +49,7 @@ impl<T> DerefMut for DerefCounter<T> { } pub fn main() { - let mut n = DerefCounter::new(0i); + let mut n = DerefCounter::new(0); let mut v = DerefCounter::new(Vec::new()); let _ = *n; // Immutable deref + copy a POD. @@ -62,7 +62,7 @@ pub fn main() { assert_eq!(n.counts(), (2, 1)); assert_eq!(v.counts(), (1, 1)); let mut v2 = Vec::new(); - v2.push(1i); + v2.push(1); *n = 5; *v = v2; // Mutable deref + assignment. assert_eq!(n.counts(), (2, 2)); assert_eq!(v.counts(), (1, 2)); diff --git a/src/test/run-pass/overloaded-deref.rs b/src/test/run-pass/overloaded-deref.rs index d02951e981e..fdaddca091f 100644 --- a/src/test/run-pass/overloaded-deref.rs +++ b/src/test/run-pass/overloaded-deref.rs @@ -22,11 +22,11 @@ struct Point { } pub fn main() { - assert_eq!(*Rc::new(5i), 5); - assert_eq!(***Rc::new(box box 5i), 5); + assert_eq!(*Rc::new(5), 5); + assert_eq!(***Rc::new(box box 5), 5); assert_eq!(*Rc::new(Point {x: 2, y: 4}), Point {x: 2, y: 4}); - let i = Rc::new(RefCell::new(2i)); + let i = Rc::new(RefCell::new(2)); let i_value = *(*i).borrow(); *(*i).borrow_mut() = 5; assert_eq!((i_value, *(*i).borrow()), (2, 5)); @@ -46,7 +46,7 @@ pub fn main() { (*(*p).borrow_mut()).y += 3; assert_eq!(*(*p).borrow(), Point {x: 3, y: 5}); - let v = Rc::new(RefCell::new(vec!(1i, 2, 3))); + let v = Rc::new(RefCell::new(vec!(1, 2, 3))); (*(*v).borrow_mut())[0] = 3; (*(*v).borrow_mut())[1] += 3; assert_eq!(((*(*v).borrow())[0], diff --git a/src/test/run-pass/overloaded-index-assoc-list.rs b/src/test/run-pass/overloaded-index-assoc-list.rs index 5e0523d7041..7e3ff198c43 100644 --- a/src/test/run-pass/overloaded-index-assoc-list.rs +++ b/src/test/run-pass/overloaded-index-assoc-list.rs @@ -46,8 +46,8 @@ pub fn main() { let bar = "bar".to_string(); let mut list = AssociationList {pairs: Vec::new()}; - list.push(foo.clone(), 22i); - list.push(bar.clone(), 44i); + list.push(foo.clone(), 22); + list.push(bar.clone(), 44); assert!(list[foo] == 22); assert!(list[bar] == 44); diff --git a/src/test/run-pass/owned-implies-static.rs b/src/test/run-pass/owned-implies-static.rs index e784318fc76..2db6f7ffaaa 100644 --- a/src/test/run-pass/owned-implies-static.rs +++ b/src/test/run-pass/owned-implies-static.rs @@ -14,5 +14,5 @@ fn f<T: 'static>(_x: T) {} pub fn main() { - f(box 5i); + f(box 5); } diff --git a/src/test/run-pass/paren-free.rs b/src/test/run-pass/paren-free.rs index 569023c4439..d9669812d2a 100644 --- a/src/test/run-pass/paren-free.rs +++ b/src/test/run-pass/paren-free.rs @@ -10,6 +10,6 @@ pub fn main() { let x = true; - if x { let mut i = 10i; while i > 0 { i -= 1; } } + if x { let mut i = 10; while i > 0 { i -= 1; } } match x { true => { println!("right"); } false => { println!("wrong"); } } } diff --git a/src/test/run-pass/parse-complex-macro-invoc-op.rs b/src/test/run-pass/parse-complex-macro-invoc-op.rs index e9ec624c13e..0995910fd4c 100644 --- a/src/test/run-pass/parse-complex-macro-invoc-op.rs +++ b/src/test/run-pass/parse-complex-macro-invoc-op.rs @@ -17,24 +17,24 @@ macro_rules! id { } fn foo() { - id!(1i) + 1; - id![1i] - 1; - id!(1i) * 1; - id![1i] / 1; - id!(1i) % 1; + id!(1) + 1; + id![1] - 1; + id!(1) * 1; + id![1] / 1; + id!(1) % 1; - id!(1i) & 1; - id![1i] | 1; - id!(1i) ^ 1; + id!(1) & 1; + id![1] | 1; + id!(1) ^ 1; - let mut x = 1i; + let mut x = 1; id![x] = 2; id!(x) += 1; id!(1f64).clone(); - id!([1i, 2, 3])[1]; - id; + id!([1, 2, 3])[1]; + id; id!(true) && true; id![true] || true; diff --git a/src/test/run-pass/parse-panic.rs b/src/test/run-pass/parse-panic.rs index 0dbba3654b6..22b24ebb3b5 100644 --- a/src/test/run-pass/parse-panic.rs +++ b/src/test/run-pass/parse-panic.rs @@ -10,6 +10,6 @@ #![allow(unreachable_code)] -fn dont_call_me() { panic!(); println!("{}", 1i); } +fn dont_call_me() { panic!(); println!("{}", 1); } pub fn main() { } diff --git a/src/test/run-pass/priv-impl-prim-ty.rs b/src/test/run-pass/priv-impl-prim-ty.rs index a8cd5e789b1..679aa3d668f 100644 --- a/src/test/run-pass/priv-impl-prim-ty.rs +++ b/src/test/run-pass/priv-impl-prim-ty.rs @@ -13,6 +13,6 @@ extern crate "priv-impl-prim-ty" as bar; pub fn main() { - bar::frob(1i); + bar::frob(1); } diff --git a/src/test/run-pass/ptr-coercion.rs b/src/test/run-pass/ptr-coercion.rs index 1b77c1316ed..a6a8890101c 100644 --- a/src/test/run-pass/ptr-coercion.rs +++ b/src/test/run-pass/ptr-coercion.rs @@ -12,24 +12,24 @@ pub fn main() { // &mut -> & - let x: &mut int = &mut 42i; + let x: &mut int = &mut 42; let x: &int = x; - let x: &int = &mut 42i; + let x: &int = &mut 42; // & -> *const - let x: &int = &42i; + let x: &int = &42; let x: *const int = x; - let x: *const int = &42i; + let x: *const int = &42; // &mut -> *const - let x: &mut int = &mut 42i; + let x: &mut int = &mut 42; let x: *const int = x; - let x: *const int = &mut 42i; + let x: *const int = &mut 42; // *mut -> *const - let x: *mut int = &mut 42i; + let x: *mut int = &mut 42; let x: *const int = x; } diff --git a/src/test/run-pass/range.rs b/src/test/run-pass/range.rs index bfd3e43768f..11e8bfa48f6 100644 --- a/src/test/run-pass/range.rs +++ b/src/test/run-pass/range.rs @@ -45,9 +45,9 @@ pub fn main() { let _ = ..42u; // Test we can use two different types with a common supertype. - let x = &42i; + let x = &42; { - let y = 42i; + let y = 42; let _ = x..&y; } } diff --git a/src/test/run-pass/reexported-static-methods-cross-crate.rs b/src/test/run-pass/reexported-static-methods-cross-crate.rs index 0d0fdb13db3..5399f3cfd35 100644 --- a/src/test/run-pass/reexported-static-methods-cross-crate.rs +++ b/src/test/run-pass/reexported-static-methods-cross-crate.rs @@ -17,8 +17,8 @@ use reexported_static_methods::Boz; use reexported_static_methods::Bort; pub fn main() { - assert_eq!(42i, Foo::foo()); - assert_eq!(84i, Baz::bar()); - assert!(Boz::boz(1i)); + assert_eq!(42, Foo::foo()); + assert_eq!(84, Baz::bar()); + assert!(Boz::boz(1)); assert_eq!("bort()".to_string(), Bort::bort()); } diff --git a/src/test/run-pass/regions-copy-closure.rs b/src/test/run-pass/regions-copy-closure.rs index 0152793d96c..dc6f377e9b2 100644 --- a/src/test/run-pass/regions-copy-closure.rs +++ b/src/test/run-pass/regions-copy-closure.rs @@ -21,7 +21,7 @@ fn box_it<'a>(x: Box<FnMut() + 'a>) -> closure_box<'a> { } pub fn main() { - let mut i = 3i; + let mut i = 3i32; assert_eq!(i, 3); { let cl = |&mut:| i += 1; diff --git a/src/test/run-pass/regions-early-bound-trait-param.rs b/src/test/run-pass/regions-early-bound-trait-param.rs index 3267ff2c7e0..6fcfaf58a02 100644 --- a/src/test/run-pass/regions-early-bound-trait-param.rs +++ b/src/test/run-pass/regions-early-bound-trait-param.rs @@ -81,7 +81,7 @@ impl<'s> Trait<'s> for (int,int) { } impl<'t> MakerTrait<'t> for Box<Trait<'t>+'static> { - fn mk() -> Box<Trait<'t>+'static> { box() (4i,5i) as Box<Trait> } + fn mk() -> Box<Trait<'t>+'static> { box() (4,5) as Box<Trait> } } enum List<'l> { @@ -111,7 +111,7 @@ impl<'t> RefMakerTrait<'t> for List<'t> { } pub fn main() { - let t = (2i,3i); + let t = (2,3); let o = &t as &Trait; let s1 = Struct1 { f: o }; let s2 = Struct2 { f: o }; diff --git a/src/test/run-pass/regions-early-bound-used-in-bound.rs b/src/test/run-pass/regions-early-bound-used-in-bound.rs index 73eb7ca7188..a3602c5fbec 100644 --- a/src/test/run-pass/regions-early-bound-used-in-bound.rs +++ b/src/test/run-pass/regions-early-bound-used-in-bound.rs @@ -32,6 +32,6 @@ fn add<'a,G:GetRef<'a, int>>(g1: G, g2: G) -> int { } pub fn main() { - let b1 = Box { t: &3i }; - assert_eq!(add(b1, b1), 6i); + let b1 = Box { t: &3 }; + assert_eq!(add(b1, b1), 6); } diff --git a/src/test/run-pass/regions-early-bound-used-in-type-param.rs b/src/test/run-pass/regions-early-bound-used-in-type-param.rs index e0d5e0a1c78..caef4e3fa9c 100644 --- a/src/test/run-pass/regions-early-bound-used-in-type-param.rs +++ b/src/test/run-pass/regions-early-bound-used-in-type-param.rs @@ -31,6 +31,6 @@ fn add<'a,G:Get<&'a int>>(g1: G, g2: G) -> int { } pub fn main() { - let b1 = Box { t: &3i }; - assert_eq!(add(b1, b1), 6i); + let b1 = Box { t: &3 }; + assert_eq!(add(b1, b1), 6); } diff --git a/src/test/run-pass/regions-infer-borrow-scope-view.rs b/src/test/run-pass/regions-infer-borrow-scope-view.rs index ce9edb5678a..d247f864571 100644 --- a/src/test/run-pass/regions-infer-borrow-scope-view.rs +++ b/src/test/run-pass/regions-infer-borrow-scope-view.rs @@ -12,7 +12,7 @@ fn view<T>(x: &[T]) -> &[T] {x} pub fn main() { - let v = vec!(1i, 2, 3); + let v = vec!(1, 2, 3); let x = view(v.as_slice()); let y = view(x.as_slice()); assert!((v[0] == x[0]) && (v[0] == y[0])); diff --git a/src/test/run-pass/regions-infer-borrow-scope-within-loop-ok.rs b/src/test/run-pass/regions-infer-borrow-scope-within-loop-ok.rs index f397b5124ca..d07110fd721 100644 --- a/src/test/run-pass/regions-infer-borrow-scope-within-loop-ok.rs +++ b/src/test/run-pass/regions-infer-borrow-scope-within-loop-ok.rs @@ -14,7 +14,7 @@ fn borrow<T>(x: &T) -> &T {x} pub fn main() { - let x = box 3i; + let x = box 3; loop { let y = borrow(&*x); assert_eq!(*x, *y); diff --git a/src/test/run-pass/regions-return-interior-of-option.rs b/src/test/run-pass/regions-return-interior-of-option.rs index 54458f0d0df..ee1d6687307 100644 --- a/src/test/run-pass/regions-return-interior-of-option.rs +++ b/src/test/run-pass/regions-return-interior-of-option.rs @@ -16,14 +16,14 @@ fn get<T>(opt: &Option<T>) -> &T { } pub fn main() { - let mut x = Some(23i); + let mut x = Some(23); { let y = get(&x); assert_eq!(*y, 23); } - x = Some(24i); + x = Some(24); { let y = get(&x); diff --git a/src/test/run-pass/regions-scope-chain-example.rs b/src/test/run-pass/regions-scope-chain-example.rs index 0388ffb7894..e5ef88006c7 100644 --- a/src/test/run-pass/regions-scope-chain-example.rs +++ b/src/test/run-pass/regions-scope-chain-example.rs @@ -31,7 +31,7 @@ struct Context<'a> { impl<'a> Context<'a> { fn foo(&mut self, scope: Scope) { - let link = if 1i < 2 { + let link = if 1 < 2 { let l = ScopeChain::Link(scope); self.take_scope(&l); l diff --git a/src/test/run-pass/repeated-vector-syntax.rs b/src/test/run-pass/repeated-vector-syntax.rs index d1d37ea5bb0..6048e0d8673 100644 --- a/src/test/run-pass/repeated-vector-syntax.rs +++ b/src/test/run-pass/repeated-vector-syntax.rs @@ -10,7 +10,7 @@ pub fn main() { let x = [ [true]; 512 ]; - let y = [ 0i; 1 ]; + let y = [ 0; 1 ]; print!("["); for xi in x.iter() { diff --git a/src/test/run-pass/resource-assign-is-not-copy.rs b/src/test/run-pass/resource-assign-is-not-copy.rs index ff38b02ae76..abc33e9f2e6 100644 --- a/src/test/run-pass/resource-assign-is-not-copy.rs +++ b/src/test/run-pass/resource-assign-is-not-copy.rs @@ -31,11 +31,11 @@ fn r(i: &Cell<int>) -> r { } pub fn main() { - let i = &Cell::new(0i); + let i = &Cell::new(0); // Even though these look like copies, they are guaranteed not to be { let a = r(i); - let b = (a, 10i); + let b = (a, 10); let (c, _d) = b; println!("{:?}", c); } diff --git a/src/test/run-pass/self-re-assign.rs b/src/test/run-pass/self-re-assign.rs index 3092898d986..cf09737e32e 100644 --- a/src/test/run-pass/self-re-assign.rs +++ b/src/test/run-pass/self-re-assign.rs @@ -17,11 +17,11 @@ use std::rc::Rc; pub fn main() { - let mut x = box 3i; + let mut x = box 3; x = x; assert!(*x == 3); - let mut x = Rc::new(3i); + let mut x = Rc::new(3); x = x; assert!(*x == 3); } diff --git a/src/test/run-pass/seq-compare.rs b/src/test/run-pass/seq-compare.rs index 29729b15aa8..ef14e0ba931 100644 --- a/src/test/run-pass/seq-compare.rs +++ b/src/test/run-pass/seq-compare.rs @@ -13,13 +13,13 @@ pub fn main() { assert!(("hello".to_string() < "hellr".to_string())); assert!(("hello ".to_string() > "hello".to_string())); assert!(("hello".to_string() != "there".to_string())); - assert!((vec!(1i, 2, 3, 4) > vec!(1, 2, 3))); - assert!((vec!(1i, 2, 3) < vec!(1, 2, 3, 4))); - assert!((vec!(1i, 2, 4, 4) > vec!(1, 2, 3, 4))); - assert!((vec!(1i, 2, 3, 4) < vec!(1, 2, 4, 4))); - assert!((vec!(1i, 2, 3) <= vec!(1, 2, 3))); - assert!((vec!(1i, 2, 3) <= vec!(1, 2, 3, 3))); - assert!((vec!(1i, 2, 3, 4) > vec!(1, 2, 3))); - assert_eq!(vec!(1i, 2, 3), vec!(1, 2, 3)); - assert!((vec!(1i, 2, 3) != vec!(1, 1, 3))); + assert!((vec!(1, 2, 3, 4) > vec!(1, 2, 3))); + assert!((vec!(1, 2, 3) < vec!(1, 2, 3, 4))); + assert!((vec!(1, 2, 4, 4) > vec!(1, 2, 3, 4))); + assert!((vec!(1, 2, 3, 4) < vec!(1, 2, 4, 4))); + assert!((vec!(1, 2, 3) <= vec!(1, 2, 3))); + assert!((vec!(1, 2, 3) <= vec!(1, 2, 3, 3))); + assert!((vec!(1, 2, 3, 4) > vec!(1, 2, 3))); + assert_eq!(vec!(1, 2, 3), vec!(1, 2, 3)); + assert!((vec!(1, 2, 3) != vec!(1, 1, 3))); } diff --git a/src/test/run-pass/shadow.rs b/src/test/run-pass/shadow.rs index 06d707d3ab0..dbe73d1b94a 100644 --- a/src/test/run-pass/shadow.rs +++ b/src/test/run-pass/shadow.rs @@ -17,7 +17,7 @@ fn foo(c: Vec<int> ) { t::some::<int>(_) => { for _i in c.iter() { println!("{}", a); - let a = 17i; + let a = 17; b.push(a); } } @@ -27,4 +27,4 @@ fn foo(c: Vec<int> ) { enum t<T> { none, some(T), } -pub fn main() { let x = 10i; let x = x + 20; assert!((x == 30)); foo(Vec::new()); } +pub fn main() { let x = 10; let x = x + 20; assert!((x == 30)); foo(Vec::new()); } diff --git a/src/test/run-pass/shift.rs b/src/test/run-pass/shift.rs index d8a67eef3f6..2dbedc3a573 100644 --- a/src/test/run-pass/shift.rs +++ b/src/test/run-pass/shift.rs @@ -18,7 +18,7 @@ pub fn main() { } fn test_misc() { - assert_eq!(1i << 1 << 1 << 1 << 1 << 1, 32); + assert_eq!(1 << 1 << 1 << 1 << 1 << 1, 32); } fn test_expr() { diff --git a/src/test/run-pass/simd-binop.rs b/src/test/run-pass/simd-binop.rs index 482eea19823..779e507f43d 100644 --- a/src/test/run-pass/simd-binop.rs +++ b/src/test/run-pass/simd-binop.rs @@ -55,17 +55,18 @@ pub fn main() { // comparison operators - assert!(eq_u32x4(u32x4(1, 2, 3, 4) == u32x4(3, 2, 1, 0), u32x4(0, !0, 0, 0))); - assert!(eq_u32x4(u32x4(1, 2, 3, 4) != u32x4(3, 2, 1, 0), u32x4(!0, 0, !0, !0))); - assert!(eq_u32x4(u32x4(1, 2, 3, 4) < u32x4(3, 2, 1, 0), u32x4(!0, 0, 0, 0))); - assert!(eq_u32x4(u32x4(1, 2, 3, 4) <= u32x4(3, 2, 1, 0), u32x4(!0, !0, 0, 0))); - assert!(eq_u32x4(u32x4(1, 2, 3, 4) >= u32x4(3, 2, 1, 0), u32x4(0, !0, !0, !0))); - assert!(eq_u32x4(u32x4(1, 2, 3, 4) > u32x4(3, 2, 1, 0), u32x4(0, 0, !0, !0))); + // check !0/-1 to ensure operators are using the correct signedness. + assert!(eq_u32x4(u32x4(1, 2, 3, !0) == u32x4(3, 2, 1, 0), u32x4(0, !0, 0, 0))); + assert!(eq_u32x4(u32x4(1, 2, 3, !0) != u32x4(3, 2, 1, 0), u32x4(!0, 0, !0, !0))); + assert!(eq_u32x4(u32x4(1, 2, 3, !0) < u32x4(3, 2, 1, 0), u32x4(!0, 0, 0, 0))); + assert!(eq_u32x4(u32x4(1, 2, 3, !0) <= u32x4(3, 2, 1, 0), u32x4(!0, !0, 0, 0))); + assert!(eq_u32x4(u32x4(1, 2, 3, !0) >= u32x4(3, 2, 1, 0), u32x4(0, !0, !0, !0))); + assert!(eq_u32x4(u32x4(1, 2, 3, !0) > u32x4(3, 2, 1, 0), u32x4(0, 0, !0, !0))); - assert!(eq_i32x4(i32x4(1, 2, 3, 4) == i32x4(3, 2, 1, 0), i32x4(0, !0, 0, 0))); - assert!(eq_i32x4(i32x4(1, 2, 3, 4) != i32x4(3, 2, 1, 0), i32x4(!0, 0, !0, !0))); - assert!(eq_i32x4(i32x4(1, 2, 3, 4) < i32x4(3, 2, 1, 0), i32x4(!0, 0, 0, 0))); - assert!(eq_i32x4(i32x4(1, 2, 3, 4) <= i32x4(3, 2, 1, 0), i32x4(!0, !0, 0, 0))); - assert!(eq_i32x4(i32x4(1, 2, 3, 4) >= i32x4(3, 2, 1, 0), i32x4(0, !0, !0, !0))); - assert!(eq_i32x4(i32x4(1, 2, 3, 4) > i32x4(3, 2, 1, 0), i32x4(0, 0, !0, !0))); + assert!(eq_i32x4(i32x4(1, 2, 3, -1) == i32x4(3, 2, 1, 0), i32x4(0, !0, 0, 0))); + assert!(eq_i32x4(i32x4(1, 2, 3, -1) != i32x4(3, 2, 1, 0), i32x4(!0, 0, !0, !0))); + assert!(eq_i32x4(i32x4(1, 2, 3, -1) < i32x4(3, 2, 1, 0), i32x4(!0, 0, 0, !0))); + assert!(eq_i32x4(i32x4(1, 2, 3, -1) <= i32x4(3, 2, 1, 0), i32x4(!0, !0, 0, !0))); + assert!(eq_i32x4(i32x4(1, 2, 3, -1) >= i32x4(3, 2, 1, 0), i32x4(0, !0, !0, 0))); + assert!(eq_i32x4(i32x4(1, 2, 3, -1) > i32x4(3, 2, 1, 0), i32x4(0, 0, !0, 0))); } diff --git a/src/test/run-pass/simple-infer.rs b/src/test/run-pass/simple-infer.rs index 4f6feb544f4..04c1af4326b 100644 --- a/src/test/run-pass/simple-infer.rs +++ b/src/test/run-pass/simple-infer.rs @@ -10,4 +10,4 @@ -pub fn main() { let mut n; n = 1i; println!("{}", n); } +pub fn main() { let mut n; n = 1; println!("{}", n); } diff --git a/src/test/run-pass/snake-case-no-lowercase-equivalent.rs b/src/test/run-pass/snake-case-no-lowercase-equivalent.rs new file mode 100644 index 00000000000..2220761a026 --- /dev/null +++ b/src/test/run-pass/snake-case-no-lowercase-equivalent.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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(non_ascii_idents)] +#![deny(non_snake_case)] + +// This name is neither upper nor lower case +fn 你好() {} + +fn main() {} diff --git a/src/test/run-pass/static-assert.rs b/src/test/run-pass/static-assert.rs index c695fa2b72e..f8fd81b9365 100644 --- a/src/test/run-pass/static-assert.rs +++ b/src/test/run-pass/static-assert.rs @@ -12,13 +12,13 @@ static b: bool = true; #[static_assert] -static c: bool = 1i == 1; +static c: bool = 1 == 1; #[static_assert] -static d: bool = 1i != 2; +static d: bool = 1 != 2; #[static_assert] -static f: bool = (4i/2) == 2; +static f: bool = (4/2) == 2; pub fn main() { } diff --git a/src/test/run-pass/static-fn-inline-xc.rs b/src/test/run-pass/static-fn-inline-xc.rs index dbe9221066f..efc374e25bb 100644 --- a/src/test/run-pass/static-fn-inline-xc.rs +++ b/src/test/run-pass/static-fn-inline-xc.rs @@ -15,5 +15,5 @@ extern crate "static_fn_inline_xc_aux" as mycore; use mycore::num; pub fn main() { - let _1: f64 = num::Num2::from_int2(1i); + let _1: f64 = num::Num2::from_int2(1); } diff --git a/src/test/run-pass/static-fn-trait-xc.rs b/src/test/run-pass/static-fn-trait-xc.rs index 5dd6b6dbc53..cb9f7c3da02 100644 --- a/src/test/run-pass/static-fn-trait-xc.rs +++ b/src/test/run-pass/static-fn-trait-xc.rs @@ -15,5 +15,5 @@ extern crate "static_fn_trait_xc_aux" as mycore; use mycore::num; pub fn main() { - let _1: f64 = num::Num2::from_int2(1i); + let _1: f64 = num::Num2::from_int2(1); } diff --git a/src/test/run-pass/static-impl.rs b/src/test/run-pass/static-impl.rs index 74c0663971e..44d77e440d1 100644 --- a/src/test/run-pass/static-impl.rs +++ b/src/test/run-pass/static-impl.rs @@ -61,10 +61,10 @@ pub fn main() { assert_eq!(10u.plus(), 30); assert_eq!(("hi".to_string()).plus(), 200); - assert_eq!((vec!(1i)).length_().str(), "1".to_string()); - let vect = vec!(3i, 4).map_(|a| *a + 4); + assert_eq!((vec!(1)).length_().str(), "1".to_string()); + let vect = vec!(3, 4).map_(|a| *a + 4); assert_eq!(vect[0], 7); - let vect = (vec!(3i, 4)).map_::<uint, _>(|a| *a as uint + 4u); + let vect = (vec!(3, 4)).map_::<uint, _>(|a| *a as uint + 4u); assert_eq!(vect[0], 7u); let mut x = 0u; 10u.multi(|_n| x += 2u ); diff --git a/src/test/run-pass/string-self-append.rs b/src/test/run-pass/string-self-append.rs index dc1e23ca09c..612483f6909 100644 --- a/src/test/run-pass/string-self-append.rs +++ b/src/test/run-pass/string-self-append.rs @@ -11,7 +11,7 @@ pub fn main() { // Make sure we properly handle repeated self-appends. let mut a: String = "A".to_string(); - let mut i = 20i; + let mut i = 20; let mut expected_len = 1u; while i > 0 { println!("{}", a.len()); diff --git a/src/test/run-pass/struct-lit-functional-no-fields.rs b/src/test/run-pass/struct-lit-functional-no-fields.rs index ebf2fbbe53c..c3b1ff0f057 100644 --- a/src/test/run-pass/struct-lit-functional-no-fields.rs +++ b/src/test/run-pass/struct-lit-functional-no-fields.rs @@ -16,8 +16,8 @@ struct Foo<T> { pub fn main() { let foo = Foo { - bar: 0i, - baz: 1i + bar: 0, + baz: 1 }; let foo_ = foo.clone(); diff --git a/src/test/run-pass/structured-compare.rs b/src/test/run-pass/structured-compare.rs index d87ff64ebd9..12d8fe8f4c8 100644 --- a/src/test/run-pass/structured-compare.rs +++ b/src/test/run-pass/structured-compare.rs @@ -21,14 +21,14 @@ impl PartialEq for foo { } pub fn main() { - let a = (1i, 2i, 3i); - let b = (1i, 2i, 3i); + let a = (1, 2, 3); + let b = (1, 2, 3); assert_eq!(a, b); assert!((a != (1, 2, 4))); assert!((a < (1, 2, 4))); assert!((a <= (1, 2, 4))); - assert!(((1i, 2i, 4i) > a)); - assert!(((1i, 2i, 4i) >= a)); + assert!(((1, 2, 4) > a)); + assert!(((1, 2, 4) >= a)); let x = foo::large; let y = foo::small; assert!((x != y)); diff --git a/src/test/run-pass/supertrait-default-generics.rs b/src/test/run-pass/supertrait-default-generics.rs index f31d9ca186f..e158ae672aa 100644 --- a/src/test/run-pass/supertrait-default-generics.rs +++ b/src/test/run-pass/supertrait-default-generics.rs @@ -38,7 +38,7 @@ impl<S: Clone> Positioned<S> for Point<S> { impl<S: Clone + Add<Output=S>> Movable<S> for Point<S> {} pub fn main() { - let mut p = Point{ x: 1i, y: 2i}; + let mut p = Point{ x: 1, y: 2}; p.translate(3); assert_eq!(p.X(), 4); } diff --git a/src/test/run-pass/supported-cast.rs b/src/test/run-pass/supported-cast.rs index 7cba4533c7f..60431fbedd0 100644 --- a/src/test/run-pass/supported-cast.rs +++ b/src/test/run-pass/supported-cast.rs @@ -34,8 +34,8 @@ pub fn main() { println!("{:?}", 1 as u16); println!("{:?}", 1 as u32); println!("{:?}", 1 as u64); - println!("{:?}", 1i as f32); - println!("{:?}", 1i as f64); + println!("{:?}", 1 as f32); + println!("{:?}", 1 as f64); println!("{:?}", 1u as int); println!("{:?}", 1u as uint); diff --git a/src/test/run-pass/swap-1.rs b/src/test/run-pass/swap-1.rs index 9a77356d7eb..82a76512e08 100644 --- a/src/test/run-pass/swap-1.rs +++ b/src/test/run-pass/swap-1.rs @@ -11,7 +11,7 @@ use std::mem::swap; pub fn main() { - let mut x = 3i; let mut y = 7i; + let mut x = 3; let mut y = 7; swap(&mut x, &mut y); assert!((x == 7)); assert!((y == 3)); } diff --git a/src/test/run-pass/tag-variant-disr-type-mismatch.rs b/src/test/run-pass/tag-variant-disr-type-mismatch.rs index c04751d51b4..7e4bd9ab273 100644 --- a/src/test/run-pass/tag-variant-disr-type-mismatch.rs +++ b/src/test/run-pass/tag-variant-disr-type-mismatch.rs @@ -9,7 +9,7 @@ // except according to those terms. enum color { - red = 1i, + red = 1, blue = 2, } diff --git a/src/test/run-pass/terminate-in-initializer.rs b/src/test/run-pass/terminate-in-initializer.rs index bfd1f5f4a74..185edb02cca 100644 --- a/src/test/run-pass/terminate-in-initializer.rs +++ b/src/test/run-pass/terminate-in-initializer.rs @@ -16,7 +16,7 @@ use std::thread::Thread; fn test_break() { loop { let _x: Box<int> = break; } } -fn test_cont() { let mut i = 0i; while i < 1 { i += 1; let _x: Box<int> = continue; } } +fn test_cont() { let mut i = 0; while i < 1 { i += 1; let _x: Box<int> = continue; } } fn test_ret() { let _x: Box<int> = return; } diff --git a/src/test/run-pass/trailing-comma.rs b/src/test/run-pass/trailing-comma.rs index 00e05064080..b5ae259bc63 100644 --- a/src/test/run-pass/trailing-comma.rs +++ b/src/test/run-pass/trailing-comma.rs @@ -28,16 +28,16 @@ enum Baz { #[allow(unused,)] pub fn main() { - f::<int,>(0i,); - let (_, _,) = (1i, 1i,); - let [_, _,] = [1i, 1,]; - let [_, _, .., _,] = [1i, 1, 1, 1,]; - let [_, _, _.., _,] = [1i, 1, 1, 1,]; + f::<int,>(0,); + let (_, _,) = (1, 1,); + let [_, _,] = [1, 1,]; + let [_, _, .., _,] = [1, 1, 1, 1,]; + let [_, _, _.., _,] = [1, 1, 1, 1,]; let x: Foo<int,> = Foo::<int,>; - Bar::f(0i,); - Bar.g(0i,); + Bar::f(0,); + Bar.g(0,); Bar.h(); let x = Baz::Qux(1,); diff --git a/src/test/run-pass/trait-default-method-bound-subst.rs b/src/test/run-pass/trait-default-method-bound-subst.rs index 6b0ab8910de..5f0e149eb28 100644 --- a/src/test/run-pass/trait-default-method-bound-subst.rs +++ b/src/test/run-pass/trait-default-method-bound-subst.rs @@ -13,14 +13,14 @@ trait A<T> { fn g<U>(&self, x: T, y: U) -> (T, U) { (x, y) } } -impl A<int> for int { } -impl<T> A<T> for uint { } +impl A<i32> for i32 { } +impl<T> A<T> for u32 { } fn f<T, U, V: A<T>>(i: V, j: T, k: U) -> (T, U) { i.g(j, k) } pub fn main () { - assert_eq!(f(0i, 1i, 2i), (1, 2)); - assert_eq!(f(0u, 1i, 2i), (1, 2)); + assert_eq!(f(0, 1, 2), (1, 2)); + assert_eq!(f(0, 1, 2), (1, 2)); } diff --git a/src/test/run-pass/trait-default-method-bound-subst2.rs b/src/test/run-pass/trait-default-method-bound-subst2.rs index d9ba9ca9220..1ea3879e7fa 100644 --- a/src/test/run-pass/trait-default-method-bound-subst2.rs +++ b/src/test/run-pass/trait-default-method-bound-subst2.rs @@ -20,5 +20,5 @@ fn f<T, V: A<T>>(i: V, j: T) -> T { } pub fn main () { - assert_eq!(f(0i, 2i), 2); + assert_eq!(f(0, 2), 2); } diff --git a/src/test/run-pass/trait-default-method-bound-subst3.rs b/src/test/run-pass/trait-default-method-bound-subst3.rs index 43fb19a58ed..aff20ffe962 100644 --- a/src/test/run-pass/trait-default-method-bound-subst3.rs +++ b/src/test/run-pass/trait-default-method-bound-subst3.rs @@ -20,6 +20,6 @@ fn f<T, V: A>(i: V, j: T, k: T) -> (T, T) { } pub fn main () { - assert_eq!(f(0i, 1i, 2i), (1, 2)); - assert_eq!(f(0i, 1u8, 2u8), (1u8, 2u8)); + assert_eq!(f(0, 1, 2), (1, 2)); + assert_eq!(f(0, 1u8, 2u8), (1u8, 2u8)); } diff --git a/src/test/run-pass/trait-default-method-bound.rs b/src/test/run-pass/trait-default-method-bound.rs index 1505d48839e..8a2f1b1743b 100644 --- a/src/test/run-pass/trait-default-method-bound.rs +++ b/src/test/run-pass/trait-default-method-bound.rs @@ -20,5 +20,5 @@ fn f<T:A>(i: T) { } pub fn main () { - f(0i); + f(0); } diff --git a/src/test/run-pass/trait-default-method-xc-2.rs b/src/test/run-pass/trait-default-method-xc-2.rs index 1aa958dafc7..b28e8bd24aa 100644 --- a/src/test/run-pass/trait-default-method-xc-2.rs +++ b/src/test/run-pass/trait-default-method-xc-2.rs @@ -20,15 +20,15 @@ use aux2::{a_struct, welp}; pub fn main () { - let a = a_struct { x: 0i }; - let b = a_struct { x: 1i }; + let a = a_struct { x: 0 }; + let b = a_struct { x: 1 }; - assert_eq!(0i.g(), 10); + assert_eq!(0.g(), 10); assert_eq!(a.g(), 10); assert_eq!(a.h(), 11); assert_eq!(b.g(), 10); assert_eq!(b.h(), 11); assert_eq!(A::lurr(&a, &b), 21); - welp(&0i); + welp(&0); } diff --git a/src/test/run-pass/trait-default-method-xc.rs b/src/test/run-pass/trait-default-method-xc.rs index c4880e97c45..4745d057952 100644 --- a/src/test/run-pass/trait-default-method-xc.rs +++ b/src/test/run-pass/trait-default-method-xc.rs @@ -52,35 +52,35 @@ impl TestEquality for stuff::thing { pub fn main() { // Some tests of random things - f(0i); + f(0); - assert_eq!(A::lurr(&0i, &1i), 21); + assert_eq!(A::lurr(&0, &1), 21); let a = stuff::thing { x: 0 }; let b = stuff::thing { x: 1 }; let c = Something { x: 1 }; - assert_eq!(0i.g(), 10); + assert_eq!(0.g(), 10); assert_eq!(a.g(), 10); assert_eq!(a.h(), 11); assert_eq!(c.h(), 11); - assert_eq!(0i.thing(3.14f64, 1i), (3.14f64, 1i)); - assert_eq!(B::staticthing(&0i, 3.14f64, 1i), (3.14f64, 1i)); - assert_eq!(B::<f64>::staticthing::<int>(&0i, 3.14, 1), (3.14, 1)); + assert_eq!(0.thing(3.14f64, 1), (3.14f64, 1)); + assert_eq!(B::staticthing(&0, 3.14f64, 1), (3.14f64, 1)); + assert_eq!(B::<f64>::staticthing::<int>(&0, 3.14, 1), (3.14, 1)); - assert_eq!(g(0i, 3.14f64, 1i), (3.14f64, 1i)); - assert_eq!(g(false, 3.14f64, 1i), (3.14, 1)); + assert_eq!(g(0, 3.14f64, 1), (3.14f64, 1)); + assert_eq!(g(false, 3.14f64, 1), (3.14, 1)); // Trying out a real one - assert!(12i.test_neq(&10i)); - assert!(!10i.test_neq(&10i)); + assert!(12.test_neq(&10)); + assert!(!10.test_neq(&10)); assert!(a.test_neq(&b)); assert!(!a.test_neq(&a)); - assert!(neq(&12i, &10i)); - assert!(!neq(&10i, &10i)); + assert!(neq(&12, &10)); + assert!(!neq(&10, &10)); assert!(neq(&a, &b)); assert!(!neq(&a, &a)); } diff --git a/src/test/run-pass/trait-generic.rs b/src/test/run-pass/trait-generic.rs index d4c1b688b47..e79b22f70cf 100644 --- a/src/test/run-pass/trait-generic.rs +++ b/src/test/run-pass/trait-generic.rs @@ -44,7 +44,7 @@ fn bar<U:to_str,T:map<U>>(x: T) -> Vec<String> { } pub fn main() { - assert_eq!(foo(vec!(1i)), vec!("hi".to_string())); + assert_eq!(foo(vec!(1)), vec!("hi".to_string())); assert_eq!(bar::<int, Vec<int> >(vec!(4, 5)), vec!("4".to_string(), "5".to_string())); assert_eq!(bar::<String, Vec<String> >(vec!("x".to_string(), "y".to_string())), vec!("x".to_string(), "y".to_string())); diff --git a/src/test/run-pass/trait-impl.rs b/src/test/run-pass/trait-impl.rs index 003686c0bbe..16ef315c206 100644 --- a/src/test/run-pass/trait-impl.rs +++ b/src/test/run-pass/trait-impl.rs @@ -33,7 +33,7 @@ struct Foo; impl<'a> Bar<'a> for Foo {} fn main() { - let x: &T = &42i; + let x: &T = &42; x.foo(); T::foo(x); diff --git a/src/test/run-pass/trait-inheritance-num.rs b/src/test/run-pass/trait-inheritance-num.rs index e606018feb9..9a30d51f4c5 100644 --- a/src/test/run-pass/trait-inheritance-num.rs +++ b/src/test/run-pass/trait-inheritance-num.rs @@ -16,7 +16,7 @@ pub trait NumExt: NumCast + PartialEq + PartialOrd {} pub trait FloatExt: NumExt {} -fn greater_than_one<T: NumExt>(n: &T) -> bool { *n > NumCast::from(1i).unwrap() } -fn greater_than_one_float<T: FloatExt>(n: &T) -> bool { *n > NumCast::from(1i).unwrap() } +fn greater_than_one<T: NumExt>(n: &T) -> bool { *n > NumCast::from(1).unwrap() } +fn greater_than_one_float<T: FloatExt>(n: &T) -> bool { *n > NumCast::from(1).unwrap() } pub fn main() {} diff --git a/src/test/run-pass/trait-inheritance-num0.rs b/src/test/run-pass/trait-inheritance-num0.rs index 42eaaa09fcd..d68b6a54f71 100644 --- a/src/test/run-pass/trait-inheritance-num0.rs +++ b/src/test/run-pass/trait-inheritance-num0.rs @@ -22,7 +22,7 @@ pub trait Num { pub trait NumExt: NumCast + PartialOrd { } fn greater_than_one<T:NumExt>(n: &T) -> bool { - n.gt(&NumCast::from(1i).unwrap()) + n.gt(&NumCast::from(1).unwrap()) } pub fn main() {} diff --git a/src/test/run-pass/trait-inheritance-num1.rs b/src/test/run-pass/trait-inheritance-num1.rs index 9407afbdd6b..15fb5df4626 100644 --- a/src/test/run-pass/trait-inheritance-num1.rs +++ b/src/test/run-pass/trait-inheritance-num1.rs @@ -14,7 +14,7 @@ use std::num::NumCast; pub trait NumExt: NumCast + PartialOrd { } fn greater_than_one<T:NumExt>(n: &T) -> bool { - *n > NumCast::from(1i).unwrap() + *n > NumCast::from(1).unwrap() } pub fn main() {} diff --git a/src/test/run-pass/trait-inheritance-num3.rs b/src/test/run-pass/trait-inheritance-num3.rs index bd93223093a..09015d983ea 100644 --- a/src/test/run-pass/trait-inheritance-num3.rs +++ b/src/test/run-pass/trait-inheritance-num3.rs @@ -16,7 +16,7 @@ pub trait NumExt: PartialEq + PartialOrd + NumCast {} impl NumExt for f32 {} fn num_eq_one<T: NumExt>(n: T) { - println!("{}", n == NumCast::from(1i).unwrap()) + println!("{}", n == NumCast::from(1).unwrap()) } pub fn main() { diff --git a/src/test/run-pass/trait-inheritance-num5.rs b/src/test/run-pass/trait-inheritance-num5.rs index 4c79600e2e9..a21026839a7 100644 --- a/src/test/run-pass/trait-inheritance-num5.rs +++ b/src/test/run-pass/trait-inheritance-num5.rs @@ -17,7 +17,7 @@ impl NumExt for f32 {} impl NumExt for int {} fn num_eq_one<T:NumExt>() -> T { - NumCast::from(1i).unwrap() + NumCast::from(1).unwrap() } pub fn main() { diff --git a/src/test/run-pass/trait-inheritance-visibility.rs b/src/test/run-pass/trait-inheritance-visibility.rs index dc84cbfb09a..3cdedd884a4 100644 --- a/src/test/run-pass/trait-inheritance-visibility.rs +++ b/src/test/run-pass/trait-inheritance-visibility.rs @@ -24,5 +24,5 @@ fn f<T:Quux>(x: &T) { } pub fn main() { - f(&0i) + f(&0) } diff --git a/src/test/run-pass/trait-to-str.rs b/src/test/run-pass/trait-to-str.rs index 9b910d24bdc..ea8a5a28c34 100644 --- a/src/test/run-pass/trait-to-str.rs +++ b/src/test/run-pass/trait-to-str.rs @@ -31,15 +31,15 @@ impl<T:to_str> to_str for Vec<T> { pub fn main() { assert!(1.to_string_() == "1".to_string()); - assert!((vec!(2i, 3, 4)).to_string_() == "[2, 3, 4]".to_string()); + assert!((vec!(2, 3, 4)).to_string_() == "[2, 3, 4]".to_string()); fn indirect<T:to_str>(x: T) -> String { format!("{}!", x.to_string_()) } - assert!(indirect(vec!(10i, 20)) == "[10, 20]!".to_string()); + assert!(indirect(vec!(10, 20)) == "[10, 20]!".to_string()); fn indirect2<T:to_str>(x: T) -> String { indirect(x) } - assert!(indirect2(vec!(1i)) == "[1]!".to_string()); + assert!(indirect2(vec!(1)) == "[1]!".to_string()); } diff --git a/src/test/run-pass/traits-conditional-dispatch.rs b/src/test/run-pass/traits-conditional-dispatch.rs index 7e2b7ae0663..5af2d4ee806 100644 --- a/src/test/run-pass/traits-conditional-dispatch.rs +++ b/src/test/run-pass/traits-conditional-dispatch.rs @@ -35,5 +35,5 @@ fn main() { assert_eq!(get_it(&1_u32), 1_u32); assert_eq!(get_it(&1_u16), 1_u16); assert_eq!(get_it(&Some(1_u16)), Some(1_u16)); - assert_eq!(get_it(&box 1i), box 1i); + assert_eq!(get_it(&box 1), box 1); } diff --git a/src/test/run-pass/trivial-message.rs b/src/test/run-pass/trivial-message.rs index df8efb42e30..fd60c614638 100644 --- a/src/test/run-pass/trivial-message.rs +++ b/src/test/run-pass/trivial-message.rs @@ -17,7 +17,7 @@ use std::sync::mpsc::channel; pub fn main() { let (tx, rx) = channel(); - tx.send(42i); + tx.send(42); let r = rx.recv(); println!("{:?}", r); } diff --git a/src/test/run-pass/tuple-index-fat-types.rs b/src/test/run-pass/tuple-index-fat-types.rs index eccd841e357..924b861a911 100644 --- a/src/test/run-pass/tuple-index-fat-types.rs +++ b/src/test/run-pass/tuple-index-fat-types.rs @@ -11,11 +11,11 @@ struct Foo<'a>(&'a [int]); fn main() { - let x: &[int] = &[1i, 2, 3]; + let x: &[int] = &[1, 2, 3]; let y = (x,); assert_eq!(y.0, x); - let x: &[int] = &[1i, 2, 3]; + let x: &[int] = &[1, 2, 3]; let y = Foo(x); assert_eq!(y.0, x); } diff --git a/src/test/run-pass/tuple-index.rs b/src/test/run-pass/tuple-index.rs index 78e0cad4712..abdf6172779 100644 --- a/src/test/run-pass/tuple-index.rs +++ b/src/test/run-pass/tuple-index.rs @@ -24,7 +24,7 @@ fn main() { } assert_eq!(x.1, 0); - let mut x = (3i, 2i); + let mut x = (3, 2); assert_eq!(x.0, 3); assert_eq!(x.1, 2); x.0 += 5; diff --git a/src/test/run-pass/type-param-constraints.rs b/src/test/run-pass/type-param-constraints.rs index 3fcb04d6848..7d1fad5d281 100644 --- a/src/test/run-pass/type-param-constraints.rs +++ b/src/test/run-pass/type-param-constraints.rs @@ -33,12 +33,12 @@ pub fn main() { p_foo(r(10)); p_foo(box r(10)); - p_foo(box 10i); - p_foo(10i); + p_foo(box 10); + p_foo(10); - s_foo(box 10i); - s_foo(10i); + s_foo(box 10); + s_foo(10); - u_foo(box 10i); - u_foo(10i); + u_foo(box 10); + u_foo(10); } diff --git a/src/test/run-pass/typestate-cfg-nesting.rs b/src/test/run-pass/typestate-cfg-nesting.rs index f1e40cc3e58..37d06bf4f83 100644 --- a/src/test/run-pass/typestate-cfg-nesting.rs +++ b/src/test/run-pass/typestate-cfg-nesting.rs @@ -12,12 +12,12 @@ #![allow(unused_variable)] fn f() { - let x = 10i; let mut y = 11i; + let x = 10; let mut y = 11; if true { match x { _ => { y = x; } } } else { } } pub fn main() { - let x = 10i; - let mut y = 11i; + let x = 10; + let mut y = 11; if true { while false { y = x; } } else { } } diff --git a/src/test/run-pass/typestate-multi-decl.rs b/src/test/run-pass/typestate-multi-decl.rs index cbb0dcc8f2b..42910c47005 100644 --- a/src/test/run-pass/typestate-multi-decl.rs +++ b/src/test/run-pass/typestate-multi-decl.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let (x, y) = (10i, 20i); + let (x, y) = (10, 20); let z = x + y; assert!((z == 30)); } diff --git a/src/test/run-pass/unboxed-closures-infer-argument-types-from-expected-bound.rs b/src/test/run-pass/unboxed-closures-infer-argument-types-from-expected-bound.rs index fdd85b71cd2..5bebc70ca54 100644 --- a/src/test/run-pass/unboxed-closures-infer-argument-types-from-expected-bound.rs +++ b/src/test/run-pass/unboxed-closures-infer-argument-types-from-expected-bound.rs @@ -22,5 +22,5 @@ fn doit<T,F>(val: T, f: &F) } pub fn main() { - doit(0i, &|&: x /*: int*/ | { x.to_int(); }); + doit(0, &|&: x /*: int*/ | { x.to_int(); }); } diff --git a/src/test/run-pass/unboxed-closures-infer-argument-types-from-expected-object-type.rs b/src/test/run-pass/unboxed-closures-infer-argument-types-from-expected-object-type.rs index cce8cd64a14..a678c7a852f 100644 --- a/src/test/run-pass/unboxed-closures-infer-argument-types-from-expected-object-type.rs +++ b/src/test/run-pass/unboxed-closures-infer-argument-types-from-expected-object-type.rs @@ -18,5 +18,5 @@ use std::num::ToPrimitive; fn doit<T>(val: T, f: &Fn(T)) { f.call((val,)) } pub fn main() { - doit(0i, &|&: x /*: int*/ | { x.to_int(); }); + doit(0, &|&: x /*: int*/ | { x.to_int(); }); } diff --git a/src/test/run-pass/unboxed-closures-infer-argument-types-with-bound-regions-from-expected-bound.rs b/src/test/run-pass/unboxed-closures-infer-argument-types-with-bound-regions-from-expected-bound.rs index 8497bf7f987..6e0b3625a2e 100644 --- a/src/test/run-pass/unboxed-closures-infer-argument-types-with-bound-regions-from-expected-bound.rs +++ b/src/test/run-pass/unboxed-closures-infer-argument-types-with-bound-regions-from-expected-bound.rs @@ -22,5 +22,5 @@ fn doit<T,F>(val: T, f: &F) } pub fn main() { - doit(0i, &|&: x /*: int*/ | { x.to_int(); }); + doit(0, &|&: x /*: int*/ | { x.to_int(); }); } diff --git a/src/test/run-pass/unboxed-closures-prelude.rs b/src/test/run-pass/unboxed-closures-prelude.rs index 915715727e8..f9fc5770a38 100644 --- a/src/test/run-pass/unboxed-closures-prelude.rs +++ b/src/test/run-pass/unboxed-closures-prelude.rs @@ -16,10 +16,10 @@ fn main() { let task: Box<Fn(int) -> int> = box |&: x| x; - task.call((0i, )); + task.call((0, )); let mut task: Box<FnMut(int) -> int> = box |&mut: x| x; - task(0i); + task(0); call(|:x| x, 22); } diff --git a/src/test/run-pass/unboxed-closures-static-call-fn-once.rs b/src/test/run-pass/unboxed-closures-static-call-fn-once.rs index 780a1e6cdf0..e4b35aada9f 100644 --- a/src/test/run-pass/unboxed-closures-static-call-fn-once.rs +++ b/src/test/run-pass/unboxed-closures-static-call-fn-once.rs @@ -12,6 +12,6 @@ fn main() { let onetime = |: x| x; - onetime(0i); + onetime(0); } diff --git a/src/test/run-pass/unique-assign-copy.rs b/src/test/run-pass/unique-assign-copy.rs index 9e3d9544d42..c19063fe464 100644 --- a/src/test/run-pass/unique-assign-copy.rs +++ b/src/test/run-pass/unique-assign-copy.rs @@ -12,7 +12,7 @@ #![feature(box_syntax)] pub fn main() { - let mut i = box 1i; + let mut i = box 1; // Should be a copy let mut j; j = i.clone(); diff --git a/src/test/run-pass/unique-assign-drop.rs b/src/test/run-pass/unique-assign-drop.rs index 81c4b6ab7e5..241258f089c 100644 --- a/src/test/run-pass/unique-assign-drop.rs +++ b/src/test/run-pass/unique-assign-drop.rs @@ -13,8 +13,8 @@ #![feature(box_syntax)] pub fn main() { - let i = box 1i; - let mut j = box 2i; + let i = box 1; + let mut j = box 2; // Should drop the previous value of j j = i; assert_eq!(*j, 1); diff --git a/src/test/run-pass/unique-assign-generic.rs b/src/test/run-pass/unique-assign-generic.rs index 7c9bbd64171..c8abb080848 100644 --- a/src/test/run-pass/unique-assign-generic.rs +++ b/src/test/run-pass/unique-assign-generic.rs @@ -18,6 +18,6 @@ fn f<T>(t: T) -> T { } pub fn main() { - let t = f(box 100i); - assert_eq!(t, box 100i); + let t = f(box 100); + assert_eq!(t, box 100); } diff --git a/src/test/run-pass/unique-assign.rs b/src/test/run-pass/unique-assign.rs index 199657fd995..cbcb6afb4c8 100644 --- a/src/test/run-pass/unique-assign.rs +++ b/src/test/run-pass/unique-assign.rs @@ -13,6 +13,6 @@ pub fn main() { let mut i; - i = box 1i; + i = box 1; assert_eq!(*i, 1); } diff --git a/src/test/run-pass/unique-autoderef-index.rs b/src/test/run-pass/unique-autoderef-index.rs index 1c7b4c534ed..30c4b2d7b56 100644 --- a/src/test/run-pass/unique-autoderef-index.rs +++ b/src/test/run-pass/unique-autoderef-index.rs @@ -12,6 +12,6 @@ #![feature(box_syntax)] pub fn main() { - let i = box vec!(100i); - assert_eq!((*i)[0], 100i); + let i = box vec!(100); + assert_eq!((*i)[0], 100); } diff --git a/src/test/run-pass/unique-cmp.rs b/src/test/run-pass/unique-cmp.rs index dba4d8db849..a2962dc00d5 100644 --- a/src/test/run-pass/unique-cmp.rs +++ b/src/test/run-pass/unique-cmp.rs @@ -12,10 +12,10 @@ #![feature(box_syntax)] pub fn main() { - let i = box 100i; - assert!(i == box 100i); - assert!(i < box 101i); - assert!(i <= box 100i); - assert!(i > box 99i); - assert!(i >= box 99i); + let i = box 100; + assert!(i == box 100); + assert!(i < box 101); + assert!(i <= box 100); + assert!(i > box 99); + assert!(i >= box 99); } diff --git a/src/test/run-pass/unique-create.rs b/src/test/run-pass/unique-create.rs index cec74d251b3..975f1e9da82 100644 --- a/src/test/run-pass/unique-create.rs +++ b/src/test/run-pass/unique-create.rs @@ -12,9 +12,9 @@ #![feature(box_syntax)] pub fn main() { - box 100i; + box 100; } fn vec() { - vec!(0i); + vec!(0); } diff --git a/src/test/run-pass/unique-decl-init-copy.rs b/src/test/run-pass/unique-decl-init-copy.rs index d0ad03b773c..3af38784add 100644 --- a/src/test/run-pass/unique-decl-init-copy.rs +++ b/src/test/run-pass/unique-decl-init-copy.rs @@ -12,11 +12,11 @@ #![feature(box_syntax)] pub fn main() { - let mut i = box 1i; + let mut i = box 1; // Should be a copy let mut j = i.clone(); - *i = 2i; - *j = 3i; - assert_eq!(*i, 2i); - assert_eq!(*j, 3i); + *i = 2; + *j = 3; + assert_eq!(*i, 2); + assert_eq!(*j, 3); } diff --git a/src/test/run-pass/unique-decl-init.rs b/src/test/run-pass/unique-decl-init.rs index d7c19eb6358..c9192748809 100644 --- a/src/test/run-pass/unique-decl-init.rs +++ b/src/test/run-pass/unique-decl-init.rs @@ -12,7 +12,7 @@ #![feature(box_syntax)] pub fn main() { - let i = box 1i; + let i = box 1; let j = i; assert_eq!(*j, 1); } diff --git a/src/test/run-pass/unique-decl-move.rs b/src/test/run-pass/unique-decl-move.rs index 0acdc8f3b80..96dd9f51fbe 100644 --- a/src/test/run-pass/unique-decl-move.rs +++ b/src/test/run-pass/unique-decl-move.rs @@ -12,7 +12,7 @@ #![feature(box_syntax)] pub fn main() { - let i = box 100i; + let i = box 100; let j = i; assert_eq!(*j, 100); } diff --git a/src/test/run-pass/unique-deref.rs b/src/test/run-pass/unique-deref.rs index 752ea830aa5..41d3b87a003 100644 --- a/src/test/run-pass/unique-deref.rs +++ b/src/test/run-pass/unique-deref.rs @@ -12,6 +12,6 @@ #![feature(box_syntax)] pub fn main() { - let i = box 100i; + let i = box 100; assert_eq!(*i, 100); } diff --git a/src/test/run-pass/unique-drop-complex.rs b/src/test/run-pass/unique-drop-complex.rs index ec2c9f8c666..c5a0a4df275 100644 --- a/src/test/run-pass/unique-drop-complex.rs +++ b/src/test/run-pass/unique-drop-complex.rs @@ -12,5 +12,5 @@ #![feature(box_syntax)] pub fn main() { - let _x = box vec!(0i,0,0,0,0); + let _x = box vec!(0,0,0,0,0); } diff --git a/src/test/run-pass/unique-fn-arg-move.rs b/src/test/run-pass/unique-fn-arg-move.rs index 0e47d39e55f..1b3f7e72a4d 100644 --- a/src/test/run-pass/unique-fn-arg-move.rs +++ b/src/test/run-pass/unique-fn-arg-move.rs @@ -16,6 +16,6 @@ fn f(i: Box<int>) { } pub fn main() { - let i = box 100i; + let i = box 100; f(i); } diff --git a/src/test/run-pass/unique-in-vec-copy.rs b/src/test/run-pass/unique-in-vec-copy.rs index 4620815e74e..3bde79fdce0 100644 --- a/src/test/run-pass/unique-in-vec-copy.rs +++ b/src/test/run-pass/unique-in-vec-copy.rs @@ -12,7 +12,7 @@ #![feature(box_syntax)] pub fn main() { - let mut a = vec!(box 10i); + let mut a = vec!(box 10); let b = a.clone(); assert_eq!(*a[0], 10); diff --git a/src/test/run-pass/unique-in-vec.rs b/src/test/run-pass/unique-in-vec.rs index 389ca2c18b1..05b0c7244de 100644 --- a/src/test/run-pass/unique-in-vec.rs +++ b/src/test/run-pass/unique-in-vec.rs @@ -12,6 +12,6 @@ #![feature(box_syntax)] pub fn main() { - let vect = vec!(box 100i); + let vect = vec!(box 100); assert!(vect[0] == box 100); } diff --git a/src/test/run-pass/unique-init.rs b/src/test/run-pass/unique-init.rs index b36d08364a2..d3f13f1609f 100644 --- a/src/test/run-pass/unique-init.rs +++ b/src/test/run-pass/unique-init.rs @@ -12,5 +12,5 @@ #![feature(box_syntax)] pub fn main() { - let _i = box 100i; + let _i = box 100; } diff --git a/src/test/run-pass/unique-kinds.rs b/src/test/run-pass/unique-kinds.rs index 56f7a3f7990..4c93c379b48 100644 --- a/src/test/run-pass/unique-kinds.rs +++ b/src/test/run-pass/unique-kinds.rs @@ -23,11 +23,11 @@ fn sendable() { assert!(i != j); } - let i = box 100i; - let j = box 100i; + let i = box 100; + let j = box 100; f(i, j); - let i = box 100i; - let j = box 101i; + let i = box 100; + let j = box 101; g(i, j); } @@ -41,11 +41,11 @@ fn copyable() { assert!(i != j); } - let i = box 100i; - let j = box 100i; + let i = box 100; + let j = box 100; f(i, j); - let i = box 100i; - let j = box 101i; + let i = box 100; + let j = box 101; g(i, j); } @@ -59,11 +59,11 @@ fn noncopyable() { assert!(i != j); } - let i = box 100i; - let j = box 100i; + let i = box 100; + let j = box 100; f(i, j); - let i = box 100i; - let j = box 101i; + let i = box 100; + let j = box 101; g(i, j); } diff --git a/src/test/run-pass/unique-log.rs b/src/test/run-pass/unique-log.rs index 05579796dab..4b21b949f88 100644 --- a/src/test/run-pass/unique-log.rs +++ b/src/test/run-pass/unique-log.rs @@ -12,6 +12,6 @@ #![feature(box_syntax)] pub fn main() { - let i = box 100i; + let i = box 100; println!("{}", i); } diff --git a/src/test/run-pass/unique-move-drop.rs b/src/test/run-pass/unique-move-drop.rs index 1388c6c5d2b..705b9d6e92c 100644 --- a/src/test/run-pass/unique-move-drop.rs +++ b/src/test/run-pass/unique-move-drop.rs @@ -13,8 +13,8 @@ #![feature(box_syntax)] pub fn main() { - let i = box 100i; - let j = box 200i; + let i = box 100; + let j = box 200; let j = i; assert_eq!(*j, 100); } diff --git a/src/test/run-pass/unique-move-temp.rs b/src/test/run-pass/unique-move-temp.rs index af82d3e14ea..b6c24f5be28 100644 --- a/src/test/run-pass/unique-move-temp.rs +++ b/src/test/run-pass/unique-move-temp.rs @@ -13,6 +13,6 @@ pub fn main() { let mut i; - i = box 100i; + i = box 100; assert_eq!(*i, 100); } diff --git a/src/test/run-pass/unique-move.rs b/src/test/run-pass/unique-move.rs index 791c4799bf0..ed13bf6a5c4 100644 --- a/src/test/run-pass/unique-move.rs +++ b/src/test/run-pass/unique-move.rs @@ -12,7 +12,7 @@ #![feature(box_syntax)] pub fn main() { - let i = box 100i; + let i = box 100; let mut j; j = i; assert_eq!(*j, 100); diff --git a/src/test/run-pass/unique-mutable.rs b/src/test/run-pass/unique-mutable.rs index c4f860d930b..403b8bf18b8 100644 --- a/src/test/run-pass/unique-mutable.rs +++ b/src/test/run-pass/unique-mutable.rs @@ -12,7 +12,7 @@ #![feature(box_syntax)] pub fn main() { - let mut i = box 0i; + let mut i = box 0; *i = 1; assert_eq!(*i, 1); } diff --git a/src/test/run-pass/unique-send.rs b/src/test/run-pass/unique-send.rs index 13728585455..2a462e9cdd8 100644 --- a/src/test/run-pass/unique-send.rs +++ b/src/test/run-pass/unique-send.rs @@ -15,7 +15,7 @@ use std::sync::mpsc::channel; pub fn main() { let (tx, rx) = channel(); - tx.send(box 100i).unwrap(); + tx.send(box 100).unwrap(); let v = rx.recv().unwrap(); - assert_eq!(v, box 100i); + assert_eq!(v, box 100); } diff --git a/src/test/run-pass/unique-swap.rs b/src/test/run-pass/unique-swap.rs index cd3b59a69ba..2adb9c22f60 100644 --- a/src/test/run-pass/unique-swap.rs +++ b/src/test/run-pass/unique-swap.rs @@ -14,9 +14,9 @@ use std::mem::swap; pub fn main() { - let mut i = box 100i; - let mut j = box 200i; + let mut i = box 100; + let mut j = box 200; swap(&mut i, &mut j); - assert_eq!(i, box 200i); - assert_eq!(j, box 100i); + assert_eq!(i, box 200); + assert_eq!(j, box 100); } diff --git a/src/test/run-pass/unreachable-code.rs b/src/test/run-pass/unreachable-code.rs index a9ac78c5d76..a28dc2c1f15 100644 --- a/src/test/run-pass/unreachable-code.rs +++ b/src/test/run-pass/unreachable-code.rs @@ -24,7 +24,7 @@ fn call_id_2() { id(true) && id(return); } fn call_id_3() { id(return) && id(return); } fn ret_guard() { - match 2i { + match 2 { x if (return) => { x; } _ => {} } diff --git a/src/test/run-pass/unused-move-capture.rs b/src/test/run-pass/unused-move-capture.rs index 27945f46920..a2d1b8780aa 100644 --- a/src/test/run-pass/unused-move-capture.rs +++ b/src/test/run-pass/unused-move-capture.rs @@ -12,7 +12,7 @@ #![feature(box_syntax)] pub fn main() { - let _x = box 1i; + let _x = box 1; let lam_move = |&:| {}; lam_move(); } diff --git a/src/test/run-pass/unused-move.rs b/src/test/run-pass/unused-move.rs index 22201c7d83f..d053b03a2ca 100644 --- a/src/test/run-pass/unused-move.rs +++ b/src/test/run-pass/unused-move.rs @@ -18,6 +18,6 @@ pub fn main() { - let y = box 1i; + let y = box 1; y; } diff --git a/src/test/run-pass/unwind-unique.rs b/src/test/run-pass/unwind-unique.rs index 74802c156a2..ea52802d245 100644 --- a/src/test/run-pass/unwind-unique.rs +++ b/src/test/run-pass/unwind-unique.rs @@ -14,7 +14,7 @@ use std::thread::Thread; fn f() { - let _a = box 0i; + let _a = box 0; panic!(); } diff --git a/src/test/run-pass/use-uninit-match.rs b/src/test/run-pass/use-uninit-match.rs index 3f23d714c0f..efa6a2c5834 100644 --- a/src/test/run-pass/use-uninit-match.rs +++ b/src/test/run-pass/use-uninit-match.rs @@ -21,4 +21,4 @@ fn foo<T>(o: myoption<T>) -> int { enum myoption<T> { none, some(T), } -pub fn main() { println!("{}", 5i); } +pub fn main() { println!("{}", 5); } diff --git a/src/test/run-pass/use-uninit-match2.rs b/src/test/run-pass/use-uninit-match2.rs index de5b32dd176..f2b487b7034 100644 --- a/src/test/run-pass/use-uninit-match2.rs +++ b/src/test/run-pass/use-uninit-match2.rs @@ -21,4 +21,4 @@ fn foo<T>(o: myoption<T>) -> int { enum myoption<T> { none, some(T), } -pub fn main() { println!("{}", 5i); } +pub fn main() { println!("{}", 5); } diff --git a/src/test/run-pass/utf8_idents.rs b/src/test/run-pass/utf8_idents.rs index c99c394969c..0e6f20358aa 100644 --- a/src/test/run-pass/utf8_idents.rs +++ b/src/test/run-pass/utf8_idents.rs @@ -26,25 +26,25 @@ fn საჭმელად_გემრიელი_სადილი() -> int // Lunch in several languages. - let ランチ = 10i; - let 午餐 = 10i; + let ランチ = 10; + let 午餐 = 10; - let ארוחת_צהריי = 10i; + let ארוחת_צהריי = 10; let غداء = 10u; - let լանչ = 10i; - let обед = 10i; - let абед = 10i; - let μεσημεριανό = 10i; - let hádegismatur = 10i; - let ручек = 10i; + let լանչ = 10; + let обед = 10; + let абед = 10; + let μεσημεριανό = 10; + let hádegismatur = 10; + let ручек = 10; - let ăn_trưa = 10i; - let อาหารกลางวัน = 10i; + let ăn_trưa = 10; + let อาหารกลางวัน = 10; // Lunchy arithmetic, mm. assert_eq!(hádegismatur * ручек * обед, 1000); - assert_eq!(10i, ארוחת_צהריי); + assert_eq!(10, ארוחת_צהריי); assert_eq!(ランチ + 午餐 + μεσημεριανό, 30); assert_eq!(ăn_trưa + อาหารกลางวัน, 20); return (абед + լանչ) >> غداء; diff --git a/src/test/run-pass/variadic-ffi.rs b/src/test/run-pass/variadic-ffi.rs index 9600a242ca1..a729fedb271 100644 --- a/src/test/run-pass/variadic-ffi.rs +++ b/src/test/run-pass/variadic-ffi.rs @@ -35,7 +35,7 @@ pub fn main() { // Call with variable number of arguments let c = CString::from_slice(b"%d %f %c %s\n"); check("42 42.500000 a %d %f %c %s\n\n", |s| { - sprintf(s, c.as_ptr(), 42i, 42.5f64, 'a' as c_int, c.as_ptr()); + sprintf(s, c.as_ptr(), 42, 42.5f64, 'a' as c_int, c.as_ptr()); }); // Make a function pointer @@ -50,7 +50,7 @@ pub fn main() { // Call with variable number of arguments let c = CString::from_slice(b"%d %f %c %s\n"); check("42 42.500000 a %d %f %c %s\n\n", |s| { - sprintf(s, c.as_ptr(), 42i, 42.5f64, 'a' as c_int, c.as_ptr()); + sprintf(s, c.as_ptr(), 42, 42.5f64, 'a' as c_int, c.as_ptr()); }); } diff --git a/src/test/run-pass/vec-growth.rs b/src/test/run-pass/vec-growth.rs index d5e5f94d261..b8626b9c8a9 100644 --- a/src/test/run-pass/vec-growth.rs +++ b/src/test/run-pass/vec-growth.rs @@ -10,11 +10,11 @@ pub fn main() { - let mut v = vec!(1i); - v.push(2i); - v.push(3i); - v.push(4i); - v.push(5i); + let mut v = vec!(1); + v.push(2); + v.push(3); + v.push(4); + v.push(5); assert_eq!(v[0], 1); assert_eq!(v[1], 2); assert_eq!(v[2], 3); diff --git a/src/test/run-pass/vec-macro-with-brackets.rs b/src/test/run-pass/vec-macro-with-brackets.rs index a263501f8fe..5d1f43fb230 100644 --- a/src/test/run-pass/vec-macro-with-brackets.rs +++ b/src/test/run-pass/vec-macro-with-brackets.rs @@ -17,5 +17,5 @@ macro_rules! vec [ ]; pub fn main() { - let my_vec = vec![1i, 2, 3, 4, 5]; + let my_vec = vec![1, 2, 3, 4, 5]; } diff --git a/src/test/run-pass/vec-macro-with-trailing-comma.rs b/src/test/run-pass/vec-macro-with-trailing-comma.rs index 80c2a5fe83e..07033d60497 100644 --- a/src/test/run-pass/vec-macro-with-trailing-comma.rs +++ b/src/test/run-pass/vec-macro-with-trailing-comma.rs @@ -10,6 +10,6 @@ pub fn main() { - assert_eq!(vec!(1i), vec!(1i,)); - assert_eq!(vec!(1i, 2, 3), vec!(1i, 2, 3,)); + assert_eq!(vec!(1), vec!(1,)); + assert_eq!(vec!(1, 2, 3), vec!(1, 2, 3,)); } diff --git a/src/test/run-pass/vec-matching-autoslice.rs b/src/test/run-pass/vec-matching-autoslice.rs index 6476f734ae6..4ed73dc2301 100644 --- a/src/test/run-pass/vec-matching-autoslice.rs +++ b/src/test/run-pass/vec-matching-autoslice.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let x = [1i, 2, 3]; + let x = [1, 2, 3]; match x { [2, _, _] => panic!(), [1, a, b] => { @@ -18,7 +18,7 @@ pub fn main() { [_, _, _] => panic!(), } - let y = ([(1i, true), (2i, false)], 0.5f64); + let y = ([(1, true), (2, false)], 0.5f64); match y { ([(1, a), (b, false)], _) => { assert_eq!(a, true); diff --git a/src/test/run-pass/vec-matching-fixed.rs b/src/test/run-pass/vec-matching-fixed.rs index a1a14823ff5..6ef1dc4ea26 100644 --- a/src/test/run-pass/vec-matching-fixed.rs +++ b/src/test/run-pass/vec-matching-fixed.rs @@ -11,7 +11,7 @@ #![feature(advanced_slice_patterns)] fn a() { - let x = [1i, 2, 3]; + let x = [1, 2, 3]; match x { [1, 2, 4] => unreachable!(), [0, 2, 3, ..] => unreachable!(), diff --git a/src/test/run-pass/vec-matching-fold.rs b/src/test/run-pass/vec-matching-fold.rs index 57660183333..e72170cb730 100644 --- a/src/test/run-pass/vec-matching-fold.rs +++ b/src/test/run-pass/vec-matching-fold.rs @@ -39,11 +39,11 @@ fn foldr<T, U, F>(values: &[T], } pub fn main() { - let x = &[1i, 2, 3, 4, 5]; + let x = &[1, 2, 3, 4, 5]; - let product = foldl(x, 1i, |a, b| a * *b); + let product = foldl(x, 1, |a, b| a * *b); assert_eq!(product, 120); - let sum = foldr(x, 0i, |a, b| *a + b); + let sum = foldr(x, 0, |a, b| *a + b); assert_eq!(sum, 15); } diff --git a/src/test/run-pass/vec-matching-legal-tail-element-borrow.rs b/src/test/run-pass/vec-matching-legal-tail-element-borrow.rs index a140399447b..64309906156 100644 --- a/src/test/run-pass/vec-matching-legal-tail-element-borrow.rs +++ b/src/test/run-pass/vec-matching-legal-tail-element-borrow.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let x = &[1i, 2, 3, 4, 5]; + let x = &[1, 2, 3, 4, 5]; let x: &[int] = &[1, 2, 3, 4, 5]; if !x.is_empty() { let el = match x { diff --git a/src/test/run-pass/vec-matching.rs b/src/test/run-pass/vec-matching.rs index 77226df7fa2..8dcf4612f47 100644 --- a/src/test/run-pass/vec-matching.rs +++ b/src/test/run-pass/vec-matching.rs @@ -11,7 +11,7 @@ #![feature(advanced_slice_patterns)] fn a() { - let x = [1i]; + let x = [1]; match x { [a] => { assert_eq!(a, 1); @@ -20,7 +20,7 @@ fn a() { } fn b() { - let x = [1i, 2, 3]; + let x = [1, 2, 3]; match x { [a, b, c..] => { assert_eq!(a, 1); @@ -55,7 +55,7 @@ fn b() { } fn c() { - let x = [1i]; + let x = [1]; match x { [2, ..] => panic!(), [..] => () @@ -63,18 +63,18 @@ fn c() { } fn d() { - let x = [1i, 2, 3]; + let x = [1, 2, 3]; let branch = match x { - [1, 1, ..] => 0i, - [1, 2, 3, ..] => 1i, - [1, 2, ..] => 2i, + [1, 1, ..] => 0, + [1, 2, 3, ..] => 1, + [1, 2, ..] => 2, _ => 3 }; assert_eq!(branch, 1); } fn e() { - let x: &[int] = &[1i, 2, 3]; + let x: &[int] = &[1, 2, 3]; match x { [1, 2] => (), [..] => () diff --git a/src/test/run-pass/vec-push.rs b/src/test/run-pass/vec-push.rs index fe0f92a0c11..33f01c5bd41 100644 --- a/src/test/run-pass/vec-push.rs +++ b/src/test/run-pass/vec-push.rs @@ -8,4 +8,4 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -pub fn main() { let mut v = vec!(1i, 2, 3); v.push(1); } +pub fn main() { let mut v = vec!(1, 2, 3); v.push(1); } diff --git a/src/test/run-pass/vec-repeat-with-cast.rs b/src/test/run-pass/vec-repeat-with-cast.rs index 97a443cb3b8..22ca6c37a8e 100644 --- a/src/test/run-pass/vec-repeat-with-cast.rs +++ b/src/test/run-pass/vec-repeat-with-cast.rs @@ -8,4 +8,4 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -pub fn main() { let _a = [0i; 1 as uint]; } +pub fn main() { let _a = [0; 1 as uint]; } diff --git a/src/test/run-pass/vec-slice.rs b/src/test/run-pass/vec-slice.rs index 374913e3cfd..5375e54e27f 100644 --- a/src/test/run-pass/vec-slice.rs +++ b/src/test/run-pass/vec-slice.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let v = vec!(1i,2,3,4,5); + let v = vec![1,2,3,4,5]; let v2 = &v[1..3]; assert_eq!(v2[0], 2); assert_eq!(v2[1], 3); diff --git a/src/test/run-pass/vec-to_str.rs b/src/test/run-pass/vec-to_str.rs index 31f26126242..5d132b2a749 100644 --- a/src/test/run-pass/vec-to_str.rs +++ b/src/test/run-pass/vec-to_str.rs @@ -9,9 +9,9 @@ // except according to those terms. pub fn main() { - assert_eq!(format!("{:?}", vec!(0i, 1)), "[0, 1]".to_string()); + assert_eq!(format!("{:?}", vec!(0, 1)), "[0, 1]".to_string()); - let foo = vec!(3i, 4); + let foo = vec!(3, 4); let bar: &[int] = &[4, 5]; assert_eq!(format!("{:?}", foo), "[3, 4]"); diff --git a/src/test/run-pass/vector-sort-panic-safe.rs b/src/test/run-pass/vector-sort-panic-safe.rs index 250bafc712d..aaefbc42d70 100644 --- a/src/test/run-pass/vector-sort-panic-safe.rs +++ b/src/test/run-pass/vector-sort-panic-safe.rs @@ -12,8 +12,8 @@ use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering}; use std::rand::{thread_rng, Rng, Rand}; use std::thread::Thread; -const REPEATS: uint = 5; -const MAX_LEN: uint = 32; +const REPEATS: usize = 5; +const MAX_LEN: usize = 32; static drop_counts: [AtomicUsize; MAX_LEN] = // FIXME #5244: AtomicUsize is not Copy. [ @@ -33,7 +33,7 @@ static drop_counts: [AtomicUsize; MAX_LEN] = static creation_count: AtomicUsize = ATOMIC_USIZE_INIT; #[derive(Clone, PartialEq, PartialOrd, Eq, Ord)] -struct DropCounter { x: uint, creation_id: uint } +struct DropCounter { x: usize, creation_id: usize } impl Rand for DropCounter { fn rand<R: Rng>(rng: &mut R) -> DropCounter { @@ -53,7 +53,7 @@ impl Drop for DropCounter { } pub fn main() { - assert!(MAX_LEN <= std::uint::BITS); + assert!(MAX_LEN <= std::usize::BITS); // len can't go above 64. for len in 2..MAX_LEN { for _ in 0..REPEATS { @@ -67,11 +67,11 @@ pub fn main() { // work out the total number of comparisons required to sort // this array... - let mut count = 0; + let mut count = 0us; main.clone().as_mut_slice().sort_by(|a, b| { count += 1; a.cmp(b) }); // ... and then panic on each and every single one. - for panic_countdown in 0i..count { + for panic_countdown in 0..count { // refresh the counters. for c in drop_counts.iter() { c.store(0, Ordering::Relaxed); diff --git a/src/test/run-pass/wait-forked-but-failed-child.rs b/src/test/run-pass/wait-forked-but-failed-child.rs index ef48bdff11d..12de40129fd 100644 --- a/src/test/run-pass/wait-forked-but-failed-child.rs +++ b/src/test/run-pass/wait-forked-but-failed-child.rs @@ -41,7 +41,7 @@ fn find_zombies() { if 0 < line_no && 0 < line.len() && my_pid == line.split(' ').filter(|w| 0 < w.len()).nth(1) .expect("1st column should be PPID") - .parse() + .parse().ok() .expect("PPID string into integer") && line.contains("defunct") { panic!("Zombie child {}", line); diff --git a/src/test/run-pass/weird-exprs.rs b/src/test/run-pass/weird-exprs.rs index c8ed1a26105..4080796b7a7 100644 --- a/src/test/run-pass/weird-exprs.rs +++ b/src/test/run-pass/weird-exprs.rs @@ -36,7 +36,7 @@ fn zombiejesus() { while (return) { if (return) { match (return) { - 1i => { + 1 => { if (return) { return } else { @@ -65,13 +65,13 @@ fn canttouchthis() -> uint { fn p() -> bool { true } let _a = (assert!((true)) == (assert!(p()))); let _c = (assert!((p())) == ()); - let _b: bool = (println!("{}", 0i) == (return 0u)); + let _b: bool = (println!("{}", 0) == (return 0u)); } fn angrydome() { loop { if break { } } - let mut i = 0i; - loop { i += 1; if i == 1 { match (continue) { 1i => { }, _ => panic!("wat") } } + let mut i = 0; + loop { i += 1; if i == 1 { match (continue) { 1 => { }, _ => panic!("wat") } } break; } } diff --git a/src/test/run-pass/where-clause-region-outlives.rs b/src/test/run-pass/where-clause-region-outlives.rs index 1ecb4b6c2dc..aa39325277e 100644 --- a/src/test/run-pass/where-clause-region-outlives.rs +++ b/src/test/run-pass/where-clause-region-outlives.rs @@ -11,7 +11,7 @@ struct A<'a, 'b> where 'a : 'b { x: &'a int, y: &'b int } fn main() { - let x = 1i; - let y = 1i; + let x = 1; + let y = 1; let a = A { x: &x, y: &y }; } diff --git a/src/test/run-pass/where-clauses-cross-crate.rs b/src/test/run-pass/where-clauses-cross-crate.rs index 648f646b637..b822abd6732 100644 --- a/src/test/run-pass/where-clauses-cross-crate.rs +++ b/src/test/run-pass/where-clauses-cross-crate.rs @@ -15,9 +15,9 @@ extern crate where_clauses_xc; use where_clauses_xc::{Equal, equal}; fn main() { - println!("{}", equal(&1i, &2i)); - println!("{}", equal(&1i, &1i)); + println!("{}", equal(&1, &2)); + println!("{}", equal(&1, &1)); println!("{}", "hello".equal(&"hello")); - println!("{}", "hello".equals::<int,&str>(&1i, &1i, &"foo", &"bar")); + println!("{}", "hello".equals::<int,&str>(&1, &1, &"foo", &"bar")); } diff --git a/src/test/run-pass/where-clauses-lifetimes.rs b/src/test/run-pass/where-clauses-lifetimes.rs index 237c83c8aa2..e3ea7cd80e7 100644 --- a/src/test/run-pass/where-clauses-lifetimes.rs +++ b/src/test/run-pass/where-clauses-lifetimes.rs @@ -11,5 +11,5 @@ fn foo<'a, I>(mut it: I) where I: Iterator<Item=&'a int> {} fn main() { - foo([1i, 2].iter()); + foo([1, 2].iter()); } diff --git a/src/test/run-pass/where-clauses-method.rs b/src/test/run-pass/where-clauses-method.rs index 2b87bcd4b39..29efe727276 100644 --- a/src/test/run-pass/where-clauses-method.rs +++ b/src/test/run-pass/where-clauses-method.rs @@ -22,8 +22,8 @@ impl<T> Foo<T> { } fn main() { - let x = Foo { value: 1i }; - let y = Foo { value: 2i }; + let x = Foo { value: 1 }; + let y = Foo { value: 2 }; println!("{}", x.equals(&x)); println!("{}", x.equals(&y)); } diff --git a/src/test/run-pass/where-clauses.rs b/src/test/run-pass/where-clauses.rs index 807d95691f4..92bc7edf285 100644 --- a/src/test/run-pass/where-clauses.rs +++ b/src/test/run-pass/where-clauses.rs @@ -29,9 +29,9 @@ fn equal<T>(x: &T, y: &T) -> bool where T: Eq { } fn main() { - println!("{}", equal(&1i, &2i)); - println!("{}", equal(&1i, &1i)); + println!("{}", equal(&1, &2)); + println!("{}", equal(&1, &1)); println!("{}", "hello".equal(&"hello")); - println!("{}", "hello".equals::<int,&str>(&1i, &1i, &"foo", &"bar")); + println!("{}", "hello".equals::<int,&str>(&1, &1, &"foo", &"bar")); } diff --git a/src/test/run-pass/while-cont.rs b/src/test/run-pass/while-cont.rs index 50feb3ef4e1..3e1a232115f 100644 --- a/src/test/run-pass/while-cont.rs +++ b/src/test/run-pass/while-cont.rs @@ -10,7 +10,7 @@ // Issue #825: Should recheck the loop condition after continuing pub fn main() { - let mut i = 1i; + let mut i = 1; while i > 0 { assert!((i > 0)); println!("{}", i); diff --git a/src/test/run-pass/while-label.rs b/src/test/run-pass/while-label.rs index 41712f7c64d..4a3cd115d20 100644 --- a/src/test/run-pass/while-label.rs +++ b/src/test/run-pass/while-label.rs @@ -10,8 +10,8 @@ pub fn main() { - let mut i = 100i; - 'w: while 1i + 1 == 2 { + let mut i = 100; + 'w: while 1 + 1 == 2 { i -= 1; if i == 95 { break 'w; diff --git a/src/test/run-pass/while-let.rs b/src/test/run-pass/while-let.rs index 94a45817ee5..1780445fb3b 100644 --- a/src/test/run-pass/while-let.rs +++ b/src/test/run-pass/while-let.rs @@ -11,16 +11,16 @@ use std::collections::BinaryHeap; fn make_pq() -> BinaryHeap<int> { - BinaryHeap::from_vec(vec![1i,2,3]) + BinaryHeap::from_vec(vec![1,2,3]) } pub fn main() { let mut pq = make_pq(); - let mut sum = 0i; + let mut sum = 0; while let Some(x) = pq.pop() { sum += x; } - assert_eq!(sum, 6i); + assert_eq!(sum, 6); pq = make_pq(); sum = 0; @@ -30,7 +30,7 @@ pub fn main() { break 'a; } } - assert_eq!(sum, 5i); + assert_eq!(sum, 5); pq = make_pq(); sum = 0; @@ -40,7 +40,7 @@ pub fn main() { } sum += x; } - assert_eq!(sum, 3i); + assert_eq!(sum, 3); let mut pq1 = make_pq(); sum = 0; @@ -50,5 +50,5 @@ pub fn main() { sum += x * y; } } - assert_eq!(sum, 6i + 12 + 18); + assert_eq!(sum, 6 + 12 + 18); } |
