From 12099ce94c239849571c6b68e22c4049a795b76d Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Mon, 2 Sep 2013 23:33:17 +1000 Subject: [PATCH] Tests for fixed issues. Closes #3794. Closes #4025. Closes #5688. Closes #5708. Closes #7012. Closes #7327. --- .../functional-struct-update-noncopyable.rs | 26 ++++++++ src/test/run-pass/issue-3794.rs | 1 - src/test/run-pass/issue-4025.rs | 32 ++++++++++ src/test/run-pass/issue-5688.rs | 26 ++++++++ src/test/run-pass/issue-5708.rs | 60 +++++++++++++++++++ src/test/run-pass/issue-7012.rs | 27 +++++++++ 6 files changed, 171 insertions(+), 1 deletion(-) create mode 100644 src/test/compile-fail/functional-struct-update-noncopyable.rs create mode 100644 src/test/run-pass/issue-4025.rs create mode 100644 src/test/run-pass/issue-5688.rs create mode 100644 src/test/run-pass/issue-5708.rs create mode 100644 src/test/run-pass/issue-7012.rs diff --git a/src/test/compile-fail/functional-struct-update-noncopyable.rs b/src/test/compile-fail/functional-struct-update-noncopyable.rs new file mode 100644 index 00000000000..dd881790ba8 --- /dev/null +++ b/src/test/compile-fail/functional-struct-update-noncopyable.rs @@ -0,0 +1,26 @@ +// Copyright 2012 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. + +// issue 7327 + +// xfail-fast #7103 +extern mod extra; +use extra::arc::*; + +struct A { y: Arc, x: Arc } + +impl Drop for A { + fn drop(&self) { println(fmt!("x=%?", self.x.get())); } +} +fn main() { + let a = A { y: Arc::new(1), x: Arc::new(2) }; + let _b = A { y: Arc::new(3), ..a }; + let _c = a; //~ ERROR use of moved value +} diff --git a/src/test/run-pass/issue-3794.rs b/src/test/run-pass/issue-3794.rs index 5ec8383dd20..fdd0955bbed 100644 --- a/src/test/run-pass/issue-3794.rs +++ b/src/test/run-pass/issue-3794.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// xfail-test trait T { fn print(&self); } diff --git a/src/test/run-pass/issue-4025.rs b/src/test/run-pass/issue-4025.rs new file mode 100644 index 00000000000..4a5cf156ce1 --- /dev/null +++ b/src/test/run-pass/issue-4025.rs @@ -0,0 +1,32 @@ +// Copyright 2013 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. + +/* +# if b { x } else { y } requires identical types for x and y +*/ + +fn print1(b: bool, s1: &str, s2: &str) { + println(if b { s1 } else { s2 }); +} +fn print2<'a, 'b>(b: bool, s1: &'a str, s2: &'b str) { + println(if b { s1 } else { s2 }); +} +fn print3(b: bool, s1: &str, s2: &str) { + let mut s: &str; + if b { s = s1; } else { s = s2; } + println(s); +} +fn print4<'a, 'b>(b: bool, s1: &'a str, s2: &'b str) { + let mut s: &str; + if b { s = s1; } else { s = s2; } + println(s); +} + +pub fn main() {} diff --git a/src/test/run-pass/issue-5688.rs b/src/test/run-pass/issue-5688.rs new file mode 100644 index 00000000000..440e2a43e42 --- /dev/null +++ b/src/test/run-pass/issue-5688.rs @@ -0,0 +1,26 @@ +// Copyright 2013 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. + +/* +# Corrupted initialization in the static struct + +...should print &[1, 2, 3] but instead prints something like +&[4492532864, 24]. It is pretty evident that the compiler messed up +with the representation of [int, ..n] and [int] somehow, or at least +failed to typecheck correctly. +*/ + +struct X { vec: &'static [int] } +static V: &'static [X] = &[X { vec: &[1, 2, 3] }]; +fn main() { + for &v in V.iter() { + println(fmt!("%?", v.vec)); + } +} diff --git a/src/test/run-pass/issue-5708.rs b/src/test/run-pass/issue-5708.rs new file mode 100644 index 00000000000..51f6ad6aa30 --- /dev/null +++ b/src/test/run-pass/issue-5708.rs @@ -0,0 +1,60 @@ +// Copyright 2013 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. + +/* +# ICE when returning struct with borrowed pointer to trait + +A function which takes a borrowed pointer to a trait and returns a +struct with that borrowed pointer results in an ICE. + +This does not occur with concrete types, only with borrowed pointers +to traits. +*/ + +// original +trait Inner { + fn print(&self); +} + +impl Inner for int { + fn print(&self) { print(fmt!("Inner: %d\n", *self)); } +} + +struct Outer<'self> { + inner: &'self Inner +} + +impl<'self> Outer<'self> { + fn new<'r>(inner: &'r Inner) -> Outer<'r> { + Outer { + inner: inner + } + } +} + +fn main() { + let inner = 5; + let outer = Outer::new(&inner as &Inner); + outer.inner.print(); +} + + +// minimal +trait MyTrait { } + +pub struct MyContainer<'self, T> { + foos: ~[&'self MyTrait], +} + +impl<'self, T> MyContainer<'self, T> { + pub fn add (&mut self, foo: &'self MyTrait) { + self.foos.push(foo); + } +} diff --git a/src/test/run-pass/issue-7012.rs b/src/test/run-pass/issue-7012.rs new file mode 100644 index 00000000000..777803d75a5 --- /dev/null +++ b/src/test/run-pass/issue-7012.rs @@ -0,0 +1,27 @@ +// Copyright 2013 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. + +/* +# Comparison of static arrays + +The expected behaviour would be that test==test1, therefore 'true' +would be printed, however the below prints false. +*/ + +struct signature<'self> { pattern : &'self [u32] } + +static test1: signature<'static> = signature { + pattern: &[0x243f6a88u32,0x85a308d3u32,0x13198a2eu32,0x03707344u32,0xa4093822u32,0x299f31d0u32] +}; + +fn main() { + let test = &[0x243f6a88u32,0x85a308d3u32,0x13198a2eu32,0x03707344u32,0xa4093822u32,0x299f31d0u32]; + println(fmt!("%b",test==test1.pattern)); +}