Skip to content

tests for E-needstest #20165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Dec 30, 2014
24 changes: 24 additions & 0 deletions src/test/compile-fail/double-type-import.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 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.

mod foo {
pub use self::bar::X;
use self::bar::X;
//~^ ERROR a value named `X` has already been imported in this module
//~| ERROR a type named `X` has already been imported in this module

mod bar {
pub struct X;
}
}

fn main() {
let _ = foo::X;
}
15 changes: 15 additions & 0 deletions src/test/compile-fail/duplicate-trait-bounds.rs
Original file line number Diff line number Diff line change
@@ -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.

trait Foo {}

fn foo<T: Foo + Foo>() {} //~ ERROR `Foo` already appears in the list of bounds

fn main() {}
16 changes: 16 additions & 0 deletions src/test/compile-fail/issue-13853-2.rs
Original file line number Diff line number Diff line change
@@ -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.

trait FromStructReader<'a> { }
trait ResponseHook {
fn get<'a, T: FromStructReader<'a>>(&'a self);
}
fn foo(res : Box<ResponseHook>) { res.get } //~ ERROR attempted to take value of method
fn main() {}
33 changes: 33 additions & 0 deletions src/test/compile-fail/issue-13853-3.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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.

#![crate_type = "lib"]

enum NodeContents<'a> {
Children(Vec<Node<'a>>),
}

impl<'a> Drop for NodeContents<'a> {
//~^ ERROR cannot implement a destructor on a structure with type parameters
fn drop( &mut self ) {
}
}

struct Node<'a> {
contents: NodeContents<'a>,
}

impl<'a> Node<'a> {
fn noName(contents: NodeContents<'a>) -> Node<'a> {
Node{ contents: contents,}
}
}

fn main() {}
21 changes: 21 additions & 0 deletions src/test/compile-fail/issue-13853-4.rs
Original file line number Diff line number Diff line change
@@ -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.

struct AutoBuilder<'a> {
context: &'a int
}

impl<'a> Drop for AutoBuilder<'a> {
//~^ ERROR cannot implement a destructor on a structure with type parameters
fn drop(&mut self) {
}
}

fn main() {}
23 changes: 23 additions & 0 deletions src/test/compile-fail/issue-13853-5.rs
Original file line number Diff line number Diff line change
@@ -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.

trait Deserializer<'a> { }

trait Deserializable {
fn deserialize_token<'a, D: Deserializer<'a>>(D, &'a str) -> Self;
}

impl<'a, T: Deserializable> Deserializable for &'a str {
//~^ ERROR unable to infer enough type information
fn deserialize_token<D: Deserializer<'a>>(_x: D, _y: &'a str) -> &'a str {
}
}

fn main() {}
45 changes: 45 additions & 0 deletions src/test/compile-fail/issue-13853.rs
Original file line number Diff line number Diff line change
@@ -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.

trait Node {
fn zomg();
}

trait Graph<N: Node> {
fn nodes<'a, I: Iterator<&'a N>>(&'a self) -> I;
}

impl<N: Node> Graph<N> for Vec<N> {
fn nodes<'a, I: Iterator<&'a N>>(&self) -> I {
self.iter() //~ ERROR mismatched types
}
}

struct Stuff;

impl Node for Stuff {
fn zomg() {
println!("zomg");
}
}

fn iterate<N: Node, G: Graph<N>>(graph: &G) {
for node in graph.iter() { //~ ERROR does not implement any method in scope named
node.zomg();
}
}

pub fn main() {
let graph = Vec::new();

graph.push(Stuff);

iterate(graph); //~ ERROR mismatched types
}
16 changes: 16 additions & 0 deletions src/test/compile-fail/issue-14227.rs
Original file line number Diff line number Diff line change
@@ -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.

extern {
pub static symbol: ();
}
static CRASH: () = symbol; //~ cannot refer to other statics by value

fn main() {}
32 changes: 32 additions & 0 deletions src/test/compile-fail/issue-15034.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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 struct Lexer<'a> {
input: &'a str,
}

impl<'a> Lexer<'a> {
pub fn new(input: &'a str) -> Lexer<'a> {
Lexer { input: input }
}
}

struct Parser<'a> {
lexer: &'a mut Lexer<'a>,
}

impl<'a> Parser<'a> {
pub fn new(lexer: &'a mut Lexer) -> Parser<'a> {
Parser { lexer: lexer }
//~^ ERROR cannot infer an appropriate lifetime for lifetime parameter
}
}

fn main() {}
25 changes: 25 additions & 0 deletions src/test/compile-fail/issue-16538.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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.

mod Y {
type X = uint;
extern {
static x: *const uint;
}
fn foo(value: *const X) -> *const X {
value
}
}

static foo: *const Y::X = Y::foo(Y::x as *const Y::X);
//~^ ERROR cannot refer to other statics by value
//~| ERROR: the trait `core::kinds::Sync` is not implemented for the type

fn main() {}
132 changes: 132 additions & 0 deletions src/test/compile-fail/issue-17728.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
// 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::fmt::{Show, Formatter, Error};
use std::collections::HashMap;

trait HasInventory {
fn getInventory<'s>(&'s self) -> &'s mut Inventory;
fn addToInventory(&self, item: &Item);
fn removeFromInventory(&self, itemName: &str) -> bool;
}

trait TraversesWorld {
fn attemptTraverse(&self, room: &Room, directionStr: &str) -> Result<&Room, &str> {
let direction = str_to_direction(directionStr);
let maybe_room = room.direction_to_room.find(&direction);
//~^ ERROR cannot infer an appropriate lifetime for autoref due to conflicting requirements
match maybe_room {
Some(entry) => Ok(entry),
_ => Err("Direction does not exist in room.")
}
}
}


#[deriving(Show, Eq, PartialEq, Hash)]
enum RoomDirection {
West,
East,
North,
South,
Up,
Down,
In,
Out,

None
}

struct Room {
description: String,
items: Vec<Item>,
direction_to_room: HashMap<RoomDirection, Room>,
}

impl Room {
fn new(description: &'static str) -> Room {
Room {
description: description.to_string(),
items: Vec::new(),
direction_to_room: HashMap::new()
}
}

fn add_direction(&mut self, direction: RoomDirection, room: Room) {
self.direction_to_room.insert(direction, room);
}
}

struct Item {
name: String,
}

struct Inventory {
items: Vec<Item>,
}

impl Inventory {
fn new() -> Inventory {
Inventory {
items: Vec::new()
}
}
}

struct Player {
name: String,
inventory: Inventory,
}

impl Player {
fn new(name: &'static str) -> Player {
Player {
name: name.to_string(),
inventory: Inventory::new()
}
}
}

impl TraversesWorld for Player {
}

impl Show for Player {
fn fmt(&self, formatter: &mut Formatter) -> Result<(), Error> {
formatter.write_str("Player{ name:");
formatter.write_str(self.name.as_slice());
formatter.write_str(" }");
Ok(())
}
}

fn str_to_direction(to_parse: &str) -> RoomDirection {
match to_parse {
"w" | "west" => RoomDirection::West,
"e" | "east" => RoomDirection::East,
"n" | "north" => RoomDirection::North,
"s" | "south" => RoomDirection::South,
"in" => RoomDirection::In,
"out" => RoomDirection::Out,
"up" => RoomDirection::Up,
"down" => RoomDirection::Down,
_ => None //~ ERROR mismatched types
}
}

fn main() {
let mut player = Player::new("Test player");
let mut room = Room::new("A test room");
println!("Made a player: {}", player);
println!("Direction parse: {}", str_to_direction("east"));
match player.attemptTraverse(&room, "west") {
Ok(_) => println!("Was able to move west"),
Err(msg) => println!("Not able to move west: {}", msg)
};
}
Loading