Skip to content

Commit 62c9a48

Browse files
committed
rollup merge of #20165: tamird/needstest-tests
@alexcrichton @jakub-
2 parents dbc8440 + 252423f commit 62c9a48

19 files changed

+547
-12
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 {
12+
pub use self::bar::X;
13+
use self::bar::X;
14+
//~^ ERROR a value named `X` has already been imported in this module
15+
//~| ERROR a type named `X` has already been imported in this module
16+
17+
mod bar {
18+
pub struct X;
19+
}
20+
}
21+
22+
fn main() {
23+
let _ = foo::X;
24+
}
Lines changed: 15 additions & 0 deletions
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+
trait Foo {}
12+
13+
fn foo<T: Foo + Foo>() {} //~ ERROR `Foo` already appears in the list of bounds
14+
15+
fn main() {}
Lines changed: 16 additions & 0 deletions
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+
trait FromStructReader<'a> { }
12+
trait ResponseHook {
13+
fn get<'a, T: FromStructReader<'a>>(&'a self);
14+
}
15+
fn foo(res : Box<ResponseHook>) { res.get } //~ ERROR attempted to take value of method
16+
fn main() {}
Lines changed: 33 additions & 0 deletions
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+
#![crate_type = "lib"]
12+
13+
enum NodeContents<'a> {
14+
Children(Vec<Node<'a>>),
15+
}
16+
17+
impl<'a> Drop for NodeContents<'a> {
18+
//~^ ERROR cannot implement a destructor on a structure with type parameters
19+
fn drop( &mut self ) {
20+
}
21+
}
22+
23+
struct Node<'a> {
24+
contents: NodeContents<'a>,
25+
}
26+
27+
impl<'a> Node<'a> {
28+
fn noName(contents: NodeContents<'a>) -> Node<'a> {
29+
Node{ contents: contents,}
30+
}
31+
}
32+
33+
fn main() {}
Lines changed: 21 additions & 0 deletions
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+
struct AutoBuilder<'a> {
12+
context: &'a int
13+
}
14+
15+
impl<'a> Drop for AutoBuilder<'a> {
16+
//~^ ERROR cannot implement a destructor on a structure with type parameters
17+
fn drop(&mut self) {
18+
}
19+
}
20+
21+
fn main() {}
Lines changed: 23 additions & 0 deletions
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+
trait Deserializer<'a> { }
12+
13+
trait Deserializable {
14+
fn deserialize_token<'a, D: Deserializer<'a>>(D, &'a str) -> Self;
15+
}
16+
17+
impl<'a, T: Deserializable> Deserializable for &'a str {
18+
//~^ ERROR unable to infer enough type information
19+
fn deserialize_token<D: Deserializer<'a>>(_x: D, _y: &'a str) -> &'a str {
20+
}
21+
}
22+
23+
fn main() {}

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 Node {
12+
fn zomg();
13+
}
14+
15+
trait Graph<N: Node> {
16+
fn nodes<'a, I: Iterator<&'a N>>(&'a self) -> I;
17+
}
18+
19+
impl<N: Node> Graph<N> for Vec<N> {
20+
fn nodes<'a, I: Iterator<&'a N>>(&self) -> I {
21+
self.iter() //~ ERROR mismatched types
22+
}
23+
}
24+
25+
struct Stuff;
26+
27+
impl Node for Stuff {
28+
fn zomg() {
29+
println!("zomg");
30+
}
31+
}
32+
33+
fn iterate<N: Node, G: Graph<N>>(graph: &G) {
34+
for node in graph.iter() { //~ ERROR does not implement any method in scope named
35+
node.zomg();
36+
}
37+
}
38+
39+
pub fn main() {
40+
let graph = Vec::new();
41+
42+
graph.push(Stuff);
43+
44+
iterate(graph); //~ ERROR mismatched types
45+
}

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

Lines changed: 16 additions & 0 deletions
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+
extern {
12+
pub static symbol: ();
13+
}
14+
static CRASH: () = symbol; //~ cannot refer to other statics by value
15+
16+
fn main() {}

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

Lines changed: 32 additions & 0 deletions
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+
pub struct Lexer<'a> {
12+
input: &'a str,
13+
}
14+
15+
impl<'a> Lexer<'a> {
16+
pub fn new(input: &'a str) -> Lexer<'a> {
17+
Lexer { input: input }
18+
}
19+
}
20+
21+
struct Parser<'a> {
22+
lexer: &'a mut Lexer<'a>,
23+
}
24+
25+
impl<'a> Parser<'a> {
26+
pub fn new(lexer: &'a mut Lexer) -> Parser<'a> {
27+
Parser { lexer: lexer }
28+
//~^ ERROR cannot infer an appropriate lifetime for lifetime parameter
29+
}
30+
}
31+
32+
fn main() {}

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

Lines changed: 25 additions & 0 deletions
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+
mod Y {
12+
type X = uint;
13+
extern {
14+
static x: *const uint;
15+
}
16+
fn foo(value: *const X) -> *const X {
17+
value
18+
}
19+
}
20+
21+
static foo: *const Y::X = Y::foo(Y::x as *const Y::X);
22+
//~^ ERROR cannot refer to other statics by value
23+
//~| ERROR: the trait `core::kinds::Sync` is not implemented for the type
24+
25+
fn main() {}

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

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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, Formatter, Error};
12+
use std::collections::HashMap;
13+
14+
trait HasInventory {
15+
fn getInventory<'s>(&'s self) -> &'s mut Inventory;
16+
fn addToInventory(&self, item: &Item);
17+
fn removeFromInventory(&self, itemName: &str) -> bool;
18+
}
19+
20+
trait TraversesWorld {
21+
fn attemptTraverse(&self, room: &Room, directionStr: &str) -> Result<&Room, &str> {
22+
let direction = str_to_direction(directionStr);
23+
let maybe_room = room.direction_to_room.find(&direction);
24+
//~^ ERROR cannot infer an appropriate lifetime for autoref due to conflicting requirements
25+
match maybe_room {
26+
Some(entry) => Ok(entry),
27+
_ => Err("Direction does not exist in room.")
28+
}
29+
}
30+
}
31+
32+
33+
#[deriving(Show, Eq, PartialEq, Hash)]
34+
enum RoomDirection {
35+
West,
36+
East,
37+
North,
38+
South,
39+
Up,
40+
Down,
41+
In,
42+
Out,
43+
44+
None
45+
}
46+
47+
struct Room {
48+
description: String,
49+
items: Vec<Item>,
50+
direction_to_room: HashMap<RoomDirection, Room>,
51+
}
52+
53+
impl Room {
54+
fn new(description: &'static str) -> Room {
55+
Room {
56+
description: description.to_string(),
57+
items: Vec::new(),
58+
direction_to_room: HashMap::new()
59+
}
60+
}
61+
62+
fn add_direction(&mut self, direction: RoomDirection, room: Room) {
63+
self.direction_to_room.insert(direction, room);
64+
}
65+
}
66+
67+
struct Item {
68+
name: String,
69+
}
70+
71+
struct Inventory {
72+
items: Vec<Item>,
73+
}
74+
75+
impl Inventory {
76+
fn new() -> Inventory {
77+
Inventory {
78+
items: Vec::new()
79+
}
80+
}
81+
}
82+
83+
struct Player {
84+
name: String,
85+
inventory: Inventory,
86+
}
87+
88+
impl Player {
89+
fn new(name: &'static str) -> Player {
90+
Player {
91+
name: name.to_string(),
92+
inventory: Inventory::new()
93+
}
94+
}
95+
}
96+
97+
impl TraversesWorld for Player {
98+
}
99+
100+
impl Show for Player {
101+
fn fmt(&self, formatter: &mut Formatter) -> Result<(), Error> {
102+
formatter.write_str("Player{ name:");
103+
formatter.write_str(self.name.as_slice());
104+
formatter.write_str(" }");
105+
Ok(())
106+
}
107+
}
108+
109+
fn str_to_direction(to_parse: &str) -> RoomDirection {
110+
match to_parse {
111+
"w" | "west" => RoomDirection::West,
112+
"e" | "east" => RoomDirection::East,
113+
"n" | "north" => RoomDirection::North,
114+
"s" | "south" => RoomDirection::South,
115+
"in" => RoomDirection::In,
116+
"out" => RoomDirection::Out,
117+
"up" => RoomDirection::Up,
118+
"down" => RoomDirection::Down,
119+
_ => None //~ ERROR mismatched types
120+
}
121+
}
122+
123+
fn main() {
124+
let mut player = Player::new("Test player");
125+
let mut room = Room::new("A test room");
126+
println!("Made a player: {}", player);
127+
println!("Direction parse: {}", str_to_direction("east"));
128+
match player.attemptTraverse(&room, "west") {
129+
Ok(_) => println!("Was able to move west"),
130+
Err(msg) => println!("Not able to move west: {}", msg)
131+
};
132+
}

0 commit comments

Comments
 (0)