diff --git a/src/test/compile-fail/double-type-import.rs b/src/test/compile-fail/double-type-import.rs new file mode 100644 index 00000000000..923f95e69d1 --- /dev/null +++ b/src/test/compile-fail/double-type-import.rs @@ -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 or the MIT license +// , 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; +} diff --git a/src/test/compile-fail/duplicate-trait-bounds.rs b/src/test/compile-fail/duplicate-trait-bounds.rs new file mode 100644 index 00000000000..d9aa9d9dfcc --- /dev/null +++ b/src/test/compile-fail/duplicate-trait-bounds.rs @@ -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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +trait Foo {} + +fn foo() {} //~ ERROR `Foo` already appears in the list of bounds + +fn main() {} diff --git a/src/test/compile-fail/issue-13853-2.rs b/src/test/compile-fail/issue-13853-2.rs new file mode 100644 index 00000000000..ea0d880f4a1 --- /dev/null +++ b/src/test/compile-fail/issue-13853-2.rs @@ -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 or the MIT license +// , 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) { res.get } //~ ERROR attempted to take value of method +fn main() {} diff --git a/src/test/compile-fail/issue-13853-3.rs b/src/test/compile-fail/issue-13853-3.rs new file mode 100644 index 00000000000..f10c47b594e --- /dev/null +++ b/src/test/compile-fail/issue-13853-3.rs @@ -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 or the MIT license +// , 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>), +} + +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() {} diff --git a/src/test/compile-fail/issue-13853-4.rs b/src/test/compile-fail/issue-13853-4.rs new file mode 100644 index 00000000000..7d653f5ab9e --- /dev/null +++ b/src/test/compile-fail/issue-13853-4.rs @@ -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 or the MIT license +// , 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() {} diff --git a/src/test/compile-fail/issue-13853-5.rs b/src/test/compile-fail/issue-13853-5.rs new file mode 100644 index 00000000000..b3a4f341f84 --- /dev/null +++ b/src/test/compile-fail/issue-13853-5.rs @@ -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 or the MIT license +// , 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>(_x: D, _y: &'a str) -> &'a str { + } +} + +fn main() {} diff --git a/src/test/compile-fail/issue-13853.rs b/src/test/compile-fail/issue-13853.rs new file mode 100644 index 00000000000..868836a4bbd --- /dev/null +++ b/src/test/compile-fail/issue-13853.rs @@ -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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +trait Node { + fn zomg(); +} + +trait Graph { + fn nodes<'a, I: Iterator<&'a N>>(&'a self) -> I; +} + +impl Graph for Vec { + 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>(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 +} diff --git a/src/test/compile-fail/issue-14227.rs b/src/test/compile-fail/issue-14227.rs new file mode 100644 index 00000000000..c4846a64f29 --- /dev/null +++ b/src/test/compile-fail/issue-14227.rs @@ -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 or the MIT license +// , 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() {} diff --git a/src/test/compile-fail/issue-15034.rs b/src/test/compile-fail/issue-15034.rs new file mode 100644 index 00000000000..13d27e7152b --- /dev/null +++ b/src/test/compile-fail/issue-15034.rs @@ -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 or the MIT license +// , 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() {} diff --git a/src/test/compile-fail/issue-16538.rs b/src/test/compile-fail/issue-16538.rs new file mode 100644 index 00000000000..0e022834bac --- /dev/null +++ b/src/test/compile-fail/issue-16538.rs @@ -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 or the MIT license +// , 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() {} diff --git a/src/test/compile-fail/issue-17728.rs b/src/test/compile-fail/issue-17728.rs new file mode 100644 index 00000000000..50b0a1a20c2 --- /dev/null +++ b/src/test/compile-fail/issue-17728.rs @@ -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 or the MIT license +// , 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, + direction_to_room: HashMap, +} + +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, +} + +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) + }; +} diff --git a/src/test/compile-fail/issue-17740.rs b/src/test/compile-fail/issue-17740.rs new file mode 100644 index 00000000000..73f86fee903 --- /dev/null +++ b/src/test/compile-fail/issue-17740.rs @@ -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 or the MIT license +// , 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() {} diff --git a/src/test/compile-fail/issue-5543.rs b/src/test/compile-fail/issue-5543.rs index 0090dd544f6..bbd41b28f03 100644 --- a/src/test/compile-fail/issue-5543.rs +++ b/src/test/compile-fail/issue-5543.rs @@ -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 = box 5; + let _m: Box = r as Box; + //~^ ERROR `core::kinds::Sized` is not implemented for the type `Foo` + //~| ERROR `Foo` is not implemented for the type `Foo` } diff --git a/src/test/compile-fail/issue-7364.rs b/src/test/compile-fail/issue-7364.rs index 2646edd7684..ab5ba296652 100644 --- a/src/test/compile-fail/issue-7364.rs +++ b/src/test/compile-fail/issue-7364.rs @@ -14,8 +14,8 @@ use std::cell::RefCell; // Regresion test for issue 7364 static boxed: Box> = 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() { } diff --git a/src/test/run-pass/inconsistent-lifetime-mismatch.rs b/src/test/run-pass/inconsistent-lifetime-mismatch.rs new file mode 100644 index 00000000000..b30583c6668 --- /dev/null +++ b/src/test/run-pass/inconsistent-lifetime-mismatch.rs @@ -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 or the MIT license +// , 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() {} diff --git a/src/test/run-pass/issue-13655.rs b/src/test/run-pass/issue-13655.rs new file mode 100644 index 00000000000..6fdaac99204 --- /dev/null +++ b/src/test/run-pass/issue-13655.rs @@ -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 or the MIT license +// , 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); + +impl Fn<(), T> for Foo { + extern "rust-call" fn call(&self, _: ()) -> T { + match *self { + Foo(t) => t + } + } +} + +fn main() { + let t: u8 = 1; + println!("{}", Foo(t)()); +} diff --git a/src/test/run-pass/issue-13665.rs b/src/test/run-pass/issue-13665.rs new file mode 100644 index 00000000000..5ccbe9a7980 --- /dev/null +++ b/src/test/run-pass/issue-13665.rs @@ -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 or the MIT license +// , 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(); +} diff --git a/src/test/run-pass/issue-13808.rs b/src/test/run-pass/issue-13808.rs new file mode 100644 index 00000000000..e20090adcf6 --- /dev/null +++ b/src/test/run-pass/issue-13808.rs @@ -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 or the MIT license +// , 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(|| {}); +} diff --git a/src/test/run-pass/trait-static-method-generic-inference.rs b/src/test/run-pass/trait-static-method-generic-inference.rs new file mode 100644 index 00000000000..4151ad6530e --- /dev/null +++ b/src/test/run-pass/trait-static-method-generic-inference.rs @@ -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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +mod base { + pub trait HasNew { + fn new() -> T; + } + + pub struct Foo { + dummy: (), + } + + impl HasNew for Foo { + fn new() -> Foo { + Foo { dummy: () } + } + } + + pub struct Bar { + dummy: (), + } + + impl HasNew for Bar { + fn new() -> Bar { + Bar { dummy: () } + } + } +} + +pub fn main() { + let _f: base::Foo = base::HasNew::new(); + let _b: base::Bar = base::HasNew::new(); +}