rollup merge of #20165: tamird/needstest-tests

@alexcrichton @jakub-
This commit is contained in:
Alex Crichton 2014-12-29 16:35:54 -08:00
commit 62c9a48953
19 changed files with 547 additions and 12 deletions

View file

@ -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;
}

View file

@ -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() {}

View file

@ -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() {}

View file

@ -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() {}

View file

@ -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() {}

View file

@ -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() {}

View file

@ -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
}

View file

@ -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() {}

View file

@ -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() {}

View file

@ -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() {}

View file

@ -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)
};
}

View file

@ -0,0 +1,22 @@
// 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 Foo<'a> {
data: &'a[u8],
}
impl <'a> Foo<'a>{
fn bar(self: &mut Foo) {
//~^ mismatched types: expected `Foo<'a>`, found `Foo<'_>` (lifetime mismatch)
//~| mismatched types: expected `Foo<'a>`, found `Foo<'_>` (lifetime mismatch)
}
}
fn main() {}

View file

@ -1,4 +1,4 @@
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
// 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.
//
@ -8,14 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-test
use std::io::ReaderUtil;
use std::io::Reader;
fn bar(r:@ReaderUtil) -> String { r.read_line() }
trait Foo {}
impl Foo for u8 {}
fn main() {
let r : @Reader = io::stdin();
let _m = bar(r as @ReaderUtil);
let r: Box<Foo> = box 5;
let _m: Box<Foo> = r as Box<Foo>;
//~^ ERROR `core::kinds::Sized` is not implemented for the type `Foo`
//~| ERROR `Foo` is not implemented for the type `Foo`
}

View file

@ -14,8 +14,8 @@ use std::cell::RefCell;
// Regresion test for issue 7364
static boxed: Box<RefCell<int>> = box RefCell::new(0);
//~^ ERROR statics are not allowed to have custom pointers
//~^^ ERROR: the trait `core::kinds::Sync` is not implemented for the type
//~^^^ ERROR: the trait `core::kinds::Sync` is not implemented for the type
//~^^^^ ERROR: the trait `core::kinds::Sync` is not implemented for the type
//~| ERROR: the trait `core::kinds::Sync` is not implemented for the type
//~| ERROR: the trait `core::kinds::Sync` is not implemented for the type
//~| ERROR: the trait `core::kinds::Sync` is not implemented for the type
fn main() { }

View file

@ -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.
fn foo(_: &[&str]) {}
fn bad(a: &str, b: &str) {
foo(&[a, b]);
}
fn good(a: &str, b: &str) {
foo(&[a.as_slice(), b.as_slice()]);
}
fn main() {}

View file

@ -0,0 +1,27 @@
// 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.
#![feature(unboxed_closures)]
use std::ops::Fn;
struct Foo<T>(T);
impl<T: Copy> Fn<(), T> for Foo<T> {
extern "rust-call" fn call(&self, _: ()) -> T {
match *self {
Foo(t) => t
}
}
}
fn main() {
let t: u8 = 1;
println!("{}", Foo(t)());
}

View file

@ -0,0 +1,22 @@
// 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.
fn foo<'r>() {
let maybe_value_ref: Option<&'r u8> = None;
let _ = maybe_value_ref.map(|& ref v| v);
let _ = maybe_value_ref.map(|& ref v| -> &'r u8 {v});
let _ = maybe_value_ref.map(|& ref v: &'r u8| -> &'r u8 {v});
let _ = maybe_value_ref.map(|& ref v: &'r u8| {v});
}
fn main() {
foo();
}

View file

@ -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.
struct Foo<'a> {
listener: ||: 'a
}
impl<'a> Foo<'a> {
fn new(listener: ||: 'a) -> Foo<'a> {
Foo { listener: listener }
}
}
fn main() {
let a = Foo::new(|| {});
}

View file

@ -0,0 +1,40 @@
// 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 base {
pub trait HasNew<T> {
fn new() -> T;
}
pub struct Foo {
dummy: (),
}
impl HasNew<Foo> for Foo {
fn new() -> Foo {
Foo { dummy: () }
}
}
pub struct Bar {
dummy: (),
}
impl HasNew<Bar> for Bar {
fn new() -> Bar {
Bar { dummy: () }
}
}
}
pub fn main() {
let _f: base::Foo = base::HasNew::new();
let _b: base::Bar = base::HasNew::new();
}