From 04fff50d512b7f2f5a9133fbebd814b80d483044 Mon Sep 17 00:00:00 2001 From: Andrew Paseltiner Date: Tue, 8 Sep 2015 14:19:08 -0400 Subject: [PATCH] Add tests for #17001, #21449, #22992, #23208, #23442 Closes #17001 Closes #21449 Closes #22992 Closes #23208 Closes #23442 --- src/test/compile-fail/issue-17001.rs | 15 +++++ src/test/compile-fail/issue-21449.rs | 15 +++++ src/test/run-pass/issue-22992-2.rs | 27 +++++++++ src/test/run-pass/issue-22992.rs | 85 ++++++++++++++++++++++++++++ src/test/run-pass/issue-23208.rs | 35 ++++++++++++ src/test/run-pass/issue-23442.rs | 31 ++++++++++ 6 files changed, 208 insertions(+) create mode 100644 src/test/compile-fail/issue-17001.rs create mode 100644 src/test/compile-fail/issue-21449.rs create mode 100644 src/test/run-pass/issue-22992-2.rs create mode 100644 src/test/run-pass/issue-22992.rs create mode 100644 src/test/run-pass/issue-23208.rs create mode 100644 src/test/run-pass/issue-23442.rs diff --git a/src/test/compile-fail/issue-17001.rs b/src/test/compile-fail/issue-17001.rs new file mode 100644 index 00000000000..0fee6dc7617 --- /dev/null +++ b/src/test/compile-fail/issue-17001.rs @@ -0,0 +1,15 @@ +// Copyright 2015 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 {} + +fn main() { + let p = foo { x: () }; //~ ERROR `foo` does not name a structure +} diff --git a/src/test/compile-fail/issue-21449.rs b/src/test/compile-fail/issue-21449.rs new file mode 100644 index 00000000000..93c4f4bfcef --- /dev/null +++ b/src/test/compile-fail/issue-21449.rs @@ -0,0 +1,15 @@ +// Copyright 2015 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 MyMod {} + +fn main() { + let myVar = MyMod { T: 0 }; //~ ERROR `MyMod` does not name a structure +} diff --git a/src/test/run-pass/issue-22992-2.rs b/src/test/run-pass/issue-22992-2.rs new file mode 100644 index 00000000000..070d4d11759 --- /dev/null +++ b/src/test/run-pass/issue-22992-2.rs @@ -0,0 +1,27 @@ +// Copyright 2015 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 A(B); +struct B; + +use std::ops::Deref; + +impl Deref for A { + type Target = B; + fn deref(&self) -> &B { &self.0 } +} + +impl B { + fn foo(&self) {} +} + +fn main() { + A(B).foo(); +} diff --git a/src/test/run-pass/issue-22992.rs b/src/test/run-pass/issue-22992.rs new file mode 100644 index 00000000000..ca8f804482a --- /dev/null +++ b/src/test/run-pass/issue-22992.rs @@ -0,0 +1,85 @@ +// Copyright 2015 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. + +// ignore-pretty + +struct X { val: i32 } +impl std::ops::Deref for X { + type Target = i32; + fn deref(&self) -> &i32 { &self.val } +} + + +trait M { fn m(self); } +impl M for i32 { fn m(self) { println!("i32::m()"); } } +impl M for X { fn m(self) { println!("X::m()"); } } +impl<'a> M for &'a X { fn m(self) { println!("&X::m()"); } } +impl<'a, 'b> M for &'a &'b X { fn m(self) { println!("&&X::m()"); } } +impl<'a, 'b, 'c> M for &'a &'b &'c X { fn m(self) { println!("&&&X::m()"); } } + +trait RefM { fn refm(&self); } +impl RefM for i32 { fn refm(&self) { println!("i32::refm()"); } } +impl RefM for X { fn refm(&self) { println!("X::refm()"); } } +impl<'a> RefM for &'a X { fn refm(&self) { println!("&X::refm()"); } } +impl<'a, 'b> RefM for &'a &'b X { fn refm(&self) { println!("&&X::refm()"); } } +impl<'a, 'b, 'c> RefM for &'a &'b &'c X { fn refm(&self) { println!("&&&X::refm()"); } } + +struct Y { val: i32 } +impl std::ops::Deref for Y { + type Target = i32; + fn deref(&self) -> &i32 { &self.val } +} + +struct Z { val: Y } +impl std::ops::Deref for Z { + type Target = Y; + fn deref(&self) -> &Y { &self.val } +} + +struct A; +impl std::marker::Copy for A {} +impl Clone for A { fn clone(&self) -> Self { *self } } +impl M for A { fn m(self) { println!("A::m()"); } } +impl<'a, 'b, 'c> M for &'a &'b &'c A { fn m(self) { println!("&&&A::m()"); } } +impl RefM for A { fn refm(&self) { println!("A::refm()"); } } +impl<'a, 'b, 'c> RefM for &'a &'b &'c A { fn refm(&self) { println!("&&&A::refm()"); } } + +fn main() { + // I'll use @ to denote left side of the dot operator + (*X{val:42}).m(); // i32::refm() , self == @ + X{val:42}.m(); // X::m() , self == @ + (&X{val:42}).m(); // &X::m() , self == @ + (&&X{val:42}).m(); // &&X::m() , self == @ + (&&&X{val:42}).m(); // &&&X:m() , self == @ + (&&&&X{val:42}).m(); // &&&X::m() , self == *@ + (&&&&&X{val:42}).m(); // &&&X::m() , self == **@ + + (*X{val:42}).refm(); // i32::refm() , self == @ + X{val:42}.refm(); // X::refm() , self == @ + (&X{val:42}).refm(); // X::refm() , self == *@ + (&&X{val:42}).refm(); // &X::refm() , self == *@ + (&&&X{val:42}).refm(); // &&X::refm() , self == *@ + (&&&&X{val:42}).refm(); // &&&X::refm(), self == *@ + (&&&&&X{val:42}).refm(); // &&&X::refm(), self == **@ + + Y{val:42}.refm(); // i32::refm() , self == *@ + Z{val:Y{val:42}}.refm(); // i32::refm() , self == **@ + + A.m(); // A::m() , self == @ + // without the Copy trait, (&A).m() would be a compilation error: + // cannot move out of borrowed content + (&A).m(); // A::m() , self == *@ + (&&A).m(); // &&&A::m() , self == &@ + (&&&A).m(); // &&&A::m() , self == @ + A.refm(); // A::refm() , self == @ + (&A).refm(); // A::refm() , self == *@ + (&&A).refm(); // A::refm() , self == **@ + (&&&A).refm(); // &&&A::refm(), self == @ +} diff --git a/src/test/run-pass/issue-23208.rs b/src/test/run-pass/issue-23208.rs new file mode 100644 index 00000000000..ee3c16be731 --- /dev/null +++ b/src/test/run-pass/issue-23208.rs @@ -0,0 +1,35 @@ +// Copyright 2015 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 TheTrait : TheSuperTrait<::Item> { + type Item; +} + +trait TheSuperTrait { + fn get(&self) -> T; +} + +impl TheTrait for i32 { + type Item = u32; +} + +impl TheSuperTrait for i32 { + fn get(&self) -> u32 { + *self as u32 + } +} + +fn foo>(t: &T) -> u32 { + t.get() +} + +fn main() { + foo::(&22); +} diff --git a/src/test/run-pass/issue-23442.rs b/src/test/run-pass/issue-23442.rs new file mode 100644 index 00000000000..88b5a92620b --- /dev/null +++ b/src/test/run-pass/issue-23442.rs @@ -0,0 +1,31 @@ +// Copyright 2015 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::marker::PhantomData; + +pub struct UnionedKeys<'a,K> + where K: UnifyKey + 'a +{ + table: &'a mut UnificationTable, + root_key: K, + stack: Vec, +} + +pub trait UnifyKey { + type Value; +} + +pub struct UnificationTable { + values: Delegate, +} + +pub struct Delegate(PhantomData); + +fn main() {}