diff options
| author | bors <bors@rust-lang.org> | 2014-11-07 00:02:18 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-11-07 00:02:18 +0000 |
| commit | 45cbdec4174778bf915f17561ef971c068a7fcbc (patch) | |
| tree | 9516c60b7323f1233858665501a5029c9c3f90f0 /src/test | |
| parent | 8ed288edb27fc83b15a549af69c82b5bb4f8ac1e (diff) | |
| parent | d27039d701a3c6e97f19e41436d06ed42c0f5f8a (diff) | |
| download | rust-45cbdec4174778bf915f17561ef971c068a7fcbc.tar.gz rust-45cbdec4174778bf915f17561ef971c068a7fcbc.zip | |
auto merge of #18719 : alexcrichton/rust/rollup, r=alexcrichton
Diffstat (limited to 'src/test')
59 files changed, 786 insertions, 106 deletions
diff --git a/src/test/auxiliary/lint_stability.rs b/src/test/auxiliary/lint_stability.rs index 06031eb6c6c..0be2f31e282 100644 --- a/src/test/auxiliary/lint_stability.rs +++ b/src/test/auxiliary/lint_stability.rs @@ -118,6 +118,9 @@ pub trait Trait { impl Trait for MethodTester {} +#[experimental] +pub trait ExperimentalTrait {} + #[deprecated] pub struct DeprecatedStruct { pub i: int } #[experimental] diff --git a/src/test/bench/core-map.rs b/src/test/bench/core-map.rs index 3933a33446d..ac6104cc38b 100644 --- a/src/test/bench/core-map.rs +++ b/src/test/bench/core-map.rs @@ -30,18 +30,18 @@ trait MutableMap { impl MutableMap for TreeMap<uint, uint> { fn insert(&mut self, k: uint, v: uint) { self.insert(k, v); } - fn remove(&mut self, k: &uint) -> bool { self.remove(k) } - fn find(&self, k: &uint) -> Option<&uint> { self.find(k) } + fn remove(&mut self, k: &uint) -> bool { self.remove(k).is_some() } + fn find(&self, k: &uint) -> Option<&uint> { self.get(k) } } impl MutableMap for HashMap<uint, uint> { fn insert(&mut self, k: uint, v: uint) { self.insert(k, v); } - fn remove(&mut self, k: &uint) -> bool { self.remove(k) } - fn find(&self, k: &uint) -> Option<&uint> { self.find(k) } + fn remove(&mut self, k: &uint) -> bool { self.remove(k).is_some() } + fn find(&self, k: &uint) -> Option<&uint> { self.get(k) } } impl MutableMap for TrieMap<uint> { fn insert(&mut self, k: uint, v: uint) { self.insert(k, v); } - fn remove(&mut self, k: &uint) -> bool { self.remove(k) } - fn find(&self, k: &uint) -> Option<&uint> { self.find(k) } + fn remove(&mut self, k: &uint) -> bool { self.remove(k).is_some() } + fn find(&self, k: &uint) -> Option<&uint> { self.get(k) } } fn ascending<M: MutableMap>(map: &mut M, n_keys: uint) { diff --git a/src/test/bench/shootout-chameneos-redux.rs b/src/test/bench/shootout-chameneos-redux.rs index abcd9f90333..191f70ac492 100644 --- a/src/test/bench/shootout-chameneos-redux.rs +++ b/src/test/bench/shootout-chameneos-redux.rs @@ -197,8 +197,8 @@ fn rendezvous(nn: uint, set: Vec<Color>) { creatures_met += 2; - to_creature.get_mut(fst_creature.name).send(snd_creature); - to_creature.get_mut(snd_creature.name).send(fst_creature); + to_creature[fst_creature.name].send(snd_creature); + to_creature[snd_creature.name].send(fst_creature); } // tell each creature to stop diff --git a/src/test/bench/shootout-fasta-redux.rs b/src/test/bench/shootout-fasta-redux.rs index e151369ff38..0a3370fa487 100644 --- a/src/test/bench/shootout-fasta-redux.rs +++ b/src/test/bench/shootout-fasta-redux.rs @@ -100,7 +100,7 @@ fn sum_and_scale(a: &'static [AminoAcid]) -> Vec<AminoAcid> { result.push(a_i); } let result_len = result.len(); - result.get_mut(result_len - 1).p = LOOKUP_SCALE; + result[result_len - 1].p = LOOKUP_SCALE; result } diff --git a/src/test/bench/shootout-k-nucleotide.rs b/src/test/bench/shootout-k-nucleotide.rs index d0e6aacdbb2..6ada34a5a58 100644 --- a/src/test/bench/shootout-k-nucleotide.rs +++ b/src/test/bench/shootout-k-nucleotide.rs @@ -171,13 +171,13 @@ impl Table { next: None, }; c.f(&mut *entry); - *self.items.get_mut(index as uint) = Some(entry); + self.items[index as uint] = Some(entry); return; } } { - let entry = self.items.get_mut(index as uint).as_mut().unwrap(); + let entry = self.items[index as uint].as_mut().unwrap(); if entry.code == key { c.f(&mut **entry); return; diff --git a/src/test/bench/shootout-meteor.rs b/src/test/bench/shootout-meteor.rs index 47e1969172d..d8df3eea83b 100644 --- a/src/test/bench/shootout-meteor.rs +++ b/src/test/bench/shootout-meteor.rs @@ -194,7 +194,7 @@ fn is_board_unfeasible(board: u64, masks: &Vec<Vec<Vec<u64>>>) -> bool { fn filter_masks(masks: &mut Vec<Vec<Vec<u64>>>) { for i in range(0, masks.len()) { for j in range(0, (*masks)[i].len()) { - *masks.get_mut(i).get_mut(j) = + masks[i][j] = (*masks)[i][j].iter().map(|&m| m) .filter(|&m| !is_board_unfeasible(m, masks)) .collect(); @@ -217,7 +217,7 @@ fn to_vec(raw_sol: &List<u64>) -> Vec<u8> { let id = '0' as u8 + get_id(m); for i in range(0u, 50) { if m & 1 << i != 0 { - *sol.get_mut(i) = id; + sol[i] = id; } } } diff --git a/src/test/bench/shootout-regex-dna.rs b/src/test/bench/shootout-regex-dna.rs index dccdafe9cf8..81de7a12690 100644 --- a/src/test/bench/shootout-regex-dna.rs +++ b/src/test/bench/shootout-regex-dna.rs @@ -114,7 +114,7 @@ fn main() { } for (i, variant) in variant_strs.iter().enumerate() { - println!("{} {}", variant, counts.get_mut(i).get()); + println!("{} {}", variant, counts[i].get()); } println!(""); println!("{}", ilen); diff --git a/src/test/bench/shootout-reverse-complement.rs b/src/test/bench/shootout-reverse-complement.rs index 5ce1b2fc40d..d7d8e94c8a7 100644 --- a/src/test/bench/shootout-reverse-complement.rs +++ b/src/test/bench/shootout-reverse-complement.rs @@ -112,14 +112,15 @@ fn read_to_end<R: Reader>(r: &mut R) -> IoResult<Vec<u8>> { let mut vec = Vec::with_capacity(CHUNK); loop { // workaround: very fast growing - if vec.capacity() - vec.len() < CHUNK { + let len = vec.len(); + if vec.capacity() - len < CHUNK { let cap = vec.capacity(); let mult = if cap < 256 * 1024 * 1024 { 16 } else { 2 }; - vec.reserve_exact(mult * cap); + vec.reserve_exact(mult * cap - len); } match r.push_at_least(1, CHUNK, &mut vec) { Ok(_) => {} diff --git a/src/test/bench/sudoku.rs b/src/test/bench/sudoku.rs index ae7594ea8a2..54824d7259f 100644 --- a/src/test/bench/sudoku.rs +++ b/src/test/bench/sudoku.rs @@ -79,7 +79,7 @@ impl Sudoku { if comps.len() == 3u { let row = from_str::<uint>(comps[0]).unwrap() as u8; let col = from_str::<uint>(comps[1]).unwrap() as u8; - *g.get_mut(row as uint).get_mut(col as uint) = + g[row as uint][col as uint] = from_str::<uint>(comps[2]).unwrap() as u8; } else { @@ -139,10 +139,10 @@ impl Sudoku { // find first remaining color that is available let next = avail.next(); - *self.grid.get_mut(row as uint).get_mut(col as uint) = next; + self.grid[row as uint][col as uint] = next; return 0u8 != next; } - *self.grid.get_mut(row as uint).get_mut(col as uint) = 0u8; + self.grid[row as uint][col as uint] = 0u8; return false; } diff --git a/src/test/compile-fail/borrowck-assign-comp-idx.rs b/src/test/compile-fail/borrowck-assign-comp-idx.rs index 5bc2edba301..e14911d3508 100644 --- a/src/test/compile-fail/borrowck-assign-comp-idx.rs +++ b/src/test/compile-fail/borrowck-assign-comp-idx.rs @@ -19,7 +19,7 @@ fn a() { // Create an immutable pointer into p's contents: let q: &int = &p[0]; - *p.get_mut(0) = 5; //~ ERROR cannot borrow + p[0] = 5; //~ ERROR cannot borrow println!("{}", *q); } @@ -34,7 +34,7 @@ fn b() { borrow( p.as_slice(), - || *p.get_mut(0) = 5); //~ ERROR cannot borrow `p` as mutable + || p[0] = 5); //~ ERROR cannot borrow `p` as mutable } fn c() { @@ -42,7 +42,7 @@ fn c() { // modification: let mut p = vec!(1); borrow(p.as_slice(), ||{}); - *p.get_mut(0) = 5; + p[0] = 5; } fn main() { diff --git a/src/test/compile-fail/borrowck-for-loop-head-linkage.rs b/src/test/compile-fail/borrowck-for-loop-head-linkage.rs index cdfb384d47c..d7128105892 100644 --- a/src/test/compile-fail/borrowck-for-loop-head-linkage.rs +++ b/src/test/compile-fail/borrowck-for-loop-head-linkage.rs @@ -13,7 +13,7 @@ fn main() { for &x in vector.iter() { let cap = vector.capacity(); vector.grow(cap, 0u); //~ ERROR cannot borrow - *vector.get_mut(1u) = 5u; //~ ERROR cannot borrow + vector[1u] = 5u; //~ ERROR cannot borrow } } diff --git a/src/test/compile-fail/borrowck-loan-vec-content.rs b/src/test/compile-fail/borrowck-loan-vec-content.rs index 31b5c44df66..200d208d140 100644 --- a/src/test/compile-fail/borrowck-loan-vec-content.rs +++ b/src/test/compile-fail/borrowck-loan-vec-content.rs @@ -26,7 +26,7 @@ fn has_mut_vec_but_tries_to_change_it() { takes_imm_elt( &v[0], || { //~ ERROR cannot borrow `v` as mutable - *v.get_mut(1) = 4; + v[1] = 4; }) } diff --git a/src/test/compile-fail/issue-11382.rs b/src/test/compile-fail/issue-11382.rs new file mode 100644 index 00000000000..44f6cd7719d --- /dev/null +++ b/src/test/compile-fail/issue-11382.rs @@ -0,0 +1,16 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { +panic!( + 1.2 +//~^ ERROR cannot determine the type of this number; add a suffix to specify the type explicitly +); +} diff --git a/src/test/compile-fail/issue-11771.rs b/src/test/compile-fail/issue-11771.rs new file mode 100644 index 00000000000..7ce23e1f6ac --- /dev/null +++ b/src/test/compile-fail/issue-11771.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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + let x = (); + 1 + + x //~ ERROR mismatched types: expected `_`, found `()` (expected integral variable, found ()) + ; + + let x: () = (); + 1 + + x //~ ERROR mismatched types: expected `_`, found `()` (expected integral variable, found ()) + ; +} diff --git a/src/test/compile-fail/issue-13058.rs b/src/test/compile-fail/issue-13058.rs new file mode 100644 index 00000000000..5203c91237b --- /dev/null +++ b/src/test/compile-fail/issue-13058.rs @@ -0,0 +1,39 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use std::iter::{Range,range}; + +trait Itble<'r, T, I: Iterator<T>> { fn iter(&'r self) -> I; } + +impl<'r> Itble<'r, uint, Range<uint>> for (uint, uint) { + fn iter(&'r self) -> Range<uint> { + let &(min, max) = self; + range(min, max) + } +} + +fn check<'r, I: Iterator<uint>, T: Itble<'r, uint, I>>(cont: &T) -> bool +//~^ HELP as shown: fn check<'r, I: Iterator<uint>, T: Itble<'r, uint, I>>(cont: &'r T) -> bool +{ + let cont_iter = cont.iter(); +//~^ ERROR cannot infer an appropriate lifetime for autoref due to conflicting requirements + let result = cont_iter.fold(Some(0u16), |state, val| { + state.map_or(None, |mask| { + let bit = 1 << val; + if mask & bit == 0 {Some(mask|bit)} else {None} + }) + }); + result.is_some() +} + +fn main() { + check((3u, 5u)); +//~^ ERROR mismatched types: expected `&_`, found `(uint, uint)` (expected &-ptr, found tuple) +} diff --git a/src/test/compile-fail/issue-14092.rs b/src/test/compile-fail/issue-14092.rs index 4d663d00fb2..0ab37a88826 100644 --- a/src/test/compile-fail/issue-14092.rs +++ b/src/test/compile-fail/issue-14092.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn fn1(0: Box) {} //~ ERROR: not enough type parameters supplied to `Box<T>` +fn fn1(0: Box) {} //~ ERROR: wrong number of type arguments: expected 1, found 0 fn main() {} diff --git a/src/test/compile-fail/issue-18423.rs b/src/test/compile-fail/issue-18423.rs new file mode 100644 index 00000000000..63b110b5579 --- /dev/null +++ b/src/test/compile-fail/issue-18423.rs @@ -0,0 +1,18 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that `Box` cannot be used with a lifetime parameter. + +struct Foo<'a> { + x: Box<'a, int> //~ ERROR wrong number of lifetime parameters +} + +pub fn main() { +} diff --git a/src/test/compile-fail/issue-2718-a.rs b/src/test/compile-fail/issue-2718-a.rs index 41bdab0941e..3ba8dd4fefe 100644 --- a/src/test/compile-fail/issue-2718-a.rs +++ b/src/test/compile-fail/issue-2718-a.rs @@ -8,18 +8,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// ignore-test - pub struct send_packet<T> { - p: T + p: T } - mod pingpong { use send_packet; pub type ping = send_packet<pong>; pub struct pong(send_packet<ping>); - //~^ ERROR illegal recursive enum type; wrap the inner value in a box to make it representable + //~^ ERROR illegal recursive struct type; wrap the inner value in a box to make it representable } fn main() {} diff --git a/src/test/compile-fail/lint-stability.rs b/src/test/compile-fail/lint-stability.rs index babf12e97f2..2074d007502 100644 --- a/src/test/compile-fail/lint-stability.rs +++ b/src/test/compile-fail/lint-stability.rs @@ -141,6 +141,12 @@ mod cross_crate { foo.trait_unmarked(); //~ ERROR use of unmarked item foo.trait_stable(); } + + struct S; + + impl ExperimentalTrait for S { } //~ ERROR use of experimental item + + trait LocalTrait : ExperimentalTrait { } //~ ERROR use of experimental item } mod inheritance { @@ -444,6 +450,15 @@ mod this_crate { foo.trait_unmarked(); foo.trait_stable(); } + + #[deprecated] + pub trait DeprecatedTrait {} + + struct S; + + impl DeprecatedTrait for S { } //~ ERROR use of deprecated item + + trait LocalTrait : DeprecatedTrait { } //~ ERROR use of deprecated item } fn main() {} diff --git a/src/test/compile-fail/unboxed-closure-sugar-default.rs b/src/test/compile-fail/unboxed-closure-sugar-default.rs new file mode 100644 index 00000000000..9866a200045 --- /dev/null +++ b/src/test/compile-fail/unboxed-closure-sugar-default.rs @@ -0,0 +1,37 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test interaction between unboxed closure sugar and default type +// parameters (should be exactly as if angle brackets were used). + +#![feature(default_type_params)] +#![allow(dead_code)] + +struct Foo<T,U,V=T> { + t: T, u: U +} + +trait Eq<X> { } +impl<X> Eq<X> for X { } +fn eq<A,B:Eq<A>>() { } + +fn test<'a,'b>() { + // Parens are equivalent to omitting default in angle. + eq::< Foo<(int,),()>, Foo(int) >(); + + // In angle version, we supply something other than the default + eq::< Foo<(int,),(),int>, Foo(int) >(); + //~^ ERROR not implemented + + // Supply default explicitly. + eq::< Foo<(int,),(),(int,)>, Foo(int) >(); +} + +fn main() { } diff --git a/src/test/compile-fail/unboxed-closure-sugar-equiv.rs b/src/test/compile-fail/unboxed-closure-sugar-equiv.rs new file mode 100644 index 00000000000..c38010c1ee2 --- /dev/null +++ b/src/test/compile-fail/unboxed-closure-sugar-equiv.rs @@ -0,0 +1,39 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that the unboxed closure sugar can be used with an arbitrary +// struct type and that it is equivalent to the same syntax using +// angle brackets. This test covers only simple types and in +// particular doesn't test bound regions. + +#![allow(dead_code)] + +struct Foo<T,U> { + t: T, u: U +} + +trait Eq<X> { } +impl<X> Eq<X> for X { } +fn eq<A,B:Eq<A>>() { } + +fn test<'a,'b>() { + // No errors expected: + eq::< Foo<(),()>, Foo() >(); + eq::< Foo<(int,),()>, Foo(int) >(); + eq::< Foo<(int,uint),()>, Foo(int,uint) >(); + eq::< Foo<(int,uint),uint>, Foo(int,uint) -> uint >(); + eq::< Foo<(&'a int,&'b uint),uint>, Foo(&'a int,&'b uint) -> uint >(); + + // Errors expected: + eq::< Foo<(),()>, Foo(char) >(); + //~^ ERROR not implemented +} + +fn main() { } diff --git a/src/test/compile-fail/unboxed-closure-sugar-nonexistent-trait.rs b/src/test/compile-fail/unboxed-closure-sugar-nonexistent-trait.rs index f51160a1b23..d89c3802508 100644 --- a/src/test/compile-fail/unboxed-closure-sugar-nonexistent-trait.rs +++ b/src/test/compile-fail/unboxed-closure-sugar-nonexistent-trait.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn f<F:Nonexist(int) -> int>(x: F) {} //~ ERROR unresolved trait +fn f<F:Nonexist(int) -> int>(x: F) {} //~ ERROR nonexistent trait `Nonexist` type Typedef = int; diff --git a/src/test/compile-fail/unboxed-closure-sugar-region.rs b/src/test/compile-fail/unboxed-closure-sugar-region.rs new file mode 100644 index 00000000000..962e233dea6 --- /dev/null +++ b/src/test/compile-fail/unboxed-closure-sugar-region.rs @@ -0,0 +1,45 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test interaction between unboxed closure sugar and region +// parameters (should be exactly as if angle brackets were used +// and regions omitted). + +#![feature(default_type_params)] +#![allow(dead_code)] + +use std::kinds::marker; + +struct Foo<'a,T,U> { + t: T, + u: U, + m: marker::InvariantLifetime<'a> +} + +trait Eq<X> { } +impl<X> Eq<X> for X { } +fn eq<A,B:Eq<A>>() { } +fn same_type<A,B:Eq<A>>(a: A, b: B) { } + +fn test<'a,'b>() { + // Parens are equivalent to omitting default in angle. + eq::< Foo<(int,),()>, Foo(int) >(); + + // Here we specify 'static explicitly in angle-bracket version. + // Parenthesized winds up getting inferred. + eq::< Foo<'static, (int,),()>, Foo(int) >(); +} + +fn test2(x: Foo<(int,),()>, y: Foo(int)) { + // Here, the omitted lifetimes are expanded to distinct things. + same_type(x, y) //~ ERROR cannot infer +} + +fn main() { } diff --git a/src/test/compile-fail/unboxed-closure-sugar-wrong-number-number-type-parameters-1.rs b/src/test/compile-fail/unboxed-closure-sugar-wrong-number-number-type-parameters-1.rs new file mode 100644 index 00000000000..e122b87b1e0 --- /dev/null +++ b/src/test/compile-fail/unboxed-closure-sugar-wrong-number-number-type-parameters-1.rs @@ -0,0 +1,16 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +struct One<A>; + +fn foo(_: One()) //~ ERROR wrong number of type arguments +{} + +fn main() { } diff --git a/src/test/compile-fail/unboxed-closure-sugar-wrong-number-number-type-parameters-3.rs b/src/test/compile-fail/unboxed-closure-sugar-wrong-number-number-type-parameters-3.rs new file mode 100644 index 00000000000..7a66abb39df --- /dev/null +++ b/src/test/compile-fail/unboxed-closure-sugar-wrong-number-number-type-parameters-3.rs @@ -0,0 +1,16 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +struct Three<A,B,C>; + +fn foo(_: Three()) //~ ERROR wrong number of type arguments +{} + +fn main() { } diff --git a/src/test/compile-fail/unboxed-closure-sugar-wrong-number-number-type-parameters.rs b/src/test/compile-fail/unboxed-closure-sugar-wrong-number-number-type-parameters.rs new file mode 100644 index 00000000000..e265a3d56b8 --- /dev/null +++ b/src/test/compile-fail/unboxed-closure-sugar-wrong-number-number-type-parameters.rs @@ -0,0 +1,16 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +struct Zero; + +fn foo(_: Zero()) //~ ERROR wrong number of type arguments +{} + +fn main() { } diff --git a/src/test/compile-fail/unboxed-closure-sugar-wrong-trait.rs b/src/test/compile-fail/unboxed-closure-sugar-wrong-trait.rs index a751ae1c518..1394f8fa65f 100644 --- a/src/test/compile-fail/unboxed-closure-sugar-wrong-trait.rs +++ b/src/test/compile-fail/unboxed-closure-sugar-wrong-trait.rs @@ -11,7 +11,7 @@ trait Trait {} fn f<F:Trait(int) -> int>(x: F) {} -//~^ ERROR unboxed function trait must be one of `Fn`, `FnMut`, or `FnOnce` +//~^ ERROR wrong number of type arguments: expected 0, found 2 fn main() {} diff --git a/src/test/run-fail/issue-18576.rs b/src/test/run-fail/issue-18576.rs new file mode 100644 index 00000000000..0b82a0d8d83 --- /dev/null +++ b/src/test/run-fail/issue-18576.rs @@ -0,0 +1,23 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// error-pattern:stop + +// #18576 +// Make sure that an calling extern function pointer in an unreachable +// context doesn't cause an LLVM assertion + +#[allow(unreachable_code)] +fn main() { + panic!("stop"); + let pointer = other; + pointer(); +} +extern fn other() {} diff --git a/src/test/run-make/target-specs/Makefile b/src/test/run-make/target-specs/Makefile index 746870d201f..a352bc3a8cc 100644 --- a/src/test/run-make/target-specs/Makefile +++ b/src/test/run-make/target-specs/Makefile @@ -2,7 +2,7 @@ all: $(RUSTC) foo.rs --target=my-awesome-platform.json --crate-type=lib --emit=asm grep --quiet --invert-match morestack < $(TMPDIR)/foo.s - $(RUSTC) foo.rs --target=my-invalid-platform.json 2>&1 | grep --quiet --invert-match "Error loading taget specification" + $(RUSTC) foo.rs --target=my-invalid-platform.json 2>&1 | grep --quiet "Error loading target specification" $(RUSTC) foo.rs --target=my-incomplete-platform.json 2>&1 | grep 'Field llvm-target' RUST_TARGET_PATH=. $(RUSTC) foo.rs --target=my-awesome-platform --crate-type=lib --emit=asm RUST_TARGET_PATH=. $(RUSTC) foo.rs --target=x86_64-unknown-linux-gnu --crate-type=lib --emit=asm diff --git a/src/test/run-make/target-specs/x86_64-unknown-linux-gnu.json b/src/test/run-make/target-specs/x86_64-unknown-linux-gnu.json index f5f622bbcda..5e0f0f40e67 100644 --- a/src/test/run-make/target-specs/x86_64-unknown-linux-gnu.json +++ b/src/test/run-make/target-specs/x86_64-unknown-linux-gnu.json @@ -1,9 +1,10 @@ { - "data-layout": "e-p:32:32-f64:32:64-i64:32:64-f80:32:32-n8:16:32", - "llvm-target": "i686-unknown-linux-gnu", + "pre-link-args": ["-m64"], + "data-layout": "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128", + "llvm-target": "x86_64-unknown-linux-gnu", "target-endian": "little", - "target-word-size": "32", - "arch": "x86", + "target-word-size": "64", + "arch": "x86_64", "os": "linux", "morestack": false } diff --git a/src/test/run-pass/deriving-default-box.rs b/src/test/run-pass/deriving-default-box.rs new file mode 100644 index 00000000000..aeef55fbbac --- /dev/null +++ b/src/test/run-pass/deriving-default-box.rs @@ -0,0 +1,22 @@ +// 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. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use std::default::Default; + +#[deriving(Default)] +struct A { + foo: Box<[bool]>, +} + +pub fn main() { + let a: A = Default::default(); + let b: Box<[_]> = box []; + assert_eq!(a.foo, b); +} diff --git a/src/test/run-pass/deriving-encodable-decodable-box.rs b/src/test/run-pass/deriving-encodable-decodable-box.rs new file mode 100644 index 00000000000..e21f64cd74c --- /dev/null +++ b/src/test/run-pass/deriving-encodable-decodable-box.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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +extern crate serialize; + +use serialize::{Encodable, Decodable}; +use serialize::json; + +#[deriving(Encodable, Decodable)] +struct A { + foo: Box<[bool]>, +} + +fn main() { + let obj = A { foo: box [true, false] }; + let s = json::encode(&obj); + let obj2: A = json::decode(s.as_slice()).unwrap(); + assert!(obj.foo == obj2.foo); +} diff --git a/src/test/run-pass/foreach-nested.rs b/src/test/run-pass/foreach-nested.rs index af6ca3c93d5..2a54f22ee66 100644 --- a/src/test/run-pass/foreach-nested.rs +++ b/src/test/run-pass/foreach-nested.rs @@ -15,7 +15,7 @@ pub fn main() { let mut a: Vec<int> = vec!(-1, -1, -1, -1); let mut p: int = 0; two(|i| { - two(|j| { *a.get_mut(p as uint) = 10 * i + j; p += 1; }) + two(|j| { a[p as uint] = 10 * i + j; p += 1; }) }); assert_eq!(a[0], 0); assert_eq!(a[1], 1); diff --git a/src/test/run-pass/hashmap-memory.rs b/src/test/run-pass/hashmap-memory.rs index 87afd1601f6..4a6a6782fb3 100644 --- a/src/test/run-pass/hashmap-memory.rs +++ b/src/test/run-pass/hashmap-memory.rs @@ -83,7 +83,7 @@ mod map_reduce { mapper_done => { num_mappers -= 1; } find_reducer(k, cc) => { let mut c; - match reducers.find(&str::from_utf8( + match reducers.get(&str::from_utf8( k.as_slice()).unwrap().to_string()) { Some(&_c) => { c = _c; } None => { c = 0; } diff --git a/src/test/run-pass/issue-10396.rs b/src/test/run-pass/issue-10396.rs new file mode 100644 index 00000000000..ce04f188e34 --- /dev/null +++ b/src/test/run-pass/issue-10396.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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#[deriving(Show)] +enum Foo<'s> { + V(&'s str) +} + +fn f(arr: &[&Foo]) { + for &f in arr.iter() { + println!("{}", f); + } +} + +fn main() {} diff --git a/src/test/run-pass/issue-10501.rs b/src/test/run-pass/issue-10501.rs new file mode 100644 index 00000000000..78f125398ed --- /dev/null +++ b/src/test/run-pass/issue-10501.rs @@ -0,0 +1,14 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +pub type Foo = fn(&int) -> (); +#[deriving(Clone)] +enum Baz { Bar(Foo) } +fn main() {} diff --git a/src/test/run-pass/issue-12741.rs b/src/test/run-pass/issue-12741.rs new file mode 100644 index 00000000000..e41613b4ae3 --- /dev/null +++ b/src/test/run-pass/issue-12741.rs @@ -0,0 +1,35 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#[deriving(Clone)] +pub struct Foo { + f: fn(char, |char| -> char) -> char +} + +impl Foo { + fn bar(&self) -> char { + ((*self).f)('a', |c: char| c) + } +} + +fn bla(c: char, cb: |char| -> char) -> char { + cb(c) +} + +pub fn make_foo() -> Foo { + Foo { + f: bla + } +} + +fn main() { + let a = make_foo(); + assert_eq!(a.bar(), 'a'); +} diff --git a/src/test/run-pass/issue-15063.rs b/src/test/run-pass/issue-15063.rs new file mode 100644 index 00000000000..0b7eb41d2aa --- /dev/null +++ b/src/test/run-pass/issue-15063.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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +enum Two { A, B} +impl Drop for Two { + fn drop(&mut self) { + println!("Dropping!"); + } +} +fn main() { + let k = A; +} diff --git a/src/test/run-pass/issue-15734.rs b/src/test/run-pass/issue-15734.rs new file mode 100644 index 00000000000..ea5bd550d53 --- /dev/null +++ b/src/test/run-pass/issue-15734.rs @@ -0,0 +1,56 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +struct Mat<T> { data: Vec<T>, cols: uint, } + +impl<T> Mat<T> { + fn new(data: Vec<T>, cols: uint) -> Mat<T> { + Mat { data: data, cols: cols } + } + fn row<'a>(&'a self, row: uint) -> Row<&'a Mat<T>> { + Row { mat: self, row: row, } + } +} + +impl<T> Index<(uint, uint), T> for Mat<T> { + fn index<'a>(&'a self, &(row, col): &(uint, uint)) -> &'a T { + &self.data[row * self.cols + col] + } +} + +impl<'a, T> Index<(uint, uint), T> for &'a Mat<T> { + fn index<'b>(&'b self, index: &(uint, uint)) -> &'b T { + (*self).index(index) + } +} + +struct Row<M> { mat: M, row: uint, } + +impl<T, M: Index<(uint, uint), T>> Index<uint, T> for Row<M> { + fn index<'a>(&'a self, col: &uint) -> &'a T { + &self.mat[(self.row, *col)] + } +} + +fn main() { + let m = Mat::new(vec!(1u, 2, 3, 4, 5, 6), 3); + let r = m.row(1); + + assert!(r.index(&2) == &6); + assert!(r[2] == 6); + assert!(r[2u] == 6u); + assert!(6 == r[2]); + + let e = r[2]; + assert!(e == 6); + + let e: uint = r[2]; + assert!(e == 6); +} diff --git a/src/test/run-pass/issue-16774.rs b/src/test/run-pass/issue-16774.rs new file mode 100644 index 00000000000..f996f9309c1 --- /dev/null +++ b/src/test/run-pass/issue-16774.rs @@ -0,0 +1,50 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(overloaded_calls, unboxed_closures)] + +struct X(Box<int>); + +static mut DESTRUCTOR_RAN: bool = false; + +impl Drop for X { + fn drop(&mut self) { + unsafe { + assert!(!DESTRUCTOR_RAN); + DESTRUCTOR_RAN = true; + } + } +} + +impl Deref<int> for X { + fn deref(&self) -> &int { + let &X(box ref x) = self; + x + } +} + +impl DerefMut<int> for X { + fn deref_mut(&mut self) -> &mut int { + let &X(box ref mut x) = self; + x + } +} + +fn main() { + { + let mut test = X(box 5i); + { + let mut change = |&mut:| { *test = 10 }; + change(); + } + assert_eq!(*test, 10); + } + assert!(unsafe { DESTRUCTOR_RAN }); +} diff --git a/src/test/run-pass/issue-18110.rs b/src/test/run-pass/issue-18110.rs new file mode 100644 index 00000000000..3d6b23c8805 --- /dev/null +++ b/src/test/run-pass/issue-18110.rs @@ -0,0 +1,13 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + ({return},); +} diff --git a/src/test/run-pass/issue-18353.rs b/src/test/run-pass/issue-18353.rs new file mode 100644 index 00000000000..c734c1a3222 --- /dev/null +++ b/src/test/run-pass/issue-18353.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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that wrapping an unsized struct in an enum which gets optimised does +// not ICE. + +struct Str { + f: [u8] +} + +fn main() { + let str: Option<&Str> = None; + str.is_some(); +} diff --git a/src/test/run-pass/issue-18619.rs b/src/test/run-pass/issue-18619.rs new file mode 100644 index 00000000000..70ccc20e01a --- /dev/null +++ b/src/test/run-pass/issue-18619.rs @@ -0,0 +1,15 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use std::io::FileType; + +pub fn main() { + let _ = FileType::TypeFile.clone(); +} diff --git a/src/test/run-pass/issue-3563-3.rs b/src/test/run-pass/issue-3563-3.rs index 84f303de705..4e330b9a0e7 100644 --- a/src/test/run-pass/issue-3563-3.rs +++ b/src/test/run-pass/issue-3563-3.rs @@ -86,8 +86,8 @@ impl AsciiArt { // element is: // 1) potentially large // 2) needs to be modified - let row = self.lines.get_mut(v); - *row.get_mut(h) = self.fill; + let row = &mut self.lines[v]; + row[h] = self.fill; } } } diff --git a/src/test/run-pass/issue-3991.rs b/src/test/run-pass/issue-3991.rs index da22da31d5b..37144fb9cce 100644 --- a/src/test/run-pass/issue-3991.rs +++ b/src/test/run-pass/issue-3991.rs @@ -15,7 +15,7 @@ struct HasNested { impl HasNested { fn method_push_local(&mut self) { - self.nest.get_mut(0).push(0); + self.nest[0].push(0); } } diff --git a/src/test/run-pass/issue-7268.rs b/src/test/run-pass/issue-7268.rs new file mode 100644 index 00000000000..8aa95927312 --- /dev/null +++ b/src/test/run-pass/issue-7268.rs @@ -0,0 +1,16 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn foo<T: 'static>(_: T) {} + +fn bar<T>(x: &'static T) { + foo(x); +} +fn main() {} diff --git a/src/test/run-pass/lint-non-camel-case-types-non-uppercase-statics-unicode.rs b/src/test/run-pass/lint-non-camel-case-types-non-uppercase-statics-unicode.rs index 36c663fc847..061f7025527 100644 --- a/src/test/run-pass/lint-non-camel-case-types-non-uppercase-statics-unicode.rs +++ b/src/test/run-pass/lint-non-camel-case-types-non-uppercase-statics-unicode.rs @@ -12,7 +12,7 @@ #![forbid(non_camel_case_types)] -#![forbid(non_uppercase_statics)] +#![forbid(non_upper_case_globals)] #![feature(non_ascii_idents)] // Some scripts (e.g. hiragana) don't have a concept of diff --git a/src/test/run-pass/lint-non-uppercase-statics-lowercase-mut-statics.rs b/src/test/run-pass/lint-non-uppercase-statics-lowercase-mut-statics.rs index 0dae07d31e4..ce3518618d0 100644 --- a/src/test/run-pass/lint-non-uppercase-statics-lowercase-mut-statics.rs +++ b/src/test/run-pass/lint-non-uppercase-statics-lowercase-mut-statics.rs @@ -10,7 +10,7 @@ #![forbid(non_camel_case_types)] -#![forbid(non_uppercase_statics)] +#![forbid(non_upper_case_globals)] static mut bar: int = 2; diff --git a/src/test/run-pass/match-static-const-rename.rs b/src/test/run-pass/match-static-const-rename.rs index f3fe93650af..164cc99e188 100644 --- a/src/test/run-pass/match-static-const-rename.rs +++ b/src/test/run-pass/match-static-const-rename.rs @@ -16,7 +16,7 @@ // around this problem locally by renaming the constant in the `use` // form to an uppercase identifier that placates the lint. -#![deny(non_uppercase_statics)] +#![deny(non_upper_case_globals)] pub const A : int = 97; @@ -34,7 +34,7 @@ fn f() { } mod m { - #[allow(non_uppercase_statics)] + #[allow(non_upper_case_globals)] pub const aha : int = 7; } diff --git a/src/test/run-pass/overloaded-deref.rs b/src/test/run-pass/overloaded-deref.rs index b63db29cf91..ca820830f02 100644 --- a/src/test/run-pass/overloaded-deref.rs +++ b/src/test/run-pass/overloaded-deref.rs @@ -44,8 +44,8 @@ pub fn main() { assert_eq!(*(*p).borrow(), Point {x: 3, y: 5}); let v = Rc::new(RefCell::new(vec!(1i, 2, 3))); - *(*(*v).borrow_mut()).get_mut(0) = 3; - *(*(*v).borrow_mut()).get_mut(1) += 3; + (*(*v).borrow_mut())[0] = 3; + (*(*v).borrow_mut())[1] += 3; assert_eq!(((*(*v).borrow())[0], (*(*v).borrow())[1], (*(*v).borrow())[2]), (3, 5, 3)); diff --git a/src/test/run-pass/send_str_hashmap.rs b/src/test/run-pass/send_str_hashmap.rs index 1edce811bcb..55003a07b5b 100644 --- a/src/test/run-pass/send_str_hashmap.rs +++ b/src/test/run-pass/send_str_hashmap.rs @@ -16,37 +16,37 @@ use std::option::Some; pub fn main() { let mut map: HashMap<SendStr, uint> = HashMap::new(); - assert!(map.insert(Slice("foo"), 42)); - assert!(!map.insert(Owned("foo".to_string()), 42)); - assert!(!map.insert(Slice("foo"), 42)); - assert!(!map.insert(Owned("foo".to_string()), 42)); + assert!(map.insert(Slice("foo"), 42).is_none()); + assert!(map.insert(Owned("foo".to_string()), 42).is_some()); + assert!(map.insert(Slice("foo"), 42).is_some()); + assert!(map.insert(Owned("foo".to_string()), 42).is_some()); - assert!(!map.insert(Slice("foo"), 43)); - assert!(!map.insert(Owned("foo".to_string()), 44)); - assert!(!map.insert(Slice("foo"), 45)); - assert!(!map.insert(Owned("foo".to_string()), 46)); + assert!(map.insert(Slice("foo"), 43).is_some()); + assert!(map.insert(Owned("foo".to_string()), 44).is_some()); + assert!(map.insert(Slice("foo"), 45).is_some()); + assert!(map.insert(Owned("foo".to_string()), 46).is_some()); let v = 46; - assert_eq!(map.find(&Owned("foo".to_string())), Some(&v)); - assert_eq!(map.find(&Slice("foo")), Some(&v)); + assert_eq!(map.get(&Owned("foo".to_string())), Some(&v)); + assert_eq!(map.get(&Slice("foo")), Some(&v)); let (a, b, c, d) = (50, 51, 52, 53); - assert!(map.insert(Slice("abc"), a)); - assert!(map.insert(Owned("bcd".to_string()), b)); - assert!(map.insert(Slice("cde"), c)); - assert!(map.insert(Owned("def".to_string()), d)); + assert!(map.insert(Slice("abc"), a).is_none()); + assert!(map.insert(Owned("bcd".to_string()), b).is_none()); + assert!(map.insert(Slice("cde"), c).is_none()); + assert!(map.insert(Owned("def".to_string()), d).is_none()); - assert!(!map.insert(Slice("abc"), a)); - assert!(!map.insert(Owned("bcd".to_string()), b)); - assert!(!map.insert(Slice("cde"), c)); - assert!(!map.insert(Owned("def".to_string()), d)); + assert!(map.insert(Slice("abc"), a).is_some()); + assert!(map.insert(Owned("bcd".to_string()), b).is_some()); + assert!(map.insert(Slice("cde"), c).is_some()); + assert!(map.insert(Owned("def".to_string()), d).is_some()); - assert!(!map.insert(Owned("abc".to_string()), a)); - assert!(!map.insert(Slice("bcd"), b)); - assert!(!map.insert(Owned("cde".to_string()), c)); - assert!(!map.insert(Slice("def"), d)); + assert!(map.insert(Owned("abc".to_string()), a).is_some()); + assert!(map.insert(Slice("bcd"), b).is_some()); + assert!(map.insert(Owned("cde".to_string()), c).is_some()); + assert!(map.insert(Slice("def"), d).is_some()); assert_eq!(map.find_equiv("abc"), Some(&a)); assert_eq!(map.find_equiv("bcd"), Some(&b)); diff --git a/src/test/run-pass/send_str_treemap.rs b/src/test/run-pass/send_str_treemap.rs index f73ab8f52d7..c52f9458f99 100644 --- a/src/test/run-pass/send_str_treemap.rs +++ b/src/test/run-pass/send_str_treemap.rs @@ -17,49 +17,49 @@ use std::option::Some; pub fn main() { let mut map: TreeMap<SendStr, uint> = TreeMap::new(); - assert!(map.insert(Slice("foo"), 42)); - assert!(!map.insert(Owned("foo".to_string()), 42)); - assert!(!map.insert(Slice("foo"), 42)); - assert!(!map.insert(Owned("foo".to_string()), 42)); + assert!(map.insert(Slice("foo"), 42).is_none()); + assert!(map.insert(Owned("foo".to_string()), 42).is_some()); + assert!(map.insert(Slice("foo"), 42).is_some()); + assert!(map.insert(Owned("foo".to_string()), 42).is_some()); - assert!(!map.insert(Slice("foo"), 43)); - assert!(!map.insert(Owned("foo".to_string()), 44)); - assert!(!map.insert(Slice("foo"), 45)); - assert!(!map.insert(Owned("foo".to_string()), 46)); + assert!(map.insert(Slice("foo"), 43).is_some()); + assert!(map.insert(Owned("foo".to_string()), 44).is_some()); + assert!(map.insert(Slice("foo"), 45).is_some()); + assert!(map.insert(Owned("foo".to_string()), 46).is_some()); let v = 46; - assert_eq!(map.find(&Owned("foo".to_string())), Some(&v)); - assert_eq!(map.find(&Slice("foo")), Some(&v)); + assert_eq!(map.get(&Owned("foo".to_string())), Some(&v)); + assert_eq!(map.get(&Slice("foo")), Some(&v)); let (a, b, c, d) = (50, 51, 52, 53); - assert!(map.insert(Slice("abc"), a)); - assert!(map.insert(Owned("bcd".to_string()), b)); - assert!(map.insert(Slice("cde"), c)); - assert!(map.insert(Owned("def".to_string()), d)); + assert!(map.insert(Slice("abc"), a).is_none()); + assert!(map.insert(Owned("bcd".to_string()), b).is_none()); + assert!(map.insert(Slice("cde"), c).is_none()); + assert!(map.insert(Owned("def".to_string()), d).is_none()); - assert!(!map.insert(Slice("abc"), a)); - assert!(!map.insert(Owned("bcd".to_string()), b)); - assert!(!map.insert(Slice("cde"), c)); - assert!(!map.insert(Owned("def".to_string()), d)); + assert!(map.insert(Slice("abc"), a).is_some()); + assert!(map.insert(Owned("bcd".to_string()), b).is_some()); + assert!(map.insert(Slice("cde"), c).is_some()); + assert!(map.insert(Owned("def".to_string()), d).is_some()); - assert!(!map.insert(Owned("abc".to_string()), a)); - assert!(!map.insert(Slice("bcd"), b)); - assert!(!map.insert(Owned("cde".to_string()), c)); - assert!(!map.insert(Slice("def"), d)); + assert!(map.insert(Owned("abc".to_string()), a).is_some()); + assert!(map.insert(Slice("bcd"), b).is_some()); + assert!(map.insert(Owned("cde".to_string()), c).is_some()); + assert!(map.insert(Slice("def"), d).is_some()); - assert_eq!(map.find(&Slice("abc")), Some(&a)); - assert_eq!(map.find(&Slice("bcd")), Some(&b)); - assert_eq!(map.find(&Slice("cde")), Some(&c)); - assert_eq!(map.find(&Slice("def")), Some(&d)); + assert_eq!(map.get(&Slice("abc")), Some(&a)); + assert_eq!(map.get(&Slice("bcd")), Some(&b)); + assert_eq!(map.get(&Slice("cde")), Some(&c)); + assert_eq!(map.get(&Slice("def")), Some(&d)); - assert_eq!(map.find(&Owned("abc".to_string())), Some(&a)); - assert_eq!(map.find(&Owned("bcd".to_string())), Some(&b)); - assert_eq!(map.find(&Owned("cde".to_string())), Some(&c)); - assert_eq!(map.find(&Owned("def".to_string())), Some(&d)); + assert_eq!(map.get(&Owned("abc".to_string())), Some(&a)); + assert_eq!(map.get(&Owned("bcd".to_string())), Some(&b)); + assert_eq!(map.get(&Owned("cde".to_string())), Some(&c)); + assert_eq!(map.get(&Owned("def".to_string())), Some(&d)); - assert!(map.pop(&Slice("foo")).is_some()); + assert!(map.remove(&Slice("foo")).is_some()); assert_eq!(map.into_iter().map(|(k, v)| format!("{}{}", k, v)) .collect::<Vec<String>>() .concat(), diff --git a/src/test/run-pass/swap-2.rs b/src/test/run-pass/swap-2.rs index 4eb9274551f..3c0f9505736 100644 --- a/src/test/run-pass/swap-2.rs +++ b/src/test/run-pass/swap-2.rs @@ -16,7 +16,7 @@ pub fn main() { assert_eq!(a[2], 4); assert_eq!(a[4], 2); let mut n = 42; - swap(&mut n, a.get_mut(0)); + swap(&mut n, &mut a[0]); assert_eq!(a[0], 42); assert_eq!(n, 0); } diff --git a/src/test/run-pass/unboxed-closures-manual-impl.rs b/src/test/run-pass/unboxed-closures-manual-impl.rs index b0947f46a86..8f6cfe04997 100644 --- a/src/test/run-pass/unboxed-closures-manual-impl.rs +++ b/src/test/run-pass/unboxed-closures-manual-impl.rs @@ -25,7 +25,7 @@ fn call_it<F:FnMut(int)->int>(mut f: F, x: int) -> int { f.call_mut((x,)) + 3 } -fn call_box(f: &mut |&mut: int|->int, x: int) -> int { +fn call_box(f: &mut FnMut(int) -> int, x: int) -> int { f.call_mut((x,)) + 3 } diff --git a/src/test/run-pass/unboxed-closures-prelude.rs b/src/test/run-pass/unboxed-closures-prelude.rs index 4226ed427e7..f9d2ba02123 100644 --- a/src/test/run-pass/unboxed-closures-prelude.rs +++ b/src/test/run-pass/unboxed-closures-prelude.rs @@ -13,7 +13,7 @@ #![feature(unboxed_closures, unboxed_closure_sugar)] fn main() { - let task: Box<|: int| -> int> = box |: x| x; + let task: Box<FnOnce(int) -> int> = box |: x| x; task.call_once((0i, )); } diff --git a/src/test/run-pass/unboxed-closures-sugar-1.rs b/src/test/run-pass/unboxed-closures-sugar-1.rs new file mode 100644 index 00000000000..b358e7ce288 --- /dev/null +++ b/src/test/run-pass/unboxed-closures-sugar-1.rs @@ -0,0 +1,34 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that the unboxed closure sugar can be used with an arbitrary +// struct type and that it is equivalent to the same syntax using +// angle brackets. This test covers only simple types and in +// particular doesn't test bound regions. + +#![allow(dead_code)] + +struct Foo<T,U> { + t: T, u: U +} + +trait Eq<X> { } +impl<X> Eq<X> for X { } +fn eq<A,B:Eq<A>>() { } + +fn test<'a,'b>() { + eq::< Foo<(),()>, Foo() >(); + eq::< Foo<(int,),()>, Foo(int) >(); + eq::< Foo<(int,uint),()>, Foo(int,uint) >(); + eq::< Foo<(int,uint),uint>, Foo(int,uint) -> uint >(); + eq::< Foo<(&'a int,&'b uint),uint>, Foo(&'a int,&'b uint) -> uint >(); +} + +fn main() { } diff --git a/src/test/run-pass/unboxed-closures-sugar-object.rs b/src/test/run-pass/unboxed-closures-sugar-object.rs new file mode 100644 index 00000000000..3b38f72432f --- /dev/null +++ b/src/test/run-pass/unboxed-closures-sugar-object.rs @@ -0,0 +1,34 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test unboxed closure sugar used in object types. + +#![allow(dead_code)] + +struct Foo<T,U> { + t: T, u: U +} + +trait Getter<A,R> { + fn get(&self, arg: A) -> R; +} + +struct Identity; +impl<X> Getter<X,X> for Identity { + fn get(&self, arg: X) -> X { + arg + } +} + +fn main() { + let x: &Getter(int) -> (int,) = &Identity; + let (y,) = x.get((22,)); + assert_eq!(y, 22); +} diff --git a/src/test/run-pass/unboxed-closures-unboxing-shim.rs b/src/test/run-pass/unboxed-closures-unboxing-shim.rs index 0a7baa3ba36..426352cadd8 100644 --- a/src/test/run-pass/unboxed-closures-unboxing-shim.rs +++ b/src/test/run-pass/unboxed-closures-unboxing-shim.rs @@ -13,7 +13,7 @@ use std::ops::FnOnce; fn main() { - let task: Box<|: int| -> int> = box |: x| x; + let task: Box<FnOnce(int) -> int> = box |: x| x; assert!(task.call_once((1234i,)) == 1234i); } diff --git a/src/test/run-pass/unique-in-vec-copy.rs b/src/test/run-pass/unique-in-vec-copy.rs index 33a28ddb2fc..577a8f1430b 100644 --- a/src/test/run-pass/unique-in-vec-copy.rs +++ b/src/test/run-pass/unique-in-vec-copy.rs @@ -17,7 +17,7 @@ pub fn main() { assert_eq!(*b[0], 10); // This should only modify the value in a, not b - **a.get_mut(0) = 20; + *a[0] = 20; assert_eq!(*a[0], 20); assert_eq!(*b[0], 10); |
