Skip to content

Commit 6998853

Browse files
author
Jakub Bukaj
committed
Add tests for E-needstest issues
1 parent 3327ecc commit 6998853

12 files changed

+303
-5
lines changed

src/test/compile-fail/issue-11382.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
panic!(
13+
1.2
14+
//~^ ERROR cannot determine the type of this number; add a suffix to specify the type explicitly
15+
);
16+
}

src/test/compile-fail/issue-11771.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
let x = ();
13+
1 +
14+
x //~ ERROR mismatched types: expected `_`, found `()` (expected integral variable, found ())
15+
;
16+
17+
let x: () = ();
18+
1 +
19+
x //~ ERROR mismatched types: expected `_`, found `()` (expected integral variable, found ())
20+
;
21+
}

src/test/compile-fail/issue-13058.rs

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use std::iter::{Range,range};
12+
13+
trait Itble<'r, T, I: Iterator<T>> { fn iter(&'r self) -> I; }
14+
15+
impl<'r> Itble<'r, uint, Range<uint>> for (uint, uint) {
16+
fn iter(&'r self) -> Range<uint> {
17+
let &(min, max) = self;
18+
range(min, max)
19+
}
20+
}
21+
22+
fn check<'r, I: Iterator<uint>, T: Itble<'r, uint, I>>(cont: &T) -> bool
23+
//~^ HELP as shown: fn check<'r, I: Iterator<uint>, T: Itble<'r, uint, I>>(cont: &'r T) -> bool
24+
{
25+
let cont_iter = cont.iter();
26+
//~^ ERROR cannot infer an appropriate lifetime for autoref due to conflicting requirements
27+
let result = cont_iter.fold(Some(0u16), |state, val| {
28+
state.map_or(None, |mask| {
29+
let bit = 1 << val;
30+
if mask & bit == 0 {Some(mask|bit)} else {None}
31+
})
32+
});
33+
result.is_some()
34+
}
35+
36+
fn main() {
37+
check((3u, 5u));
38+
//~^ ERROR mismatched types: expected `&_`, found `(uint, uint)` (expected &-ptr, found tuple)
39+
}

src/test/compile-fail/issue-2718-a.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,15 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// ignore-test
12-
1311
pub struct send_packet<T> {
14-
p: T
12+
p: T
1513
}
1614

17-
1815
mod pingpong {
1916
use send_packet;
2017
pub type ping = send_packet<pong>;
2118
pub struct pong(send_packet<ping>);
22-
//~^ ERROR illegal recursive enum type; wrap the inner value in a box to make it representable
19+
//~^ ERROR illegal recursive struct type; wrap the inner value in a box to make it representable
2320
}
2421

2522
fn main() {}

src/test/run-pass/issue-10396.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#[deriving(Show)]
12+
enum Foo<'s> {
13+
V(&'s str)
14+
}
15+
16+
fn f(arr: &[&Foo]) {
17+
for &f in arr.iter() {
18+
println!("{}", f);
19+
}
20+
}
21+
22+
fn main() {}

src/test/run-pass/issue-10501.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
pub type Foo = fn(&int) -> ();
12+
#[deriving(Clone)]
13+
enum Baz { Bar(Foo) }
14+
fn main() {}

src/test/run-pass/issue-12741.rs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#[deriving(Clone)]
12+
pub struct Foo {
13+
f: fn(char, |char| -> char) -> char
14+
}
15+
16+
impl Foo {
17+
fn bar(&self) -> char {
18+
((*self).f)('a', |c: char| c)
19+
}
20+
}
21+
22+
fn bla(c: char, cb: |char| -> char) -> char {
23+
cb(c)
24+
}
25+
26+
pub fn make_foo() -> Foo {
27+
Foo {
28+
f: bla
29+
}
30+
}
31+
32+
fn main() {
33+
let a = make_foo();
34+
assert_eq!(a.bar(), 'a');
35+
}

src/test/run-pass/issue-15063.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
enum Two { A, B}
12+
impl Drop for Two {
13+
fn drop(&mut self) {
14+
println!("Dropping!");
15+
}
16+
}
17+
fn main() {
18+
let k = A;
19+
}

src/test/run-pass/issue-15734.rs

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
struct Mat<T> { data: Vec<T>, cols: uint, }
12+
13+
impl<T> Mat<T> {
14+
fn new(data: Vec<T>, cols: uint) -> Mat<T> {
15+
Mat { data: data, cols: cols }
16+
}
17+
fn row<'a>(&'a self, row: uint) -> Row<&'a Mat<T>> {
18+
Row { mat: self, row: row, }
19+
}
20+
}
21+
22+
impl<T> Index<(uint, uint), T> for Mat<T> {
23+
fn index<'a>(&'a self, &(row, col): &(uint, uint)) -> &'a T {
24+
&self.data[row * self.cols + col]
25+
}
26+
}
27+
28+
impl<'a, T> Index<(uint, uint), T> for &'a Mat<T> {
29+
fn index<'b>(&'b self, index: &(uint, uint)) -> &'b T {
30+
(*self).index(index)
31+
}
32+
}
33+
34+
struct Row<M> { mat: M, row: uint, }
35+
36+
impl<T, M: Index<(uint, uint), T>> Index<uint, T> for Row<M> {
37+
fn index<'a>(&'a self, col: &uint) -> &'a T {
38+
&self.mat[(self.row, *col)]
39+
}
40+
}
41+
42+
fn main() {
43+
let m = Mat::new(vec!(1u, 2, 3, 4, 5, 6), 3);
44+
let r = m.row(1);
45+
46+
assert!(r.index(&2) == &6);
47+
assert!(r[2] == 6);
48+
assert!(r[2u] == 6u);
49+
assert!(6 == r[2]);
50+
51+
let e = r[2];
52+
assert!(e == 6);
53+
54+
let e: uint = r[2];
55+
assert!(e == 6);
56+
}

src/test/run-pass/issue-16774.rs

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(overloaded_calls, unboxed_closures)]
12+
13+
struct X(Box<int>);
14+
15+
static mut DESTRUCTOR_RAN: bool = false;
16+
17+
impl Drop for X {
18+
fn drop(&mut self) {
19+
unsafe {
20+
assert!(!DESTRUCTOR_RAN);
21+
DESTRUCTOR_RAN = true;
22+
}
23+
}
24+
}
25+
26+
impl Deref<int> for X {
27+
fn deref(&self) -> &int {
28+
let &X(box ref x) = self;
29+
x
30+
}
31+
}
32+
33+
impl DerefMut<int> for X {
34+
fn deref_mut(&mut self) -> &mut int {
35+
let &X(box ref mut x) = self;
36+
x
37+
}
38+
}
39+
40+
fn main() {
41+
{
42+
let mut test = X(box 5i);
43+
{
44+
let mut change = |&mut:| { *test = 10 };
45+
change();
46+
}
47+
assert_eq!(*test, 10);
48+
}
49+
assert!(unsafe { DESTRUCTOR_RAN });
50+
}

src/test/run-pass/issue-18110.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
({return},);
13+
}

src/test/run-pass/issue-7268.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn foo<T: 'static>(_: T) {}
12+
13+
fn bar<T>(x: &'static T) {
14+
foo(x);
15+
}
16+
fn main() {}

0 commit comments

Comments
 (0)