From 37250679bc01a2e48d4a00e70dbf480c492983f1 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 22 Dec 2014 12:38:04 -0800 Subject: [PATCH 01/14] Regression test for #3902 Closes #3902. --- .../trait-static-method-generic-inference.rs | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/test/run-pass/trait-static-method-generic-inference.rs 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(); +} From 5e9a2ab8463e930905afa787546bd696456e2931 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 22 Dec 2014 18:45:18 -0800 Subject: [PATCH 02/14] Update test for #5543 Closes #5543. --- src/test/compile-fail/issue-5543.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) 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` } From dd8fdff4fb6cbf63ef47e4a29c2cfb63e21f9744 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 22 Dec 2014 20:15:43 -0800 Subject: [PATCH 03/14] Regression test for #8874 Closes #8874. --- .../inconsistent-lifetime-mismatch.rs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/test/run-pass/inconsistent-lifetime-mismatch.rs 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() {} From ee6b97d5af6b6cf78732b994cda5c244c8b99436 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 22 Dec 2014 20:21:43 -0800 Subject: [PATCH 04/14] Regression test for simple case of #9197 --- src/test/compile-fail/duplicate-trait-bounds.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/test/compile-fail/duplicate-trait-bounds.rs 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() {} From 0579d5846b00eb577d8a89aa563e43e81cc4426b Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 22 Dec 2014 21:09:40 -0800 Subject: [PATCH 05/14] Regression test for #13655 Closes #13655. --- src/test/run-pass/issue-13655.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/test/run-pass/issue-13655.rs 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)()); +} From 885d7de97534cc56941c3cee33fd1d3f84144732 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 22 Dec 2014 21:20:31 -0800 Subject: [PATCH 06/14] Regression test for #13665 Closes #13665. --- src/test/run-pass/issue-13665.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/test/run-pass/issue-13665.rs 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(); +} From 7a758d188aa9e6bf3dc1e4305068ba21edf74f31 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 22 Dec 2014 21:20:31 -0800 Subject: [PATCH 07/14] Regression test for #13808 Closes #13808. --- src/test/run-pass/issue-13808.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/test/run-pass/issue-13808.rs 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(|| {}); +} From 9cd7864147a5f18731908245c8aa5575e2542fb6 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 22 Dec 2014 21:20:31 -0800 Subject: [PATCH 08/14] Regression tests for #13853 Closes #13853, #14889. --- src/test/compile-fail/issue-13853-2.rs | 16 +++++++++ src/test/compile-fail/issue-13853-3.rs | 33 +++++++++++++++++++ src/test/compile-fail/issue-13853-4.rs | 21 ++++++++++++ src/test/compile-fail/issue-13853-5.rs | 23 +++++++++++++ src/test/compile-fail/issue-13853.rs | 45 ++++++++++++++++++++++++++ 5 files changed, 138 insertions(+) create mode 100644 src/test/compile-fail/issue-13853-2.rs create mode 100644 src/test/compile-fail/issue-13853-3.rs create mode 100644 src/test/compile-fail/issue-13853-4.rs create mode 100644 src/test/compile-fail/issue-13853-5.rs create mode 100644 src/test/compile-fail/issue-13853.rs 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 +} From 1fd491c3b436753c25c153f24b95a481a36c4804 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 22 Dec 2014 21:20:31 -0800 Subject: [PATCH 09/14] Regression test for #14386 Closes #14386. --- src/test/compile-fail/double-type-import.rs | 24 +++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/test/compile-fail/double-type-import.rs 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; +} From b745a4f944b45980bc714f4420424ee6d5756efe Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 22 Dec 2014 21:20:31 -0800 Subject: [PATCH 10/14] Regression test for #14227 Closes #14227. --- src/test/compile-fail/issue-14227.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/test/compile-fail/issue-14227.rs 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() {} From d1438f50cf711dcb2be87d0604ebe51cd11bcac6 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 22 Dec 2014 21:20:31 -0800 Subject: [PATCH 11/14] Regression test for #15034 Closes #15034. --- src/test/compile-fail/issue-15034.rs | 32 ++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/test/compile-fail/issue-15034.rs 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() {} From 01cdf00c2fbc388f777366a5ee303019c462b99a Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 22 Dec 2014 21:20:31 -0800 Subject: [PATCH 12/14] Regression test for #16538 Closes #16538. --- src/test/compile-fail/issue-16538.rs | 25 +++++++++++++++++++++++++ src/test/compile-fail/issue-7364.rs | 6 +++--- 2 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 src/test/compile-fail/issue-16538.rs 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-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() { } From 2d100212a916107f336e92c8c0ed79a5bedc4f6a Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 22 Dec 2014 21:20:31 -0800 Subject: [PATCH 13/14] Regression test for #17728 Closes #17728. --- src/test/compile-fail/issue-17728.rs | 132 +++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 src/test/compile-fail/issue-17728.rs 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) + }; +} From 252423f8b75b25228090b7606c2afaa3fcc51835 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 22 Dec 2014 21:20:31 -0800 Subject: [PATCH 14/14] Regression test for #17740 Closes #17740. --- src/test/compile-fail/issue-17740.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/test/compile-fail/issue-17740.rs 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() {}