diff --git a/AUTHORS.txt b/AUTHORS.txt index eb80b1ff85d7..83f9bbff8aa6 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -121,6 +121,7 @@ Cole Mickens Colin Davidson Colin Sherratt Conrad Kleinespel +Corey Farwell Corey Ford Corey Richardson DJUrsus diff --git a/configure b/configure index e3351000ca27..8a6ba86dd475 100755 --- a/configure +++ b/configure @@ -893,7 +893,10 @@ CFG_PREFIX=${CFG_PREFIX%/} CFG_MANDIR=${CFG_MANDIR%/} CFG_HOST="$(echo $CFG_HOST | tr ',' ' ')" CFG_TARGET="$(echo $CFG_TARGET | tr ',' ' ')" -CFG_SUPPORTED_TARGET="$(ls ${CFG_SRC_DIR}mk/cfg)" +CFG_SUPPORTED_TARGET="" +for target_file in ${CFG_SRC_DIR}mk/cfg/*.mk; do + CFG_SUPPORTED_TARGET="${CFG_SUPPORTED_TARGET} $(basename "$target_file" .mk)" +done # copy host-triples to target-triples so that hosts are a subset of targets V_TEMP="" diff --git a/mk/cfg/arm-apple-ios b/mk/cfg/arm-apple-ios.mk similarity index 100% rename from mk/cfg/arm-apple-ios rename to mk/cfg/arm-apple-ios.mk diff --git a/mk/cfg/arm-linux-androideabi b/mk/cfg/arm-linux-androideabi.mk similarity index 100% rename from mk/cfg/arm-linux-androideabi rename to mk/cfg/arm-linux-androideabi.mk diff --git a/mk/cfg/arm-unknown-linux-gnueabi b/mk/cfg/arm-unknown-linux-gnueabi.mk similarity index 100% rename from mk/cfg/arm-unknown-linux-gnueabi rename to mk/cfg/arm-unknown-linux-gnueabi.mk diff --git a/mk/cfg/arm-unknown-linux-gnueabihf b/mk/cfg/arm-unknown-linux-gnueabihf.mk similarity index 100% rename from mk/cfg/arm-unknown-linux-gnueabihf rename to mk/cfg/arm-unknown-linux-gnueabihf.mk diff --git a/mk/cfg/i386-apple-ios b/mk/cfg/i386-apple-ios.mk similarity index 100% rename from mk/cfg/i386-apple-ios rename to mk/cfg/i386-apple-ios.mk diff --git a/mk/cfg/i686-apple-darwin b/mk/cfg/i686-apple-darwin.mk similarity index 100% rename from mk/cfg/i686-apple-darwin rename to mk/cfg/i686-apple-darwin.mk diff --git a/mk/cfg/i686-pc-windows-gnu b/mk/cfg/i686-pc-windows-gnu.mk similarity index 100% rename from mk/cfg/i686-pc-windows-gnu rename to mk/cfg/i686-pc-windows-gnu.mk diff --git a/mk/cfg/i686-unknown-linux-gnu b/mk/cfg/i686-unknown-linux-gnu.mk similarity index 100% rename from mk/cfg/i686-unknown-linux-gnu rename to mk/cfg/i686-unknown-linux-gnu.mk diff --git a/mk/cfg/mips-unknown-linux-gnu b/mk/cfg/mips-unknown-linux-gnu.mk similarity index 100% rename from mk/cfg/mips-unknown-linux-gnu rename to mk/cfg/mips-unknown-linux-gnu.mk diff --git a/mk/cfg/mipsel-unknown-linux-gnu b/mk/cfg/mipsel-unknown-linux-gnu.mk similarity index 100% rename from mk/cfg/mipsel-unknown-linux-gnu rename to mk/cfg/mipsel-unknown-linux-gnu.mk diff --git a/mk/cfg/x86_64-apple-darwin b/mk/cfg/x86_64-apple-darwin.mk similarity index 100% rename from mk/cfg/x86_64-apple-darwin rename to mk/cfg/x86_64-apple-darwin.mk diff --git a/mk/cfg/x86_64-pc-windows-gnu b/mk/cfg/x86_64-pc-windows-gnu.mk similarity index 100% rename from mk/cfg/x86_64-pc-windows-gnu rename to mk/cfg/x86_64-pc-windows-gnu.mk diff --git a/mk/cfg/x86_64-unknown-dragonfly b/mk/cfg/x86_64-unknown-dragonfly.mk similarity index 100% rename from mk/cfg/x86_64-unknown-dragonfly rename to mk/cfg/x86_64-unknown-dragonfly.mk diff --git a/mk/cfg/x86_64-unknown-freebsd b/mk/cfg/x86_64-unknown-freebsd.mk similarity index 100% rename from mk/cfg/x86_64-unknown-freebsd rename to mk/cfg/x86_64-unknown-freebsd.mk diff --git a/mk/cfg/x86_64-unknown-linux-gnu b/mk/cfg/x86_64-unknown-linux-gnu.mk similarity index 100% rename from mk/cfg/x86_64-unknown-linux-gnu rename to mk/cfg/x86_64-unknown-linux-gnu.mk diff --git a/mk/platform.mk b/mk/platform.mk index 6da01efcaaad..7ca24736cb85 100644 --- a/mk/platform.mk +++ b/mk/platform.mk @@ -113,7 +113,7 @@ $(foreach cvar,CC CXX CPP CFLAGS CXXFLAGS CPPFLAGS, \ CFG_RLIB_GLOB=lib$(1)-*.rlib -include $(wildcard $(CFG_SRC_DIR)mk/cfg/*) +include $(wildcard $(CFG_SRC_DIR)mk/cfg/*.mk) # The -Qunused-arguments sidesteps spurious warnings from clang define FILTER_FLAGS diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index 75dc45d16eb3..9bf45de0a17d 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -1566,7 +1566,7 @@ fn _arm_exec_compiled_test(config: &Config, let mut exitcode: int = 0; for c in exitcode_out.as_slice().chars() { - if !c.is_digit() { break; } + if !c.is_numeric() { break; } exitcode = exitcode * 10 + match c { '0' ... '9' => c as int - ('0' as int), _ => 101, diff --git a/src/etc/vim/compiler/cargo.vim b/src/etc/vim/compiler/cargo.vim index 89c1cff110e2..ed487a308e19 100644 --- a/src/etc/vim/compiler/cargo.vim +++ b/src/etc/vim/compiler/cargo.vim @@ -1,29 +1,35 @@ " Vim compiler file " Compiler: Cargo Compiler " Maintainer: Damien Radtke -" Latest Revision: 2014 Sep 18 +" Latest Revision: 2014 Sep 24 -if exists("current_compiler") +if exists('current_compiler') finish endif +runtime compiler/rustc.vim let current_compiler = "cargo" -if exists(":CompilerSet") != 2 +if exists(':CompilerSet') != 2 command -nargs=* CompilerSet setlocal endif -CompilerSet errorformat& -CompilerSet makeprg=cargo\ $* +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'. -if !exists('g:cargo_toml_name') - let g:cargo_toml_name = 'Cargo.toml' -endif +let s:cargo_manifest_name = get(g:, 'cargo_manifest_name', 'Cargo.toml') -let s:toml_dir = fnamemodify(findfile(g:cargo_toml_name, '.;'), ':p:h').'/' +function! s:is_absolute(path) + return a:path[0] == '/' || a:path =~ '[A-Z]\+:' +endfunction -if s:toml_dir != '' +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() @@ -33,15 +39,25 @@ if s:toml_dir != '' " 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'] + 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 stridx(filename, s:toml_dir) == -1 - let filename = s:toml_dir.filename + let filename = bufname(qf.bufnr) + if s:is_absolute(filename) + continue endif - let qf['filename'] = simplify(s:toml_dir.bufname(qf['bufnr'])) + let qf.filename = simplify(manifest.filename) call remove(qf, 'bufnr') endfor call setqflist(qflist, 'r') diff --git a/src/etc/vim/doc/rust.txt b/src/etc/vim/doc/rust.txt index 0295d68d97e7..e117b0c155b7 100644 --- a/src/etc/vim/doc/rust.txt +++ b/src/etc/vim/doc/rust.txt @@ -88,6 +88,13 @@ g:ftplugin_rust_source_path~ 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* diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index 9c93669b5acb..0fe40081a462 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -630,7 +630,9 @@ pub trait StrAllocating: Str { let me = self.as_slice(); let mut out = String::with_capacity(me.len()); for c in me.chars() { - c.escape_default(|c| out.push(c)); + for c in c.escape_default() { + out.push(c); + } } out } @@ -640,7 +642,9 @@ pub trait StrAllocating: Str { let me = self.as_slice(); let mut out = String::with_capacity(me.len()); for c in me.chars() { - c.escape_unicode(|c| out.push(c)); + for c in c.escape_unicode() { + out.push(c); + } } out } @@ -1189,7 +1193,7 @@ mod tests { assert_eq!("11foo1bar11".trim_left_chars('1'), "foo1bar11"); let chars: &[char] = &['1', '2']; assert_eq!("12foo1bar12".trim_left_chars(chars), "foo1bar12"); - assert_eq!("123foo1bar123".trim_left_chars(|c: char| c.is_digit()), "foo1bar123"); + assert_eq!("123foo1bar123".trim_left_chars(|c: char| c.is_numeric()), "foo1bar123"); } #[test] @@ -1204,7 +1208,7 @@ mod tests { assert_eq!("11foo1bar11".trim_right_chars('1'), "11foo1bar"); let chars: &[char] = &['1', '2']; assert_eq!("12foo1bar12".trim_right_chars(chars), "12foo1bar"); - assert_eq!("123foo1bar123".trim_right_chars(|c: char| c.is_digit()), "123foo1bar"); + assert_eq!("123foo1bar123".trim_right_chars(|c: char| c.is_numeric()), "123foo1bar"); } #[test] @@ -1219,7 +1223,7 @@ mod tests { assert_eq!("11foo1bar11".trim_chars('1'), "foo1bar"); let chars: &[char] = &['1', '2']; assert_eq!("12foo1bar12".trim_chars(chars), "foo1bar"); - assert_eq!("123foo1bar123".trim_chars(|c: char| c.is_digit()), "foo1bar"); + assert_eq!("123foo1bar123".trim_chars(|c: char| c.is_numeric()), "foo1bar"); } #[test] diff --git a/src/libcore/char.rs b/src/libcore/char.rs index e4dc9ce5bd46..272b36847991 100644 --- a/src/libcore/char.rs +++ b/src/libcore/char.rs @@ -17,7 +17,7 @@ use mem::transmute; use option::{None, Option, Some}; -use iter::range_step; +use iter::{range_step, Iterator, RangeStep}; use slice::SlicePrelude; // UTF-8 ranges and tags for encoding characters @@ -63,10 +63,12 @@ static MAX_THREE_B: u32 = 0x10000u32; */ /// The highest valid code point +#[stable] pub const MAX: char = '\U0010ffff'; /// Converts from `u32` to a `char` #[inline] +#[unstable = "pending decisions about costructors for primitives"] pub fn from_u32(i: u32) -> Option { // catch out-of-bounds and surrogates if (i > MAX as u32) || (i >= 0xD800 && i <= 0xDFFF) { @@ -96,11 +98,9 @@ pub fn from_u32(i: u32) -> Option { /// This just wraps `to_digit()`. /// #[inline] +#[deprecated = "use the Char::is_digit method"] pub fn is_digit_radix(c: char, radix: uint) -> bool { - match to_digit(c, radix) { - Some(_) => true, - None => false, - } + c.is_digit(radix) } /// @@ -118,18 +118,9 @@ pub fn is_digit_radix(c: char, radix: uint) -> bool { /// Panics if given a `radix` outside the range `[0..36]`. /// #[inline] +#[deprecated = "use the Char::to_digit method"] pub fn to_digit(c: char, radix: uint) -> Option { - if radix > 36 { - panic!("to_digit: radix is too high (maximum 36)"); - } - let val = match c { - '0' ... '9' => c as uint - ('0' as uint), - 'a' ... 'z' => c as uint + 10u - ('a' as uint), - 'A' ... 'Z' => c as uint + 10u - ('A' as uint), - _ => return None, - }; - if val < radix { Some(val) } - else { None } + c.to_digit(radix) } /// @@ -145,6 +136,7 @@ pub fn to_digit(c: char, radix: uint) -> Option { /// Panics if given an `radix` > 36. /// #[inline] +#[unstable = "pending decisions about costructors for primitives"] pub fn from_digit(num: uint, radix: uint) -> Option { if radix > 36 { panic!("from_digit: radix is to high (maximum 36)"); @@ -171,23 +163,10 @@ pub fn from_digit(num: uint, radix: uint) -> Option { /// - chars in [0x100,0xffff] get 4-digit escapes: `\\uNNNN` /// - chars above 0x10000 get 8-digit escapes: `\\UNNNNNNNN` /// +#[deprecated = "use the Char::escape_unicode method"] pub fn escape_unicode(c: char, f: |char|) { - // avoid calling str::to_str_radix because we don't really need to allocate - // here. - f('\\'); - let pad = match () { - _ if c <= '\x7f' => { f('x'); 2 } - _ if c <= '\uffff' => { f('u'); 4 } - _ => { f('U'); 8 } - }; - for offset in range_step::(4 * (pad - 1), -1, -4) { - let offset = offset as uint; - unsafe { - match ((c as i32) >> offset) & 0xf { - i @ 0 ... 9 => { f(transmute('0' as i32 + i)); } - i => { f(transmute('a' as i32 + (i - 10))); } - } - } + for char in c.escape_unicode() { + f(char); } } @@ -203,32 +182,22 @@ pub fn escape_unicode(c: char, f: |char|) { /// - Any other chars in the range [0x20,0x7e] are not escaped. /// - Any other chars are given hex Unicode escapes; see `escape_unicode`. /// +#[deprecated = "use the Char::escape_default method"] pub fn escape_default(c: char, f: |char|) { - match c { - '\t' => { f('\\'); f('t'); } - '\r' => { f('\\'); f('r'); } - '\n' => { f('\\'); f('n'); } - '\\' => { f('\\'); f('\\'); } - '\'' => { f('\\'); f('\''); } - '"' => { f('\\'); f('"'); } - '\x20' ... '\x7e' => { f(c); } - _ => c.escape_unicode(f), + for c in c.escape_default() { + f(c); } } /// Returns the amount of bytes this `char` would need if encoded in UTF-8 #[inline] +#[deprecated = "use the Char::len_utf8 method"] pub fn len_utf8_bytes(c: char) -> uint { - let code = c as u32; - match () { - _ if code < MAX_ONE_B => 1u, - _ if code < MAX_TWO_B => 2u, - _ if code < MAX_THREE_B => 3u, - _ => 4u, - } + c.len_utf8() } /// Basic `char` manipulations. +#[experimental = "trait organization may change"] pub trait Char { /// Checks if a `char` parses as a numeric digit in the given radix. /// @@ -243,7 +212,24 @@ pub trait Char { /// # Panics /// /// Panics if given a radix > 36. - fn is_digit_radix(&self, radix: uint) -> bool; + #[deprecated = "use is_digit"] + fn is_digit_radix(self, radix: uint) -> bool; + + /// Checks if a `char` parses as a numeric digit in the given radix. + /// + /// Compared to `is_digit()`, this function only recognizes the characters + /// `0-9`, `a-z` and `A-Z`. + /// + /// # Return value + /// + /// Returns `true` if `c` is a valid digit under `radix`, and `false` + /// otherwise. + /// + /// # Panics + /// + /// Panics if given a radix > 36. + #[unstable = "pending error conventions"] + fn is_digit(self, radix: uint) -> bool; /// Converts a character to the corresponding digit. /// @@ -256,7 +242,8 @@ pub trait Char { /// # Panics /// /// Panics if given a radix outside the range [0..36]. - fn to_digit(&self, radix: uint) -> Option; + #[unstable = "pending error conventions, trait organization"] + fn to_digit(self, radix: uint) -> Option; /// Converts a number to the character representing it. /// @@ -268,19 +255,26 @@ pub trait Char { /// # Panics /// /// Panics if given a radix > 36. + #[deprecated = "use the char::from_digit free function"] fn from_digit(num: uint, radix: uint) -> Option; - /// Returns the hexadecimal Unicode escape of a character. + /// Converts from `u32` to a `char` + #[deprecated = "use the char::from_u32 free function"] + fn from_u32(i: u32) -> Option; + + /// Returns an iterator that yields the hexadecimal Unicode escape + /// of a character, as `char`s. /// /// The rules are as follows: /// /// * Characters in [0,0xff] get 2-digit escapes: `\\xNN` /// * Characters in [0x100,0xffff] get 4-digit escapes: `\\uNNNN`. /// * Characters above 0x10000 get 8-digit escapes: `\\UNNNNNNNN`. - fn escape_unicode(&self, f: |char|); + #[unstable = "pending error conventions, trait organization"] + fn escape_unicode(self) -> UnicodeEscapedChars; - /// Returns a 'default' ASCII and C++11-like literal escape of a - /// character. + /// Returns an iterator that yields the 'default' ASCII and + /// C++11-like literal escape of a character, as `char`s. /// /// The default is chosen with a bias toward producing literals that are /// legal in a variety of languages, including C++11 and similar C-family @@ -291,17 +285,30 @@ pub trait Char { /// escaped. /// * Any other chars in the range [0x20,0x7e] are not escaped. /// * Any other chars are given hex Unicode escapes; see `escape_unicode`. - fn escape_default(&self, f: |char|); + #[unstable = "pending error conventions, trait organization"] + fn escape_default(self) -> DefaultEscapedChars; /// Returns the amount of bytes this character would need if encoded in /// UTF-8. - fn len_utf8_bytes(&self) -> uint; + #[deprecated = "use len_utf8"] + fn len_utf8_bytes(self) -> uint; + + /// Returns the amount of bytes this character would need if encoded in + /// UTF-8. + #[unstable = "pending trait organization"] + fn len_utf8(self) -> uint; + + /// Returns the amount of bytes this character would need if encoded in + /// UTF-16. + #[unstable = "pending trait organization"] + fn len_utf16(self) -> uint; /// Encodes this character as UTF-8 into the provided byte buffer, /// and then returns the number of bytes written. /// /// If the buffer is not large enough, nothing will be written into it /// and a `None` will be returned. + #[unstable = "pending trait organization"] fn encode_utf8(&self, dst: &mut [u8]) -> Option; /// Encodes this character as UTF-16 into the provided `u16` buffer, @@ -309,24 +316,90 @@ pub trait Char { /// /// If the buffer is not large enough, nothing will be written into it /// and a `None` will be returned. + #[unstable = "pending trait organization"] fn encode_utf16(&self, dst: &mut [u16]) -> Option; } +#[experimental = "trait is experimental"] impl Char for char { - fn is_digit_radix(&self, radix: uint) -> bool { is_digit_radix(*self, radix) } + #[deprecated = "use is_digit"] + fn is_digit_radix(self, radix: uint) -> bool { self.is_digit(radix) } - fn to_digit(&self, radix: uint) -> Option { to_digit(*self, radix) } + #[unstable = "pending trait organization"] + fn is_digit(self, radix: uint) -> bool { + match self.to_digit(radix) { + Some(_) => true, + None => false, + } + } + #[unstable = "pending trait organization"] + fn to_digit(self, radix: uint) -> Option { + if radix > 36 { + panic!("to_digit: radix is too high (maximum 36)"); + } + let val = match self { + '0' ... '9' => self as uint - ('0' as uint), + 'a' ... 'z' => self as uint + 10u - ('a' as uint), + 'A' ... 'Z' => self as uint + 10u - ('A' as uint), + _ => return None, + }; + if val < radix { Some(val) } + else { None } + } + + #[deprecated = "use the char::from_digit free function"] fn from_digit(num: uint, radix: uint) -> Option { from_digit(num, radix) } - fn escape_unicode(&self, f: |char|) { escape_unicode(*self, f) } + #[inline] + #[deprecated = "use the char::from_u32 free function"] + fn from_u32(i: u32) -> Option { from_u32(i) } - fn escape_default(&self, f: |char|) { escape_default(*self, f) } + #[unstable = "pending error conventions, trait organization"] + fn escape_unicode(self) -> UnicodeEscapedChars { + UnicodeEscapedChars { c: self, state: UnicodeEscapedCharsState::Backslash } + } + + #[unstable = "pending error conventions, trait organization"] + fn escape_default(self) -> DefaultEscapedChars { + let init_state = match self { + '\t' => DefaultEscapedCharsState::Backslash('t'), + '\r' => DefaultEscapedCharsState::Backslash('r'), + '\n' => DefaultEscapedCharsState::Backslash('n'), + '\\' => DefaultEscapedCharsState::Backslash('\\'), + '\'' => DefaultEscapedCharsState::Backslash('\''), + '"' => DefaultEscapedCharsState::Backslash('"'), + '\x20' ... '\x7e' => DefaultEscapedCharsState::Char(self), + _ => DefaultEscapedCharsState::Unicode(self.escape_unicode()) + }; + DefaultEscapedChars { state: init_state } + } #[inline] - fn len_utf8_bytes(&self) -> uint { len_utf8_bytes(*self) } + #[deprecated = "use len_utf8"] + fn len_utf8_bytes(self) -> uint { self.len_utf8() } #[inline] + #[unstable = "pending trait organization"] + fn len_utf8(self) -> uint { + let code = self as u32; + match () { + _ if code < MAX_ONE_B => 1u, + _ if code < MAX_TWO_B => 2u, + _ if code < MAX_THREE_B => 3u, + _ => 4u, + } + } + + #[inline] + #[unstable = "pending trait organization"] + fn len_utf16(self) -> uint { + let ch = self as u32; + if (ch & 0xFFFF_u32) == ch { 1 } else { 2 } + } + + #[inline] + #[unstable = "pending error conventions, trait organization"] fn encode_utf8<'a>(&self, dst: &'a mut [u8]) -> Option { // Marked #[inline] to allow llvm optimizing it away let code = *self as u32; @@ -354,6 +427,7 @@ impl Char for char { } #[inline] + #[unstable = "pending error conventions, trait organization"] fn encode_utf16(&self, dst: &mut [u16]) -> Option { // Marked #[inline] to allow llvm optimizing it away let mut ch = *self as u32; @@ -372,3 +446,75 @@ impl Char for char { } } } + +/// An iterator over the characters that represent a `char`, as escaped by +/// Rust's unicode escaping rules. +pub struct UnicodeEscapedChars { + c: char, + state: UnicodeEscapedCharsState +} + +enum UnicodeEscapedCharsState { + Backslash, + Type, + Value(RangeStep), +} + +impl Iterator for UnicodeEscapedChars { + fn next(&mut self) -> Option { + match self.state { + UnicodeEscapedCharsState::Backslash => { + self.state = UnicodeEscapedCharsState::Type; + Some('\\') + } + UnicodeEscapedCharsState::Type => { + let (typechar, pad) = if self.c <= '\x7f' { ('x', 2) } + else if self.c <= '\uffff' { ('u', 4) } + else { ('U', 8) }; + self.state = UnicodeEscapedCharsState::Value(range_step(4 * (pad - 1), -1, -4i32)); + Some(typechar) + } + UnicodeEscapedCharsState::Value(ref mut range_step) => match range_step.next() { + Some(offset) => { + let offset = offset as uint; + let v = match ((self.c as i32) >> offset) & 0xf { + i @ 0 ... 9 => '0' as i32 + i, + i => 'a' as i32 + (i - 10) + }; + Some(unsafe { transmute(v) }) + } + None => None + } + } + } +} + +/// An iterator over the characters that represent a `char`, escaped +/// for maximum portability. +pub struct DefaultEscapedChars { + state: DefaultEscapedCharsState +} + +enum DefaultEscapedCharsState { + Backslash(char), + Char(char), + Done, + Unicode(UnicodeEscapedChars), +} + +impl Iterator for DefaultEscapedChars { + fn next(&mut self) -> Option { + match self.state { + DefaultEscapedCharsState::Backslash(c) => { + self.state = DefaultEscapedCharsState::Char(c); + Some('\\') + } + DefaultEscapedCharsState::Char(c) => { + self.state = DefaultEscapedCharsState::Done; + Some(c) + } + DefaultEscapedCharsState::Done => None, + DefaultEscapedCharsState::Unicode(ref mut iter) => iter.next() + } + } +} diff --git a/src/libcore/fmt/float.rs b/src/libcore/fmt/float.rs index 5fd4e2e326df..1760c4d8e661 100644 --- a/src/libcore/fmt/float.rs +++ b/src/libcore/fmt/float.rs @@ -15,6 +15,7 @@ pub use self::SignificantDigits::*; pub use self::SignFormat::*; use char; +use char::Char; use fmt; use iter::{range, DoubleEndedIterator}; use num::{Float, FPNaN, FPInfinite, ToPrimitive}; @@ -222,7 +223,7 @@ pub fn float_to_str_bytes_common( // round the remaining ones. if limit_digits && dig == digit_count { let ascii2value = |chr: u8| { - char::to_digit(chr as char, radix).unwrap() + (chr as char).to_digit(radix).unwrap() }; let value2ascii = |val: uint| { char::from_digit(val, radix).unwrap() as u8 diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 68e490ecb19c..8d26a970eb8b 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -1315,7 +1315,7 @@ pub trait StrPrelude for Sized? { /// let v: Vec<&str> = "Mary had a little lamb".split(' ').collect(); /// assert_eq!(v, vec!["Mary", "had", "a", "little", "lamb"]); /// - /// let v: Vec<&str> = "abc1def2ghi".split(|c: char| c.is_digit()).collect(); + /// let v: Vec<&str> = "abc1def2ghi".split(|c: char| c.is_numeric()).collect(); /// assert_eq!(v, vec!["abc", "def", "ghi"]); /// /// let v: Vec<&str> = "lionXXtigerXleopard".split('X').collect(); @@ -1336,7 +1336,7 @@ pub trait StrPrelude for Sized? { /// let v: Vec<&str> = "Mary had a little lambda".splitn(2, ' ').collect(); /// assert_eq!(v, vec!["Mary", "had", "a little lambda"]); /// - /// let v: Vec<&str> = "abc1def2ghi".splitn(1, |c: char| c.is_digit()).collect(); + /// let v: Vec<&str> = "abc1def2ghi".splitn(1, |c: char| c.is_numeric()).collect(); /// assert_eq!(v, vec!["abc", "def2ghi"]); /// /// let v: Vec<&str> = "lionXXtigerXleopard".splitn(2, 'X').collect(); @@ -1368,7 +1368,7 @@ pub trait StrPrelude for Sized? { /// let v: Vec<&str> = "Mary had a little lamb".split(' ').rev().collect(); /// assert_eq!(v, vec!["lamb", "little", "a", "had", "Mary"]); /// - /// let v: Vec<&str> = "abc1def2ghi".split(|c: char| c.is_digit()).rev().collect(); + /// let v: Vec<&str> = "abc1def2ghi".split(|c: char| c.is_numeric()).rev().collect(); /// assert_eq!(v, vec!["ghi", "def", "abc"]); /// /// let v: Vec<&str> = "lionXXtigerXleopard".split('X').rev().collect(); @@ -1386,7 +1386,7 @@ pub trait StrPrelude for Sized? { /// let v: Vec<&str> = "Mary had a little lamb".rsplitn(2, ' ').collect(); /// assert_eq!(v, vec!["lamb", "little", "Mary had a"]); /// - /// let v: Vec<&str> = "abc1def2ghi".rsplitn(1, |c: char| c.is_digit()).collect(); + /// let v: Vec<&str> = "abc1def2ghi".rsplitn(1, |c: char| c.is_numeric()).collect(); /// assert_eq!(v, vec!["ghi", "abc1def"]); /// /// let v: Vec<&str> = "lionXXtigerXleopard".rsplitn(2, 'X').collect(); @@ -1596,7 +1596,7 @@ pub trait StrPrelude for Sized? { /// assert_eq!("11foo1bar11".trim_chars('1'), "foo1bar") /// let x: &[_] = &['1', '2']; /// assert_eq!("12foo1bar12".trim_chars(x), "foo1bar") - /// assert_eq!("123foo1bar123".trim_chars(|c: char| c.is_digit()), "foo1bar") + /// assert_eq!("123foo1bar123".trim_chars(|c: char| c.is_numeric()), "foo1bar") /// ``` fn trim_chars<'a, C: CharEq>(&'a self, to_trim: C) -> &'a str; @@ -1612,7 +1612,7 @@ pub trait StrPrelude for Sized? { /// assert_eq!("11foo1bar11".trim_left_chars('1'), "foo1bar11") /// let x: &[_] = &['1', '2']; /// assert_eq!("12foo1bar12".trim_left_chars(x), "foo1bar12") - /// assert_eq!("123foo1bar123".trim_left_chars(|c: char| c.is_digit()), "foo1bar123") + /// assert_eq!("123foo1bar123".trim_left_chars(|c: char| c.is_numeric()), "foo1bar123") /// ``` fn trim_left_chars<'a, C: CharEq>(&'a self, to_trim: C) -> &'a str; @@ -1628,7 +1628,7 @@ pub trait StrPrelude for Sized? { /// assert_eq!("11foo1bar11".trim_right_chars('1'), "11foo1bar") /// let x: &[_] = &['1', '2']; /// assert_eq!("12foo1bar12".trim_right_chars(x), "12foo1bar") - /// assert_eq!("123foo1bar123".trim_right_chars(|c: char| c.is_digit()), "123foo1bar") + /// assert_eq!("123foo1bar123".trim_right_chars(|c: char| c.is_numeric()), "123foo1bar") /// ``` fn trim_right_chars<'a, C: CharEq>(&'a self, to_trim: C) -> &'a str; diff --git a/src/libcoretest/char.rs b/src/libcoretest/char.rs index 8ec3c59da4e0..507ddf65e55b 100644 --- a/src/libcoretest/char.rs +++ b/src/libcoretest/char.rs @@ -105,12 +105,12 @@ fn test_is_control() { #[test] fn test_is_digit() { - assert!('2'.is_digit()); - assert!('7'.is_digit()); - assert!(!'c'.is_digit()); - assert!(!'i'.is_digit()); - assert!(!'z'.is_digit()); - assert!(!'Q'.is_digit()); + assert!('2'.is_numeric()); + assert!('7'.is_numeric()); + assert!(!'c'.is_numeric()); + assert!(!'i'.is_numeric()); + assert!(!'z'.is_numeric()); + assert!(!'Q'.is_numeric()); } #[test] @@ -197,6 +197,14 @@ fn test_encode_utf16() { check('\U0001f4a9', &[0xd83d, 0xdca9]); } +#[test] +fn test_len_utf16() { + assert!('x'.len_utf16() == 1); + assert!('\u00e9'.len_utf16() == 1); + assert!('\ua66e'.len_utf16() == 1); + assert!('\U0001f4a9'.len_utf16() == 2); +} + #[test] fn test_width() { assert_eq!('\x00'.width(false),Some(0)); diff --git a/src/libfmt_macros/lib.rs b/src/libfmt_macros/lib.rs index 71a3f24babb8..d3bee557220b 100644 --- a/src/libfmt_macros/lib.rs +++ b/src/libfmt_macros/lib.rs @@ -26,7 +26,6 @@ pub use self::Alignment::*; pub use self::Flag::*; pub use self::Count::*; -use std::char; use std::str; use std::string; @@ -221,7 +220,7 @@ impl<'a> Parser<'a> { fn ws(&mut self) { loop { match self.cur.clone().next() { - Some((_, c)) if char::is_whitespace(c) => { self.cur.next(); } + Some((_, c)) if c.is_whitespace() => { self.cur.next(); } Some(..) | None => { return } } } @@ -261,7 +260,7 @@ impl<'a> Parser<'a> { Some(i) => { ArgumentIs(i) } None => { match self.cur.clone().next() { - Some((_, c)) if char::is_alphabetic(c) => { + Some((_, c)) if c.is_alphabetic() => { ArgumentNamed(self.word()) } _ => ArgumentNext @@ -384,7 +383,7 @@ impl<'a> Parser<'a> { /// characters. fn word(&mut self) -> &'a str { let start = match self.cur.clone().next() { - Some((pos, c)) if char::is_XID_start(c) => { + Some((pos, c)) if c.is_xid_start() => { self.cur.next(); pos } @@ -393,7 +392,7 @@ impl<'a> Parser<'a> { let mut end; loop { match self.cur.clone().next() { - Some((_, c)) if char::is_XID_continue(c) => { + Some((_, c)) if c.is_xid_continue() => { self.cur.next(); } Some((pos, _)) => { end = pos; break } @@ -411,7 +410,7 @@ impl<'a> Parser<'a> { loop { match self.cur.clone().next() { Some((_, c)) => { - match char::to_digit(c, 10) { + match c.to_digit(10) { Some(i) => { cur = cur * 10 + i; found = true; diff --git a/src/libgetopts/lib.rs b/src/libgetopts/lib.rs index c4d712cb6736..a182f582b5f3 100644 --- a/src/libgetopts/lib.rs +++ b/src/libgetopts/lib.rs @@ -886,7 +886,7 @@ fn each_split_within<'a>(ss: &'a str, lim: uint, it: |&'a str| -> bool) } let machine: |&mut bool, (uint, char)| -> bool = |cont, (i, c)| { - let whitespace = if ::std::char::is_whitespace(c) { Ws } else { Cr }; + let whitespace = if c.is_whitespace() { Ws } else { Cr }; let limit = if (i - slice_start + 1) <= lim { UnderLim } else { OverLim }; state = match (state, whitespace, limit) { diff --git a/src/libgraphviz/lib.rs b/src/libgraphviz/lib.rs index df8cdabbcaa4..3ad546edf8de 100644 --- a/src/libgraphviz/lib.rs +++ b/src/libgraphviz/lib.rs @@ -431,7 +431,7 @@ impl<'a> LabelText<'a> { // not escaping \\, since Graphviz escString needs to // interpret backslashes; see EscStr above. '\\' => f(c), - _ => c.escape_default(f) + _ => for c in c.escape_default() { f(c) } } } fn escape_str(s: &str) -> String { diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index 0da9b05d4f86..f272bb52a143 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -29,7 +29,7 @@ This API is completely unstable and subject to change. html_root_url = "http://doc.rust-lang.org/nightly/")] #![feature(default_type_params, globs, if_let, import_shadowing, macro_rules, phase, quote)] -#![feature(slicing_syntax, struct_variant, tuple_indexing, unsafe_destructor)] +#![feature(slicing_syntax, tuple_indexing, unsafe_destructor)] #![feature(rustc_diagnostic_macros)] extern crate arena; diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index c763ac889c25..00c68f42c324 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -920,7 +920,7 @@ impl NonSnakeCase { let mut allow_underscore = true; ident.chars().all(|c| { allow_underscore = match c { - c if c.is_lowercase() || c.is_digit() => true, + c if c.is_lowercase() || c.is_numeric() => true, '_' if allow_underscore => false, _ => return false, }; diff --git a/src/librustc_back/target/mod.rs b/src/librustc_back/target/mod.rs index d7b4285cdb0a..68a80edc5d07 100644 --- a/src/librustc_back/target/mod.rs +++ b/src/librustc_back/target/mod.rs @@ -250,7 +250,7 @@ impl Target { } ); ($key_name:ident, list) => ( { let name = (stringify!($key_name)).replace("_", "-"); - obj.find(name[]).map(|o| o.as_list() + obj.find(name[]).map(|o| o.as_array() .map(|v| base.options.$key_name = v.iter() .map(|a| a.as_string().unwrap().to_string()).collect() ) diff --git a/src/librustc_trans/back/link.rs b/src/librustc_trans/back/link.rs index d27a338b308c..3715256e3ec2 100644 --- a/src/librustc_trans/back/link.rs +++ b/src/librustc_trans/back/link.rs @@ -27,7 +27,6 @@ use util::common::time; use util::ppaux; use util::sha2::{Digest, Sha256}; -use std::char; use std::io::fs::PathExtensions; use std::io::{fs, TempDir, Command}; use std::io; @@ -262,7 +261,7 @@ pub fn sanitize(s: &str) -> String { _ => { let mut tstr = String::new(); - char::escape_unicode(c, |c| tstr.push(c)); + for c in c.escape_unicode() { tstr.push(c) } result.push('$'); result.push_str(tstr.as_slice().slice_from(1)); } @@ -272,7 +271,7 @@ pub fn sanitize(s: &str) -> String { // Underscore-qualify anything that didn't start as an ident. if result.len() > 0u && result.as_bytes()[0] != '_' as u8 && - ! char::is_XID_start(result.as_bytes()[0] as char) { + ! (result.as_bytes()[0] as char).is_xid_start() { return format!("_{}", result.as_slice()); } diff --git a/src/librustc_trans/lib.rs b/src/librustc_trans/lib.rs index ad9333e57942..f89580b768ea 100644 --- a/src/librustc_trans/lib.rs +++ b/src/librustc_trans/lib.rs @@ -29,7 +29,7 @@ This API is completely unstable and subject to change. html_root_url = "http://doc.rust-lang.org/nightly/")] #![feature(default_type_params, globs, if_let, import_shadowing, macro_rules, phase, quote)] -#![feature(slicing_syntax, struct_variant, unsafe_destructor)] +#![feature(slicing_syntax, unsafe_destructor)] #![feature(rustc_diagnostic_macros)] extern crate arena; diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 209d8c7ca0f2..52aab752c576 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -2033,9 +2033,9 @@ fn lit_to_string(lit: &ast::Lit) -> String { ast::LitBinary(ref data) => format!("{}", data), ast::LitByte(b) => { let mut res = String::from_str("b'"); - (b as char).escape_default(|c| { + for c in (b as char).escape_default() { res.push(c); - }); + } res.push('\''); res }, diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 5e4ac259e718..97a18e9708fe 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -101,6 +101,8 @@ pub struct Context { /// real location of an item. This is used to allow external links to /// publicly reused items to redirect to the right location. pub render_redirect_pages: bool, + /// All the passes that were run on this crate. + pub passes: HashSet, } /// Indicates where an external crate can be found. @@ -190,6 +192,7 @@ pub struct Cache { parent_stack: Vec, search_index: Vec, privmod: bool, + remove_priv: bool, public_items: NodeSet, // In rare case where a structure is defined in one module but implemented @@ -236,9 +239,13 @@ local_data_key!(pub cache_key: Arc) local_data_key!(pub current_location_key: Vec ) /// Generates the documentation for `crate` into the directory `dst` -pub fn run(mut krate: clean::Crate, external_html: &ExternalHtml, dst: Path) -> io::IoResult<()> { +pub fn run(mut krate: clean::Crate, + external_html: &ExternalHtml, + dst: Path, + passes: HashSet) -> io::IoResult<()> { let mut cx = Context { dst: dst, + passes: passes, current: Vec::new(), root_path: String::new(), sidebar: HashMap::new(), @@ -320,6 +327,7 @@ pub fn run(mut krate: clean::Crate, external_html: &ExternalHtml, dst: Path) -> search_index: Vec::new(), extern_locations: HashMap::new(), primitive_locations: HashMap::new(), + remove_priv: cx.passes.contains("strip-private"), privmod: false, public_items: public_items, orphan_methods: Vec::new(), @@ -767,7 +775,7 @@ impl DocFolder for Cache { let orig_privmod = match item.inner { clean::ModuleItem(..) => { let prev = self.privmod; - self.privmod = prev || item.visibility != Some(ast::Public); + self.privmod = prev || (self.remove_priv && item.visibility != Some(ast::Public)); prev } _ => self.privmod, @@ -1192,7 +1200,7 @@ impl Context { // these modules are recursed into, but not rendered normally (a // flag on the context). if !self.render_redirect_pages { - self.render_redirect_pages = ignore_private_item(&item); + self.render_redirect_pages = self.ignore_private_item(&item); } match item.inner { @@ -1211,7 +1219,7 @@ impl Context { clean::ModuleItem(m) => m, _ => unreachable!() }; - this.sidebar = build_sidebar(&m); + this.sidebar = this.build_sidebar(&m); for item in m.items.into_iter() { f(this,item); } @@ -1230,6 +1238,40 @@ impl Context { _ => Ok(()) } } + + fn build_sidebar(&self, m: &clean::Module) -> HashMap> { + let mut map = HashMap::new(); + for item in m.items.iter() { + if self.ignore_private_item(item) { continue } + + let short = shortty(item).to_static_str(); + let myname = match item.name { + None => continue, + Some(ref s) => s.to_string(), + }; + let v = match map.entry(short.to_string()) { + Vacant(entry) => entry.set(Vec::with_capacity(1)), + Occupied(entry) => entry.into_mut(), + }; + v.push(myname); + } + + for (_, items) in map.iter_mut() { + items.as_mut_slice().sort(); + } + return map; + } + + fn ignore_private_item(&self, it: &clean::Item) -> bool { + match it.inner { + clean::ModuleItem(ref m) => { + (m.items.len() == 0 && it.doc_value().is_none()) || + (self.passes.contains("strip-private") && it.visibility != Some(ast::Public)) + } + clean::PrimitiveItem(..) => it.visibility != Some(ast::Public), + _ => false, + } + } } impl<'a> Item<'a> { @@ -1443,7 +1485,7 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context, try!(document(w, item)); let mut indices = range(0, items.len()).filter(|i| { - !ignore_private_item(&items[*i]) + !cx.ignore_private_item(&items[*i]) }).collect::>(); fn cmp(i1: &clean::Item, i2: &clean::Item, idx1: uint, idx2: uint) -> Ordering { @@ -2157,29 +2199,6 @@ impl<'a> fmt::Show for Sidebar<'a> { } } -fn build_sidebar(m: &clean::Module) -> HashMap> { - let mut map = HashMap::new(); - for item in m.items.iter() { - if ignore_private_item(item) { continue } - - let short = shortty(item).to_static_str(); - let myname = match item.name { - None => continue, - Some(ref s) => s.to_string(), - }; - let v = match map.entry(short.to_string()) { - Vacant(entry) => entry.set(Vec::with_capacity(1)), - Occupied(entry) => entry.into_mut(), - }; - v.push(myname); - } - - for (_, items) in map.iter_mut() { - items.as_mut_slice().sort(); - } - return map; -} - impl<'a> fmt::Show for Source<'a> { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { let Source(s) = *self; @@ -2214,17 +2233,6 @@ fn item_primitive(w: &mut fmt::Formatter, render_methods(w, it) } -fn ignore_private_item(it: &clean::Item) -> bool { - match it.inner { - clean::ModuleItem(ref m) => { - (m.items.len() == 0 && it.doc_value().is_none()) || - it.visibility != Some(ast::Public) - } - clean::PrimitiveItem(..) => it.visibility != Some(ast::Public), - _ => false, - } -} - fn get_basic_keywords() -> &'static str { "rust, rustlang, rust-lang" } diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 4a512ca33fc4..8770e473dea6 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -16,7 +16,7 @@ #![crate_type = "rlib"] #![allow(unknown_features)] -#![feature(globs, struct_variant, macro_rules, phase, slicing_syntax, tuple_indexing)] +#![feature(globs, macro_rules, phase, slicing_syntax, tuple_indexing)] extern crate arena; extern crate getopts; @@ -86,7 +86,11 @@ static DEFAULT_PASSES: &'static [&'static str] = &[ local_data_key!(pub analysiskey: core::CrateAnalysis) -type Output = (clean::Crate, Vec ); +struct Output { + krate: clean::Crate, + json_plugins: Vec, + passes: Vec, +} pub fn main() { std::os::set_exit_status(main_args(std::os::args().as_slice())); @@ -229,24 +233,26 @@ pub fn main_args(args: &[String]) -> int { (false, false) => {} } - let (krate, res) = match acquire_input(input, externs, &matches) { - Ok(pair) => pair, + let out = match acquire_input(input, externs, &matches) { + Ok(out) => out, Err(s) => { println!("input error: {}", s); return 1; } }; - + let Output { krate, json_plugins, passes, } = out; info!("going to format"); match matches.opt_str("w").as_ref().map(|s| s.as_slice()) { Some("html") | None => { - match html::render::run(krate, &external_html, output.unwrap_or(Path::new("doc"))) { + match html::render::run(krate, &external_html, output.unwrap_or(Path::new("doc")), + passes.into_iter().collect()) { Ok(()) => {} Err(e) => panic!("failed to generate documentation: {}", e), } } Some("json") => { - match json_output(krate, res, output.unwrap_or(Path::new("doc.json"))) { + match json_output(krate, json_plugins, + output.unwrap_or(Path::new("doc.json"))) { Ok(()) => {} Err(e) => panic!("failed to write json: {}", e), } @@ -397,7 +403,8 @@ fn rust_input(cratefile: &str, externs: core::Externs, matches: &getopts::Matche // Run everything! info!("Executing passes/plugins"); - return pm.run_plugins(krate); + let (krate, json) = pm.run_plugins(krate); + return Output { krate: krate, json_plugins: json, passes: passes, }; } /// This input format purely deserializes the json output file. No passes are @@ -435,7 +442,7 @@ fn json_input(input: &str) -> Result { // FIXME: this should read from the "plugins" field, but currently // Json doesn't implement decodable... let plugin_output = Vec::new(); - Ok((krate, plugin_output)) + Ok(Output { krate: krate, json_plugins: plugin_output, passes: Vec::new(), }) } Ok(..) => { Err("malformed json input: expected an object at the \ diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index 2dc1bcf776eb..2a5972bb3d90 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -9,7 +9,6 @@ // except according to those terms. use std::cell::RefCell; -use std::char; use std::dynamic_lib::DynamicLibrary; use std::io::{Command, TempDir}; use std::io; @@ -300,8 +299,8 @@ impl Collector { // we use these headings as test names, so it's good if // they're valid identifiers. let name = name.chars().enumerate().map(|(i, c)| { - if (i == 0 && char::is_XID_start(c)) || - (i != 0 && char::is_XID_continue(c)) { + if (i == 0 && c.is_xid_start()) || + (i != 0 && c.is_xid_continue()) { c } else { '_' diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index 030ee1d4352b..d59edafb2b42 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -28,7 +28,7 @@ Data types that can be encoded are JavaScript types (see the `Json` enum for mor * `Boolean`: equivalent to rust's `bool` * `Number`: equivalent to rust's `f64` * `String`: equivalent to rust's `String` -* `List`: equivalent to rust's `Vec`, but also allowing objects of different types in the same +* `Array`: equivalent to rust's `Vec`, but also allowing objects of different types in the same array * `Object`: equivalent to rust's `Treemap` * `Null` @@ -223,12 +223,12 @@ pub enum Json { F64(f64), String(string::String), Boolean(bool), - List(JsonList), + Array(JsonArray), Object(JsonObject), Null, } -pub type JsonList = Vec; +pub type JsonArray = Vec; pub type JsonObject = TreeMap; /// The errors that can arise while parsing a JSON stream. @@ -237,7 +237,7 @@ pub enum ErrorCode { InvalidSyntax, InvalidNumber, EOFWhileParsingObject, - EOFWhileParsingList, + EOFWhileParsingArray, EOFWhileParsingValue, EOFWhileParsingString, KeyMustBeAString, @@ -278,7 +278,7 @@ pub fn error_str(error: ErrorCode) -> &'static str { InvalidSyntax => "invalid syntax", InvalidNumber => "invalid number", EOFWhileParsingObject => "EOF While parsing object", - EOFWhileParsingList => "EOF While parsing list", + EOFWhileParsingArray => "EOF While parsing array", EOFWhileParsingValue => "EOF While parsing value", EOFWhileParsingString => "EOF While parsing string", KeyMustBeAString => "key must be a string", @@ -868,7 +868,7 @@ impl, S> Encodable for Json { F64(v) => v.encode(e), String(ref v) => v.encode(e), Boolean(v) => v.encode(e), - List(ref v) => v.encode(e), + Array(ref v) => v.encode(e), Object(ref v) => v.encode(e), Null => e.emit_nil(), } @@ -956,16 +956,16 @@ impl Json { } } - /// Returns true if the Json value is a List. Returns false otherwise. - pub fn is_list<'a>(&'a self) -> bool { - self.as_list().is_some() + /// Returns true if the Json value is an Array. Returns false otherwise. + pub fn is_array<'a>(&'a self) -> bool { + self.as_array().is_some() } - /// If the Json value is a List, returns the associated vector. + /// If the Json value is an Array, returns the associated vector. /// Returns None otherwise. - pub fn as_list<'a>(&'a self) -> Option<&'a JsonList> { + pub fn as_array<'a>(&'a self) -> Option<&'a JsonArray> { match self { - &List(ref list) => Some(&*list), + &Array(ref array) => Some(&*array), _ => None } } @@ -1085,8 +1085,8 @@ impl<'a> ops::Index<&'a str, Json> for Json { impl ops::Index for Json { fn index<'a>(&'a self, idx: &uint) -> &'a Json { match self { - &List(ref v) => v.index(idx), - _ => panic!("can only index Json with uint if it is a list") + &Array(ref v) => v.index(idx), + _ => panic!("can only index Json with uint if it is an array") } } } @@ -1096,8 +1096,8 @@ impl ops::Index for Json { pub enum JsonEvent { ObjectStart, ObjectEnd, - ListStart, - ListEnd, + ArrayStart, + ArrayEnd, BooleanValue(bool), I64Value(i64), U64Value(u64), @@ -1109,10 +1109,10 @@ pub enum JsonEvent { #[deriving(PartialEq, Show)] enum ParserState { - // Parse a value in a list, true means first element. + // Parse a value in an array, true means first element. ParseArray(bool), - // Parse ',' or ']' after an element in a list. - ParseListComma, + // Parse ',' or ']' after an element in an array. + ParseArrayComma, // Parse a key:value in an object, true means first element. ParseObject(bool), // Parse ',' or ']' after an element in an object. @@ -1601,7 +1601,7 @@ impl> Parser { fn parse(&mut self) -> JsonEvent { loop { // The only paths where the loop can spin a new iteration - // are in the cases ParseListComma and ParseObjectComma if ',' + // are in the cases ParseArrayComma and ParseObjectComma if ',' // is parsed. In these cases the state is set to (respectively) // ParseArray(false) and ParseObject(false), which always return, // so there is no risk of getting stuck in an infinite loop. @@ -1613,10 +1613,10 @@ impl> Parser { return self.parse_start(); } ParseArray(first) => { - return self.parse_list(first); + return self.parse_array(first); } - ParseListComma => { - match self.parse_list_comma_or_end() { + ParseArrayComma => { + match self.parse_array_comma_or_end() { Some(evt) => { return evt; } None => {} } @@ -1644,14 +1644,14 @@ impl> Parser { let val = self.parse_value(); self.state = match val { Error(_) => { ParseFinished } - ListStart => { ParseArray(true) } + ArrayStart => { ParseArray(true) } ObjectStart => { ParseObject(true) } _ => { ParseBeforeFinish } }; return val; } - fn parse_list(&mut self, first: bool) -> JsonEvent { + fn parse_array(&mut self, first: bool) -> JsonEvent { if self.ch_is(']') { if !first { return self.error_event(InvalidSyntax); @@ -1660,13 +1660,13 @@ impl> Parser { self.state = ParseBeforeFinish; } else { self.state = if self.stack.last_is_index() { - ParseListComma + ParseArrayComma } else { ParseObjectComma } } self.bump(); - return ListEnd; + return ArrayEnd; } if first { self.stack.push_index(0); @@ -1676,14 +1676,14 @@ impl> Parser { self.state = match val { Error(_) => { ParseFinished } - ListStart => { ParseArray(true) } + ArrayStart => { ParseArray(true) } ObjectStart => { ParseObject(true) } - _ => { ParseListComma } + _ => { ParseArrayComma } }; return val; } - fn parse_list_comma_or_end(&mut self) -> Option { + fn parse_array_comma_or_end(&mut self) -> Option { if self.ch_is(',') { self.stack.bump_index(); self.state = ParseArray(false); @@ -1695,15 +1695,15 @@ impl> Parser { self.state = ParseBeforeFinish; } else { self.state = if self.stack.last_is_index() { - ParseListComma + ParseArrayComma } else { ParseObjectComma } } self.bump(); - return Some(ListEnd); + return Some(ArrayEnd); } else if self.eof() { - return Some(self.error_event(EOFWhileParsingList)); + return Some(self.error_event(EOFWhileParsingArray)); } else { return Some(self.error_event(InvalidSyntax)); } @@ -1722,7 +1722,7 @@ impl> Parser { self.state = ParseBeforeFinish; } else { self.state = if self.stack.last_is_index() { - ParseListComma + ParseArrayComma } else { ParseObjectComma } @@ -1757,7 +1757,7 @@ impl> Parser { self.state = match val { Error(_) => { ParseFinished } - ListStart => { ParseArray(true) } + ArrayStart => { ParseArray(true) } ObjectStart => { ParseObject(true) } _ => { ParseObjectComma } }; @@ -1770,7 +1770,7 @@ impl> Parser { self.state = ParseBeforeFinish; } else { self.state = if self.stack.last_is_index() { - ParseListComma + ParseArrayComma } else { ParseObjectComma } @@ -1797,7 +1797,7 @@ impl> Parser { }, '[' => { self.bump(); - ListStart + ArrayStart } '{' => { self.bump(); @@ -1864,21 +1864,21 @@ impl> Builder { Ok(String(temp)) } Some(Error(e)) => { Err(e) } - Some(ListStart) => { self.build_list() } + Some(ArrayStart) => { self.build_array() } Some(ObjectStart) => { self.build_object() } Some(ObjectEnd) => { self.parser.error(InvalidSyntax) } - Some(ListEnd) => { self.parser.error(InvalidSyntax) } + Some(ArrayEnd) => { self.parser.error(InvalidSyntax) } None => { self.parser.error(EOFWhileParsingValue) } } } - fn build_list(&mut self) -> Result { + fn build_array(&mut self) -> Result { self.bump(); let mut values = Vec::new(); loop { - if self.token == Some(ListEnd) { - return Ok(List(values.into_iter().collect())); + if self.token == Some(ArrayEnd) { + return Ok(Array(values.into_iter().collect())); } match self.build_value() { Ok(v) => values.push(v), @@ -2093,13 +2093,13 @@ impl ::Decoder for Decoder { } }; match o.remove(&"fields".to_string()) { - Some(List(l)) => { + Some(Array(l)) => { for field in l.into_iter().rev() { self.stack.push(field); } }, Some(val) => { - return Err(ExpectedError("List".to_string(), format!("{}", val))) + return Err(ExpectedError("Array".to_string(), format!("{}", val))) } None => { return Err(MissingFieldError("fields".to_string())) @@ -2229,9 +2229,9 @@ impl ::Decoder for Decoder { fn read_seq(&mut self, f: |&mut Decoder, uint| -> DecodeResult) -> DecodeResult { debug!("read_seq()"); - let list = try!(expect!(self.pop(), List)); - let len = list.len(); - for v in list.into_iter().rev() { + let array = try!(expect!(self.pop(), Array)); + let len = array.len(); + for v in array.into_iter().rev() { self.stack.push(v); } f(self, len) @@ -2343,7 +2343,7 @@ macro_rules! tuple_impl { #[allow(non_snake_case)] fn to_json(&self) -> Json { match *self { - ($(ref $tyvar),*,) => List(vec![$($tyvar.to_json()),*]) + ($(ref $tyvar),*,) => Array(vec![$($tyvar.to_json()),*]) } } } @@ -2364,11 +2364,11 @@ tuple_impl!{A, B, C, D, E, F, G, H, I, J, K} tuple_impl!{A, B, C, D, E, F, G, H, I, J, K, L} impl ToJson for [A] { - fn to_json(&self) -> Json { List(self.iter().map(|elt| elt.to_json()).collect()) } + fn to_json(&self) -> Json { Array(self.iter().map(|elt| elt.to_json()).collect()) } } impl ToJson for Vec { - fn to_json(&self) -> Json { List(self.iter().map(|elt| elt.to_json()).collect()) } + fn to_json(&self) -> Json { Array(self.iter().map(|elt| elt.to_json()).collect()) } } impl ToJson for TreeMap { @@ -2420,13 +2420,13 @@ mod tests { use self::DecodeEnum::*; use self::test::Bencher; use {Encodable, Decodable}; - use super::{List, Encoder, Decoder, Error, Boolean, I64, U64, F64, String, Null, + use super::{Array, Encoder, Decoder, Error, Boolean, I64, U64, F64, String, Null, PrettyEncoder, Object, Json, from_str, ParseError, ExpectedError, MissingFieldError, UnknownVariantError, DecodeResult, DecoderError, JsonEvent, Parser, StackElement, - ObjectStart, ObjectEnd, ListStart, ListEnd, BooleanValue, U64Value, + ObjectStart, ObjectEnd, ArrayStart, ArrayEnd, BooleanValue, U64Value, F64Value, StringValue, NullValue, SyntaxError, Key, Index, Stack, - InvalidSyntax, InvalidNumber, EOFWhileParsingObject, EOFWhileParsingList, + InvalidSyntax, InvalidNumber, EOFWhileParsingObject, EOFWhileParsingArray, EOFWhileParsingValue, EOFWhileParsingString, KeyMustBeAString, ExpectedColon, TrailingCharacters, TrailingComma}; use std::{i64, u64, f32, f64, io}; @@ -2558,28 +2558,28 @@ mod tests { } #[test] - fn test_write_list() { - assert_eq!(List(vec![]).to_string().into_string(), "[]".to_string()); - assert_eq!(List(vec![]).to_pretty_str().into_string(), "[]".to_string()); + fn test_write_array() { + assert_eq!(Array(vec![]).to_string().into_string(), "[]".to_string()); + assert_eq!(Array(vec![]).to_pretty_str().into_string(), "[]".to_string()); - assert_eq!(List(vec![Boolean(true)]).to_string().into_string(), "[true]".to_string()); + assert_eq!(Array(vec![Boolean(true)]).to_string().into_string(), "[true]".to_string()); assert_eq!( - List(vec![Boolean(true)]).to_pretty_str().into_string(), + Array(vec![Boolean(true)]).to_pretty_str().into_string(), "\ [\n \ true\n\ ]".to_string() ); - let long_test_list = List(vec![ + let long_test_array = Array(vec![ Boolean(false), Null, - List(vec![String("foo\nbar".to_string()), F64(3.5)])]); + Array(vec![String("foo\nbar".to_string()), F64(3.5)])]); - assert_eq!(long_test_list.to_string().into_string(), + assert_eq!(long_test_array.to_string().into_string(), "[false,null,[\"foo\\nbar\",3.5]]".to_string()); assert_eq!( - long_test_list.to_pretty_str().into_string(), + long_test_array.to_pretty_str().into_string(), "\ [\n \ false,\n \ @@ -2612,7 +2612,7 @@ mod tests { ); let complex_obj = mk_object(&[ - ("b".to_string(), List(vec![ + ("b".to_string(), Array(vec![ mk_object(&[("c".to_string(), String("\x0c\r".to_string()))]), mk_object(&[("d".to_string(), String("".to_string()))]) ])) @@ -2644,7 +2644,7 @@ mod tests { let a = mk_object(&[ ("a".to_string(), Boolean(true)), - ("b".to_string(), List(vec![ + ("b".to_string(), Array(vec![ mk_object(&[("c".to_string(), String("\x0c\r".to_string()))]), mk_object(&[("d".to_string(), String("".to_string()))]) ])) @@ -2878,28 +2878,28 @@ mod tests { } #[test] - fn test_read_list() { + fn test_read_array() { assert_eq!(from_str("["), Err(SyntaxError(EOFWhileParsingValue, 1, 2))); - assert_eq!(from_str("[1"), Err(SyntaxError(EOFWhileParsingList, 1, 3))); + assert_eq!(from_str("[1"), Err(SyntaxError(EOFWhileParsingArray, 1, 3))); assert_eq!(from_str("[1,"), Err(SyntaxError(EOFWhileParsingValue, 1, 4))); assert_eq!(from_str("[1,]"), Err(SyntaxError(InvalidSyntax, 1, 4))); assert_eq!(from_str("[6 7]"), Err(SyntaxError(InvalidSyntax, 1, 4))); - assert_eq!(from_str("[]"), Ok(List(vec![]))); - assert_eq!(from_str("[ ]"), Ok(List(vec![]))); - assert_eq!(from_str("[true]"), Ok(List(vec![Boolean(true)]))); - assert_eq!(from_str("[ false ]"), Ok(List(vec![Boolean(false)]))); - assert_eq!(from_str("[null]"), Ok(List(vec![Null]))); + assert_eq!(from_str("[]"), Ok(Array(vec![]))); + assert_eq!(from_str("[ ]"), Ok(Array(vec![]))); + assert_eq!(from_str("[true]"), Ok(Array(vec![Boolean(true)]))); + assert_eq!(from_str("[ false ]"), Ok(Array(vec![Boolean(false)]))); + assert_eq!(from_str("[null]"), Ok(Array(vec![Null]))); assert_eq!(from_str("[3, 1]"), - Ok(List(vec![U64(3), U64(1)]))); + Ok(Array(vec![U64(3), U64(1)]))); assert_eq!(from_str("\n[3, 2]\n"), - Ok(List(vec![U64(3), U64(2)]))); + Ok(Array(vec![U64(3), U64(2)]))); assert_eq!(from_str("[2, [4, 1]]"), - Ok(List(vec![U64(2), List(vec![U64(4), U64(1)])]))); + Ok(Array(vec![U64(2), Array(vec![U64(4), U64(1)])]))); } #[test] - fn test_decode_list() { + fn test_decode_array() { let v: Vec<()> = super::decode("[]").unwrap(); assert_eq!(v, vec![]); @@ -2967,7 +2967,7 @@ mod tests { "{\"a\" : 1.0 ,\"b\": [ true ]}").unwrap(), mk_object(&[ ("a".to_string(), F64(1.0)), - ("b".to_string(), List(vec![Boolean(true)])) + ("b".to_string(), Array(vec![Boolean(true)])) ])); assert_eq!(from_str( "{\ @@ -2980,7 +2980,7 @@ mod tests { }").unwrap(), mk_object(&[ ("a".to_string(), F64(1.0)), - ("b".to_string(), List(vec![ + ("b".to_string(), Array(vec![ Boolean(true), String("foo\nbar".to_string()), mk_object(&[ @@ -3097,7 +3097,7 @@ mod tests { check_err::("{\"x\": 1, \"y\": true, \"z\": {}, \"w\": []}", ExpectedError("String".to_string(), "{}".to_string())); check_err::("{\"x\": 1, \"y\": true, \"z\": \"\", \"w\": null}", - ExpectedError("List".to_string(), "null".to_string())); + ExpectedError("Array".to_string(), "null".to_string())); check_err::("{\"x\": 1, \"y\": true, \"z\": \"\"}", MissingFieldError("w".to_string())); } @@ -3110,7 +3110,7 @@ mod tests { check_err::("{\"variant\": \"A\"}", MissingFieldError("fields".to_string())); check_err::("{\"variant\": \"A\", \"fields\": null}", - ExpectedError("List".to_string(), "null".to_string())); + ExpectedError("Array".to_string(), "null".to_string())); check_err::("{\"variant\": \"C\", \"fields\": []}", UnknownVariantError("C".to_string())); } @@ -3139,10 +3139,10 @@ mod tests { #[test] fn test_index(){ let json_value = from_str("{\"animals\":[\"dog\",\"cat\",\"mouse\"]}").unwrap(); - let ref list = json_value["animals"]; - assert_eq!(list[0].as_string().unwrap(), "dog"); - assert_eq!(list[1].as_string().unwrap(), "cat"); - assert_eq!(list[2].as_string().unwrap(), "mouse"); + let ref array = json_value["animals"]; + assert_eq!(array[0].as_string().unwrap(), "dog"); + assert_eq!(array[1].as_string().unwrap(), "cat"); + assert_eq!(array[2].as_string().unwrap(), "mouse"); } #[test] @@ -3159,17 +3159,17 @@ mod tests { } #[test] - fn test_is_list(){ + fn test_is_array(){ let json_value = from_str("[1, 2, 3]").unwrap(); - assert!(json_value.is_list()); + assert!(json_value.is_array()); } #[test] - fn test_as_list(){ + fn test_as_array(){ let json_value = from_str("[1, 2, 3]").unwrap(); - let json_list = json_value.as_list(); + let json_array = json_value.as_array(); let expected_length = 3; - assert!(json_list.is_some() && json_list.unwrap().len() == expected_length); + assert!(json_array.is_some() && json_array.unwrap().len() == expected_length); } #[test] @@ -3328,7 +3328,7 @@ mod tests { tree.insert("hello".into_string(), String("guten tag".into_string())); tree.insert("goodbye".into_string(), String("sayonara".into_string())); - let json = List( + let json = Array( // The following layout below should look a lot like // the pretty-printed JSON (indent * x) vec! @@ -3336,7 +3336,7 @@ mod tests { String("greetings".into_string()), // 1x Object(tree), // 1x + 2x + 2x + 1x ) // 0x - // End JSON list (7 lines) + // End JSON array (7 lines) ); // Helper function for counting indents @@ -3425,19 +3425,19 @@ mod tests { vec![ (ObjectStart, vec![]), (StringValue("bar".to_string()), vec![Key("foo")]), - (ListStart, vec![Key("array")]), + (ArrayStart, vec![Key("array")]), (U64Value(0), vec![Key("array"), Index(0)]), (U64Value(1), vec![Key("array"), Index(1)]), (U64Value(2), vec![Key("array"), Index(2)]), (U64Value(3), vec![Key("array"), Index(3)]), (U64Value(4), vec![Key("array"), Index(4)]), (U64Value(5), vec![Key("array"), Index(5)]), - (ListEnd, vec![Key("array")]), - (ListStart, vec![Key("idents")]), + (ArrayEnd, vec![Key("array")]), + (ArrayStart, vec![Key("idents")]), (NullValue, vec![Key("idents"), Index(0)]), (BooleanValue(true), vec![Key("idents"), Index(1)]), (BooleanValue(false), vec![Key("idents"), Index(2)]), - (ListEnd, vec![Key("idents")]), + (ArrayEnd, vec![Key("idents")]), (ObjectEnd, vec![]), ] ); @@ -3495,9 +3495,9 @@ mod tests { vec![ (ObjectStart, vec![]), (F64Value(1.0), vec![Key("a")]), - (ListStart, vec![Key("b")]), + (ArrayStart, vec![Key("b")]), (BooleanValue(true),vec![Key("b"), Index(0)]), - (ListEnd, vec![Key("b")]), + (ArrayEnd, vec![Key("b")]), (ObjectEnd, vec![]), ] ); @@ -3513,7 +3513,7 @@ mod tests { vec![ (ObjectStart, vec![]), (F64Value(1.0), vec![Key("a")]), - (ListStart, vec![Key("b")]), + (ArrayStart, vec![Key("b")]), (BooleanValue(true), vec![Key("b"), Index(0)]), (StringValue("foo\nbar".to_string()), vec![Key("b"), Index(1)]), (ObjectStart, vec![Key("b"), Index(2)]), @@ -3521,87 +3521,87 @@ mod tests { (NullValue, vec![Key("b"), Index(2), Key("c"), Key("d")]), (ObjectEnd, vec![Key("b"), Index(2), Key("c")]), (ObjectEnd, vec![Key("b"), Index(2)]), - (ListEnd, vec![Key("b")]), + (ArrayEnd, vec![Key("b")]), (ObjectEnd, vec![]), ] ); } #[test] #[cfg_attr(target_word_size = "32", ignore)] // FIXME(#14064) - fn test_read_list_streaming() { + fn test_read_array_streaming() { assert_stream_equal( "[]", vec![ - (ListStart, vec![]), - (ListEnd, vec![]), + (ArrayStart, vec![]), + (ArrayEnd, vec![]), ] ); assert_stream_equal( "[ ]", vec![ - (ListStart, vec![]), - (ListEnd, vec![]), + (ArrayStart, vec![]), + (ArrayEnd, vec![]), ] ); assert_stream_equal( "[true]", vec![ - (ListStart, vec![]), + (ArrayStart, vec![]), (BooleanValue(true), vec![Index(0)]), - (ListEnd, vec![]), + (ArrayEnd, vec![]), ] ); assert_stream_equal( "[ false ]", vec![ - (ListStart, vec![]), + (ArrayStart, vec![]), (BooleanValue(false), vec![Index(0)]), - (ListEnd, vec![]), + (ArrayEnd, vec![]), ] ); assert_stream_equal( "[null]", vec![ - (ListStart, vec![]), + (ArrayStart, vec![]), (NullValue, vec![Index(0)]), - (ListEnd, vec![]), + (ArrayEnd, vec![]), ] ); assert_stream_equal( "[3, 1]", vec![ - (ListStart, vec![]), + (ArrayStart, vec![]), (U64Value(3), vec![Index(0)]), (U64Value(1), vec![Index(1)]), - (ListEnd, vec![]), + (ArrayEnd, vec![]), ] ); assert_stream_equal( "\n[3, 2]\n", vec![ - (ListStart, vec![]), + (ArrayStart, vec![]), (U64Value(3), vec![Index(0)]), (U64Value(2), vec![Index(1)]), - (ListEnd, vec![]), + (ArrayEnd, vec![]), ] ); assert_stream_equal( "[2, [4, 1]]", vec![ - (ListStart, vec![]), + (ArrayStart, vec![]), (U64Value(2), vec![Index(0)]), - (ListStart, vec![Index(1)]), + (ArrayStart, vec![Index(1)]), (U64Value(4), vec![Index(1), Index(0)]), (U64Value(1), vec![Index(1), Index(1)]), - (ListEnd, vec![Index(1)]), - (ListEnd, vec![]), + (ArrayEnd, vec![Index(1)]), + (ArrayEnd, vec![]), ] ); assert_eq!(last_event("["), Error(SyntaxError(EOFWhileParsingValue, 1, 2))); assert_eq!(from_str("["), Err(SyntaxError(EOFWhileParsingValue, 1, 2))); - assert_eq!(from_str("[1"), Err(SyntaxError(EOFWhileParsingList, 1, 3))); + assert_eq!(from_str("[1"), Err(SyntaxError(EOFWhileParsingArray, 1, 3))); assert_eq!(from_str("[1,"), Err(SyntaxError(EOFWhileParsingValue, 1, 4))); assert_eq!(from_str("[1,]"), Err(SyntaxError(InvalidSyntax, 1, 4))); assert_eq!(from_str("[6 7]"), Err(SyntaxError(InvalidSyntax, 1, 4))); @@ -3693,8 +3693,8 @@ mod tests { use std::collections::{HashMap,TreeMap}; use super::ToJson; - let list2 = List(vec!(U64(1), U64(2))); - let list3 = List(vec!(U64(1), U64(2), U64(3))); + let array2 = Array(vec!(U64(1), U64(2))); + let array3 = Array(vec!(U64(1), U64(2), U64(3))); let object = { let mut tree_map = TreeMap::new(); tree_map.insert("a".to_string(), U64(1)); @@ -3702,7 +3702,7 @@ mod tests { Object(tree_map) }; - assert_eq!(list2.to_json(), list2); + assert_eq!(array2.to_json(), array2); assert_eq!(object.to_json(), object); assert_eq!(3_i.to_json(), I64(3)); assert_eq!(4_i8.to_json(), I64(4)); @@ -3723,12 +3723,12 @@ mod tests { assert_eq!(false.to_json(), Boolean(false)); assert_eq!("abc".to_json(), String("abc".into_string())); assert_eq!("abc".into_string().to_json(), String("abc".into_string())); - assert_eq!((1u, 2u).to_json(), list2); - assert_eq!((1u, 2u, 3u).to_json(), list3); - assert_eq!([1u, 2].to_json(), list2); - assert_eq!((&[1u, 2, 3]).to_json(), list3); - assert_eq!((vec![1u, 2]).to_json(), list2); - assert_eq!(vec!(1u, 2, 3).to_json(), list3); + assert_eq!((1u, 2u).to_json(), array2); + assert_eq!((1u, 2u, 3u).to_json(), array3); + assert_eq!([1u, 2].to_json(), array2); + assert_eq!((&[1u, 2, 3]).to_json(), array3); + assert_eq!((vec![1u, 2]).to_json(), array2); + assert_eq!(vec!(1u, 2, 3).to_json(), array3); let mut tree_map = TreeMap::new(); tree_map.insert("a".to_string(), 1u); tree_map.insert("b".to_string(), 2); diff --git a/src/libstd/num/strconv.rs b/src/libstd/num/strconv.rs index f8ba9b720118..649298d9c081 100644 --- a/src/libstd/num/strconv.rs +++ b/src/libstd/num/strconv.rs @@ -17,6 +17,7 @@ pub use self::SignificantDigits::*; pub use self::SignFormat::*; use char; +use char::Char; use num; use num::{Int, Float, FPNaN, FPInfinite, ToPrimitive}; use slice::{SlicePrelude, CloneSliceAllocPrelude}; @@ -320,7 +321,7 @@ pub fn float_to_str_bytes_common( // round the remaining ones. if limit_digits && dig == digit_count { let ascii2value = |chr: u8| { - char::to_digit(chr as char, radix).unwrap() + (chr as char).to_digit(radix).unwrap() }; let value2ascii = |val: uint| { char::from_digit(val, radix).unwrap() as u8 diff --git a/src/libstd/rt/backtrace.rs b/src/libstd/rt/backtrace.rs index 107518ef27c9..810229943874 100644 --- a/src/libstd/rt/backtrace.rs +++ b/src/libstd/rt/backtrace.rs @@ -71,7 +71,7 @@ fn demangle(writer: &mut Writer, s: &str) -> IoResult<()> { while valid { let mut i = 0; for c in chars { - if c.is_digit() { + if c.is_numeric() { i = i * 10 + c as uint - '0' as uint; } else { break @@ -101,7 +101,7 @@ fn demangle(writer: &mut Writer, s: &str) -> IoResult<()> { first = false; } let mut rest = s; - while rest.char_at(0).is_digit() { + while rest.char_at(0).is_numeric() { rest = rest.slice_from(1); } let i: uint = from_str(s.slice_to(s.len() - rest.len())).unwrap(); diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index fa10cb90f83a..c9d72603b891 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -25,7 +25,7 @@ #![allow(unknown_features)] #![feature(if_let, macro_rules, globs, default_type_params, phase, slicing_syntax)] -#![feature(quote, struct_variant, unsafe_destructor, import_shadowing)] +#![feature(quote, unsafe_destructor, import_shadowing)] extern crate arena; extern crate fmt_macros; diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index fbca4868255f..a88029e087b1 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -193,7 +193,7 @@ impl<'a> StringReader<'a> { fn fatal_span_char(&self, from_pos: BytePos, to_pos: BytePos, m: &str, c: char) -> ! { let mut m = m.to_string(); m.push_str(": "); - char::escape_default(c, |c| m.push(c)); + for c in c.escape_default() { m.push(c) } self.fatal_span_(from_pos, to_pos, m.as_slice()); } @@ -202,7 +202,7 @@ impl<'a> StringReader<'a> { fn err_span_char(&self, from_pos: BytePos, to_pos: BytePos, m: &str, c: char) { let mut m = m.to_string(); m.push_str(": "); - char::escape_default(c, |c| m.push(c)); + for c in c.escape_default() { m.push(c) } self.err_span_(from_pos, to_pos, m.as_slice()); } @@ -645,7 +645,7 @@ impl<'a> StringReader<'a> { loop { let c = self.curr; if c == Some('_') { debug!("skipping a _"); self.bump(); continue; } - match c.and_then(|cc| char::to_digit(cc, radix)) { + match c.and_then(|cc| cc.to_digit(radix)) { Some(_) => { debug!("{} in scan_digits", c); len += 1; @@ -677,7 +677,7 @@ impl<'a> StringReader<'a> { return token::Integer(self.name_from(start_bpos)); } } - } else if c.is_digit_radix(10) { + } else if c.is_digit(10) { num_digits = self.scan_digits(10) + 1; } else { num_digits = 0; @@ -692,11 +692,11 @@ impl<'a> StringReader<'a> { // integer literal followed by field/method access or a range pattern // (`0..2` and `12.foo()`) if self.curr_is('.') && !self.nextch_is('.') && !self.nextch().unwrap_or('\0') - .is_XID_start() { + .is_xid_start() { // might have stuff after the ., and if it does, it needs to start // with a number self.bump(); - if self.curr.unwrap_or('\0').is_digit_radix(10) { + if self.curr.unwrap_or('\0').is_digit(10) { self.scan_digits(10); self.scan_float_exponent(); } @@ -1385,7 +1385,7 @@ fn ident_start(c: Option) -> bool { (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' - || (c > '\x7f' && char::is_XID_start(c)) + || (c > '\x7f' && c.is_xid_start()) } fn ident_continue(c: Option) -> bool { @@ -1395,7 +1395,7 @@ fn ident_continue(c: Option) -> bool { || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_' - || (c > '\x7f' && char::is_XID_continue(c)) + || (c > '\x7f' && c.is_xid_continue()) } #[cfg(test)] diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 5652a9a9d3a6..4ce0d74bd37f 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -2756,7 +2756,9 @@ impl<'a> State<'a> { } ast::LitChar(ch) => { let mut res = String::from_str("'"); - ch.escape_default(|c| res.push(c)); + for c in ch.escape_default() { + res.push(c); + } res.push('\''); word(&mut self.s, res.as_slice()) } diff --git a/src/libterm/terminfo/parm.rs b/src/libterm/terminfo/parm.rs index f910bfc5bd44..cfab64949007 100644 --- a/src/libterm/terminfo/parm.rs +++ b/src/libterm/terminfo/parm.rs @@ -14,8 +14,6 @@ pub use self::Param::*; use self::States::*; use self::FormatState::*; use self::FormatOp::*; - -use std::char; use std::mem::replace; #[deriving(PartialEq)] @@ -298,7 +296,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) }, PushParam => { // params are 1-indexed - stack.push(mparams[match char::to_digit(cur, 10) { + stack.push(mparams[match cur.to_digit(10) { Some(d) => d - 1, None => return Err("bad param number".to_string()) }].clone()); diff --git a/src/libunicode/u_char.rs b/src/libunicode/u_char.rs index bac8b21ea68b..369336639a7f 100644 --- a/src/libunicode/u_char.rs +++ b/src/libunicode/u_char.rs @@ -20,12 +20,9 @@ use tables::{derived_property, property, general_category, conversions, charwidt /// Returns whether the specified `char` is considered a Unicode alphabetic /// code point +#[deprecated = "use UnicodeChar::is_alphabetic"] pub fn is_alphabetic(c: char) -> bool { - match c { - 'a' ... 'z' | 'A' ... 'Z' => true, - c if c > '\x7f' => derived_property::Alphabetic(c), - _ => false - } + c.is_alphabetic() } /// Returns whether the specified `char` satisfies the 'XID_Start' Unicode property @@ -34,6 +31,7 @@ pub fn is_alphabetic(c: char) -> bool { /// [UAX #31](http://unicode.org/reports/tr31/#NFKC_Modifications), /// mostly similar to ID_Start but modified for closure under NFKx. #[allow(non_snake_case)] +#[deprecated = "use UnicodeChar::is_XID_start"] pub fn is_XID_start(c: char) -> bool { derived_property::XID_Start(c) } /// Returns whether the specified `char` satisfies the 'XID_Continue' Unicode property @@ -42,6 +40,7 @@ pub fn is_XID_start(c: char) -> bool { derived_property::XID_Start(c) } /// [UAX #31](http://unicode.org/reports/tr31/#NFKC_Modifications), /// mostly similar to 'ID_Continue' but modified for closure under NFKx. #[allow(non_snake_case)] +#[deprecated = "use UnicodeChar::is_XID_continue"] pub fn is_XID_continue(c: char) -> bool { derived_property::XID_Continue(c) } /// @@ -50,12 +49,9 @@ pub fn is_XID_continue(c: char) -> bool { derived_property::XID_Continue(c) } /// This is defined according to the terms of the Unicode Derived Core Property 'Lowercase'. /// #[inline] +#[deprecated = "use UnicodeChar::is_lowercase"] pub fn is_lowercase(c: char) -> bool { - match c { - 'a' ... 'z' => true, - c if c > '\x7f' => derived_property::Lowercase(c), - _ => false - } + c.is_lowercase() } /// @@ -64,12 +60,9 @@ pub fn is_lowercase(c: char) -> bool { /// This is defined according to the terms of the Unicode Derived Core Property 'Uppercase'. /// #[inline] +#[deprecated = "use UnicodeChar::is_uppercase"] pub fn is_uppercase(c: char) -> bool { - match c { - 'A' ... 'Z' => true, - c if c > '\x7f' => derived_property::Uppercase(c), - _ => false - } + c.is_uppercase() } /// @@ -78,12 +71,9 @@ pub fn is_uppercase(c: char) -> bool { /// Whitespace is defined in terms of the Unicode Property 'White_Space'. /// #[inline] +#[deprecated = "use UnicodeChar::is_whitespace"] pub fn is_whitespace(c: char) -> bool { - match c { - ' ' | '\x09' ... '\x0d' => true, - c if c > '\x7f' => property::White_Space(c), - _ => false - } + c.is_whitespace() } /// @@ -93,9 +83,9 @@ pub fn is_whitespace(c: char) -> bool { /// 'Nd', 'Nl', 'No' and the Derived Core Property 'Alphabetic'. /// #[inline] +#[deprecated = "use UnicodeChar::is_alphanumeric"] pub fn is_alphanumeric(c: char) -> bool { - is_alphabetic(c) - || is_digit(c) + c.is_alphanumeric() } /// @@ -105,16 +95,14 @@ pub fn is_alphanumeric(c: char) -> bool { /// 'Cc'. /// #[inline] +#[deprecated = "use UnicodeChar::is_control"] pub fn is_control(c: char) -> bool { general_category::Cc(c) } /// Indicates whether the `char` is numeric (Nd, Nl, or No) #[inline] +#[deprecated = "use UnicodeChar::is_numeric"] pub fn is_digit(c: char) -> bool { - match c { - '0' ... '9' => true, - c if c > '\x7f' => general_category::N(c), - _ => false - } + c.is_numeric() } /// Convert a char to its uppercase equivalent @@ -132,6 +120,7 @@ pub fn is_digit(c: char) -> bool { /// /// Returns the char itself if no conversion was made #[inline] +#[deprecated = "use UnicodeChar::to_uppercase"] pub fn to_uppercase(c: char) -> char { conversions::to_upper(c) } @@ -145,6 +134,7 @@ pub fn to_uppercase(c: char) -> char { /// /// Returns the char itself if no conversion if possible #[inline] +#[deprecated = "use UnicodeChar::to_lowercase"] pub fn to_lowercase(c: char) -> char { conversions::to_lower(c) } @@ -158,15 +148,17 @@ pub fn to_lowercase(c: char) -> char { /// [Unicode Standard Annex #11](http://www.unicode.org/reports/tr11/) /// recommends that these characters be treated as 1 column (i.e., /// `is_cjk` = `false`) if the context cannot be reliably determined. +#[deprecated = "use UnicodeChar::width"] pub fn width(c: char, is_cjk: bool) -> Option { charwidth::width(c, is_cjk) } /// Useful functions for Unicode characters. +#[experimental = "pending prelude organization"] pub trait UnicodeChar { /// Returns whether the specified character is considered a Unicode /// alphabetic code point. - fn is_alphabetic(&self) -> bool; + fn is_alphabetic(self) -> bool; /// Returns whether the specified character satisfies the 'XID_Start' /// Unicode property. @@ -175,7 +167,16 @@ pub trait UnicodeChar { /// [UAX #31](http://unicode.org/reports/tr31/#NFKC_Modifications), /// mostly similar to ID_Start but modified for closure under NFKx. #[allow(non_snake_case)] - fn is_XID_start(&self) -> bool; + #[deprecated = "use is_xid_start"] + fn is_XID_start(self) -> bool; + + /// Returns whether the specified character satisfies the 'XID_Start' + /// Unicode property. + /// + /// 'XID_Start' is a Unicode Derived Property specified in + /// [UAX #31](http://unicode.org/reports/tr31/#NFKC_Modifications), + /// mostly similar to ID_Start but modified for closure under NFKx. + fn is_xid_start(self) -> bool; /// Returns whether the specified `char` satisfies the 'XID_Continue' /// Unicode property. @@ -184,40 +185,48 @@ pub trait UnicodeChar { /// [UAX #31](http://unicode.org/reports/tr31/#NFKC_Modifications), /// mostly similar to 'ID_Continue' but modified for closure under NFKx. #[allow(non_snake_case)] - fn is_XID_continue(&self) -> bool; + #[deprecated = "use is_xid_continue"] + fn is_XID_continue(self) -> bool; + /// Returns whether the specified `char` satisfies the 'XID_Continue' + /// Unicode property. + /// + /// 'XID_Continue' is a Unicode Derived Property specified in + /// [UAX #31](http://unicode.org/reports/tr31/#NFKC_Modifications), + /// mostly similar to 'ID_Continue' but modified for closure under NFKx. + fn is_xid_continue(self) -> bool; /// Indicates whether a character is in lowercase. /// /// This is defined according to the terms of the Unicode Derived Core /// Property `Lowercase`. - fn is_lowercase(&self) -> bool; + fn is_lowercase(self) -> bool; /// Indicates whether a character is in uppercase. /// /// This is defined according to the terms of the Unicode Derived Core /// Property `Uppercase`. - fn is_uppercase(&self) -> bool; + fn is_uppercase(self) -> bool; /// Indicates whether a character is whitespace. /// /// Whitespace is defined in terms of the Unicode Property `White_Space`. - fn is_whitespace(&self) -> bool; + fn is_whitespace(self) -> bool; /// Indicates whether a character is alphanumeric. /// /// Alphanumericness is defined in terms of the Unicode General Categories /// 'Nd', 'Nl', 'No' and the Derived Core Property 'Alphabetic'. - fn is_alphanumeric(&self) -> bool; + fn is_alphanumeric(self) -> bool; /// Indicates whether a character is a control code point. /// /// Control code points are defined in terms of the Unicode General /// Category `Cc`. - fn is_control(&self) -> bool; + fn is_control(self) -> bool; /// Indicates whether the character is numeric (Nd, Nl, or No). - fn is_digit(&self) -> bool; + fn is_numeric(self) -> bool; /// Converts a character to its lowercase equivalent. /// @@ -228,7 +237,7 @@ pub trait UnicodeChar { /// /// Returns the lowercase equivalent of the character, or the character /// itself if no conversion is possible. - fn to_lowercase(&self) -> char; + fn to_lowercase(self) -> char; /// Converts a character to its uppercase equivalent. /// @@ -250,7 +259,7 @@ pub trait UnicodeChar { /// [`SpecialCasing`.txt`]: ftp://ftp.unicode.org/Public/UNIDATA/SpecialCasing.txt /// /// [2]: http://www.unicode.org/versions/Unicode4.0.0/ch03.pdf#G33992 - fn to_uppercase(&self) -> char; + fn to_uppercase(self) -> char; /// Returns this character's displayed width in columns, or `None` if it is a /// control character other than `'\x00'`. @@ -261,31 +270,72 @@ pub trait UnicodeChar { /// [Unicode Standard Annex #11](http://www.unicode.org/reports/tr11/) /// recommends that these characters be treated as 1 column (i.e., /// `is_cjk` = `false`) if the context cannot be reliably determined. - fn width(&self, is_cjk: bool) -> Option; + #[experimental = "needs expert opinion. is_cjk flag stands out as ugly"] + fn width(self, is_cjk: bool) -> Option; } +#[experimental = "pending prelude organization"] impl UnicodeChar for char { - fn is_alphabetic(&self) -> bool { is_alphabetic(*self) } + fn is_alphabetic(self) -> bool { + match self { + 'a' ... 'z' | 'A' ... 'Z' => true, + c if c > '\x7f' => derived_property::Alphabetic(c), + _ => false + } + } - fn is_XID_start(&self) -> bool { is_XID_start(*self) } + #[deprecated = "use is_xid_start"] + fn is_XID_start(self) -> bool { derived_property::XID_Start(self) } - fn is_XID_continue(&self) -> bool { is_XID_continue(*self) } + #[deprecated = "use is_xid_continue"] + fn is_XID_continue(self) -> bool { derived_property::XID_Continue(self) } - fn is_lowercase(&self) -> bool { is_lowercase(*self) } + fn is_xid_start(self) -> bool { derived_property::XID_Start(self) } - fn is_uppercase(&self) -> bool { is_uppercase(*self) } + fn is_xid_continue(self) -> bool { derived_property::XID_Continue(self) } - fn is_whitespace(&self) -> bool { is_whitespace(*self) } + fn is_lowercase(self) -> bool { + match self { + 'a' ... 'z' => true, + c if c > '\x7f' => derived_property::Lowercase(c), + _ => false + } + } - fn is_alphanumeric(&self) -> bool { is_alphanumeric(*self) } + fn is_uppercase(self) -> bool { + match self { + 'A' ... 'Z' => true, + c if c > '\x7f' => derived_property::Uppercase(c), + _ => false + } + } - fn is_control(&self) -> bool { is_control(*self) } + fn is_whitespace(self) -> bool { + match self { + ' ' | '\x09' ... '\x0d' => true, + c if c > '\x7f' => property::White_Space(c), + _ => false + } + } - fn is_digit(&self) -> bool { is_digit(*self) } + fn is_alphanumeric(self) -> bool { + self.is_alphabetic() || self.is_numeric() + } - fn to_lowercase(&self) -> char { to_lowercase(*self) } + fn is_control(self) -> bool { general_category::Cc(self) } - fn to_uppercase(&self) -> char { to_uppercase(*self) } + fn is_numeric(self) -> bool { + match self { + '0' ... '9' => true, + c if c > '\x7f' => general_category::N(c), + _ => false + } + } - fn width(&self, is_cjk: bool) -> Option { width(*self, is_cjk) } + fn to_lowercase(self) -> char { conversions::to_lower(self) } + + fn to_uppercase(self) -> char { conversions::to_upper(self) } + + #[experimental = "needs expert opinion. is_cjk flag stands out as ugly"] + fn width(self, is_cjk: bool) -> Option { charwidth::width(self, is_cjk) } } diff --git a/src/libunicode/u_str.rs b/src/libunicode/u_str.rs index 99c1ce503cc4..56b1f0907d5a 100644 --- a/src/libunicode/u_str.rs +++ b/src/libunicode/u_str.rs @@ -24,13 +24,13 @@ use core::iter::{Filter, AdditiveIterator, Iterator, DoubleEndedIterator}; use core::kinds::Sized; use core::option::{Option, None, Some}; use core::str::{CharSplits, StrPrelude}; -use u_char; use u_char::UnicodeChar; use tables::grapheme::GraphemeCat; /// An iterator over the words of a string, separated by a sequence of whitespace +/// FIXME: This should be opaque pub type Words<'a> = - Filter<'a, &'a str, CharSplits<'a, extern "Rust" fn(char) -> bool>>; + Filter<'a, &'a str, CharSplits<'a, |char|:'a -> bool>>; /// Methods for Unicode string slices pub trait UnicodeStrPrelude for Sized? { @@ -143,14 +143,15 @@ impl UnicodeStrPrelude for str { #[inline] fn words(&self) -> Words { - self.split(u_char::is_whitespace).filter(|s| !s.is_empty()) + let f = |c: char| c.is_whitespace(); + self.split(f).filter(|s| !s.is_empty()) } #[inline] - fn is_whitespace(&self) -> bool { self.chars().all(u_char::is_whitespace) } + fn is_whitespace(&self) -> bool { self.chars().all(|c| c.is_whitespace()) } #[inline] - fn is_alphanumeric(&self) -> bool { self.chars().all(u_char::is_alphanumeric) } + fn is_alphanumeric(&self) -> bool { self.chars().all(|c| c.is_alphanumeric()) } #[inline] fn width(&self, is_cjk: bool) -> uint { @@ -164,12 +165,12 @@ impl UnicodeStrPrelude for str { #[inline] fn trim_left(&self) -> &str { - self.trim_left_chars(u_char::is_whitespace) + self.trim_left_chars(|c: char| c.is_whitespace()) } #[inline] fn trim_right(&self) -> &str { - self.trim_right_chars(u_char::is_whitespace) + self.trim_right_chars(|c: char| c.is_whitespace()) } } diff --git a/src/test/auxiliary/issue-8044.rs b/src/test/auxiliary/issue-8044.rs index 03f8d49ad627..7096146a43af 100644 --- a/src/test/auxiliary/issue-8044.rs +++ b/src/test/auxiliary/issue-8044.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(struct_variant)] - pub struct BTree { pub node: TreeItem, } diff --git a/src/test/auxiliary/namespaced_enum_emulate_flat.rs b/src/test/auxiliary/namespaced_enum_emulate_flat.rs index 3a11f30049c6..c7387dd284eb 100644 --- a/src/test/auxiliary/namespaced_enum_emulate_flat.rs +++ b/src/test/auxiliary/namespaced_enum_emulate_flat.rs @@ -7,7 +7,7 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(globs, struct_variant)] +#![feature(globs)] pub use Foo::*; diff --git a/src/test/auxiliary/namespaced_enums.rs b/src/test/auxiliary/namespaced_enums.rs index a6e6f9b01916..5b21d130d170 100644 --- a/src/test/auxiliary/namespaced_enums.rs +++ b/src/test/auxiliary/namespaced_enums.rs @@ -7,7 +7,6 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(struct_variant)] pub enum Foo { A, diff --git a/src/test/auxiliary/struct_variant_privacy.rs b/src/test/auxiliary/struct_variant_privacy.rs index 7ebce96dd2ed..0bdda2350803 100644 --- a/src/test/auxiliary/struct_variant_privacy.rs +++ b/src/test/auxiliary/struct_variant_privacy.rs @@ -7,7 +7,6 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(struct_variant)] enum Bar { Baz { a: int } diff --git a/src/test/auxiliary/struct_variant_xc_aux.rs b/src/test/auxiliary/struct_variant_xc_aux.rs index 2cfc94139b62..76fd619f6896 100644 --- a/src/test/auxiliary/struct_variant_xc_aux.rs +++ b/src/test/auxiliary/struct_variant_xc_aux.rs @@ -11,8 +11,6 @@ #![crate_name="struct_variant_xc_aux"] #![crate_type = "lib"] -#![feature(struct_variant)] - pub enum Enum { Variant(u8), StructVariant { arg: u8 } diff --git a/src/test/debuginfo/borrowed-enum.rs b/src/test/debuginfo/borrowed-enum.rs index d1ace0fbe3d3..9cda56a77438 100644 --- a/src/test/debuginfo/borrowed-enum.rs +++ b/src/test/debuginfo/borrowed-enum.rs @@ -40,7 +40,6 @@ // lldb-check:[...]$2 = TheOnlyCase(4820353753753434) #![allow(unused_variables)] -#![feature(struct_variant)] // The first element is to ensure proper alignment, irrespective of the machines word size. Since // the size of the discriminant value is machine dependent, this has be taken into account when diff --git a/src/test/debuginfo/by-value-non-immediate-argument.rs b/src/test/debuginfo/by-value-non-immediate-argument.rs index 78101d669dc9..258c49afcc42 100644 --- a/src/test/debuginfo/by-value-non-immediate-argument.rs +++ b/src/test/debuginfo/by-value-non-immediate-argument.rs @@ -71,8 +71,6 @@ // lldb-check:[...]$6 = Case1 { x: 0, y: 8970181431921507452 } // lldb-command:continue -#![feature(struct_variant)] - #[deriving(Clone)] struct Struct { a: int, diff --git a/src/test/debuginfo/gdb-pretty-struct-and-enums.rs b/src/test/debuginfo/gdb-pretty-struct-and-enums.rs index 00b157d49d11..9a42cd92fdc8 100644 --- a/src/test/debuginfo/gdb-pretty-struct-and-enums.rs +++ b/src/test/debuginfo/gdb-pretty-struct-and-enums.rs @@ -64,8 +64,6 @@ // gdb-command: print nested_variant2 // gdb-check:$14 = NestedVariant2 = {abc = NestedStruct = {regular_struct = RegularStruct = {the_first_field = 117, the_second_field = 118.5, the_third_field = false, the_fourth_field = "NestedStructString10"}, tuple_struct = TupleStruct = {119.5, 120}, empty_struct = EmptyStruct, c_style_enum = CStyleEnumVar3, mixed_enum = MixedEnumStructVar = {field1 = 121.5, field2 = -122}}} -#![feature(struct_variant)] - use self::CStyleEnum::{CStyleEnumVar1, CStyleEnumVar2, CStyleEnumVar3}; use self::MixedEnum::{MixedEnumCStyleVar, MixedEnumTupleVar, MixedEnumStructVar}; use self::NestedEnum::{NestedVariant1, NestedVariant2}; 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 28897a9e837a..d69d432fcb30 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 @@ -31,8 +31,6 @@ // gdb-check:$5 = 5 // gdb-command:continue -#![feature(struct_variant)] - struct Struct { x: int } diff --git a/src/test/debuginfo/generic-struct-style-enum.rs b/src/test/debuginfo/generic-struct-style-enum.rs index fe5c13e4b8d5..5e9672664217 100644 --- a/src/test/debuginfo/generic-struct-style-enum.rs +++ b/src/test/debuginfo/generic-struct-style-enum.rs @@ -29,8 +29,6 @@ // gdb-command:print univariant // gdb-check:$4 = {{a = -1}} -#![feature(struct_variant)] - use self::Regular::{Case1, Case2, Case3}; use self::Univariant::TheOnlyCase; diff --git a/src/test/debuginfo/method-on-enum.rs b/src/test/debuginfo/method-on-enum.rs index 399d9fabd7a1..d86aa54f451e 100644 --- a/src/test/debuginfo/method-on-enum.rs +++ b/src/test/debuginfo/method-on-enum.rs @@ -113,8 +113,6 @@ // lldb-check:[...]$14 = -10 // lldb-command:continue -#![feature(struct_variant)] - enum Enum { Variant1 { x: u16, y: u16 }, Variant2 (u32) diff --git a/src/test/debuginfo/option-like-enum.rs b/src/test/debuginfo/option-like-enum.rs index 7b8526adba76..11c594bac599 100644 --- a/src/test/debuginfo/option-like-enum.rs +++ b/src/test/debuginfo/option-like-enum.rs @@ -62,8 +62,6 @@ // lldb-check:[...]$5 = Void -#![feature(struct_variant)] - // If a struct has exactly two variants, one of them is empty, and the other one // contains a non-nullable pointer, then this value is used as the discriminator. // The test cases in this file make sure that something readable is generated for diff --git a/src/test/debuginfo/recursive-struct.rs b/src/test/debuginfo/recursive-struct.rs index b0c01ecce08c..032b8b1fa262 100644 --- a/src/test/debuginfo/recursive-struct.rs +++ b/src/test/debuginfo/recursive-struct.rs @@ -69,7 +69,6 @@ // gdb-command:continue #![allow(unused_variables)] -#![feature(struct_variant)] use self::Opt::{Empty, Val}; diff --git a/src/test/debuginfo/static-method-on-struct-and-enum.rs b/src/test/debuginfo/static-method-on-struct-and-enum.rs index 32016a7f68f5..f808e7f8a90f 100644 --- a/src/test/debuginfo/static-method-on-struct-and-enum.rs +++ b/src/test/debuginfo/static-method-on-struct-and-enum.rs @@ -54,8 +54,6 @@ // lldb-check:[...]$4 = 5 // lldb-command:continue -#![feature(struct_variant)] - struct Struct { x: int } diff --git a/src/test/debuginfo/struct-style-enum.rs b/src/test/debuginfo/struct-style-enum.rs index 899b43ad5596..48c6c2d79fb4 100644 --- a/src/test/debuginfo/struct-style-enum.rs +++ b/src/test/debuginfo/struct-style-enum.rs @@ -49,7 +49,6 @@ // lldb-check:[...]$3 = TheOnlyCase { a: -1 } #![allow(unused_variables)] -#![feature(struct_variant)] use self::Regular::{Case1, Case2, Case3}; use self::Univariant::TheOnlyCase; diff --git a/src/test/debuginfo/unique-enum.rs b/src/test/debuginfo/unique-enum.rs index 017853407441..3c0a4a21b4fc 100644 --- a/src/test/debuginfo/unique-enum.rs +++ b/src/test/debuginfo/unique-enum.rs @@ -42,7 +42,6 @@ // lldb-check:[...]$2 = TheOnlyCase(123234) #![allow(unused_variables)] -#![feature(struct_variant)] // The first element is to ensure proper alignment, irrespective of the machines word size. Since // the size of the discriminant value is machine dependent, this has be taken into account when diff --git a/src/test/run-pass/const-enum-structlike.rs b/src/test/run-pass/const-enum-structlike.rs index fa32df2db739..ac48752b0a94 100644 --- a/src/test/run-pass/const-enum-structlike.rs +++ b/src/test/run-pass/const-enum-structlike.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(struct_variant)] - enum E { S0 { s: String }, S1 { u: uint } 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 a7be1c4b37d8..0c70102d57e2 100644 --- a/src/test/run-pass/deriving-cmp-generic-struct-enum.rs +++ b/src/test/run-pass/deriving-cmp-generic-struct-enum.rs @@ -10,8 +10,6 @@ // no-pretty-expanded FIXME #15189 -#![feature(struct_variant)] - #[deriving(PartialEq, Eq, PartialOrd, Ord)] enum ES { ES1 { x: T }, diff --git a/src/test/run-pass/deriving-encodable-decodable.rs b/src/test/run-pass/deriving-encodable-decodable.rs index 021b609efe25..7bee4bc7b0d2 100644 --- a/src/test/run-pass/deriving-encodable-decodable.rs +++ b/src/test/run-pass/deriving-encodable-decodable.rs @@ -13,8 +13,6 @@ // ignore-test FIXME(#5121) -#![feature(struct_variant)] - extern crate rand; extern crate rbml; extern crate serialize; diff --git a/src/test/run-pass/deriving-rand.rs b/src/test/run-pass/deriving-rand.rs index f0f2f86a7c62..544c0052433d 100644 --- a/src/test/run-pass/deriving-rand.rs +++ b/src/test/run-pass/deriving-rand.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(struct_variant)] - use std::rand; #[deriving(Rand)] diff --git a/src/test/run-pass/deriving-show-2.rs b/src/test/run-pass/deriving-show-2.rs index 5880066dcece..df4bc1ae1d09 100644 --- a/src/test/run-pass/deriving-show-2.rs +++ b/src/test/run-pass/deriving-show-2.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(struct_variant)] - use std::fmt; #[deriving(Show)] diff --git a/src/test/run-pass/deriving-show.rs b/src/test/run-pass/deriving-show.rs index 1107986c42ba..ccfaac8378fa 100644 --- a/src/test/run-pass/deriving-show.rs +++ b/src/test/run-pass/deriving-show.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(struct_variant, macro_rules)] +#![feature(macro_rules)] #[deriving(Show)] struct Unit; diff --git a/src/test/run-pass/deriving-via-extension-struct-like-enum-variant.rs b/src/test/run-pass/deriving-via-extension-struct-like-enum-variant.rs index 790d002705b8..b091787b1ee2 100644 --- a/src/test/run-pass/deriving-via-extension-struct-like-enum-variant.rs +++ b/src/test/run-pass/deriving-via-extension-struct-like-enum-variant.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(struct_variant)] - #[deriving(PartialEq, Show)] enum S { X { x: int, y: int }, diff --git a/src/test/run-pass/drop-trait-enum.rs b/src/test/run-pass/drop-trait-enum.rs index fb543c86d5da..15f028e1716f 100644 --- a/src/test/run-pass/drop-trait-enum.rs +++ b/src/test/run-pass/drop-trait-enum.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(struct_variant)] - use std::task; #[deriving(PartialEq, Show)] diff --git a/src/test/run-pass/enum-variants.rs b/src/test/run-pass/enum-variants.rs index 65e0e9ecb379..4a3a1156698a 100644 --- a/src/test/run-pass/enum-variants.rs +++ b/src/test/run-pass/enum-variants.rs @@ -10,7 +10,6 @@ #![allow(dead_assignment)] #![allow(unused_variable)] -#![feature(struct_variant)] enum Animal { Dog (String, f64), diff --git a/src/test/run-pass/issue-11085.rs b/src/test/run-pass/issue-11085.rs index 3c01df475bfd..9440e0c2874a 100644 --- a/src/test/run-pass/issue-11085.rs +++ b/src/test/run-pass/issue-11085.rs @@ -10,8 +10,6 @@ // compile-flags: --cfg foo -#![feature(struct_variant)] - struct Foo { #[cfg(fail)] bar: baz, diff --git a/src/test/run-pass/issue-11577.rs b/src/test/run-pass/issue-11577.rs index b8b54e7b20ac..687de4847405 100644 --- a/src/test/run-pass/issue-11577.rs +++ b/src/test/run-pass/issue-11577.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(struct_variant)] - // Destructuring struct variants would ICE where regular structs wouldn't enum Foo { diff --git a/src/test/run-pass/issue-14837.rs b/src/test/run-pass/issue-14837.rs index f622d31346fd..1155027d426d 100644 --- a/src/test/run-pass/issue-14837.rs +++ b/src/test/run-pass/issue-14837.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(struct_variant)] - #[deny(dead_code)] pub enum Foo { Bar { diff --git a/src/test/run-pass/issue-2804.rs b/src/test/run-pass/issue-2804.rs index 55648b0057d5..4f66139789b1 100644 --- a/src/test/run-pass/issue-2804.rs +++ b/src/test/run-pass/issue-2804.rs @@ -59,7 +59,7 @@ fn add_interfaces(store: int, managed_ip: String, device: HashMap Vec<(String, object)> { match device["interfaces".to_string()] { - json::List(ref interfaces) => + json::Array(ref interfaces) => { interfaces.iter().map(|interface| { add_interface(store, managed_ip.clone(), (*interface).clone()) diff --git a/src/test/run-pass/issue-5530.rs b/src/test/run-pass/issue-5530.rs index ec697cdf9e0e..a9e1ffcb3451 100644 --- a/src/test/run-pass/issue-5530.rs +++ b/src/test/run-pass/issue-5530.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(struct_variant)] - enum Enum { Foo { foo: uint }, Bar { bar: uint } diff --git a/src/test/run-pass/issue-8351-1.rs b/src/test/run-pass/issue-8351-1.rs index 479cac98b8e6..b7e6facc5818 100644 --- a/src/test/run-pass/issue-8351-1.rs +++ b/src/test/run-pass/issue-8351-1.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(struct_variant)] - enum E { Foo{f: int}, Bar, diff --git a/src/test/run-pass/issue-8351-2.rs b/src/test/run-pass/issue-8351-2.rs index d6409443d262..40e0b3a8eecc 100644 --- a/src/test/run-pass/issue-8351-2.rs +++ b/src/test/run-pass/issue-8351-2.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(struct_variant)] - enum E { Foo{f: int, b: bool}, Bar, diff --git a/src/test/run-pass/match-arm-statics.rs b/src/test/run-pass/match-arm-statics.rs index 338790146115..85fa61266a33 100644 --- a/src/test/run-pass/match-arm-statics.rs +++ b/src/test/run-pass/match-arm-statics.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(struct_variant)] - struct NewBool(bool); enum Direction { diff --git a/src/test/run-pass/match-enum-struct-0.rs b/src/test/run-pass/match-enum-struct-0.rs index 6b0e351c8923..5cc512abfe37 100644 --- a/src/test/run-pass/match-enum-struct-0.rs +++ b/src/test/run-pass/match-enum-struct-0.rs @@ -10,8 +10,6 @@ // regression test for issue #5625 -#![feature(struct_variant)] - enum E { Foo{f : int}, Bar diff --git a/src/test/run-pass/match-enum-struct-1.rs b/src/test/run-pass/match-enum-struct-1.rs index 9e0de69c1ab0..fdfadf8eb444 100644 --- a/src/test/run-pass/match-enum-struct-1.rs +++ b/src/test/run-pass/match-enum-struct-1.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(struct_variant)] - enum E { Foo{f : int}, Bar diff --git a/src/test/run-pass/match-in-macro.rs b/src/test/run-pass/match-in-macro.rs index b6834f8026d1..2f8e184033ae 100644 --- a/src/test/run-pass/match-in-macro.rs +++ b/src/test/run-pass/match-in-macro.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(macro_rules, struct_variant)] +#![feature(macro_rules)] enum Foo { B { b1: int, bb1: int}, diff --git a/src/test/run-pass/namespaced-enum-emulate-flat-xc.rs b/src/test/run-pass/namespaced-enum-emulate-flat-xc.rs index 540a0acb1231..680cdf14e8f2 100644 --- a/src/test/run-pass/namespaced-enum-emulate-flat-xc.rs +++ b/src/test/run-pass/namespaced-enum-emulate-flat-xc.rs @@ -9,7 +9,6 @@ // except according to those terms. // aux-build:namespaced_enum_emulate_flat.rs -#![feature(struct_variant)] extern crate namespaced_enum_emulate_flat; diff --git a/src/test/run-pass/namespaced-enum-emulate-flat.rs b/src/test/run-pass/namespaced-enum-emulate-flat.rs index 2aad9bcff561..676fe6500818 100644 --- a/src/test/run-pass/namespaced-enum-emulate-flat.rs +++ b/src/test/run-pass/namespaced-enum-emulate-flat.rs @@ -7,7 +7,7 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(globs, struct_variant)] +#![feature(globs)] pub use Foo::*; use nest::{Bar, D, E, F}; diff --git a/src/test/run-pass/namespaced-enum-glob-import-xcrate.rs b/src/test/run-pass/namespaced-enum-glob-import-xcrate.rs index 35fb66769543..cc4985927f19 100644 --- a/src/test/run-pass/namespaced-enum-glob-import-xcrate.rs +++ b/src/test/run-pass/namespaced-enum-glob-import-xcrate.rs @@ -9,7 +9,7 @@ // except according to those terms. // aux-build:namespaced_enums.rs -#![feature(globs, struct_variant)] +#![feature(globs)] extern crate namespaced_enums; diff --git a/src/test/run-pass/namespaced-enum-glob-import.rs b/src/test/run-pass/namespaced-enum-glob-import.rs index fe6f34273836..137dd543566b 100644 --- a/src/test/run-pass/namespaced-enum-glob-import.rs +++ b/src/test/run-pass/namespaced-enum-glob-import.rs @@ -7,7 +7,7 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(globs, struct_variant)] +#![feature(globs)] mod m2 { pub enum Foo { diff --git a/src/test/run-pass/namespaced-enums-xcrate.rs b/src/test/run-pass/namespaced-enums-xcrate.rs index c5f80eaea5a3..7545908dcbbf 100644 --- a/src/test/run-pass/namespaced-enums-xcrate.rs +++ b/src/test/run-pass/namespaced-enums-xcrate.rs @@ -9,7 +9,6 @@ // except according to those terms. // aux-build:namespaced_enums.rs -#![feature(struct_variant)] extern crate namespaced_enums; diff --git a/src/test/run-pass/namespaced-enums.rs b/src/test/run-pass/namespaced-enums.rs index afa39c326b60..13f70f6a740a 100644 --- a/src/test/run-pass/namespaced-enums.rs +++ b/src/test/run-pass/namespaced-enums.rs @@ -7,7 +7,6 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(struct_variant)] enum Foo { A, diff --git a/src/test/run-pass/struct-like-variant-construct.rs b/src/test/run-pass/struct-like-variant-construct.rs index 625c1e864ca1..364c6da98039 100644 --- a/src/test/run-pass/struct-like-variant-construct.rs +++ b/src/test/run-pass/struct-like-variant-construct.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(struct_variant)] - enum Foo { Bar { a: int, diff --git a/src/test/run-pass/struct-like-variant-match.rs b/src/test/run-pass/struct-like-variant-match.rs index 3097b4005d84..3afa44a3142b 100644 --- a/src/test/run-pass/struct-like-variant-match.rs +++ b/src/test/run-pass/struct-like-variant-match.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(struct_variant)] - enum Foo { Bar { x: int, diff --git a/src/test/run-pass/struct-variant-field-visibility.rs b/src/test/run-pass/struct-variant-field-visibility.rs index a3946bd8dd95..aad3ba01a487 100644 --- a/src/test/run-pass/struct-variant-field-visibility.rs +++ b/src/test/run-pass/struct-variant-field-visibility.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(struct_variant)] - mod foo { pub enum Foo { Bar { a: int } diff --git a/src/test/run-pass/unsized2.rs b/src/test/run-pass/unsized2.rs index ada4da37ba11..d28d47c0cfb8 100644 --- a/src/test/run-pass/unsized2.rs +++ b/src/test/run-pass/unsized2.rs @@ -9,8 +9,6 @@ // except according to those terms. // // ignore-lexer-test FIXME #15879 -#![feature(struct_variant)] - // Test sized-ness checking in substitution. diff --git a/src/test/run-pass/variant-structs-trivial.rs b/src/test/run-pass/variant-structs-trivial.rs index a74f97825f4c..e078fa1485d1 100644 --- a/src/test/run-pass/variant-structs-trivial.rs +++ b/src/test/run-pass/variant-structs-trivial.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(struct_variant)] - enum Foo { Bar { x: int }, Baz { y: int }