diff --git a/configure b/configure index 1d6c387caa7c6..6cdbfadf63798 100755 --- a/configure +++ b/configure @@ -707,7 +707,7 @@ then | cut -d ' ' -f 2) case $CFG_CLANG_VERSION in - (3.0svn | 3.0 | 3.1* | 3.2* | 3.3* | 3.4* | 3.5* ) + (3.0svn | 3.0 | 3.1* | 3.2* | 3.3* | 3.4* | 3.5* | 3.6*) step_msg "found ok version of CLANG: $CFG_CLANG_VERSION" if [ -z "$CC" ] then diff --git a/src/doc/guide.md b/src/doc/guide.md index e4bb3ae6ba671..6d0fd54cd4c13 100644 --- a/src/doc/guide.md +++ b/src/doc/guide.md @@ -520,10 +520,8 @@ error: aborting due to previous error Could not compile `hello_world`. ``` -Rust will not let us use a value that has not been initialized. So why let us -declare a binding without initializing it? You'd think our first example would -have errored. Well, Rust is smarter than that. Before we get to that, let's talk -about this stuff we've added to `println!`. +Rust will not let us use a value that has not been initialized. Next, let's +talk about this stuff we've added to `println!`. If you include two curly braces (`{}`, some call them moustaches...) in your string to print, Rust will interpret this as a request to interpolate some sort @@ -538,12 +536,6 @@ format in a more detailed manner, there are a [wide number of options available](std/fmt/index.html). For now, we'll just stick to the default: integers aren't very complicated to print. -So, we've cleared up all of the confusion around bindings, with one exception: -why does Rust let us declare a variable binding without an initial value if we -must initialize the binding before we use it? And how does it know that we have -or have not initialized the binding? For that, we need to learn our next -concept: `if`. - # If Rust's take on `if` is not particularly complex, but it's much more like the @@ -582,7 +574,6 @@ if x == 5i { This is all pretty standard. However, you can also do this: - ``` let x = 5i; diff --git a/src/doc/rust.md b/src/doc/rust.md index 86776d50e7951..eb97a75e7660b 100644 --- a/src/doc/rust.md +++ b/src/doc/rust.md @@ -3290,17 +3290,19 @@ between `_` and `..` is that the pattern `C(_)` is only type-correct if `C` has exactly one argument, while the pattern `C(..)` is type-correct for any enum variant `C`, regardless of how many arguments `C` has. -Used inside a vector pattern, `..` stands for any number of elements. This -wildcard can be used at most once for a given vector, which implies that it -cannot be used to specifically match elements that are at an unknown distance -from both ends of a vector, like `[.., 42, ..]`. If followed by a variable name, -it will bind the corresponding slice to the variable. Example: +Used inside a vector pattern, `..` stands for any number of elements, when the +`advanced_slice_patterns` feature gate is turned on. This wildcard can be used +at most once for a given vector, which implies that it cannot be used to +specifically match elements that are at an unknown distance from both ends of a +vector, like `[.., 42, ..]`. If followed by a variable name, it will bind the +corresponding slice to the variable. Example: ~~~~ +# #![feature(advanced_slice_patterns)] fn is_symmetric(list: &[uint]) -> bool { match list { [] | [_] => true, - [x, ..inside, y] if x == y => is_symmetric(inside), + [x, inside.., y] if x == y => is_symmetric(inside), _ => false } } diff --git a/src/doc/tutorial.md b/src/doc/tutorial.md index 0db25c4090ebc..0e5a624b27333 100644 --- a/src/doc/tutorial.md +++ b/src/doc/tutorial.md @@ -1707,7 +1707,7 @@ let score = match numbers { [] => 0, [a] => a * 10, [a, b] => a * 6 + b * 4, - [a, b, c, ..rest] => a * 5 + b * 3 + c * 2 + rest.len() as int + [a, b, c, rest..] => a * 5 + b * 3 + c * 2 + rest.len() as int }; ~~~~ diff --git a/src/etc/licenseck.py b/src/etc/licenseck.py index de0d5c18766ad..328a2ff6c9408 100644 --- a/src/etc/licenseck.py +++ b/src/etc/licenseck.py @@ -43,12 +43,15 @@ "libsync/mpmc_bounded_queue.rs", # BSD "libsync/mpsc_intrusive.rs", # BSD "test/bench/shootout-binarytrees.rs", # BSD + "test/bench/shootout-chameneos-redux.rs", # BSD "test/bench/shootout-fannkuch-redux.rs", # BSD "test/bench/shootout-k-nucleotide.rs", # BSD "test/bench/shootout-mandelbrot.rs", # BSD "test/bench/shootout-meteor.rs", # BSD + "test/bench/shootout-nbody.rs", # BSD "test/bench/shootout-pidigits.rs", # BSD "test/bench/shootout-regex-dna.rs", # BSD + "test/bench/shootout-reverse-complement.rs", # BSD "test/bench/shootout-threadring.rs", # BSD ] diff --git a/src/libarena/lib.rs b/src/libarena/lib.rs index e91898548533c..ee3fd6ad0eb0d 100644 --- a/src/libarena/lib.rs +++ b/src/libarena/lib.rs @@ -509,6 +509,7 @@ mod tests { use self::test::Bencher; use super::{Arena, TypedArena}; + #[allow(dead_code)] struct Point { x: int, y: int, @@ -564,6 +565,7 @@ mod tests { }) } + #[allow(dead_code)] struct Noncopy { string: String, array: Vec, diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 2418fabfff1d8..36edd913de2f8 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -864,6 +864,7 @@ mod tests { } #[test] + #[allow(deprecated)] fn test_tailn() { let mut a = vec![11i, 12, 13]; let b: &[int] = &[11, 12, 13]; @@ -875,6 +876,7 @@ mod tests { #[test] #[should_fail] + #[allow(deprecated)] fn test_tailn_empty() { let a: Vec = vec![]; a.tailn(2); @@ -909,6 +911,7 @@ mod tests { #[test] #[should_fail] + #[allow(deprecated)] fn test_initn_empty() { let a: Vec = vec![]; a.as_slice().initn(2); @@ -1466,6 +1469,7 @@ mod tests { } #[test] + #[allow(deprecated)] fn test_unshift() { let mut x = vec![1i, 2, 3]; x.unshift(0); @@ -2079,6 +2083,7 @@ mod tests { } #[test] + #[allow(deprecated)] fn test_shift_ref() { let mut x: &[int] = [1, 2, 3, 4, 5]; let h = x.shift_ref(); @@ -2092,6 +2097,7 @@ mod tests { } #[test] + #[allow(deprecated)] fn test_pop_ref() { let mut x: &[int] = [1, 2, 3, 4, 5]; let h = x.pop_ref(); @@ -2171,6 +2177,7 @@ mod tests { } #[test] + #[allow(deprecated)] fn test_mut_shift_ref() { let mut x: &mut [int] = [1, 2, 3, 4, 5]; let h = x.mut_shift_ref(); @@ -2184,6 +2191,7 @@ mod tests { } #[test] + #[allow(deprecated)] fn test_mut_pop_ref() { let mut x: &mut [int] = [1, 2, 3, 4, 5]; let h = x.mut_pop_ref(); @@ -2441,7 +2449,7 @@ mod bench { b.iter(|| { v.sort(); }); - b.bytes = (v.len() * mem::size_of_val(v.get(0))) as u64; + b.bytes = (v.len() * mem::size_of_val(&v[0])) as u64; } type BigSortable = (u64,u64,u64,u64); @@ -2485,6 +2493,6 @@ mod bench { b.iter(|| { v.sort(); }); - b.bytes = (v.len() * mem::size_of_val(v.get(0))) as u64; + b.bytes = (v.len() * mem::size_of_val(&v[0])) as u64; } } diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index da7f026aed4f5..89b2f9cc853b8 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -2185,7 +2185,7 @@ pub type Iterate<'a, T> = Unfold<'a, T, IterateState<'a, T>>; /// Creates a new iterator that produces an infinite sequence of /// repeated applications of the given function `f`. #[allow(visible_private_types)] -pub fn iterate<'a, T: Clone>(f: |T|: 'a -> T, seed: T) -> Iterate<'a, T> { +pub fn iterate<'a, T: Clone>(seed: T, f: |T|: 'a -> T) -> Iterate<'a, T> { Unfold::new((f, Some(seed), true), |st| { let &(ref mut f, ref mut val, ref mut first) = st; if *first { diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 836285bc3135a..94febf0363594 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -55,6 +55,8 @@ * */ +use kinds::Sized; + /** * * The `Drop` trait is used to run some code when a value goes out of scope. This @@ -700,7 +702,7 @@ pub trait IndexMut { * ``` */ #[lang="deref"] -pub trait Deref { +pub trait Deref { /// The method called to dereference a value fn deref<'a>(&'a self) -> &'a Result; } @@ -740,7 +742,7 @@ pub trait Deref { * ``` */ #[lang="deref_mut"] -pub trait DerefMut: Deref { +pub trait DerefMut: Deref { /// The method called to mutably dereference a value fn deref_mut<'a>(&'a mut self) -> &'a mut Result; } diff --git a/src/libcoretest/any.rs b/src/libcoretest/any.rs index fae4a26cd3863..9656a6caba08c 100644 --- a/src/libcoretest/any.rs +++ b/src/libcoretest/any.rs @@ -51,22 +51,22 @@ fn any_owning() { } #[test] -fn any_as_ref() { +fn any_downcast_ref() { let a = &5u as &Any; - match a.as_ref::() { + match a.downcast_ref::() { Some(&5) => {} x => fail!("Unexpected value {}", x) } - match a.as_ref::() { + match a.downcast_ref::() { None => {} x => fail!("Unexpected value {}", x) } } #[test] -fn any_as_mut() { +fn any_downcast_mut() { let mut a = 5u; let mut b = box 7u; @@ -74,7 +74,7 @@ fn any_as_mut() { let tmp: &mut uint = &mut *b; let b_r = tmp as &mut Any; - match a_r.as_mut::() { + match a_r.downcast_mut::() { Some(x) => { assert_eq!(*x, 5u); *x = 612; @@ -82,7 +82,7 @@ fn any_as_mut() { x => fail!("Unexpected value {}", x) } - match b_r.as_mut::() { + match b_r.downcast_mut::() { Some(x) => { assert_eq!(*x, 7u); *x = 413; @@ -90,22 +90,22 @@ fn any_as_mut() { x => fail!("Unexpected value {}", x) } - match a_r.as_mut::() { + match a_r.downcast_mut::() { None => (), x => fail!("Unexpected value {}", x) } - match b_r.as_mut::() { + match b_r.downcast_mut::() { None => (), x => fail!("Unexpected value {}", x) } - match a_r.as_mut::() { + match a_r.downcast_mut::() { Some(&612) => {} x => fail!("Unexpected value {}", x) } - match b_r.as_mut::() { + match b_r.downcast_mut::() { Some(&413) => {} x => fail!("Unexpected value {}", x) } @@ -121,11 +121,11 @@ fn any_fixed_vec() { #[bench] -fn bench_as_ref(b: &mut Bencher) { +fn bench_downcast_ref(b: &mut Bencher) { b.iter(|| { let mut x = 0i; let mut y = &mut x as &mut Any; test::black_box(&mut y); - test::black_box(y.as_ref::() == Some(&0)); + test::black_box(y.downcast_ref::() == Some(&0)); }); } diff --git a/src/libcoretest/iter.rs b/src/libcoretest/iter.rs index 99ac7cfed027f..9b703a18caee9 100644 --- a/src/libcoretest/iter.rs +++ b/src/libcoretest/iter.rs @@ -839,7 +839,7 @@ fn test_min_max_result() { #[test] fn test_iterate() { - let mut it = iterate(|x| x * 2, 1u); + let mut it = iterate(1u, |x| x * 2); assert_eq!(it.next(), Some(1u)); assert_eq!(it.next(), Some(2u)); assert_eq!(it.next(), Some(4u)); diff --git a/src/libcoretest/option.rs b/src/libcoretest/option.rs index 2dad9fc3a22c4..6e5bf6e8f2dac 100644 --- a/src/libcoretest/option.rs +++ b/src/libcoretest/option.rs @@ -131,6 +131,7 @@ fn test_or_else() { } #[test] +#[allow(deprecated)] fn test_option_while_some() { let mut i = 0i; Some(10i).while_some(|j| { @@ -184,6 +185,7 @@ fn test_unwrap_or_else() { } #[test] +#[allow(deprecated)] fn test_filtered() { let some_stuff = Some(42i); let modified_stuff = some_stuff.filtered(|&x| {x < 10}); @@ -256,6 +258,7 @@ fn test_mutate() { } #[test] +#[allow(deprecated)] fn test_collect() { let v: Option> = collect(range(0i, 0) .map(|_| Some(0i))); diff --git a/src/libcoretest/result.rs b/src/libcoretest/result.rs index 7c7e0a542cd87..dbc393967d3e5 100644 --- a/src/libcoretest/result.rs +++ b/src/libcoretest/result.rs @@ -69,6 +69,7 @@ pub fn test_impl_map_err() { } #[test] +#[allow(deprecated)] fn test_collect() { let v: Result, ()> = collect(range(0i, 0).map(|_| Ok::(0))); assert!(v == Ok(vec![])); diff --git a/src/libdebug/repr.rs b/src/libdebug/repr.rs index 1f66d0352da59..7fe6f2dbf67d2 100644 --- a/src/libdebug/repr.rs +++ b/src/libdebug/repr.rs @@ -568,6 +568,7 @@ pub fn repr_to_string(t: &T) -> String { } #[cfg(test)] +#[allow(dead_code)] struct P {a: int, b: f64} #[test] diff --git a/src/libgraphviz/lib.rs b/src/libgraphviz/lib.rs index d8325e05cdf4c..ea298f5e05f71 100644 --- a/src/libgraphviz/lib.rs +++ b/src/libgraphviz/lib.rs @@ -632,9 +632,9 @@ mod tests { id_name(n) } fn node_label(&'a self, n: &Node) -> LabelText<'a> { - match self.node_labels.get(*n) { - &Some(ref l) => LabelStr(str::Slice(l.as_slice())), - &None => LabelStr(id_name(n).name()), + match self.node_labels[*n] { + Some(ref l) => LabelStr(str::Slice(l.as_slice())), + None => LabelStr(id_name(n).name()), } } fn edge_label(&'a self, e: & &'a Edge) -> LabelText<'a> { diff --git a/src/libgreen/sched.rs b/src/libgreen/sched.rs index 084a66fdddf15..1075466d099f9 100644 --- a/src/libgreen/sched.rs +++ b/src/libgreen/sched.rs @@ -1414,6 +1414,7 @@ mod test { // Regression test that the `start` task entrypoint can // contain dtors that use task resources run(proc() { + #[allow(dead_code)] struct S { field: () } impl Drop for S { diff --git a/src/libnative/io/file_unix.rs b/src/libnative/io/file_unix.rs index 136652f3ebfc9..bc1d877dc547b 100644 --- a/src/libnative/io/file_unix.rs +++ b/src/libnative/io/file_unix.rs @@ -11,12 +11,10 @@ //! Blocking posix-based file I/O use alloc::arc::Arc; -use libc::{c_int, c_void}; -use libc; +use libc::{mod, c_int, c_void}; use std::c_str::CString; use std::mem; -use std::rt::rtio; -use std::rt::rtio::IoResult; +use std::rt::rtio::{mod, IoResult}; use io::{retry, keep_going}; use io::util; @@ -55,7 +53,7 @@ impl FileDesc { let ret = retry(|| unsafe { libc::read(self.fd(), buf.as_mut_ptr() as *mut libc::c_void, - buf.len() as libc::size_t) as libc::c_int + buf.len() as libc::size_t) }); if ret == 0 { Err(util::eof()) @@ -93,7 +91,7 @@ impl rtio::RtioFileStream for FileDesc { match retry(|| unsafe { libc::pread(self.fd(), buf.as_ptr() as *mut _, buf.len() as libc::size_t, - offset as libc::off_t) as libc::c_int + offset as libc::off_t) }) { -1 => Err(super::last_error()), n => Ok(n as int) @@ -103,7 +101,7 @@ impl rtio::RtioFileStream for FileDesc { super::mkerr_libc(retry(|| unsafe { libc::pwrite(self.fd(), buf.as_ptr() as *const _, buf.len() as libc::size_t, offset as libc::off_t) - } as c_int)) + })) } fn seek(&mut self, pos: i64, whence: rtio::SeekStyle) -> IoResult { let whence = match whence { diff --git a/src/libnative/io/mod.rs b/src/libnative/io/mod.rs index 276194feaf0e3..7881e088388ca 100644 --- a/src/libnative/io/mod.rs +++ b/src/libnative/io/mod.rs @@ -23,12 +23,11 @@ #![allow(non_snake_case)] -use libc::c_int; -use libc; +use libc::{mod, c_int}; use std::c_str::CString; use std::os; -use std::rt::rtio; -use std::rt::rtio::{IoResult, IoError}; +use std::rt::rtio::{mod, IoResult, IoError}; +use std::num; // Local re-exports pub use self::file::FileDesc; @@ -97,8 +96,8 @@ fn last_error() -> IoError { } // unix has nonzero values as errors -fn mkerr_libc(ret: libc::c_int) -> IoResult<()> { - if ret != 0 { +fn mkerr_libc (ret: Int) -> IoResult<()> { + if !ret.is_zero() { Err(last_error()) } else { Ok(()) @@ -117,39 +116,33 @@ fn mkerr_winbool(ret: libc::c_int) -> IoResult<()> { #[cfg(windows)] #[inline] -fn retry(f: || -> libc::c_int) -> libc::c_int { - loop { - match f() { - -1 if os::errno() as int == libc::WSAEINTR as int => {} - n => return n, - } - } -} +fn retry (f: || -> I) -> I { f() } // PR rust-lang/rust/#17020 #[cfg(unix)] #[inline] -fn retry(f: || -> libc::c_int) -> libc::c_int { +fn retry> (f: || -> I) -> I { + let minus_one = -num::one::(); loop { - match f() { - -1 if os::errno() as int == libc::EINTR as int => {} - n => return n, - } + let n = f(); + if n == minus_one && os::errno() == libc::EINTR as int { } + else { return n } } } + fn keep_going(data: &[u8], f: |*const u8, uint| -> i64) -> i64 { let origamt = data.len(); let mut data = data.as_ptr(); let mut amt = origamt; while amt > 0 { - let ret = retry(|| f(data, amt) as libc::c_int); + let ret = retry(|| f(data, amt)); if ret == 0 { break } else if ret != -1 { amt -= ret as uint; data = unsafe { data.offset(ret as int) }; } else { - return ret as i64; + return ret; } } return (origamt - amt) as i64; diff --git a/src/libnative/io/net.rs b/src/libnative/io/net.rs index 1a7a8da391a4a..ba951cdef26b9 100644 --- a/src/libnative/io/net.rs +++ b/src/libnative/io/net.rs @@ -13,8 +13,7 @@ use libc; use std::mem; use std::ptr; use std::rt::mutex; -use std::rt::rtio; -use std::rt::rtio::{IoResult, IoError}; +use std::rt::rtio::{mod, IoResult, IoError}; use std::sync::atomic; use super::{retry, keep_going}; @@ -988,9 +987,7 @@ pub fn write(fd: sock_t, write(false, inner, len) }); } else { - ret = retry(|| { - write(false, buf.as_ptr(), buf.len()) as libc::c_int - }) as i64; + ret = retry(|| { write(false, buf.as_ptr(), buf.len()) }); if ret > 0 { written = ret as uint; } } } @@ -1017,7 +1014,7 @@ pub fn write(fd: sock_t, let _guard = lock(); let ptr = buf.slice_from(written).as_ptr(); let len = buf.len() - written; - match retry(|| write(deadline.is_some(), ptr, len) as libc::c_int) { + match retry(|| write(deadline.is_some(), ptr, len)) { -1 if util::wouldblock() => {} -1 => return Err(os::last_error()), n => { written += n as uint; } diff --git a/src/libnum/bigint.rs b/src/libnum/bigint.rs index 39e21cfc48664..c97f9513fc34a 100644 --- a/src/libnum/bigint.rs +++ b/src/libnum/bigint.rs @@ -1978,10 +1978,10 @@ mod biguint_tests { #[test] fn test_checked_add() { for elm in sum_triples.iter() { - let (aVec, bVec, cVec) = *elm; - let a = BigUint::from_slice(aVec); - let b = BigUint::from_slice(bVec); - let c = BigUint::from_slice(cVec); + let (a_vec, b_vec, c_vec) = *elm; + let a = BigUint::from_slice(a_vec); + let b = BigUint::from_slice(b_vec); + let c = BigUint::from_slice(c_vec); assert!(a.checked_add(&b).unwrap() == c); assert!(b.checked_add(&a).unwrap() == c); @@ -1991,10 +1991,10 @@ mod biguint_tests { #[test] fn test_checked_sub() { for elm in sum_triples.iter() { - let (aVec, bVec, cVec) = *elm; - let a = BigUint::from_slice(aVec); - let b = BigUint::from_slice(bVec); - let c = BigUint::from_slice(cVec); + let (a_vec, b_vec, c_vec) = *elm; + let a = BigUint::from_slice(a_vec); + let b = BigUint::from_slice(b_vec); + let c = BigUint::from_slice(c_vec); assert!(c.checked_sub(&a).unwrap() == b); assert!(c.checked_sub(&b).unwrap() == a); @@ -2011,21 +2011,21 @@ mod biguint_tests { #[test] fn test_checked_mul() { for elm in mul_triples.iter() { - let (aVec, bVec, cVec) = *elm; - let a = BigUint::from_slice(aVec); - let b = BigUint::from_slice(bVec); - let c = BigUint::from_slice(cVec); + let (a_vec, b_vec, c_vec) = *elm; + let a = BigUint::from_slice(a_vec); + let b = BigUint::from_slice(b_vec); + let c = BigUint::from_slice(c_vec); assert!(a.checked_mul(&b).unwrap() == c); assert!(b.checked_mul(&a).unwrap() == c); } for elm in div_rem_quadruples.iter() { - let (aVec, bVec, cVec, dVec) = *elm; - let a = BigUint::from_slice(aVec); - let b = BigUint::from_slice(bVec); - let c = BigUint::from_slice(cVec); - let d = BigUint::from_slice(dVec); + let (a_vec, b_vec, c_vec, d_vec) = *elm; + let a = BigUint::from_slice(a_vec); + let b = BigUint::from_slice(b_vec); + let c = BigUint::from_slice(c_vec); + let d = BigUint::from_slice(d_vec); assert!(a == b.checked_mul(&c).unwrap() + d); assert!(a == c.checked_mul(&b).unwrap() + d); @@ -2035,10 +2035,10 @@ mod biguint_tests { #[test] fn test_checked_div() { for elm in mul_triples.iter() { - let (aVec, bVec, cVec) = *elm; - let a = BigUint::from_slice(aVec); - let b = BigUint::from_slice(bVec); - let c = BigUint::from_slice(cVec); + let (a_vec, b_vec, c_vec) = *elm; + let a = BigUint::from_slice(a_vec); + let b = BigUint::from_slice(b_vec); + let c = BigUint::from_slice(c_vec); if !a.is_zero() { assert!(c.checked_div(&a).unwrap() == b); @@ -2651,10 +2651,10 @@ mod bigint_tests { #[test] fn test_checked_add() { for elm in sum_triples.iter() { - let (aVec, bVec, cVec) = *elm; - let a = BigInt::from_slice(Plus, aVec); - let b = BigInt::from_slice(Plus, bVec); - let c = BigInt::from_slice(Plus, cVec); + let (a_vec, b_vec, c_vec) = *elm; + let a = BigInt::from_slice(Plus, a_vec); + let b = BigInt::from_slice(Plus, b_vec); + let c = BigInt::from_slice(Plus, c_vec); assert!(a.checked_add(&b).unwrap() == c); assert!(b.checked_add(&a).unwrap() == c); @@ -2670,10 +2670,10 @@ mod bigint_tests { #[test] fn test_checked_sub() { for elm in sum_triples.iter() { - let (aVec, bVec, cVec) = *elm; - let a = BigInt::from_slice(Plus, aVec); - let b = BigInt::from_slice(Plus, bVec); - let c = BigInt::from_slice(Plus, cVec); + let (a_vec, b_vec, c_vec) = *elm; + let a = BigInt::from_slice(Plus, a_vec); + let b = BigInt::from_slice(Plus, b_vec); + let c = BigInt::from_slice(Plus, c_vec); assert!(c.checked_sub(&a).unwrap() == b); assert!(c.checked_sub(&b).unwrap() == a); @@ -2689,10 +2689,10 @@ mod bigint_tests { #[test] fn test_checked_mul() { for elm in mul_triples.iter() { - let (aVec, bVec, cVec) = *elm; - let a = BigInt::from_slice(Plus, aVec); - let b = BigInt::from_slice(Plus, bVec); - let c = BigInt::from_slice(Plus, cVec); + let (a_vec, b_vec, c_vec) = *elm; + let a = BigInt::from_slice(Plus, a_vec); + let b = BigInt::from_slice(Plus, b_vec); + let c = BigInt::from_slice(Plus, c_vec); assert!(a.checked_mul(&b).unwrap() == c); assert!(b.checked_mul(&a).unwrap() == c); @@ -2702,11 +2702,11 @@ mod bigint_tests { } for elm in div_rem_quadruples.iter() { - let (aVec, bVec, cVec, dVec) = *elm; - let a = BigInt::from_slice(Plus, aVec); - let b = BigInt::from_slice(Plus, bVec); - let c = BigInt::from_slice(Plus, cVec); - let d = BigInt::from_slice(Plus, dVec); + let (a_vec, b_vec, c_vec, d_vec) = *elm; + let a = BigInt::from_slice(Plus, a_vec); + let b = BigInt::from_slice(Plus, b_vec); + let c = BigInt::from_slice(Plus, c_vec); + let d = BigInt::from_slice(Plus, d_vec); assert!(a == b.checked_mul(&c).unwrap() + d); assert!(a == c.checked_mul(&b).unwrap() + d); @@ -2715,10 +2715,10 @@ mod bigint_tests { #[test] fn test_checked_div() { for elm in mul_triples.iter() { - let (aVec, bVec, cVec) = *elm; - let a = BigInt::from_slice(Plus, aVec); - let b = BigInt::from_slice(Plus, bVec); - let c = BigInt::from_slice(Plus, cVec); + let (a_vec, b_vec, c_vec) = *elm; + let a = BigInt::from_slice(Plus, a_vec); + let b = BigInt::from_slice(Plus, b_vec); + let c = BigInt::from_slice(Plus, c_vec); if !a.is_zero() { assert!(c.checked_div(&a).unwrap() == b); diff --git a/src/librbml/lib.rs b/src/librbml/lib.rs index 933f2b223e9ec..6171a9946b608 100644 --- a/src/librbml/lib.rs +++ b/src/librbml/lib.rs @@ -1047,10 +1047,7 @@ mod tests { use serialize::{Encodable, Decodable}; - use std::io::{IoError, IoResult, SeekStyle}; - use std::io; use std::option::{None, Option, Some}; - use std::slice; #[test] fn test_vuint_at() { diff --git a/src/librlibc/lib.rs b/src/librlibc/lib.rs index d51d5a0aef2e1..2ab7a6c52fac3 100644 --- a/src/librlibc/lib.rs +++ b/src/librlibc/lib.rs @@ -108,8 +108,6 @@ pub unsafe extern "C" fn memcmp(s1: *const u8, s2: *const u8, n: uint) -> i32 { #[cfg(test)] mod test { - use core::option::{Some, None}; - use core::iter::Iterator; use core::collections::Collection; use core::str::StrSlice; use core::slice::{MutableSlice, ImmutableSlice}; diff --git a/src/librustc/front/feature_gate.rs b/src/librustc/front/feature_gate.rs index 2305434726599..c83b81660d58f 100644 --- a/src/librustc/front/feature_gate.rs +++ b/src/librustc/front/feature_gate.rs @@ -69,6 +69,7 @@ static KNOWN_FEATURES: &'static [(&'static str, Status)] = &[ ("rustc_diagnostic_macros", Active), ("unboxed_closures", Active), ("import_shadowing", Active), + ("advanced_slice_patterns", Active), // if you change this list without updating src/doc/rust.md, cmr will be sad @@ -364,6 +365,20 @@ impl<'a> Visitor<()> for Context<'a> { } } + fn visit_pat(&mut self, pattern: &ast::Pat, (): ()) { + match pattern.node { + ast::PatVec(_, Some(_), ref last) if !last.is_empty() => { + self.gate_feature("advanced_slice_patterns", + pattern.span, + "multiple-element slice matches anywhere \ + but at the end of a slice (e.g. \ + `[0, ..xs, 0]` are experimental") + } + _ => {} + } + visit::walk_pat(self, pattern, ()) + } + fn visit_fn(&mut self, fn_kind: &visit::FnKind, fn_decl: &ast::FnDecl, diff --git a/src/librustc/front/test.rs b/src/librustc/front/test.rs index 13f6243fb7ba7..63e93d266c770 100644 --- a/src/librustc/front/test.rs +++ b/src/librustc/front/test.rs @@ -96,7 +96,7 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> { // Add a special __test module to the crate that will contain code // generated for the test harness - let (mod_, reexport) = mk_test_module(&self.cx, &self.cx.reexport_test_harness_main); + let (mod_, reexport) = mk_test_module(&mut self.cx); folded.module.items.push(mod_); match reexport { Some(re) => folded.module.view_items.push(re), @@ -378,8 +378,7 @@ fn mk_std(cx: &TestCtxt) -> ast::ViewItem { } } -fn mk_test_module(cx: &TestCtxt, reexport_test_harness_main: &Option) - -> (Gc, Option) { +fn mk_test_module(cx: &mut TestCtxt) -> (Gc, Option) { // Link to test crate let view_items = vec!(mk_std(cx)); @@ -388,7 +387,7 @@ fn mk_test_module(cx: &TestCtxt, reexport_test_harness_main: &Option = __test::main` let reexport_ident = token::str_to_ident(s.get()); diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index c3c4cf51f5775..721e5f296e2e7 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -172,33 +172,24 @@ impl LintPass for TypeLimits { ast::ExprLit(lit) => { match ty::get(ty::expr_ty(cx.tcx, e)).sty { ty::ty_int(t) => { - let int_type = if t == ast::TyI { - cx.sess().targ_cfg.int_type - } else { t }; - let (min, max) = int_ty_range(int_type); - let mut lit_val: i64 = match lit.node { + match lit.node { ast::LitInt(v, ast::SignedIntLit(_, ast::Plus)) | ast::LitInt(v, ast::UnsuffixedIntLit(ast::Plus)) => { - if v > i64::MAX as u64{ + let int_type = if t == ast::TyI { + cx.sess().targ_cfg.int_type + } else { t }; + let (min, max) = int_ty_range(int_type); + let negative = self.negated_expr_id == e.id; + + if (negative && v > (min.abs() as u64)) || + (!negative && v > (max.abs() as u64)) { cx.span_lint(TYPE_OVERFLOW, e.span, "literal out of range for its type"); return; } - v as i64 - } - ast::LitInt(v, ast::SignedIntLit(_, ast::Minus)) | - ast::LitInt(v, ast::UnsuffixedIntLit(ast::Minus)) => { - -(v as i64) } _ => fail!() }; - if self.negated_expr_id == e.id { - lit_val *= -1; - } - if lit_val < min || lit_val > max { - cx.span_lint(TYPE_OVERFLOW, e.span, - "literal out of range for its type"); - } }, ty::ty_uint(t) => { let uint_type = if t == ast::TyU { diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index 0e64be3d0b70b..b7597b50b4906 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -1951,7 +1951,7 @@ fn roundtrip(in_item: Option>) { #[test] fn test_basic() { let cx = mk_ctxt(); - roundtrip(quote_item!(cx, + roundtrip(quote_item!(&cx, fn foo() {} )); } @@ -1959,7 +1959,7 @@ fn test_basic() { #[test] fn test_smalltalk() { let cx = mk_ctxt(); - roundtrip(quote_item!(cx, + roundtrip(quote_item!(&cx, fn foo() -> int { 3 + 4 } // first smalltalk program ever executed. )); } @@ -1968,7 +1968,7 @@ fn test_smalltalk() { #[test] fn test_more() { let cx = mk_ctxt(); - roundtrip(quote_item!(cx, + roundtrip(quote_item!(&cx, fn foo(x: uint, y: uint) -> uint { let z = x + y; return z; @@ -1987,7 +1987,7 @@ fn test_simplification() { ).unwrap(); let item_in = e::IIItemRef(&*item); let item_out = simplify_ast(item_in); - let item_exp = ast::IIItem(quote_item!(cx, + let item_exp = ast::IIItem(quote_item!(&cx, fn new_int_alist() -> alist { return alist {eq_fn: eq_int, data: Vec::new()}; } diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index e853b5961ec4f..605c90a49c667 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -500,42 +500,44 @@ pub fn eval_const_expr_partial(tcx: &ty::ctxt, e: &Expr) -> Result base, - Ok(val) => { - match ty::get(ety).sty { - ty::ty_float(_) => { - match val { - const_bool(b) => Ok(const_float(b as f64)), - const_uint(u) => Ok(const_float(u as f64)), - const_int(i) => Ok(const_float(i as f64)), - const_float(f) => Ok(const_float(f)), - _ => Err("can't cast this type to float".to_string()), - } + macro_rules! define_casts( + ($val:ident, { + $($ty_pat:pat => ( + $intermediate_ty:ty, + $const_type:ident, + $target_ty:ty + )),* + }) => (match ty::get(ety).sty { + $($ty_pat => { + match $val { + const_bool(b) => Ok($const_type(b as $intermediate_ty as $target_ty)), + const_uint(u) => Ok($const_type(u as $intermediate_ty as $target_ty)), + const_int(i) => Ok($const_type(i as $intermediate_ty as $target_ty)), + const_float(f) => Ok($const_type(f as $intermediate_ty as $target_ty)), + _ => Err(concat!( + "can't cast this type to ", stringify!($const_type) + ).to_string()) } - ty::ty_uint(_) => { - match val { - const_bool(b) => Ok(const_uint(b as u64)), - const_uint(u) => Ok(const_uint(u)), - const_int(i) => Ok(const_uint(i as u64)), - const_float(f) => Ok(const_uint(f as u64)), - _ => Err("can't cast this type to uint".to_string()), - } - } - ty::ty_int(_) => { - match val { - const_bool(b) => Ok(const_int(b as i64)), - const_uint(u) => Ok(const_int(u as i64)), - const_int(i) => Ok(const_int(i)), - const_float(f) => Ok(const_int(f as i64)), - _ => Err("can't cast this type to int".to_string()), - } - } - _ => Err("can't cast this type".to_string()) - } - } - } + },)* + _ => Err("can't cast this type".to_string()) + }) + ) + + eval_const_expr_partial(tcx, &**base) + .and_then(|val| define_casts!(val, { + ty::ty_int(ast::TyI) => (int, const_int, i64), + ty::ty_int(ast::TyI8) => (i8, const_int, i64), + ty::ty_int(ast::TyI16) => (i16, const_int, i64), + ty::ty_int(ast::TyI32) => (i32, const_int, i64), + ty::ty_int(ast::TyI64) => (i64, const_int, i64), + ty::ty_uint(ast::TyU) => (uint, const_uint, u64), + ty::ty_uint(ast::TyU8) => (u8, const_uint, u64), + ty::ty_uint(ast::TyU16) => (u16, const_uint, u64), + ty::ty_uint(ast::TyU32) => (u32, const_uint, u64), + ty::ty_uint(ast::TyU64) => (u64, const_uint, u64), + ty::ty_float(ast::TyF32) => (f32, const_float, f64), + ty::ty_float(ast::TyF64) => (f64, const_float, f64) + })) } ExprPath(_) => { match lookup_const(tcx, e) { diff --git a/src/librustc/middle/kind.rs b/src/librustc/middle/kind.rs index e556c5a59c224..e8b0afa98c2d0 100644 --- a/src/librustc/middle/kind.rs +++ b/src/librustc/middle/kind.rs @@ -199,6 +199,15 @@ fn check_item(cx: &mut Context, item: &Item) { cx, item.span, &*trait_ref); + + let trait_def = ty::lookup_trait_def(cx.tcx, trait_ref.def_id); + for (ty, type_param_def) in trait_ref.substs.types + .iter() + .zip(trait_def.generics + .types + .iter()) { + check_typaram_bounds(cx, item.span, *ty, type_param_def); + } } } } diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 0c8697d31f3c9..854b8b9ba7711 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -1549,18 +1549,13 @@ impl<'a> Resolver<'a> { PathListMod { .. } => Some(item.span), _ => None }).collect::>(); - match mod_spans.as_slice() { - [first, second, ..other] => { - self.resolve_error(first, - "`mod` import can only appear once in the list"); - self.session.span_note(second, - "another `mod` import appears here"); - for &other_span in other.iter() { - self.session.span_note(other_span, - "another `mod` import appears here"); - } - }, - [_] | [] => () + if mod_spans.len() > 1 { + self.resolve_error(mod_spans[0], + "`mod` import can only appear once in the list"); + for other_span in mod_spans.iter().skip(1) { + self.session.span_note(*other_span, + "another `mod` import appears here"); + } } for source_item in source_items.iter() { @@ -3936,6 +3931,7 @@ impl<'a> Resolver<'a> { item.id, ItemRibKind), |this| { + this.resolve_type_parameters(&generics.ty_params); visit::walk_item(this, item, ()); }); } diff --git a/src/librustc/middle/typeck/check/regionck.rs b/src/librustc/middle/typeck/check/regionck.rs index eb630d0fc7bbe..c08401375ca7d 100644 --- a/src/librustc/middle/typeck/check/regionck.rs +++ b/src/librustc/middle/typeck/check/regionck.rs @@ -769,6 +769,10 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) { } rcx.visit_expr(&**head, ()); + type_of_node_must_outlive(rcx, + infer::AddrOf(expr.span), + head.id, + ty::ReScope(expr.id)); let repeating_scope = rcx.set_repeating_scope(body.id); rcx.visit_block(&**body, ()); diff --git a/src/librustc/middle/typeck/collect.rs b/src/librustc/middle/typeck/collect.rs index 742d22cc3793f..d1d76734941e8 100644 --- a/src/librustc/middle/typeck/collect.rs +++ b/src/librustc/middle/typeck/collect.rs @@ -488,7 +488,9 @@ pub fn ensure_no_ty_param_bounds(ccx: &CrateCtxt, generics: &ast::Generics, thing: &'static str) { for ty_param in generics.ty_params.iter() { - for bound in ty_param.bounds.iter() { + let bounds = ty_param.bounds.iter(); + let mut bounds = bounds.chain(ty_param.unbound.iter()); + for bound in bounds { match *bound { ast::TraitTyParamBound(..) | ast::UnboxedFnTyParamBound(..) => { // According to accepted RFC #XXX, we should @@ -1076,9 +1078,10 @@ fn add_unsized_bound(ccx: &CrateCtxt, desc: &str, span: Span) { let kind_id = ccx.tcx.lang_items.require(SizedTraitLangItem); + match unbound { &Some(ast::TraitTyParamBound(ref tpb)) => { - // #FIXME(8559) currently requires the unbound to be built-in. + // FIXME(#8559) currently requires the unbound to be built-in. let trait_def_id = ty::trait_ref_to_def_id(ccx.tcx, tpb); match kind_id { Ok(kind_id) if trait_def_id != kind_id => { diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index 305c18480f669..86f56660d3a64 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -153,27 +153,17 @@ local_data_key!(test_idx: Cell) local_data_key!(pub playground_krate: Option) pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result { - extern fn block(ob: *mut hoedown_buffer, text: *const hoedown_buffer, + extern fn block(ob: *mut hoedown_buffer, orig_text: *const hoedown_buffer, lang: *const hoedown_buffer, opaque: *mut libc::c_void) { unsafe { - if text.is_null() { return } + if orig_text.is_null() { return } let opaque = opaque as *mut hoedown_html_renderer_state; let my_opaque: &MyOpaque = &*((*opaque).opaque as *const MyOpaque); - slice::raw::buf_as_slice((*text).data, (*text).size as uint, |text| { + slice::raw::buf_as_slice((*orig_text).data, (*orig_text).size as uint, + |text| { let origtext = str::from_utf8(text).unwrap(); debug!("docblock: ==============\n{}\n=======", text); - let mut lines = origtext.lines().filter(|l| { - stripped_filtered_line(*l).is_none() - }); - let text = lines.collect::>().connect("\n"); - - let buf = hoedown_buffer { - data: text.as_bytes().as_ptr(), - size: text.len() as libc::size_t, - asize: text.len() as libc::size_t, - unit: 0, - }; let rendered = if lang.is_null() { false } else { @@ -181,7 +171,7 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result { (*lang).size as uint, |rlang| { let rlang = str::from_utf8(rlang).unwrap(); if LangString::parse(rlang).notrust { - (my_opaque.dfltblk)(ob, &buf, lang, + (my_opaque.dfltblk)(ob, orig_text, lang, opaque as *mut libc::c_void); true } else { @@ -190,6 +180,10 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result { }) }; + let mut lines = origtext.lines().filter(|l| { + stripped_filtered_line(*l).is_none() + }); + let text = lines.collect::>().connect("\n"); if !rendered { let mut s = String::new(); let id = playground_krate.get().map(|krate| { diff --git a/src/librustrt/c_str.rs b/src/librustrt/c_str.rs index 000def0cc3b62..5e0004f2a2a3e 100644 --- a/src/librustrt/c_str.rs +++ b/src/librustrt/c_str.rs @@ -671,7 +671,7 @@ mod tests { #[test] #[should_fail] fn test_new_fail() { - let c_str = unsafe { CString::new(ptr::null(), false) }; + let _c_str = unsafe { CString::new(ptr::null(), false) }; } #[test] diff --git a/src/librustrt/task.rs b/src/librustrt/task.rs index 9d921943313d8..3d42b91fef17e 100644 --- a/src/librustrt/task.rs +++ b/src/librustrt/task.rs @@ -662,7 +662,7 @@ mod test { #[test] fn block_and_wake() { let task = box Task::new(); - let mut task = BlockedTask::block(task).wake().unwrap(); + let task = BlockedTask::block(task).wake().unwrap(); task.drop(); } } diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index b29200597aa1c..733bc593922de 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -2128,7 +2128,15 @@ impl ::Decoder for Decoder { let mut obj = try!(expect!(self.pop(), Object)); let value = match obj.pop(&name.to_string()) { - None => return Err(MissingFieldError(name.to_string())), + None => { + // Add a Null and try to parse it as an Option<_> + // to get None as a default value. + self.stack.push(Null); + match f(self) { + Ok(x) => x, + Err(_) => return Err(MissingFieldError(name.to_string())), + } + }, Some(json) => { self.stack.push(json); try!(f(self)) @@ -2167,6 +2175,7 @@ impl ::Decoder for Decoder { } fn read_option(&mut self, f: |&mut Decoder, bool| -> DecodeResult) -> DecodeResult { + debug!("read_option()"); match self.pop() { Null => f(self, false), value => { self.stack.push(value); f(self, true) } @@ -2372,6 +2381,33 @@ mod tests { use std::{i64, u64, f32, f64, io}; use std::collections::TreeMap; + #[deriving(Decodable, Eq, PartialEq, Show)] + struct OptionData { + opt: Option, + } + + #[test] + fn test_decode_option_none() { + let s ="{}"; + let obj: OptionData = super::decode(s).unwrap(); + assert_eq!(obj, OptionData { opt: None }); + } + + #[test] + fn test_decode_option_some() { + let s = "{ \"opt\": 10 }"; + let obj: OptionData = super::decode(s).unwrap(); + assert_eq!(obj, OptionData { opt: Some(10u) }); + } + + #[test] + fn test_decode_option_malformed() { + check_err::("{ \"opt\": [] }", + ExpectedError("Number".to_string(), "[]".to_string())); + check_err::("{ \"opt\": false }", + ExpectedError("Number".to_string(), "false".to_string())); + } + #[deriving(PartialEq, Encodable, Decodable, Show)] enum Animal { Dog, diff --git a/src/libsync/spsc_queue.rs b/src/libsync/spsc_queue.rs index 32b77be78a438..cb4d33049d84f 100644 --- a/src/libsync/spsc_queue.rs +++ b/src/libsync/spsc_queue.rs @@ -298,7 +298,7 @@ mod test { use native; - use super::{queue, Queue}; + use super::{queue}; #[test] fn smoke() { diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index 0c41db7ecd685..808e671f868d3 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -766,7 +766,9 @@ fn expand_wrapper(cx: &ExtCtxt, cx.view_use_glob(sp, ast::Inherited, ids_ext(path)) }).collect(); - let stmt_let_ext_cx = cx.stmt_let(sp, false, id_ext("ext_cx"), cx_expr); + // Explicitly borrow to avoid moving from the invoker (#16992) + let cx_expr_borrow = cx.expr_addr_of(sp, cx.expr_deref(sp, cx_expr)); + let stmt_let_ext_cx = cx.stmt_let(sp, false, id_ext("ext_cx"), cx_expr_borrow); cx.expr_block(cx.block_all(sp, uses, vec!(stmt_let_ext_cx), Some(expr))) } diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index 5273addf4f57d..ec6fd013d08ae 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -35,6 +35,7 @@ pub enum ObsoleteSyntax { ObsoleteManagedType, ObsoleteManagedExpr, ObsoleteImportRenaming, + ObsoleteSubsliceMatch, } pub trait ParserObsoleteMethods { @@ -87,6 +88,10 @@ impl<'a> ParserObsoleteMethods for parser::Parser<'a> { ObsoleteImportRenaming => ( "`use foo = bar` syntax", "write `use bar as foo` instead" + ), + ObsoleteSubsliceMatch => ( + "subslice match syntax", + "instead of `..xs`, write `xs..` in a pattern" ) }; diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 936cabc54d178..6aff1152f7e1d 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2858,43 +2858,42 @@ impl<'a> Parser<'a> { let mut before_slice = true; while self.token != token::RBRACKET { - if first { first = false; } - else { self.expect(&token::COMMA); } + if first { + first = false; + } else { + self.expect(&token::COMMA); + } - let mut is_slice = false; if before_slice { if self.token == token::DOTDOT { self.bump(); - is_slice = true; - before_slice = false; - } - } - if is_slice { - if self.token == token::COMMA || self.token == token::RBRACKET { - slice = Some(box(GC) ast::Pat { - id: ast::DUMMY_NODE_ID, - node: PatWild(PatWildMulti), - span: self.span, - }) - } else { - let subpat = self.parse_pat(); - match *subpat { - ast::Pat { node: PatIdent(_, _, _), .. } => { - slice = Some(subpat); - } - ast::Pat { span, .. } => self.span_fatal( - span, "expected an identifier or nothing" - ) + if self.token == token::COMMA || + self.token == token::RBRACKET { + slice = Some(box(GC) ast::Pat { + id: ast::DUMMY_NODE_ID, + node: PatWild(PatWildMulti), + span: self.span, + }); + before_slice = false; + } else { + let _ = self.parse_pat(); + let span = self.span; + self.obsolete(span, ObsoleteSubsliceMatch); } + continue } + } + + let subpat = self.parse_pat(); + if before_slice && self.token == token::DOTDOT { + self.bump(); + slice = Some(subpat); + before_slice = false; + } else if before_slice { + before.push(subpat); } else { - let subpat = self.parse_pat(); - if before_slice { - before.push(subpat); - } else { - after.push(subpat); - } + after.push(subpat); } } @@ -3065,7 +3064,11 @@ impl<'a> Parser<'a> { // These expressions are limited to literals (possibly // preceded by unary-minus) or identifiers. let val = self.parse_literal_maybe_minus(); - if self.eat(&token::DOTDOT) { + if self.token == token::DOTDOT && + self.look_ahead(1, |t| { + *t != token::COMMA && *t != token::RBRACKET + }) { + self.bump(); let end = if is_ident_or_path(&self.token) { let path = self.parse_path(LifetimeAndTypesWithColons) .path; @@ -3106,7 +3109,10 @@ impl<'a> Parser<'a> { } }); - if self.look_ahead(1, |t| *t == token::DOTDOT) { + if self.look_ahead(1, |t| *t == token::DOTDOT) && + self.look_ahead(2, |t| { + *t != token::COMMA && *t != token::RBRACKET + }) { let start = self.parse_expr_res(RESTRICT_NO_BAR_OP); self.eat(&token::DOTDOT); let end = self.parse_expr_res(RESTRICT_NO_BAR_OP); diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index d5bc1bfe956fb..eaeb6aaab8a75 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1912,13 +1912,13 @@ impl<'a> State<'a> { |s, p| s.print_pat(&**p))); for p in slice.iter() { if !before.is_empty() { try!(self.word_space(",")); } + try!(self.print_pat(&**p)); match **p { ast::Pat { node: ast::PatWild(ast::PatWildMulti), .. } => { // this case is handled by print_pat } _ => try!(word(&mut self.s, "..")), } - try!(self.print_pat(&**p)); if !after.is_empty() { try!(self.word_space(",")); } } try!(self.commasep(Inconsistent, diff --git a/src/libuuid/lib.rs b/src/libuuid/lib.rs index 98dd129f3d251..09dc8166908d9 100644 --- a/src/libuuid/lib.rs +++ b/src/libuuid/lib.rs @@ -527,7 +527,6 @@ mod uuidtest { use super::{Uuid, VariantMicrosoft, VariantNCS, VariantRFC4122, Version1Mac, Version2Dce, Version3Md5, Version4Random, Version5Sha1}; - use std::io::MemWriter; use std::rand; #[test] @@ -798,7 +797,6 @@ mod uuidtest { #[test] fn test_serialize_round_trip() { use serialize::json; - use serialize::{Encodable, Decodable}; let u = Uuid::new_v4(); let s = json::encode(&u); @@ -809,7 +807,7 @@ mod uuidtest { #[test] fn test_bad_decode() { use serialize::json; - use serialize::{Encodable, Decodable}; + use serialize::{Decodable}; let js_good = json::String("a1a2a3a4a5a6a7a8a1a2a3a4a5a6a7a8".to_string()); let js_bad1 = json::String("a1a2a3a4a5a6a7a8a1a2a3a4a5a6a7ah".to_string()); diff --git a/src/test/bench/shootout-chameneos-redux.rs b/src/test/bench/shootout-chameneos-redux.rs index 0c76d14852e08..05ecb9def9b5c 100644 --- a/src/test/bench/shootout-chameneos-redux.rs +++ b/src/test/bench/shootout-chameneos-redux.rs @@ -1,12 +1,42 @@ -// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. +// The Computer Language Benchmarks Game +// http://benchmarksgame.alioth.debian.org/ // -// 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. +// contributed by the Rust Project Developers + +// Copyright (c) 2012-2014 The Rust Project Developers +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// - Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// - Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in +// the documentation and/or other materials provided with the +// distribution. +// +// - Neither the name of "The Computer Language Benchmarks Game" nor +// the name of "The Computer Language Shootout Benchmarks" nor the +// names of its contributors may be used to endorse or promote +// products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +// OF THE POSSIBILITY OF SUCH DAMAGE. // no-pretty-expanded diff --git a/src/test/bench/shootout-nbody.rs b/src/test/bench/shootout-nbody.rs index 5a077b377475c..9e30a51247719 100644 --- a/src/test/bench/shootout-nbody.rs +++ b/src/test/bench/shootout-nbody.rs @@ -1,12 +1,42 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. +// The Computer Language Benchmarks Game +// http://benchmarksgame.alioth.debian.org/ // -// 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. +// contributed by the Rust Project Developers + +// Copyright (c) 2011-2014 The Rust Project Developers +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// - Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// - Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in +// the documentation and/or other materials provided with the +// distribution. +// +// - Neither the name of "The Computer Language Benchmarks Game" nor +// the name of "The Computer Language Shootout Benchmarks" nor the +// names of its contributors may be used to endorse or promote +// products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +// OF THE POSSIBILITY OF SUCH DAMAGE. static PI: f64 = 3.141592653589793; static SOLAR_MASS: f64 = 4.0 * PI * PI; diff --git a/src/test/bench/shootout-reverse-complement.rs b/src/test/bench/shootout-reverse-complement.rs index fdd711d22c760..52defe6a2767d 100644 --- a/src/test/bench/shootout-reverse-complement.rs +++ b/src/test/bench/shootout-reverse-complement.rs @@ -1,12 +1,42 @@ -// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. +// The Computer Language Benchmarks Game +// http://benchmarksgame.alioth.debian.org/ // -// 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. +// contributed by the Rust Project Developers + +// Copyright (c) 2013-2014 The Rust Project Developers +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// - Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// - Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in +// the documentation and/or other materials provided with the +// distribution. +// +// - Neither the name of "The Computer Language Benchmarks Game" nor +// the name of "The Computer Language Shootout Benchmarks" nor the +// names of its contributors may be used to endorse or promote +// products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +// OF THE POSSIBILITY OF SUCH DAMAGE. // ignore-pretty very bad with line comments // ignore-android doesn't terminate? diff --git a/src/test/compile-fail/borrowck-for-loop-head-linkage.rs b/src/test/compile-fail/borrowck-for-loop-head-linkage.rs new file mode 100644 index 0000000000000..600c0ac801b7e --- /dev/null +++ b/src/test/compile-fail/borrowck-for-loop-head-linkage.rs @@ -0,0 +1,19 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + let mut vector = vec![1u, 2]; + for &x in vector.iter() { + let cap = vector.capacity(); + vector.grow(cap, &0u); //~ ERROR cannot borrow + *vector.get_mut(1u) = 5u; //~ ERROR cannot borrow + } +} + diff --git a/src/test/compile-fail/borrowck-move-out-of-vec-tail.rs b/src/test/compile-fail/borrowck-move-out-of-vec-tail.rs index d87557a46f753..d3c6a280e8c2a 100644 --- a/src/test/compile-fail/borrowck-move-out-of-vec-tail.rs +++ b/src/test/compile-fail/borrowck-move-out-of-vec-tail.rs @@ -25,7 +25,7 @@ pub fn main() { ); let x: &[Foo] = x.as_slice(); match x { - [_, ..tail] => { + [_, tail..] => { match tail { [Foo { string: a }, //~ ERROR cannot move out of dereference of `&`-pointer Foo { string: b }] => { diff --git a/src/test/compile-fail/borrowck-vec-pattern-element-loan.rs b/src/test/compile-fail/borrowck-vec-pattern-element-loan.rs index 53ebaa38fddba..d256b033298ed 100644 --- a/src/test/compile-fail/borrowck-vec-pattern-element-loan.rs +++ b/src/test/compile-fail/borrowck-vec-pattern-element-loan.rs @@ -8,11 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(advanced_slice_patterns)] + fn a<'a>() -> &'a [int] { let vec = vec!(1, 2, 3, 4); let vec: &[int] = vec.as_slice(); //~ ERROR does not live long enough let tail = match vec { - [_, ..tail] => tail, + [_, tail..] => tail, _ => fail!("a") }; tail @@ -22,7 +24,7 @@ fn b<'a>() -> &'a [int] { let vec = vec!(1, 2, 3, 4); let vec: &[int] = vec.as_slice(); //~ ERROR does not live long enough let init = match vec { - [..init, _] => init, + [init.., _] => init, _ => fail!("b") }; init @@ -32,7 +34,7 @@ fn c<'a>() -> &'a [int] { let vec = vec!(1, 2, 3, 4); let vec: &[int] = vec.as_slice(); //~ ERROR does not live long enough let slice = match vec { - [_, ..slice, _] => slice, + [_, slice.., _] => slice, _ => fail!("c") }; slice diff --git a/src/test/compile-fail/borrowck-vec-pattern-loan-from-mut.rs b/src/test/compile-fail/borrowck-vec-pattern-loan-from-mut.rs index 393ec8b0b1b3b..cc1dbc8195543 100644 --- a/src/test/compile-fail/borrowck-vec-pattern-loan-from-mut.rs +++ b/src/test/compile-fail/borrowck-vec-pattern-loan-from-mut.rs @@ -12,7 +12,7 @@ fn a() { let mut v = vec!(1, 2, 3); let vb: &mut [int] = v.as_mut_slice(); match vb { - [_a, ..tail] => { + [_a, tail..] => { v.push(tail[0] + tail[1]); //~ ERROR cannot borrow } _ => {} diff --git a/src/test/compile-fail/borrowck-vec-pattern-move-tail.rs b/src/test/compile-fail/borrowck-vec-pattern-move-tail.rs index 7b092d16eec69..cb8762f44fb79 100644 --- a/src/test/compile-fail/borrowck-vec-pattern-move-tail.rs +++ b/src/test/compile-fail/borrowck-vec-pattern-move-tail.rs @@ -11,7 +11,7 @@ fn main() { let mut a = [1i, 2, 3, 4]; let t = match a { - [1, 2, ..tail] => tail, + [1, 2, tail..] => tail, _ => unreachable!() }; a[0] = 0; //~ ERROR cannot assign to `a[..]` because it is borrowed diff --git a/src/test/compile-fail/borrowck-vec-pattern-nesting.rs b/src/test/compile-fail/borrowck-vec-pattern-nesting.rs index 4a56f9821065b..2eec788785605 100644 --- a/src/test/compile-fail/borrowck-vec-pattern-nesting.rs +++ b/src/test/compile-fail/borrowck-vec-pattern-nesting.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(advanced_slice_patterns)] fn a() { let mut vec = [box 1i, box 2, box 3]; @@ -22,7 +23,7 @@ fn b() { let mut vec = vec!(box 1i, box 2, box 3); let vec: &mut [Box] = vec.as_mut_slice(); match vec { - [.._b] => { + [_b..] => { vec[0] = box 4; //~ ERROR cannot assign } } @@ -33,7 +34,7 @@ fn c() { let vec: &mut [Box] = vec.as_mut_slice(); match vec { [_a, //~ ERROR cannot move out - .._b] => { //~^ NOTE attempting to move value to here + _b..] => { //~^ NOTE attempting to move value to here // Note: `_a` is *moved* here, but `b` is borrowing, // hence illegal. @@ -50,7 +51,7 @@ fn d() { let mut vec = vec!(box 1i, box 2, box 3); let vec: &mut [Box] = vec.as_mut_slice(); match vec { - [.._a, //~ ERROR cannot move out + [_a.., //~ ERROR cannot move out _b] => {} //~ NOTE attempting to move value to here _ => {} } diff --git a/src/test/compile-fail/borrowck-vec-pattern-tail-element-loan.rs b/src/test/compile-fail/borrowck-vec-pattern-tail-element-loan.rs index 57a276bec81bc..2c9cf7d1b65be 100644 --- a/src/test/compile-fail/borrowck-vec-pattern-tail-element-loan.rs +++ b/src/test/compile-fail/borrowck-vec-pattern-tail-element-loan.rs @@ -12,7 +12,7 @@ fn a<'a>() -> &'a int { let vec = vec!(1, 2, 3, 4); let vec: &[int] = vec.as_slice(); //~ ERROR `vec` does not live long enough let tail = match vec { - [_a, ..tail] => &tail[0], + [_a, tail..] => &tail[0], _ => fail!("foo") }; tail diff --git a/src/test/compile-fail/feature-gate-advanced-slice-features.rs b/src/test/compile-fail/feature-gate-advanced-slice-features.rs new file mode 100644 index 0000000000000..97d593d310e13 --- /dev/null +++ b/src/test/compile-fail/feature-gate-advanced-slice-features.rs @@ -0,0 +1,19 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + let x = [ 1i, 2, 3, 4, 5 ]; + match x { + [ xs.., 4, 5 ] => {} //~ ERROR multiple-element slice matches + [ 1, xs.., 5 ] => {} //~ ERROR multiple-element slice matches + [ 1, 2, xs.. ] => {} // OK without feature gate + } +} + diff --git a/src/test/compile-fail/generic-lifetime-trait-impl.rs b/src/test/compile-fail/generic-lifetime-trait-impl.rs new file mode 100644 index 0000000000000..8b52324848bf4 --- /dev/null +++ b/src/test/compile-fail/generic-lifetime-trait-impl.rs @@ -0,0 +1,30 @@ +// Copyright 2012 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. + +// This code used to produce an ICE on the definition of trait Bar +// with the following message: +// +// Type parameter out of range when substituting in region 'a (root +// type=fn(Self) -> 'astr) (space=FnSpace, index=0) +// +// Regression test for issue #16218. + +trait Bar<'a> {} + +trait Foo<'a> { + fn bar<'a, T: Bar<'a>>(self) -> &'a str; +} + +impl<'a> Foo<'a> for &'a str { + fn bar>(self) -> &'a str { fail!() } //~ ERROR lifetime +} + +fn main() { +} diff --git a/src/test/compile-fail/issue-12369.rs b/src/test/compile-fail/issue-12369.rs index 7d800899e5209..4522b536ffd34 100644 --- a/src/test/compile-fail/issue-12369.rs +++ b/src/test/compile-fail/issue-12369.rs @@ -13,7 +13,7 @@ fn main() { let v: int = match sl.as_slice() { [] => 0, [a,b,c] => 3, - [a, ..rest] => a, - [10,a, ..rest] => 10 //~ ERROR: unreachable pattern + [a, rest..] => a, + [10,a, rest..] => 10 //~ ERROR: unreachable pattern }; } diff --git a/src/test/compile-fail/issue-12567.rs b/src/test/compile-fail/issue-12567.rs index d5a8339ba1938..26866cbbc6033 100644 --- a/src/test/compile-fail/issue-12567.rs +++ b/src/test/compile-fail/issue-12567.rs @@ -11,10 +11,10 @@ fn match_vecs<'a, T>(l1: &'a [T], l2: &'a [T]) { match (l1, l2) { ([], []) => println!("both empty"), - ([], [hd, ..tl]) | ([hd, ..tl], []) => println!("one empty"), + ([], [hd, tl..]) | ([hd, tl..], []) => println!("one empty"), //~^ ERROR: cannot move out of dereference //~^^ ERROR: cannot move out of dereference - ([hd1, ..tl1], [hd2, ..tl2]) => println!("both nonempty"), + ([hd1, tl1..], [hd2, tl2..]) => println!("both nonempty"), //~^ ERROR: cannot move out of dereference //~^^ ERROR: cannot move out of dereference } diff --git a/src/test/compile-fail/lint-type-overflow.rs b/src/test/compile-fail/lint-type-overflow.rs index c8179c3adb039..81b186a2998a8 100644 --- a/src/test/compile-fail/lint-type-overflow.rs +++ b/src/test/compile-fail/lint-type-overflow.rs @@ -49,6 +49,7 @@ fn main() { let x = -2147483649_i32; //~ error: literal out of range for its type let x = 9223372036854775808_i64; //~ error: literal out of range for its type + let x = -9223372036854775808_i64; // should be OK let x = 18446744073709551615_i64; //~ error: literal out of range for its type let x = -3.40282348e+38_f32; //~ error: literal out of range for its type diff --git a/src/test/compile-fail/match-vec-invalid.rs b/src/test/compile-fail/match-vec-invalid.rs index 389e26aa400dc..51e83c14aa008 100644 --- a/src/test/compile-fail/match-vec-invalid.rs +++ b/src/test/compile-fail/match-vec-invalid.rs @@ -11,7 +11,7 @@ fn main() { let a = Vec::new(); match a { - [1, ..tail, ..tail] => {}, //~ ERROR: unexpected token: `..` + [1, tail.., tail..] => {}, //~ ERROR: expected `,`, found `..` _ => () } } diff --git a/src/test/compile-fail/match-vec-unreachable.rs b/src/test/compile-fail/match-vec-unreachable.rs index a94b070964638..a85ce660e8b1f 100644 --- a/src/test/compile-fail/match-vec-unreachable.rs +++ b/src/test/compile-fail/match-vec-unreachable.rs @@ -31,7 +31,7 @@ fn main() { let x: Vec = vec!('a', 'b', 'c'); let x: &[char] = x.as_slice(); match x { - ['a', 'b', 'c', .._tail] => {} + ['a', 'b', 'c', _tail..] => {} ['a', 'b', 'c'] => {} //~ ERROR unreachable pattern _ => {} } diff --git a/src/test/compile-fail/non-exhaustive-match.rs b/src/test/compile-fail/non-exhaustive-match.rs index 4de4af877127d..ae5f40d4874c9 100644 --- a/src/test/compile-fail/non-exhaustive-match.rs +++ b/src/test/compile-fail/non-exhaustive-match.rs @@ -38,14 +38,14 @@ fn main() { let vec = vec!(Some(42i), None, Some(21i)); let vec: &[Option] = vec.as_slice(); match vec { //~ ERROR non-exhaustive patterns: `[]` not covered - [Some(..), None, ..tail] => {} - [Some(..), Some(..), ..tail] => {} + [Some(..), None, tail..] => {} + [Some(..), Some(..), tail..] => {} [None] => {} } let vec = vec!(1i); let vec: &[int] = vec.as_slice(); match vec { - [_, ..tail] => (), + [_, tail..] => (), [] => () } let vec = vec!(0.5f32); @@ -59,10 +59,10 @@ fn main() { let vec = vec!(Some(42i), None, Some(21i)); let vec: &[Option] = vec.as_slice(); match vec { - [Some(..), None, ..tail] => {} - [Some(..), Some(..), ..tail] => {} - [None, None, ..tail] => {} - [None, Some(..), ..tail] => {} + [Some(..), None, tail..] => {} + [Some(..), Some(..), tail..] => {} + [None, None, tail..] => {} + [None, Some(..), tail..] => {} [Some(_)] => {} [None] => {} [] => {} diff --git a/src/test/compile-fail/non-exhaustive-pattern-witness.rs b/src/test/compile-fail/non-exhaustive-pattern-witness.rs index 6dc5ad8b606c3..b7ff3a18fcf7a 100644 --- a/src/test/compile-fail/non-exhaustive-pattern-witness.rs +++ b/src/test/compile-fail/non-exhaustive-pattern-witness.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(struct_variant)] +#![feature(advanced_slice_patterns, struct_variant)] struct Foo { first: bool, @@ -63,7 +63,7 @@ fn vectors_with_nested_enums() { [Second(true), First] => (), [Second(true), Second(true)] => (), [Second(false), _] => (), - [_, _, ..tail, _] => () + [_, _, tail.., _] => () } } diff --git a/src/test/compile-fail/unsized3.rs b/src/test/compile-fail/unsized3.rs index cf42e79b3941e..f71afeb1b308f 100644 --- a/src/test/compile-fail/unsized3.rs +++ b/src/test/compile-fail/unsized3.rs @@ -57,20 +57,18 @@ fn f9(x1: Box>, x2: Box>) { //~^ ERROR instantiating a type parameter with an incompatible type } -// I would like these to fail eventually. -/* // impl - bounded trait T1 { } struct S3; -impl T1 for S3 { //ERROR instantiating a type parameter with an incompatible type +impl T1 for S3 { //~ ERROR instantiating a type parameter with an incompatible } // impl - unbounded trait T2 { } -impl T2 for S3 { //ERROR instantiating a type parameter with an incompatible type `X -*/ +impl T2 for S3 { //~ ERROR instantiating a type parameter with an incompatible type +} // impl - struct trait T3 { diff --git a/src/test/compile-fail/vec-matching-obsolete-syntax.rs b/src/test/compile-fail/vec-matching-obsolete-syntax.rs new file mode 100644 index 0000000000000..6330aac2d8b75 --- /dev/null +++ b/src/test/compile-fail/vec-matching-obsolete-syntax.rs @@ -0,0 +1,22 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + let x = [1i, 2, 3]; + match x { + [a, b, ..c] => { //~ ERROR obsolete syntax + assert_eq!(a, 1); + assert_eq!(b, 2); + let expected: &[_] = &[3]; + assert_eq!(c, expected); + } + } +} + diff --git a/src/test/run-pass-fulldeps/issue-16992.rs b/src/test/run-pass-fulldeps/issue-16992.rs new file mode 100644 index 0000000000000..563b839496325 --- /dev/null +++ b/src/test/run-pass-fulldeps/issue-16992.rs @@ -0,0 +1,26 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// ignore-pretty +// ignore-android + +#![feature(quote)] + +extern crate syntax; + +use syntax::ext::base::ExtCtxt; + +#[allow(dead_code)] +fn foobar(cx: &mut ExtCtxt) { + quote_expr!(cx, 1i); + quote_expr!(cx, 2i); +} + +fn main() { } diff --git a/src/test/run-pass/borrowck-trait-lifetime.rs b/src/test/run-pass/borrowck-trait-lifetime.rs new file mode 100644 index 0000000000000..b39f03a93c9fe --- /dev/null +++ b/src/test/run-pass/borrowck-trait-lifetime.rs @@ -0,0 +1,21 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// This test verifies that casting from the same lifetime on a value +// to the same lifetime on a trait succeeds. See issue #10766. + +#![allow(dead_code)] +fn main() { + trait T {} + + fn f<'a, V: T>(v: &'a V) -> &'a T { + v as &'a T + } +} diff --git a/src/test/run-pass/for-loop-does-not-borrow-iterators.rs b/src/test/run-pass/for-loop-does-not-borrow-iterators.rs deleted file mode 100644 index 206ab0dfeb2d0..0000000000000 --- a/src/test/run-pass/for-loop-does-not-borrow-iterators.rs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - - -// The `for` loop use to keep a mutable borrow when executing its body, -// making it impossible to re-use the iterator as follows. -// https://github.com/rust-lang/rust/issues/8372 -// -// This was fixed in https://github.com/rust-lang/rust/pull/15809 - -pub fn main() { - let mut for_loop_values = Vec::new(); - let mut explicit_next_call_values = Vec::new(); - - let mut iter = range(1i, 10); - for i in iter { - for_loop_values.push(i); - explicit_next_call_values.push(iter.next()); - } - - assert_eq!(for_loop_values, vec![1, 3, 5, 7, 9]); - assert_eq!(explicit_next_call_values, vec![Some(2), Some(4), Some(6), Some(8), None]); -} diff --git a/src/test/run-pass/ignore-all-the-things.rs b/src/test/run-pass/ignore-all-the-things.rs index 27c63d425bf38..1c87b6dad8970 100644 --- a/src/test/run-pass/ignore-all-the-things.rs +++ b/src/test/run-pass/ignore-all-the-things.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(advanced_slice_patterns)] + struct Foo(int, int, int, int); struct Bar{a: int, b: int, c: int, d: int} diff --git a/src/test/run-pass/issue-15080.rs b/src/test/run-pass/issue-15080.rs index 444e8bd37707e..1709321a71cfd 100644 --- a/src/test/run-pass/issue-15080.rs +++ b/src/test/run-pass/issue-15080.rs @@ -14,11 +14,11 @@ fn main() { let mut result = vec!(); loop { x = match x { - [1, n, 3, ..rest] => { + [1, n, 3, rest..] => { result.push(n); rest } - [n, ..rest] => { + [n, rest..] => { result.push(n); rest } diff --git a/src/test/run-pass/issue-15104.rs b/src/test/run-pass/issue-15104.rs index d2711339ccbd4..c6c9e8004558c 100644 --- a/src/test/run-pass/issue-15104.rs +++ b/src/test/run-pass/issue-15104.rs @@ -16,6 +16,6 @@ fn count_members(v: &[uint]) -> uint { match v { [] => 0, [_] => 1, - [_x, ..xs] => 1 + count_members(xs) + [_x, xs..] => 1 + count_members(xs) } } diff --git a/src/test/run-pass/issue-17074.rs b/src/test/run-pass/issue-17074.rs new file mode 100644 index 0000000000000..e346148691d86 --- /dev/null +++ b/src/test/run-pass/issue-17074.rs @@ -0,0 +1,20 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +static X: u64 = -1 as u16 as u64; +static Y: u64 = -1 as u32 as u64; + +fn main() { + assert_eq!(match 1 { + X => unreachable!(), + Y => unreachable!(), + _ => 1i + }, 1); +} diff --git a/src/test/run-pass/issue-7784.rs b/src/test/run-pass/issue-7784.rs index d307a05703843..666847517efde 100644 --- a/src/test/run-pass/issue-7784.rs +++ b/src/test/run-pass/issue-7784.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(advanced_slice_patterns)] + fn foo + Clone>([x, y, z]: [T, ..3]) -> (T, T, T) { (x.clone(), x.clone() + y.clone(), x + y + z) } @@ -29,7 +31,7 @@ fn main() { assert_eq!(d, "baz"); let out = bar("baz", "foo"); - let [a, ..xs, d] = out; + let [a, xs.., d] = out; assert_eq!(a, "baz"); assert!(xs == ["foo", "foo"]); assert_eq!(d, "baz"); diff --git a/src/test/run-pass/match-vec-alternatives.rs b/src/test/run-pass/match-vec-alternatives.rs index de1bb02bfefc6..ae4fd1f1993b7 100644 --- a/src/test/run-pass/match-vec-alternatives.rs +++ b/src/test/run-pass/match-vec-alternatives.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(advanced_slice_patterns)] + fn match_vecs<'a, T>(l1: &'a [T], l2: &'a [T]) -> &'static str { match (l1, l2) { ([], []) => "both empty", diff --git a/src/test/run-pass/unboxed-closures-unique-type-id.rs b/src/test/run-pass/unboxed-closures-unique-type-id.rs new file mode 100644 index 0000000000000..55d89d4e4f689 --- /dev/null +++ b/src/test/run-pass/unboxed-closures-unique-type-id.rs @@ -0,0 +1,34 @@ +// Copyright 2012 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. +// +// This code used to produce the following ICE: +// +// error: internal compiler error: get_unique_type_id_of_type() - +// unexpected type: closure, +// ty_unboxed_closure(syntax::ast::DefId{krate: 0u32, node: 66u32}, +// ReScope(63u32)) +// +// This is a regression test for issue #17021. + +#![feature(unboxed_closures, overloaded_calls)] + +use std::ptr; + +pub fn replace_map<'a, T, F>(src: &mut T, prod: F) +where F: |: T| -> T { + unsafe { *src = prod(ptr::read(src as *mut T as *const T)); } +} + +pub fn main() { + let mut a = 7u; + let b = &mut a; + replace_map(b, |: x: uint| x * 2); + assert_eq!(*b, 14u); +} diff --git a/src/test/run-pass/unsized.rs b/src/test/run-pass/unsized.rs index 0530c8a6ab3dd..141d6c88dd961 100644 --- a/src/test/run-pass/unsized.rs +++ b/src/test/run-pass/unsized.rs @@ -24,6 +24,7 @@ struct S1; enum E {} impl T1 for S1 {} fn f() {} +type TT = T; pub fn main() { } diff --git a/src/test/run-pass/vec-matching-fixed.rs b/src/test/run-pass/vec-matching-fixed.rs index 3e9d4b9fc3a24..a1a14823ff595 100644 --- a/src/test/run-pass/vec-matching-fixed.rs +++ b/src/test/run-pass/vec-matching-fixed.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(advanced_slice_patterns)] + fn a() { let x = [1i, 2, 3]; match x { diff --git a/src/test/run-pass/vec-matching-fold.rs b/src/test/run-pass/vec-matching-fold.rs index 07ee5f535e9ba..63914a8df31cd 100644 --- a/src/test/run-pass/vec-matching-fold.rs +++ b/src/test/run-pass/vec-matching-fold.rs @@ -8,12 +8,14 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(advanced_slice_patterns)] + fn foldl(values: &[T], initial: U, function: |partial: U, element: &T| -> U) -> U { match values { - [ref head, ..tail] => + [ref head, tail..] => foldl(tail, function(initial, head), function), [] => initial.clone() } @@ -24,7 +26,7 @@ fn foldr(values: &[T], function: |element: &T, partial: U| -> U) -> U { match values { - [..head, ref tail] => + [head.., ref tail] => foldr(head, function(tail, initial), function), [] => initial.clone() } diff --git a/src/test/run-pass/vec-matching-legal-tail-element-borrow.rs b/src/test/run-pass/vec-matching-legal-tail-element-borrow.rs index 2fd8a4ab256fd..a140399447b3b 100644 --- a/src/test/run-pass/vec-matching-legal-tail-element-borrow.rs +++ b/src/test/run-pass/vec-matching-legal-tail-element-borrow.rs @@ -13,7 +13,7 @@ pub fn main() { let x: &[int] = &[1, 2, 3, 4, 5]; if !x.is_empty() { let el = match x { - [1, ..ref tail] => &tail[0], + [1, ref tail..] => &tail[0], _ => unreachable!() }; println!("{}", *el); diff --git a/src/test/run-pass/vec-matching.rs b/src/test/run-pass/vec-matching.rs index e95495a42d282..187d97f483dda 100644 --- a/src/test/run-pass/vec-matching.rs +++ b/src/test/run-pass/vec-matching.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(advanced_slice_patterns)] + fn a() { let x = [1i]; match x { @@ -20,7 +22,7 @@ fn a() { fn b() { let x = [1i, 2, 3]; match x { - [a, b, ..c] => { + [a, b, c..] => { assert_eq!(a, 1); assert_eq!(b, 2); let expected: &[_] = &[3]; @@ -28,7 +30,7 @@ fn b() { } } match x { - [..a, b, c] => { + [a.., b, c] => { let expected: &[_] = &[1]; assert_eq!(a, expected); assert_eq!(b, 2); @@ -36,7 +38,7 @@ fn b() { } } match x { - [a, ..b, c] => { + [a, b.., c] => { assert_eq!(a, 1); let expected: &[_] = &[2]; assert_eq!(b, expected); diff --git a/src/test/run-pass/vec-tail-matching.rs b/src/test/run-pass/vec-tail-matching.rs index e58aebcddfe0e..a1a222549a086 100644 --- a/src/test/run-pass/vec-tail-matching.rs +++ b/src/test/run-pass/vec-tail-matching.rs @@ -20,14 +20,14 @@ pub fn main() { Foo { string: "baz".to_string() } ]; match x { - [ref first, ..tail] => { + [ref first, tail..] => { assert!(first.string == "foo".to_string()); assert_eq!(tail.len(), 2); assert!(tail[0].string == "bar".to_string()); assert!(tail[1].string == "baz".to_string()); match tail { - [Foo { .. }, _, Foo { .. }, .. _tail] => { + [Foo { .. }, _, Foo { .. }, _tail..] => { unreachable!(); } [Foo { string: ref a }, Foo { string: ref b }] => {