From 7dc36e9d9991608c59ac9e40e89573318cd08b74 Mon Sep 17 00:00:00 2001 From: topecongiro Date: Tue, 7 Mar 2017 00:19:48 +0900 Subject: [PATCH] Add tests for issues with the 'E-needtest' label. --- src/test/codegen/issue-15953.rs | 39 ++++++++++++++++++++++++++++ src/test/compile-fail/issue-18446.rs | 29 +++++++++++++++++++++ src/test/compile-fail/issue-22874.rs | 20 ++++++++++++++ src/test/run-pass/issue-18446.rs | 21 +++++++++++++++ src/test/run-pass/issue-23311.rs | 21 +++++++++++++++ 5 files changed, 130 insertions(+) create mode 100644 src/test/codegen/issue-15953.rs create mode 100644 src/test/compile-fail/issue-18446.rs create mode 100644 src/test/compile-fail/issue-22874.rs create mode 100644 src/test/run-pass/issue-18446.rs create mode 100644 src/test/run-pass/issue-23311.rs diff --git a/src/test/codegen/issue-15953.rs b/src/test/codegen/issue-15953.rs new file mode 100644 index 00000000000..320ea6b5cc4 --- /dev/null +++ b/src/test/codegen/issue-15953.rs @@ -0,0 +1,39 @@ +// Copyright 2017 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. + +// Test that llvm generates `memcpy` for moving a value +// inside a function and moving an argument. + +struct Foo { + x: Vec, +} + +#[inline(never)] +#[no_mangle] +// CHECK: memcpy +fn interior(x: Vec) -> Vec { + let Foo { x } = Foo { x: x }; + x +} + +#[inline(never)] +#[no_mangle] +// CHECK: memcpy +fn exterior(x: Vec) -> Vec { + x +} + +fn main() { + let x = interior(Vec::new()); + println!("{:?}", x); + + let x = exterior(Vec::new()); + println!("{:?}", x); +} diff --git a/src/test/compile-fail/issue-18446.rs b/src/test/compile-fail/issue-18446.rs new file mode 100644 index 00000000000..60afea5a621 --- /dev/null +++ b/src/test/compile-fail/issue-18446.rs @@ -0,0 +1,29 @@ +// Copyright 2017 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. + +// Test that name clashes between the method in an impl for the type +// and the method in the trait when both are in the same scope. + +trait T { + fn foo(&self); +} + +impl<'a> T + 'a { + fn foo(&self) {} +} + +impl T for i32 { + fn foo(&self) {} +} + +fn main() { + let x: &T = &0i32; + x.foo(); //~ ERROR multiple applicable items in scope [E0034] +} diff --git a/src/test/compile-fail/issue-22874.rs b/src/test/compile-fail/issue-22874.rs new file mode 100644 index 00000000000..0df84a436c0 --- /dev/null +++ b/src/test/compile-fail/issue-22874.rs @@ -0,0 +1,20 @@ +// Copyright 2017 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 Table { + rows: [[String]], + //~^ ERROR the trait bound `[std::string::String]: std::marker::Sized` is not satisfied [E0277] +} + +fn f(table: &Table) -> &[String] { + &table.rows[0] +} + +fn main() {} diff --git a/src/test/run-pass/issue-18446.rs b/src/test/run-pass/issue-18446.rs new file mode 100644 index 00000000000..eb321e046dc --- /dev/null +++ b/src/test/run-pass/issue-18446.rs @@ -0,0 +1,21 @@ +// Copyright 2017 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. + +// Test that methods in trait impls should override default methods. + +trait T { + fn foo(&self) -> i32 { 0 } +} + +impl<'a> T + 'a { + fn foo(&self) -> i32 { 1 } +} + +fn main() {} diff --git a/src/test/run-pass/issue-23311.rs b/src/test/run-pass/issue-23311.rs new file mode 100644 index 00000000000..fc286184dcb --- /dev/null +++ b/src/test/run-pass/issue-23311.rs @@ -0,0 +1,21 @@ +// Copyright 2017 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. + +// Test that we do not ICE when pattern matching an array against a slice. + +#![feature(slice_patterns)] + +fn main() { + match "foo".as_bytes() { + b"food" => (), + &[b'f', ..] => (), + _ => () + } +}