From 2c744c7f32a737be1c01a4fd717f18bef278a93c Mon Sep 17 00:00:00 2001 From: Jakub Bukaj Date: Sun, 26 Oct 2014 00:07:41 +0200 Subject: [PATCH] Add test cases for E-needstest issues --- src/test/compile-fail/issue-12863.rs | 17 +++++++++++ src/test/compile-fail/issue-14721.rs | 15 ++++++++++ src/test/compile-fail/issue-16683.rs | 18 ++++++++++++ src/test/compile-fail/issue-17551.rs | 18 ++++++++++++ src/test/compile-fail/issue-18118.rs | 17 +++++++++++ src/test/compile-fail/issue-18252.rs | 19 ++++++++++++ src/test/compile-fail/issue-6991.rs | 15 ++++++++++ src/test/compile-fail/issue-7867.rs | 27 +++++++++++++++++ src/test/run-pass/closure-syntax.rs | 6 ++++ src/test/run-pass/issue-12028.rs | 44 ++++++++++++++++++++++++++++ src/test/run-pass/issue-14901.rs | 27 +++++++++++++++++ src/test/run-pass/issue-16560.rs | 25 ++++++++++++++++ src/test/run-pass/issue-16668.rs | 30 +++++++++++++++++++ 13 files changed, 278 insertions(+) create mode 100644 src/test/compile-fail/issue-12863.rs create mode 100644 src/test/compile-fail/issue-14721.rs create mode 100644 src/test/compile-fail/issue-16683.rs create mode 100644 src/test/compile-fail/issue-17551.rs create mode 100644 src/test/compile-fail/issue-18118.rs create mode 100644 src/test/compile-fail/issue-18252.rs create mode 100644 src/test/compile-fail/issue-6991.rs create mode 100644 src/test/compile-fail/issue-7867.rs create mode 100644 src/test/run-pass/issue-12028.rs create mode 100644 src/test/run-pass/issue-14901.rs create mode 100644 src/test/run-pass/issue-16560.rs create mode 100644 src/test/run-pass/issue-16668.rs diff --git a/src/test/compile-fail/issue-12863.rs b/src/test/compile-fail/issue-12863.rs new file mode 100644 index 00000000000..07676679ef1 --- /dev/null +++ b/src/test/compile-fail/issue-12863.rs @@ -0,0 +1,17 @@ +// 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 fn bar() {} } + +fn main() { + match () { + foo::bar => {} //~ ERROR `bar` is not an enum variant, struct or const + } +} diff --git a/src/test/compile-fail/issue-14721.rs b/src/test/compile-fail/issue-14721.rs new file mode 100644 index 00000000000..92add18f941 --- /dev/null +++ b/src/test/compile-fail/issue-14721.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 foo = "str"; + println!("{}", foo.desc); //~ ERROR attempted access of field `desc` on type `&str`, + // but no field with that name was found +} diff --git a/src/test/compile-fail/issue-16683.rs b/src/test/compile-fail/issue-16683.rs new file mode 100644 index 00000000000..d9dfaac5720 --- /dev/null +++ b/src/test/compile-fail/issue-16683.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. + +trait T<'a> { + fn a(&'a self) -> &'a bool; + fn b(&self) { + self.a(); //~ ERROR mismatched types: expected `&'a Self`, found `&Self` (lifetime mismatch) + } +} + +fn main() {} diff --git a/src/test/compile-fail/issue-17551.rs b/src/test/compile-fail/issue-17551.rs new file mode 100644 index 00000000000..197319b6d43 --- /dev/null +++ b/src/test/compile-fail/issue-17551.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. + +#![feature(unboxed_closures)] + +struct B; + +fn main() { + let foo = B; //~ ERROR unable to infer enough type information to locate the impl of the trait + let closure = |:| foo; +} diff --git a/src/test/compile-fail/issue-18118.rs b/src/test/compile-fail/issue-18118.rs new file mode 100644 index 00000000000..4497c8088c3 --- /dev/null +++ b/src/test/compile-fail/issue-18118.rs @@ -0,0 +1,17 @@ +// 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 fn main() { + static z: &'static int = { + let p = 3; + &p +//~^ ERROR cannot borrow a local variable inside a static block, define a separate static instead + }; +} diff --git a/src/test/compile-fail/issue-18252.rs b/src/test/compile-fail/issue-18252.rs new file mode 100644 index 00000000000..c884f02892f --- /dev/null +++ b/src/test/compile-fail/issue-18252.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. + +#![feature(struct_variant)] + +enum Foo { + Variant { x: uint } +} + +fn main() { + let f = Variant(42u); //~ ERROR expected function, found `Foo` +} diff --git a/src/test/compile-fail/issue-6991.rs b/src/test/compile-fail/issue-6991.rs new file mode 100644 index 00000000000..a5d23c70bd5 --- /dev/null +++ b/src/test/compile-fail/issue-6991.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. + +static x: &'static uint = &1; +static y: uint = *x; +//~^ ERROR cannot refer to other statics by value, +// use the address-of operator or a constant instead +fn main() {} diff --git a/src/test/compile-fail/issue-7867.rs b/src/test/compile-fail/issue-7867.rs new file mode 100644 index 00000000000..0ab551642a0 --- /dev/null +++ b/src/test/compile-fail/issue-7867.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. + +enum A { B, C } + +mod foo { pub fn bar() {} } + +fn main() { + match (true, false) { + B => (), //~ ERROR expected `(bool,bool)`, found `A` (expected tuple, found enum A) + _ => () + } + + match &Some(42i) { + Some(x) => (), //~ ERROR expected `&core::option::Option`, + // found `core::option::Option<>` + None => () //~ ERROR expected `&core::option::Option`, + // found `core::option::Option<>` + } +} diff --git a/src/test/run-pass/closure-syntax.rs b/src/test/run-pass/closure-syntax.rs index b5a94a02b34..9d98a7ac12f 100644 --- a/src/test/run-pass/closure-syntax.rs +++ b/src/test/run-pass/closure-syntax.rs @@ -9,6 +9,9 @@ // except according to those terms. #![allow(dead_code)] +#![feature(unboxed_closures, unboxed_closure_sugar)] + +// compile-flags:-g fn foo() {} @@ -82,6 +85,9 @@ fn bar<'b>() { // issue #13490 let _ = || -> ! loop {}; let _ = proc() -> ! loop {}; + + // issue #17021 + let c = box |&:| {}; } struct B; diff --git a/src/test/run-pass/issue-12028.rs b/src/test/run-pass/issue-12028.rs new file mode 100644 index 00000000000..4d64103e502 --- /dev/null +++ b/src/test/run-pass/issue-12028.rs @@ -0,0 +1,44 @@ +// 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 Hash { + fn hash2(&self, hasher: &H) -> u64; +} + +trait Stream { + fn input(&mut self, bytes: &[u8]); + fn result(&self) -> u64; +} + +trait StreamHasher { + fn stream(&self) -> S; +} + +////////////////////////////////////////////////////////////////////////////// + +trait StreamHash>: Hash { + fn input_stream(&self, stream: &mut S); +} + +impl> Hash for u8 { + fn hash2(&self, hasher: &H) -> u64 { + let mut stream = hasher.stream(); + self.input_stream(&mut stream); + stream.result() + } +} + +impl> StreamHash for u8 { + fn input_stream(&self, stream: &mut S) { + stream.input([*self]); + } +} + +fn main() {} diff --git a/src/test/run-pass/issue-14901.rs b/src/test/run-pass/issue-14901.rs new file mode 100644 index 00000000000..f93347f4366 --- /dev/null +++ b/src/test/run-pass/issue-14901.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. + +use std::io::Reader; + +enum Wrapper<'a> { + WrapReader(&'a Reader + 'a) +} + +trait Wrap<'a> { + fn wrap(self) -> Wrapper<'a>; +} + +impl<'a, R: Reader> Wrap<'a> for &'a mut R { + fn wrap(self) -> Wrapper<'a> { + WrapReader(self as &'a mut Reader) + } +} + +pub fn main() {} diff --git a/src/test/run-pass/issue-16560.rs b/src/test/run-pass/issue-16560.rs new file mode 100644 index 00000000000..77eba0245b1 --- /dev/null +++ b/src/test/run-pass/issue-16560.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. + +#![feature(unboxed_closures)] + +use std::mem; + +fn main() { + let y = 0u8; + let closure = move |&: x| y + x; + + // Check that both closures are capturing by value + assert_eq!(1, mem::size_of_val(&closure)); + + spawn(proc() { + let ok = closure; + }) +} diff --git a/src/test/run-pass/issue-16668.rs b/src/test/run-pass/issue-16668.rs new file mode 100644 index 00000000000..1bfa79b8a11 --- /dev/null +++ b/src/test/run-pass/issue-16668.rs @@ -0,0 +1,30 @@ +// 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)] + +struct Parser<'a, I, O> { + parse: Box> + 'a> +} + +impl<'a, I, O: 'a> Parser<'a, I, O> { + fn compose(mut self, mut rhs: Parser) -> Parser<'a, I, K> { + Parser { + parse: box move |&mut: x: I| { + match self.parse.call_mut((x,)) { + Ok(r) => rhs.parse.call_mut((r,)), + Err(e) => Err(e) + } + } + } + } +} + +fn main() {}