From 13e10f5b7e6fef35770cb6f835492893d43c2e07 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 6 Mar 2014 09:55:35 -0800 Subject: [PATCH] test: Add some tests for closed issues Closes #6738 Closes #7061 Closes #7899 Closes #9719 Closes #10028 Closes #10228 Closes #10401 Closes #11192 Closes #11508 Closes #11529 Closes #11873 Closes #11925 --- src/test/auxiliary/issue-10028.rs | 20 +++++++++++++ src/test/auxiliary/issue-11508.rs | 20 +++++++++++++ src/test/auxiliary/issue-11529.rs | 11 +++++++ src/test/auxiliary/issue-7899.rs | 11 +++++++ src/test/compile-fail/issue-10401.rs | 15 ++++++++++ src/test/compile-fail/issue-11192.rs | 31 ++++++++++++++++++++ src/test/compile-fail/issue-11873.rs | 19 ++++++++++++ src/test/compile-fail/issue-11925.rs | 19 ++++++++++++ src/test/compile-fail/issue-6738.rs | 20 +++++++++++++ src/test/compile-fail/issue-7061.rs | 20 +++++++++++++ src/test/run-pass/issue-10028.rs | 28 ++++++++++++++++++ src/test/run-pass/issue-10228.rs | 25 ++++++++++++++++ src/test/run-pass/issue-11508.rs | 21 ++++++++++++++ src/test/run-pass/issue-11529.rs | 19 ++++++++++++ src/test/run-pass/issue-7899.rs | 18 ++++++++++++ src/test/run-pass/issue-9719.rs | 43 ++++++++++++++++++++++++++++ 16 files changed, 340 insertions(+) create mode 100644 src/test/auxiliary/issue-10028.rs create mode 100644 src/test/auxiliary/issue-11508.rs create mode 100644 src/test/auxiliary/issue-11529.rs create mode 100644 src/test/auxiliary/issue-7899.rs create mode 100644 src/test/compile-fail/issue-10401.rs create mode 100644 src/test/compile-fail/issue-11192.rs create mode 100644 src/test/compile-fail/issue-11873.rs create mode 100644 src/test/compile-fail/issue-11925.rs create mode 100644 src/test/compile-fail/issue-6738.rs create mode 100644 src/test/compile-fail/issue-7061.rs create mode 100644 src/test/run-pass/issue-10028.rs create mode 100644 src/test/run-pass/issue-10228.rs create mode 100644 src/test/run-pass/issue-11508.rs create mode 100644 src/test/run-pass/issue-11529.rs create mode 100644 src/test/run-pass/issue-7899.rs create mode 100644 src/test/run-pass/issue-9719.rs diff --git a/src/test/auxiliary/issue-10028.rs b/src/test/auxiliary/issue-10028.rs new file mode 100644 index 0000000000000..00fdb3e40b975 --- /dev/null +++ b/src/test/auxiliary/issue-10028.rs @@ -0,0 +1,20 @@ +// 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. + +#[unsafe_no_drop_flag] +pub struct ZeroLengthThingWithDestructor; +impl Drop for ZeroLengthThingWithDestructor { + fn drop(&mut self) {} +} +impl ZeroLengthThingWithDestructor { + pub fn new() -> ZeroLengthThingWithDestructor { + ZeroLengthThingWithDestructor + } +} diff --git a/src/test/auxiliary/issue-11508.rs b/src/test/auxiliary/issue-11508.rs new file mode 100644 index 0000000000000..dfdde5e5e4e03 --- /dev/null +++ b/src/test/auxiliary/issue-11508.rs @@ -0,0 +1,20 @@ +// 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 Closed01(F); + +pub trait Bar { fn new() -> Self; } + +impl Bar for Closed01 { + fn new() -> Closed01 { Closed01(Bar::new()) } +} +impl Bar for f32 { fn new() -> f32 { 1.0 } } + +pub fn random() -> T { Bar::new() } diff --git a/src/test/auxiliary/issue-11529.rs b/src/test/auxiliary/issue-11529.rs new file mode 100644 index 0000000000000..9d5005324010e --- /dev/null +++ b/src/test/auxiliary/issue-11529.rs @@ -0,0 +1,11 @@ +// 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 A<'a>(&'a int); diff --git a/src/test/auxiliary/issue-7899.rs b/src/test/auxiliary/issue-7899.rs new file mode 100644 index 0000000000000..f1a0fcffd1658 --- /dev/null +++ b/src/test/auxiliary/issue-7899.rs @@ -0,0 +1,11 @@ +// 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 V2(T, T); diff --git a/src/test/compile-fail/issue-10401.rs b/src/test/compile-fail/issue-10401.rs new file mode 100644 index 0000000000000..e36193aee25c0 --- /dev/null +++ b/src/test/compile-fail/issue-10401.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. + +fn main() { + let mut a = "a"; + a += { "b" }; + //~^ ERROR: binary assignment operation `+=` cannot be applied +} diff --git a/src/test/compile-fail/issue-11192.rs b/src/test/compile-fail/issue-11192.rs new file mode 100644 index 0000000000000..f1da30328905a --- /dev/null +++ b/src/test/compile-fail/issue-11192.rs @@ -0,0 +1,31 @@ +// 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 { + x: int +} + +impl Drop for Foo { + fn drop(&mut self) { + println!("drop {}", self.x); + } +} + +fn main() { + let mut ptr = ~Foo { x: 0 }; + let test = |foo: &Foo| { + println!("access {}", foo.x); + ptr = ~Foo { x: ptr.x + 1 }; + println!("access {}", foo.x); + }; + test(ptr); + //~^ ERROR: cannot borrow `*ptr` as immutable +} + diff --git a/src/test/compile-fail/issue-11873.rs b/src/test/compile-fail/issue-11873.rs new file mode 100644 index 0000000000000..49b226b882ea7 --- /dev/null +++ b/src/test/compile-fail/issue-11873.rs @@ -0,0 +1,19 @@ +// Copyright 2012-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::vec_ng::Vec; + +fn main() { + let mut v = vec!(1); + let f = || v.push(2); + let _w = v; //~ ERROR: cannot move out of `v` + + f(); +} diff --git a/src/test/compile-fail/issue-11925.rs b/src/test/compile-fail/issue-11925.rs new file mode 100644 index 0000000000000..06a976ecf3d30 --- /dev/null +++ b/src/test/compile-fail/issue-11925.rs @@ -0,0 +1,19 @@ +// 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 main() { + let r = { + let x = ~42; + let f = proc() &x; //~ ERROR: borrowed value does not live long enough + f() + }; + + drop(r); +} diff --git a/src/test/compile-fail/issue-6738.rs b/src/test/compile-fail/issue-6738.rs new file mode 100644 index 0000000000000..447d0e061ee54 --- /dev/null +++ b/src/test/compile-fail/issue-6738.rs @@ -0,0 +1,20 @@ +// 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 { + x: T, +} +impl Foo { + fn add(&mut self, v: Foo){ + self.x += v.x; + //~^ ERROR: binary assignment operation `+=` cannot be applied + } +} +fn main() {} diff --git a/src/test/compile-fail/issue-7061.rs b/src/test/compile-fail/issue-7061.rs new file mode 100644 index 0000000000000..c7fa286d351fe --- /dev/null +++ b/src/test/compile-fail/issue-7061.rs @@ -0,0 +1,20 @@ +// 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(managed_boxes)]; + +struct BarStruct; + +impl<'a> BarStruct { + fn foo(&'a mut self) -> @BarStruct { self } + //~^ ERROR: error: mismatched types: expected `@BarStruct` but found `&'a mut BarStruct +} + +fn main() {} diff --git a/src/test/run-pass/issue-10028.rs b/src/test/run-pass/issue-10028.rs new file mode 100644 index 0000000000000..e69aabd46f585 --- /dev/null +++ b/src/test/run-pass/issue-10028.rs @@ -0,0 +1,28 @@ +// 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. + +// aux-build:issue-10028.rs +// ignore-fast + +extern crate issue10028 = "issue-10028"; + +use issue10028::ZeroLengthThingWithDestructor; + +struct Foo { + zero_length_thing: ZeroLengthThingWithDestructor +} + +fn make_foo() -> Foo { + Foo { zero_length_thing: ZeroLengthThingWithDestructor::new() } +} + +fn main() { + let _f:Foo = make_foo(); +} diff --git a/src/test/run-pass/issue-10228.rs b/src/test/run-pass/issue-10228.rs new file mode 100644 index 0000000000000..7059087685637 --- /dev/null +++ b/src/test/run-pass/issue-10228.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. + +enum StdioContainer { + CreatePipe(bool) +} + +struct Test<'a> { + args: &'a [~str], + io: &'a [StdioContainer] +} + +pub fn main() { + let test = Test { + args: &[], + io: &[CreatePipe(true)] + }; +} diff --git a/src/test/run-pass/issue-11508.rs b/src/test/run-pass/issue-11508.rs new file mode 100644 index 0000000000000..a7ad38cde0fc9 --- /dev/null +++ b/src/test/run-pass/issue-11508.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. + +// aux-build:issue-11508.rs +// ignore-fast + +extern crate rand = "issue-11508"; + +use rand::{Closed01, random}; + +fn main() { + let Closed01(val) = random::>(); + println!("{}", val); +} diff --git a/src/test/run-pass/issue-11529.rs b/src/test/run-pass/issue-11529.rs new file mode 100644 index 0000000000000..643e6ca4bda3a --- /dev/null +++ b/src/test/run-pass/issue-11529.rs @@ -0,0 +1,19 @@ +// 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. + +// aux-build:issue-11529.rs +// ignore-fast + +extern crate a = "issue-11529"; + +fn main() { + let one = 1; + let _a = a::A(&one); +} diff --git a/src/test/run-pass/issue-7899.rs b/src/test/run-pass/issue-7899.rs new file mode 100644 index 0000000000000..6ee734d0212aa --- /dev/null +++ b/src/test/run-pass/issue-7899.rs @@ -0,0 +1,18 @@ +// 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. + +// ignore-fast +// aux-build:issue-7899.rs + +extern crate testcrate = "issue-7899"; + +fn main() { + let f = testcrate::V2(1.0f32, 2.0f32); +} diff --git a/src/test/run-pass/issue-9719.rs b/src/test/run-pass/issue-9719.rs new file mode 100644 index 0000000000000..52204c9e0c2e5 --- /dev/null +++ b/src/test/run-pass/issue-9719.rs @@ -0,0 +1,43 @@ +// 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 a { + pub enum Enum { + A(T), + } + + pub trait X {} + impl X for int {} + + pub struct Z<'a>(Enum<&'a X>); + fn foo() { let x = 42; let z = Z(A(&x as &X)); let _ = z; } +} + +mod b { + trait X {} + impl X for int {} + struct Y<'a>{ + x:Option<&'a X>, + } + + fn bar() { + let x = 42; + let _y = Y { x: Some(&x as &X) }; + } +} + +mod c { + pub trait X { fn f(&self); } + impl X for int { fn f(&self) {} } + pub struct Z<'a>(Option<&'a X>); + fn main() { let x = 42; let z = Z(Some(&x as &X)); let _ = z; } +} + +pub fn main() {}