diff --git a/src/doc/index.md b/src/doc/index.md index 124a82aa7dc..5a437e959b7 100644 --- a/src/doc/index.md +++ b/src/doc/index.md @@ -19,7 +19,7 @@ ideas behind Rust. donated to the Rust project. As the name implies, it teaches you Rust through a series of small examples. -[rbe]: rustbyexample.com +[rbe]: http://rustbyexample.com/ # Community & Getting Help diff --git a/src/doc/trpl/ffi.md b/src/doc/trpl/ffi.md index 23f6e17b860..2c5e6b2e5fc 100644 --- a/src/doc/trpl/ffi.md +++ b/src/doc/trpl/ffi.md @@ -166,7 +166,7 @@ pub fn uncompress(src: &[u8]) -> Option> { } ``` -For reference, the examples used here are also available as an [library on +For reference, the examples used here are also available as a [library on GitHub](https://github.com/thestinger/rust-snappy). # Destructors diff --git a/src/doc/trpl/hello-world.md b/src/doc/trpl/hello-world.md index 6c320d27ba6..e58bac656d0 100644 --- a/src/doc/trpl/hello-world.md +++ b/src/doc/trpl/hello-world.md @@ -104,10 +104,10 @@ We’ll get to the details eventually, you’ll just have to trust us for now. Next, `"Hello, world!"` is a ‘string’. Strings are a surprisingly complicated topic in a systems programming language, and this is a ‘statically allocated’ -string. If you want to read further about allocation, check out [the stack and -the heap], but you don’t need to right now if you don’t want to. We pass this -string as an argument to `println!`, which prints the string to the screen. -Easy enough! +string. If you want to read further about allocation, check out +[the stack and the heap][allocation], but you don’t need to right now if you +don’t want to. We pass this string as an argument to `println!`, which prints the +string to the screen. Easy enough! [allocation]: the-stack-and-the-heap.html diff --git a/src/doc/trpl/installing-rust.md b/src/doc/trpl/installing-rust.md index e4054a09798..09b4495ffe9 100644 --- a/src/doc/trpl/installing-rust.md +++ b/src/doc/trpl/installing-rust.md @@ -90,8 +90,8 @@ If not, there are a number of places where you can get help. The easiest is [the #rust IRC channel on irc.mozilla.org][irc], which you can access through [Mibbit][mibbit]. Click that link, and you'll be chatting with other Rustaceans (a silly nickname we call ourselves), and we can help you out. Other great -resources include [the user’s forum][users], and [Stack Overflow][stack -overflow]. +resources include [the user’s forum][users], and +[Stack Overflow][stack overflow]. [irc]: irc://irc.mozilla.org/#rust [mibbit]: http://chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust diff --git a/src/doc/trpl/no-stdlib.md b/src/doc/trpl/no-stdlib.md index 094c82a08cc..67db919c59f 100644 --- a/src/doc/trpl/no-stdlib.md +++ b/src/doc/trpl/no-stdlib.md @@ -103,7 +103,7 @@ necessary functionality for writing idiomatic and effective Rust code. As an example, here is a program that will calculate the dot product of two vectors provided from C, using idiomatic Rust practices. -``` +```ignore #![feature(lang_items, start, no_std, core, libc)] #![no_std] diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index ff176d81591..0cfdcd2413f 100644 --- a/src/liballoc/arc.rs +++ b/src/liballoc/arc.rs @@ -274,7 +274,7 @@ pub fn get_mut(this: &mut Arc) -> Option<&mut T> { // reference to the inner data. let inner = unsafe { &mut **this._ptr }; Some(&mut inner.data) - }else { + } else { None } } diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 4a0706906ee..e44b0d1147c 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -273,8 +273,9 @@ pub trait Iterator { FilterMap { iter: self, f: f } } - /// Creates an iterator that yields a pair of the value returned by this - /// iterator plus the current index of iteration. + /// Creates an iterator that yields pairs `(i, val)` where `i` is the + /// current index of iteration and `val` is the value returned by the + /// iterator. /// /// `enumerate` keeps its count as a `usize`. If you want to count by a /// different sized integer, the `zip` function provides similar @@ -1129,7 +1130,7 @@ pub trait FromIterator { /// Conversion into an `Iterator` /// /// Implementing this trait allows you to use your type with Rust's `for` loop. See -/// the [module level documentation](../index.html) for more details. +/// the [module level documentation](index.html) for more details. #[stable(feature = "rust1", since = "1.0.0")] pub trait IntoIterator { /// The type of the elements being iterated diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 9a165a2e317..0e9570df09d 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -15,9 +15,9 @@ //! Working with unsafe pointers in Rust is uncommon, //! typically limited to a few patterns. //! -//! Use the [`null` function](fn.null.html) to create null pointers, and -//! the `is_null` method of the `*const T` type to check for null. -//! The `*const T` type also defines the `offset` method, for pointer math. +//! Use the `null` function to create null pointers, and the `is_null` method +//! of the `*const T` type to check for null. The `*const T` type also defines +//! the `offset` method, for pointer math. //! //! # Common ways to create unsafe pointers //! diff --git a/src/librustc/metadata/loader.rs b/src/librustc/metadata/loader.rs index 7b63e38b585..4a77f80d3b8 100644 --- a/src/librustc/metadata/loader.rs +++ b/src/librustc/metadata/loader.rs @@ -129,7 +129,7 @@ //! > Dear rustc, //! > //! > When you are attempting to load the immediate dependency `crate-name`, I -//! > would like you too assume that the library is located at +//! > would like you to assume that the library is located at //! > `path/to/the/crate.rlib`, and look nowhere else. Also, please do not //! > assume that the path I specified has the name `crate-name`. //! diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index c1c05da4ee4..04513e9d048 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -172,7 +172,7 @@ impl CString { /// /// This method is equivalent to `new` except that no runtime assertion /// is made that `v` contains no 0 bytes, and it requires an actual - /// byte vector, not anyhting that can be converted to one with Into. + /// byte vector, not anything that can be converted to one with Into. #[stable(feature = "rust1", since = "1.0.0")] pub unsafe fn from_vec_unchecked(mut v: Vec) -> CString { v.push(0); diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index 6e902a47396..d30d44a04d3 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -1099,8 +1099,8 @@ impl PathExt for Path { /// Changes the timestamps for a file's last modification and access time. /// /// The file at the path specified will have its last access time set to -/// `atime` and its modification time set to `mtime`. The times specified should -/// be in milliseconds. +/// `accessed` and its modification time set to `modified`. The times specified +/// should be in milliseconds. #[unstable(feature = "fs_time", reason = "the argument type of u64 is not quite appropriate for \ this function and may change if the standard library \ diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index f3ba5cd7854..93c6deac6e5 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -148,7 +148,7 @@ pub trait Read { /// /// If the return value of this method is `Ok(n)`, then it must be /// guaranteed that `0 <= n <= buf.len()`. A nonzero `n` value indicates - /// that the buffer `buf` has ben filled in with `n` bytes of data from this + /// that the buffer `buf` has been filled in with `n` bytes of data from this /// source. If `n` is `0`, then it can indicate one of two scenarios: /// /// 1. This reader has reached its "end of file" and will likely no longer diff --git a/src/libstd/net/addr.rs b/src/libstd/net/addr.rs index 05a3ca91948..2e34e46726f 100644 --- a/src/libstd/net/addr.rs +++ b/src/libstd/net/addr.rs @@ -461,264 +461,7 @@ mod tests { use io; use net::*; use net::Ipv6MulticastScope::*; - - #[test] - fn test_from_str_ipv4() { - assert_eq!(Ok(Ipv4Addr::new(127, 0, 0, 1)), "127.0.0.1".parse()); - assert_eq!(Ok(Ipv4Addr::new(255, 255, 255, 255)), "255.255.255.255".parse()); - assert_eq!(Ok(Ipv4Addr::new(0, 0, 0, 0)), "0.0.0.0".parse()); - - // out of range - let none: Option = "256.0.0.1".parse().ok(); - assert_eq!(None, none); - // too short - let none: Option = "255.0.0".parse().ok(); - assert_eq!(None, none); - // too long - let none: Option = "255.0.0.1.2".parse().ok(); - assert_eq!(None, none); - // no number between dots - let none: Option = "255.0..1".parse().ok(); - assert_eq!(None, none); - } - - #[test] - fn test_from_str_ipv6() { - assert_eq!(Ok(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0)), "0:0:0:0:0:0:0:0".parse()); - assert_eq!(Ok(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)), "0:0:0:0:0:0:0:1".parse()); - - assert_eq!(Ok(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)), "::1".parse()); - assert_eq!(Ok(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0)), "::".parse()); - - assert_eq!(Ok(Ipv6Addr::new(0x2a02, 0x6b8, 0, 0, 0, 0, 0x11, 0x11)), - "2a02:6b8::11:11".parse()); - - // too long group - let none: Option = "::00000".parse().ok(); - assert_eq!(None, none); - // too short - let none: Option = "1:2:3:4:5:6:7".parse().ok(); - assert_eq!(None, none); - // too long - let none: Option = "1:2:3:4:5:6:7:8:9".parse().ok(); - assert_eq!(None, none); - // triple colon - let none: Option = "1:2:::6:7:8".parse().ok(); - assert_eq!(None, none); - // two double colons - let none: Option = "1:2::6::8".parse().ok(); - assert_eq!(None, none); - } - - #[test] - fn test_from_str_ipv4_in_ipv6() { - assert_eq!(Ok(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 49152, 545)), - "::192.0.2.33".parse()); - assert_eq!(Ok(Ipv6Addr::new(0, 0, 0, 0, 0, 0xFFFF, 49152, 545)), - "::FFFF:192.0.2.33".parse()); - assert_eq!(Ok(Ipv6Addr::new(0x64, 0xff9b, 0, 0, 0, 0, 49152, 545)), - "64:ff9b::192.0.2.33".parse()); - assert_eq!(Ok(Ipv6Addr::new(0x2001, 0xdb8, 0x122, 0xc000, 0x2, 0x2100, 49152, 545)), - "2001:db8:122:c000:2:2100:192.0.2.33".parse()); - - // colon after v4 - let none: Option = "::127.0.0.1:".parse().ok(); - assert_eq!(None, none); - // not enough groups - let none: Option = "1.2.3.4.5:127.0.0.1".parse().ok(); - assert_eq!(None, none); - // too many groups - let none: Option = "1.2.3.4.5:6:7:127.0.0.1".parse().ok(); - assert_eq!(None, none); - } - - #[test] - fn test_from_str_socket_addr() { - assert_eq!(Ok(sa4(Ipv4Addr::new(77, 88, 21, 11), 80)), - "77.88.21.11:80".parse()); - assert_eq!(Ok(sa6(Ipv6Addr::new(0x2a02, 0x6b8, 0, 1, 0, 0, 0, 1), 53)), - "[2a02:6b8:0:1::1]:53".parse()); - assert_eq!(Ok(sa6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0x7F00, 1), 22)), - "[::127.0.0.1]:22".parse()); - - // without port - let none: Option = "127.0.0.1".parse().ok(); - assert_eq!(None, none); - // without port - let none: Option = "127.0.0.1:".parse().ok(); - assert_eq!(None, none); - // wrong brackets around v4 - let none: Option = "[127.0.0.1]:22".parse().ok(); - assert_eq!(None, none); - // port out of range - let none: Option = "127.0.0.1:123456".parse().ok(); - assert_eq!(None, none); - } - - #[test] - fn ipv6_addr_to_string() { - // ipv4-mapped address - let a1 = Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc000, 0x280); - assert_eq!(a1.to_string(), "::ffff:192.0.2.128"); - - // ipv4-compatible address - let a1 = Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0xc000, 0x280); - assert_eq!(a1.to_string(), "::192.0.2.128"); - - // v6 address with no zero segments - assert_eq!(Ipv6Addr::new(8, 9, 10, 11, 12, 13, 14, 15).to_string(), - "8:9:a:b:c:d:e:f"); - - // reduce a single run of zeros - assert_eq!("ae::ffff:102:304", - Ipv6Addr::new(0xae, 0, 0, 0, 0, 0xffff, 0x0102, 0x0304).to_string()); - - // don't reduce just a single zero segment - assert_eq!("1:2:3:4:5:6:0:8", - Ipv6Addr::new(1, 2, 3, 4, 5, 6, 0, 8).to_string()); - - // 'any' address - assert_eq!("::", Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0).to_string()); - - // loopback address - assert_eq!("::1", Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1).to_string()); - - // ends in zeros - assert_eq!("1::", Ipv6Addr::new(1, 0, 0, 0, 0, 0, 0, 0).to_string()); - - // two runs of zeros, second one is longer - assert_eq!("1:0:0:4::8", Ipv6Addr::new(1, 0, 0, 4, 0, 0, 0, 8).to_string()); - - // two runs of zeros, equal length - assert_eq!("1::4:5:0:0:8", Ipv6Addr::new(1, 0, 0, 4, 5, 0, 0, 8).to_string()); - } - - #[test] - fn ipv4_to_ipv6() { - assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0x1234, 0x5678), - Ipv4Addr::new(0x12, 0x34, 0x56, 0x78).to_ipv6_mapped()); - assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0x1234, 0x5678), - Ipv4Addr::new(0x12, 0x34, 0x56, 0x78).to_ipv6_compatible()); - } - - #[test] - fn ipv6_to_ipv4() { - assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0x1234, 0x5678).to_ipv4(), - Some(Ipv4Addr::new(0x12, 0x34, 0x56, 0x78))); - assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0x1234, 0x5678).to_ipv4(), - Some(Ipv4Addr::new(0x12, 0x34, 0x56, 0x78))); - assert_eq!(Ipv6Addr::new(0, 0, 1, 0, 0, 0, 0x1234, 0x5678).to_ipv4(), - None); - } - - #[test] - fn ipv4_properties() { - fn check(octets: &[u8; 4], unspec: bool, loopback: bool, - private: bool, link_local: bool, global: bool, - multicast: bool, broadcast: bool, documentation: bool) { - let ip = Ipv4Addr::new(octets[0], octets[1], octets[2], octets[3]); - assert_eq!(octets, &ip.octets()); - - assert_eq!(ip.is_unspecified(), unspec); - assert_eq!(ip.is_loopback(), loopback); - assert_eq!(ip.is_private(), private); - assert_eq!(ip.is_link_local(), link_local); - assert_eq!(ip.is_global(), global); - assert_eq!(ip.is_multicast(), multicast); - assert_eq!(ip.is_broadcast(), broadcast); - assert_eq!(ip.is_documentation(), documentation); - } - - // address unspec loopbk privt linloc global multicast brdcast doc - check(&[0, 0, 0, 0], true, false, false, false, true, false, false, false); - check(&[0, 0, 0, 1], false, false, false, false, true, false, false, false); - check(&[1, 0, 0, 0], false, false, false, false, true, false, false, false); - check(&[10, 9, 8, 7], false, false, true, false, false, false, false, false); - check(&[127, 1, 2, 3], false, true, false, false, false, false, false, false); - check(&[172, 31, 254, 253], false, false, true, false, false, false, false, false); - check(&[169, 254, 253, 242], false, false, false, true, false, false, false, false); - check(&[192, 168, 254, 253], false, false, true, false, false, false, false, false); - check(&[224, 0, 0, 0], false, false, false, false, true, true, false, false); - check(&[239, 255, 255, 255], false, false, false, false, true, true, false, false); - check(&[255, 255, 255, 255], false, false, false, false, false, false, true, false); - check(&[198, 51, 100, 0], false, false, false, false, false, false, false, true); - } - - #[test] - fn ipv6_properties() { - fn check(str_addr: &str, unspec: bool, loopback: bool, - unique_local: bool, global: bool, - u_link_local: bool, u_site_local: bool, u_global: bool, - m_scope: Option) { - let ip: Ipv6Addr = str_addr.parse().unwrap(); - assert_eq!(str_addr, ip.to_string()); - - assert_eq!(ip.is_unspecified(), unspec); - assert_eq!(ip.is_loopback(), loopback); - assert_eq!(ip.is_unique_local(), unique_local); - assert_eq!(ip.is_global(), global); - assert_eq!(ip.is_unicast_link_local(), u_link_local); - assert_eq!(ip.is_unicast_site_local(), u_site_local); - assert_eq!(ip.is_unicast_global(), u_global); - assert_eq!(ip.multicast_scope(), m_scope); - assert_eq!(ip.is_multicast(), m_scope.is_some()); - } - - // unspec loopbk uniqlo global unill unisl uniglo mscope - check("::", - true, false, false, true, false, false, true, None); - check("::1", - false, true, false, false, false, false, false, None); - check("::0.0.0.2", - false, false, false, true, false, false, true, None); - check("1::", - false, false, false, true, false, false, true, None); - check("fc00::", - false, false, true, false, false, false, false, None); - check("fdff:ffff::", - false, false, true, false, false, false, false, None); - check("fe80:ffff::", - false, false, false, false, true, false, false, None); - check("febf:ffff::", - false, false, false, false, true, false, false, None); - check("fec0::", - false, false, false, false, false, true, false, None); - check("ff01::", - false, false, false, false, false, false, false, Some(InterfaceLocal)); - check("ff02::", - false, false, false, false, false, false, false, Some(LinkLocal)); - check("ff03::", - false, false, false, false, false, false, false, Some(RealmLocal)); - check("ff04::", - false, false, false, false, false, false, false, Some(AdminLocal)); - check("ff05::", - false, false, false, false, false, false, false, Some(SiteLocal)); - check("ff08::", - false, false, false, false, false, false, false, Some(OrganizationLocal)); - check("ff0e::", - false, false, false, true, false, false, false, Some(Global)); - } - - fn tsa(a: A) -> Result, String> { - match a.to_socket_addrs() { - Ok(a) => Ok(a.collect()), - Err(e) => Err(e.to_string()), - } - } - - #[test] - fn to_socket_addr_socketaddr() { - let a = sa4(Ipv4Addr::new(77, 88, 21, 11), 12345); - assert_eq!(Ok(vec![a]), tsa(a)); - } - - fn sa4(a: Ipv4Addr, p: u16) -> SocketAddr { - SocketAddr::V4(SocketAddrV4::new(a, p)) - } - - fn sa6(a: Ipv6Addr, p: u16) -> SocketAddr { - SocketAddr::V6(SocketAddrV6::new(a, p, 0, 0)) - } + use net::test::{tsa, sa6, sa4}; #[test] fn to_socket_addr_ipaddr_u16() { diff --git a/src/libstd/net/ip.rs b/src/libstd/net/ip.rs index 0e493b271f9..065126c6fdb 100644 --- a/src/libstd/net/ip.rs +++ b/src/libstd/net/ip.rs @@ -486,3 +486,256 @@ impl FromInner for Ipv6Addr { Ipv6Addr { inner: addr } } } + +// Tests for this module +#[cfg(test)] +mod tests { + use prelude::v1::*; + use io; + use net::*; + use net::Ipv6MulticastScope::*; + use net::test::{tsa, sa6, sa4}; + + #[test] + fn test_from_str_ipv4() { + assert_eq!(Ok(Ipv4Addr::new(127, 0, 0, 1)), "127.0.0.1".parse()); + assert_eq!(Ok(Ipv4Addr::new(255, 255, 255, 255)), "255.255.255.255".parse()); + assert_eq!(Ok(Ipv4Addr::new(0, 0, 0, 0)), "0.0.0.0".parse()); + + // out of range + let none: Option = "256.0.0.1".parse().ok(); + assert_eq!(None, none); + // too short + let none: Option = "255.0.0".parse().ok(); + assert_eq!(None, none); + // too long + let none: Option = "255.0.0.1.2".parse().ok(); + assert_eq!(None, none); + // no number between dots + let none: Option = "255.0..1".parse().ok(); + assert_eq!(None, none); + } + + #[test] + fn test_from_str_ipv6() { + assert_eq!(Ok(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0)), "0:0:0:0:0:0:0:0".parse()); + assert_eq!(Ok(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)), "0:0:0:0:0:0:0:1".parse()); + + assert_eq!(Ok(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)), "::1".parse()); + assert_eq!(Ok(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0)), "::".parse()); + + assert_eq!(Ok(Ipv6Addr::new(0x2a02, 0x6b8, 0, 0, 0, 0, 0x11, 0x11)), + "2a02:6b8::11:11".parse()); + + // too long group + let none: Option = "::00000".parse().ok(); + assert_eq!(None, none); + // too short + let none: Option = "1:2:3:4:5:6:7".parse().ok(); + assert_eq!(None, none); + // too long + let none: Option = "1:2:3:4:5:6:7:8:9".parse().ok(); + assert_eq!(None, none); + // triple colon + let none: Option = "1:2:::6:7:8".parse().ok(); + assert_eq!(None, none); + // two double colons + let none: Option = "1:2::6::8".parse().ok(); + assert_eq!(None, none); + } + + #[test] + fn test_from_str_ipv4_in_ipv6() { + assert_eq!(Ok(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 49152, 545)), + "::192.0.2.33".parse()); + assert_eq!(Ok(Ipv6Addr::new(0, 0, 0, 0, 0, 0xFFFF, 49152, 545)), + "::FFFF:192.0.2.33".parse()); + assert_eq!(Ok(Ipv6Addr::new(0x64, 0xff9b, 0, 0, 0, 0, 49152, 545)), + "64:ff9b::192.0.2.33".parse()); + assert_eq!(Ok(Ipv6Addr::new(0x2001, 0xdb8, 0x122, 0xc000, 0x2, 0x2100, 49152, 545)), + "2001:db8:122:c000:2:2100:192.0.2.33".parse()); + + // colon after v4 + let none: Option = "::127.0.0.1:".parse().ok(); + assert_eq!(None, none); + // not enough groups + let none: Option = "1.2.3.4.5:127.0.0.1".parse().ok(); + assert_eq!(None, none); + // too many groups + let none: Option = "1.2.3.4.5:6:7:127.0.0.1".parse().ok(); + assert_eq!(None, none); + } + + #[test] + fn test_from_str_socket_addr() { + assert_eq!(Ok(sa4(Ipv4Addr::new(77, 88, 21, 11), 80)), + "77.88.21.11:80".parse()); + assert_eq!(Ok(sa6(Ipv6Addr::new(0x2a02, 0x6b8, 0, 1, 0, 0, 0, 1), 53)), + "[2a02:6b8:0:1::1]:53".parse()); + assert_eq!(Ok(sa6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0x7F00, 1), 22)), + "[::127.0.0.1]:22".parse()); + + // without port + let none: Option = "127.0.0.1".parse().ok(); + assert_eq!(None, none); + // without port + let none: Option = "127.0.0.1:".parse().ok(); + assert_eq!(None, none); + // wrong brackets around v4 + let none: Option = "[127.0.0.1]:22".parse().ok(); + assert_eq!(None, none); + // port out of range + let none: Option = "127.0.0.1:123456".parse().ok(); + assert_eq!(None, none); + } + + #[test] + fn ipv6_addr_to_string() { + // ipv4-mapped address + let a1 = Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc000, 0x280); + assert_eq!(a1.to_string(), "::ffff:192.0.2.128"); + + // ipv4-compatible address + let a1 = Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0xc000, 0x280); + assert_eq!(a1.to_string(), "::192.0.2.128"); + + // v6 address with no zero segments + assert_eq!(Ipv6Addr::new(8, 9, 10, 11, 12, 13, 14, 15).to_string(), + "8:9:a:b:c:d:e:f"); + + // reduce a single run of zeros + assert_eq!("ae::ffff:102:304", + Ipv6Addr::new(0xae, 0, 0, 0, 0, 0xffff, 0x0102, 0x0304).to_string()); + + // don't reduce just a single zero segment + assert_eq!("1:2:3:4:5:6:0:8", + Ipv6Addr::new(1, 2, 3, 4, 5, 6, 0, 8).to_string()); + + // 'any' address + assert_eq!("::", Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0).to_string()); + + // loopback address + assert_eq!("::1", Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1).to_string()); + + // ends in zeros + assert_eq!("1::", Ipv6Addr::new(1, 0, 0, 0, 0, 0, 0, 0).to_string()); + + // two runs of zeros, second one is longer + assert_eq!("1:0:0:4::8", Ipv6Addr::new(1, 0, 0, 4, 0, 0, 0, 8).to_string()); + + // two runs of zeros, equal length + assert_eq!("1::4:5:0:0:8", Ipv6Addr::new(1, 0, 0, 4, 5, 0, 0, 8).to_string()); + } + + #[test] + fn ipv4_to_ipv6() { + assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0x1234, 0x5678), + Ipv4Addr::new(0x12, 0x34, 0x56, 0x78).to_ipv6_mapped()); + assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0x1234, 0x5678), + Ipv4Addr::new(0x12, 0x34, 0x56, 0x78).to_ipv6_compatible()); + } + + #[test] + fn ipv6_to_ipv4() { + assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0x1234, 0x5678).to_ipv4(), + Some(Ipv4Addr::new(0x12, 0x34, 0x56, 0x78))); + assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0x1234, 0x5678).to_ipv4(), + Some(Ipv4Addr::new(0x12, 0x34, 0x56, 0x78))); + assert_eq!(Ipv6Addr::new(0, 0, 1, 0, 0, 0, 0x1234, 0x5678).to_ipv4(), + None); + } + + #[test] + fn ipv4_properties() { + fn check(octets: &[u8; 4], unspec: bool, loopback: bool, + private: bool, link_local: bool, global: bool, + multicast: bool, broadcast: bool, documentation: bool) { + let ip = Ipv4Addr::new(octets[0], octets[1], octets[2], octets[3]); + assert_eq!(octets, &ip.octets()); + + assert_eq!(ip.is_unspecified(), unspec); + assert_eq!(ip.is_loopback(), loopback); + assert_eq!(ip.is_private(), private); + assert_eq!(ip.is_link_local(), link_local); + assert_eq!(ip.is_global(), global); + assert_eq!(ip.is_multicast(), multicast); + assert_eq!(ip.is_broadcast(), broadcast); + assert_eq!(ip.is_documentation(), documentation); + } + + // address unspec loopbk privt linloc global multicast brdcast doc + check(&[0, 0, 0, 0], true, false, false, false, true, false, false, false); + check(&[0, 0, 0, 1], false, false, false, false, true, false, false, false); + check(&[1, 0, 0, 0], false, false, false, false, true, false, false, false); + check(&[10, 9, 8, 7], false, false, true, false, false, false, false, false); + check(&[127, 1, 2, 3], false, true, false, false, false, false, false, false); + check(&[172, 31, 254, 253], false, false, true, false, false, false, false, false); + check(&[169, 254, 253, 242], false, false, false, true, false, false, false, false); + check(&[192, 168, 254, 253], false, false, true, false, false, false, false, false); + check(&[224, 0, 0, 0], false, false, false, false, true, true, false, false); + check(&[239, 255, 255, 255], false, false, false, false, true, true, false, false); + check(&[255, 255, 255, 255], false, false, false, false, false, false, true, false); + check(&[198, 51, 100, 0], false, false, false, false, false, false, false, true); + } + + #[test] + fn ipv6_properties() { + fn check(str_addr: &str, unspec: bool, loopback: bool, + unique_local: bool, global: bool, + u_link_local: bool, u_site_local: bool, u_global: bool, + m_scope: Option) { + let ip: Ipv6Addr = str_addr.parse().unwrap(); + assert_eq!(str_addr, ip.to_string()); + + assert_eq!(ip.is_unspecified(), unspec); + assert_eq!(ip.is_loopback(), loopback); + assert_eq!(ip.is_unique_local(), unique_local); + assert_eq!(ip.is_global(), global); + assert_eq!(ip.is_unicast_link_local(), u_link_local); + assert_eq!(ip.is_unicast_site_local(), u_site_local); + assert_eq!(ip.is_unicast_global(), u_global); + assert_eq!(ip.multicast_scope(), m_scope); + assert_eq!(ip.is_multicast(), m_scope.is_some()); + } + + // unspec loopbk uniqlo global unill unisl uniglo mscope + check("::", + true, false, false, true, false, false, true, None); + check("::1", + false, true, false, false, false, false, false, None); + check("::0.0.0.2", + false, false, false, true, false, false, true, None); + check("1::", + false, false, false, true, false, false, true, None); + check("fc00::", + false, false, true, false, false, false, false, None); + check("fdff:ffff::", + false, false, true, false, false, false, false, None); + check("fe80:ffff::", + false, false, false, false, true, false, false, None); + check("febf:ffff::", + false, false, false, false, true, false, false, None); + check("fec0::", + false, false, false, false, false, true, false, None); + check("ff01::", + false, false, false, false, false, false, false, Some(InterfaceLocal)); + check("ff02::", + false, false, false, false, false, false, false, Some(LinkLocal)); + check("ff03::", + false, false, false, false, false, false, false, Some(RealmLocal)); + check("ff04::", + false, false, false, false, false, false, false, Some(AdminLocal)); + check("ff05::", + false, false, false, false, false, false, false, Some(SiteLocal)); + check("ff08::", + false, false, false, false, false, false, false, Some(OrganizationLocal)); + check("ff0e::", + false, false, false, true, false, false, false, Some(Global)); + } + + #[test] + fn to_socket_addr_socketaddr() { + let a = sa4(Ipv4Addr::new(77, 88, 21, 11), 12345); + assert_eq!(Ok(vec![a]), tsa(a)); + } +} diff --git a/src/libstd/net/tcp.rs b/src/libstd/net/tcp.rs index 209a0032fb4..e48d0e6008b 100644 --- a/src/libstd/net/tcp.rs +++ b/src/libstd/net/tcp.rs @@ -213,7 +213,7 @@ impl TcpListener { /// Returns an iterator over the connections being received on this /// listener. /// - /// The returned iterator will never returned `None` and will also not yield + /// The returned iterator will never return `None` and will also not yield /// the peer's `SocketAddr` structure. #[stable(feature = "rust1", since = "1.0.0")] pub fn incoming(&self) -> Incoming { diff --git a/src/libstd/net/test.rs b/src/libstd/net/test.rs index 3d42472f0fc..d77d6f1d6de 100644 --- a/src/libstd/net/test.rs +++ b/src/libstd/net/test.rs @@ -11,7 +11,7 @@ use prelude::v1::*; use env; -use net::{SocketAddr, SocketAddrV4, SocketAddrV6, Ipv4Addr, Ipv6Addr}; +use net::{SocketAddr, SocketAddrV4, SocketAddrV6, Ipv4Addr, Ipv6Addr, ToSocketAddrs}; use sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering}; static PORT: AtomicUsize = ATOMIC_USIZE_INIT; @@ -27,6 +27,21 @@ pub fn next_test_ip6() -> SocketAddr { port, 0, 0)) } +pub fn sa4(a: Ipv4Addr, p: u16) -> SocketAddr { + SocketAddr::V4(SocketAddrV4::new(a, p)) +} + +pub fn sa6(a: Ipv6Addr, p: u16) -> SocketAddr { + SocketAddr::V6(SocketAddrV6::new(a, p, 0, 0)) +} + +pub fn tsa(a: A) -> Result, String> { + match a.to_socket_addrs() { + Ok(a) => Ok(a.collect()), + Err(e) => Err(e.to_string()), + } +} + // The bots run multiple builds at the same time, and these builds // all want to use ports. This function figures out which workspace // it is running in and assigns a port range based on it. diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index e45b7c1df91..bef2068f0dd 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1972,7 +1972,7 @@ impl<'a> Parser<'a> { } try!(self.bump()); - hi = self.span.hi; + hi = self.last_span.hi; return if es.len() == 1 && !trailing_comma { Ok(self.mk_expr(lo, hi, ExprParen(es.into_iter().nth(0).unwrap()))) } else { diff --git a/src/test/parse-fail/issue-24197.rs b/src/test/parse-fail/issue-24197.rs new file mode 100644 index 00000000000..37d62182612 --- /dev/null +++ b/src/test/parse-fail/issue-24197.rs @@ -0,0 +1,13 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + let buf[0] = 0; //~ ERROR expected one of `:`, `;`, `=`, or `@`, found `[` +} diff --git a/src/test/parse-fail/issue-24375.rs b/src/test/parse-fail/issue-24375.rs new file mode 100644 index 00000000000..8723423325c --- /dev/null +++ b/src/test/parse-fail/issue-24375.rs @@ -0,0 +1,19 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +static tmp : [&'static str; 2] = ["hello", "he"]; + +fn main() { + let z = "hello"; + match z { + tmp[0] => {} //~ ERROR expected one of `=>`, `@`, `if`, or `|`, found `[` + _ => {} + } +} diff --git a/src/test/run-pass/method-two-trait-defer-resolution-2.rs b/src/test/run-pass/method-two-trait-defer-resolution-2.rs index e1b64f250d8..cf9bc9bb56a 100644 --- a/src/test/run-pass/method-two-trait-defer-resolution-2.rs +++ b/src/test/run-pass/method-two-trait-defer-resolution-2.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// Test that when we write `x.foo()`, we do nothave to know the +// Test that when we write `x.foo()`, we do not have to know the // complete type of `x` in order to type-check the method call. In // this case, we know that `x: Vec<_1>`, but we don't know what type // `_1` is (because the call to `push` comes later). To pick between