Skip to content

Commit 2c744c7

Browse files
author
Jakub Bukaj
committed
Add test cases for E-needstest issues
1 parent 80e5fe1 commit 2c744c7

13 files changed

+278
-0
lines changed

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

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
mod foo { pub fn bar() {} }
12+
13+
fn main() {
14+
match () {
15+
foo::bar => {} //~ ERROR `bar` is not an enum variant, struct or const
16+
}
17+
}

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

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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 foo = "str";
13+
println!("{}", foo.desc); //~ ERROR attempted access of field `desc` on type `&str`,
14+
// but no field with that name was found
15+
}

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

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
trait T<'a> {
12+
fn a(&'a self) -> &'a bool;
13+
fn b(&self) {
14+
self.a(); //~ ERROR mismatched types: expected `&'a Self`, found `&Self` (lifetime mismatch)
15+
}
16+
}
17+
18+
fn main() {}

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

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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(unboxed_closures)]
12+
13+
struct B<T>;
14+
15+
fn main() {
16+
let foo = B; //~ ERROR unable to infer enough type information to locate the impl of the trait
17+
let closure = |:| foo;
18+
}

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

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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 fn main() {
12+
static z: &'static int = {
13+
let p = 3;
14+
&p
15+
//~^ ERROR cannot borrow a local variable inside a static block, define a separate static instead
16+
};
17+
}

src/test/compile-fail/issue-18252.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+
#![feature(struct_variant)]
12+
13+
enum Foo {
14+
Variant { x: uint }
15+
}
16+
17+
fn main() {
18+
let f = Variant(42u); //~ ERROR expected function, found `Foo`
19+
}

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

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
static x: &'static uint = &1;
12+
static y: uint = *x;
13+
//~^ ERROR cannot refer to other statics by value,
14+
// use the address-of operator or a constant instead
15+
fn main() {}

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

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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 A { B, C }
12+
13+
mod foo { pub fn bar() {} }
14+
15+
fn main() {
16+
match (true, false) {
17+
B => (), //~ ERROR expected `(bool,bool)`, found `A` (expected tuple, found enum A)
18+
_ => ()
19+
}
20+
21+
match &Some(42i) {
22+
Some(x) => (), //~ ERROR expected `&core::option::Option<int>`,
23+
// found `core::option::Option<<generic #4>>`
24+
None => () //~ ERROR expected `&core::option::Option<int>`,
25+
// found `core::option::Option<<generic #5>>`
26+
}
27+
}

src/test/run-pass/closure-syntax.rs

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
// except according to those terms.
1010

1111
#![allow(dead_code)]
12+
#![feature(unboxed_closures, unboxed_closure_sugar)]
13+
14+
// compile-flags:-g
1215

1316
fn foo<T>() {}
1417

@@ -82,6 +85,9 @@ fn bar<'b>() {
8285
// issue #13490
8386
let _ = || -> ! loop {};
8487
let _ = proc() -> ! loop {};
88+
89+
// issue #17021
90+
let c = box |&:| {};
8591
}
8692

8793
struct B<T>;

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

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
trait Hash<H> {
12+
fn hash2(&self, hasher: &H) -> u64;
13+
}
14+
15+
trait Stream {
16+
fn input(&mut self, bytes: &[u8]);
17+
fn result(&self) -> u64;
18+
}
19+
20+
trait StreamHasher<S: Stream> {
21+
fn stream(&self) -> S;
22+
}
23+
24+
//////////////////////////////////////////////////////////////////////////////
25+
26+
trait StreamHash<S: Stream, H: StreamHasher<S>>: Hash<H> {
27+
fn input_stream(&self, stream: &mut S);
28+
}
29+
30+
impl<S: Stream, H: StreamHasher<S>> Hash<H> for u8 {
31+
fn hash2(&self, hasher: &H) -> u64 {
32+
let mut stream = hasher.stream();
33+
self.input_stream(&mut stream);
34+
stream.result()
35+
}
36+
}
37+
38+
impl<S: Stream, H: StreamHasher<S>> StreamHash<S, H> for u8 {
39+
fn input_stream(&self, stream: &mut S) {
40+
stream.input([*self]);
41+
}
42+
}
43+
44+
fn main() {}

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

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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::io::Reader;
12+
13+
enum Wrapper<'a> {
14+
WrapReader(&'a Reader + 'a)
15+
}
16+
17+
trait Wrap<'a> {
18+
fn wrap(self) -> Wrapper<'a>;
19+
}
20+
21+
impl<'a, R: Reader> Wrap<'a> for &'a mut R {
22+
fn wrap(self) -> Wrapper<'a> {
23+
WrapReader(self as &'a mut Reader)
24+
}
25+
}
26+
27+
pub fn main() {}

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

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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(unboxed_closures)]
12+
13+
use std::mem;
14+
15+
fn main() {
16+
let y = 0u8;
17+
let closure = move |&: x| y + x;
18+
19+
// Check that both closures are capturing by value
20+
assert_eq!(1, mem::size_of_val(&closure));
21+
22+
spawn(proc() {
23+
let ok = closure;
24+
})
25+
}

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

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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(unboxed_closures)]
12+
13+
struct Parser<'a, I, O> {
14+
parse: Box<FnMut<(I,), Result<O, String>> + 'a>
15+
}
16+
17+
impl<'a, I, O: 'a> Parser<'a, I, O> {
18+
fn compose<K: 'a>(mut self, mut rhs: Parser<O, K>) -> Parser<'a, I, K> {
19+
Parser {
20+
parse: box move |&mut: x: I| {
21+
match self.parse.call_mut((x,)) {
22+
Ok(r) => rhs.parse.call_mut((r,)),
23+
Err(e) => Err(e)
24+
}
25+
}
26+
}
27+
}
28+
}
29+
30+
fn main() {}

0 commit comments

Comments
 (0)