Skip to content

Commit 52d2f2a

Browse files
author
Jakub Wieczorek
committed
Add tests for a few resolved issues
1 parent b224dfe commit 52d2f2a

13 files changed

+339
-0
lines changed
+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+
fn read_lines_borrowed<'a>() -> Vec<&'a str> {
12+
let rawLines: Vec<String> = vec!["foo ".to_string(), " bar".to_string()];
13+
rawLines //~ ERROR `rawLines` does not live long enough
14+
.iter().map(|l| l.as_slice().trim()).collect()
15+
}
16+
17+
fn main() {}

src/test/compile-fail/issue-13497.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+
fn read_lines_borrowed1() -> Vec<
12+
&str //~ ERROR missing lifetime specifier
13+
> {
14+
let rawLines: Vec<String> = vec!["foo ".to_string(), " bar".to_string()];
15+
rawLines.iter().map(|l| l.as_slice().trim()).collect()
16+
}
17+
18+
fn main() {}

src/test/compile-fail/issue-14366.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+
fn main() {
12+
let _x = "test" as &::std::any::Any;
13+
//~^ ERROR the trait `core::kinds::Sized` is not implemented for the type `str`
14+
//~^^ NOTE the trait `core::kinds::Sized` must be implemented for the cast to the object type
15+
//~^^^ ERROR the trait `core::kinds::Sized` is not implemented for the type `str`
16+
//~^^^^ NOTE the trait `core::kinds::Sized` must be implemented for the cast to the object type
17+
}

src/test/compile-fail/issue-14853.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+
use std::fmt::Show;
12+
13+
trait Something {
14+
fn yay<T: Show>(_: Option<Self>, thing: &[T]) -> String {
15+
}
16+
}
17+
18+
struct X { data: u32 }
19+
20+
impl Something for X {
21+
fn yay<T: Str>(_:Option<X>, thing: &[T]) -> String {
22+
//~^ ERROR in method `yay`, type parameter 0 requires bound `core::str::Str`, which is not required
23+
format!("{:s}", thing[0])
24+
}
25+
}
26+
27+
fn main() {
28+
let arr = &["one", "two", "three"];
29+
println!("{}", Something::yay(None::<X>, arr));
30+
}

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

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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 A {
12+
a: String
13+
}
14+
15+
fn borrow<'a>(binding: &'a A) -> &'a str {
16+
match binding.a.as_slice() {
17+
"in" => "in_",
18+
"ref" => "ref_",
19+
ident => ident
20+
}
21+
}
22+
23+
fn main() {}

src/test/run-pass/issue-13167.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::slice;
12+
13+
pub struct PhfMapEntries<'a, T> {
14+
iter: slice::Items<'a, (&'static str, T)>,
15+
}
16+
17+
impl<'a, T> Iterator<(&'static str, &'a T)> for PhfMapEntries<'a, T> {
18+
fn next(&mut self) -> Option<(&'static str, &'a T)> {
19+
self.iter.by_ref().map(|&(key, ref value)| (key, value)).next()
20+
}
21+
22+
fn size_hint(&self) -> (uint, Option<uint>) {
23+
self.iter.size_hint()
24+
}
25+
}
26+
27+
fn main() {}

src/test/run-pass/issue-13405.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+
struct Foo<'a> {
12+
i: &'a bool,
13+
j: Option<&'a int>,
14+
}
15+
16+
impl<'a> Foo<'a> {
17+
fn bar(&mut self, j: &int) {
18+
let child = Foo {
19+
i: self.i,
20+
j: Some(j)
21+
};
22+
}
23+
}
24+
25+
fn main() {}

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

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
extern crate debug;
12+
13+
struct MyStruct;
14+
15+
trait Repro {
16+
fn repro(self, s: MyStruct) -> String;
17+
}
18+
19+
impl Repro for |MyStruct|:'static -> String {
20+
fn repro(self, s: MyStruct) -> String {
21+
self(s)
22+
}
23+
}
24+
25+
fn do_stuff<R: Repro>(r: R) -> String {
26+
r.repro(MyStruct)
27+
}
28+
29+
pub fn main() {
30+
assert_eq!("MyStruct".to_string(), do_stuff(|s: MyStruct| format!("{:?}", s)));
31+
}

src/test/run-pass/issue-13703.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+
pub struct Foo<'a, 'b: 'a> { foo: &'a &'b int }
12+
pub fn foo<'a, 'b>(x: Foo<'a, 'b>, _o: Option<& & ()>) { let _y = x.foo; }
13+
fn main() {}

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

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 Matcher {
12+
fn next_match(&mut self) -> Option<(uint, uint)>;
13+
}
14+
15+
struct CharPredMatcher<'a, 'b> {
16+
str: &'a str,
17+
pred: |char|:'b -> bool
18+
}
19+
20+
impl<'a, 'b> Matcher for CharPredMatcher<'a, 'b> {
21+
fn next_match(&mut self) -> Option<(uint, uint)> {
22+
None
23+
}
24+
}
25+
26+
trait IntoMatcher<'a, T> {
27+
fn into_matcher(self, &'a str) -> T;
28+
}
29+
30+
impl<'a, 'b> IntoMatcher<'a, CharPredMatcher<'a, 'b>> for |char|:'b -> bool {
31+
fn into_matcher(self, s: &'a str) -> CharPredMatcher<'a, 'b> {
32+
CharPredMatcher {
33+
str: s,
34+
pred: self
35+
}
36+
}
37+
}
38+
39+
struct MatchIndices<M> {
40+
matcher: M
41+
}
42+
43+
impl<M: Matcher> Iterator<(uint, uint)> for MatchIndices<M> {
44+
fn next(&mut self) -> Option<(uint, uint)> {
45+
self.matcher.next_match()
46+
}
47+
}
48+
49+
fn match_indices<'a, M, T: IntoMatcher<'a, M>>(s: &'a str, from: T) -> MatchIndices<M> {
50+
let string_matcher = from.into_matcher(s);
51+
MatchIndices { matcher: string_matcher }
52+
}
53+
54+
fn main() {
55+
let s = "abcbdef";
56+
match_indices(s, |c: char| c == 'b')
57+
.collect::<Vec<(uint, uint)>>();
58+
}

src/test/run-pass/issue-15673.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+
use std::iter::AdditiveIterator;
12+
fn main() {
13+
let x: [u64, ..3] = [1, 2, 3];
14+
assert_eq!(6, range(0, 3).map(|i| x[i]).sum());
15+
}

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

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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(unsafe_destructor)]
12+
13+
extern crate serialize;
14+
15+
use std::io::IoError;
16+
use serialize::{Encoder, Encodable};
17+
use serialize::json;
18+
19+
struct Foo<T> {
20+
v: T,
21+
}
22+
23+
#[unsafe_destructor]
24+
impl<'a, T: Encodable<json::Encoder<'a>, IoError>> Drop for Foo<T> {
25+
fn drop(&mut self) {
26+
json::encode(&self.v);
27+
}
28+
}
29+
30+
fn main() {
31+
let _ = Foo { v: 10i };
32+
}

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

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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(macro_rules)]
12+
13+
struct Element;
14+
15+
macro_rules! foo {
16+
($tag: expr, $string: expr) => {
17+
if $tag == $string {
18+
let element = box Element;
19+
unsafe {
20+
return std::mem::transmute::<_, uint>(element);
21+
}
22+
}
23+
}
24+
}
25+
26+
fn bar() -> uint {
27+
foo!("a", "b");
28+
0
29+
}
30+
31+
fn main() {
32+
bar();
33+
}

0 commit comments

Comments
 (0)