From 4e2dd8d24ae58fad215416b89bf00e2444a5128e Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 5 Aug 2016 22:18:01 +0200 Subject: [PATCH] Add new error code tests --- src/test/compile-fail/E0271.rs | 21 +++++++++++++++++++++ src/test/compile-fail/E0275.rs | 18 ++++++++++++++++++ src/test/compile-fail/E0276.rs | 20 ++++++++++++++++++++ src/test/compile-fail/E0277.rs | 21 +++++++++++++++++++++ src/test/compile-fail/E0281.rs | 16 ++++++++++++++++ src/test/compile-fail/E0282.rs | 13 +++++++++++++ src/test/compile-fail/E0283.rs | 29 +++++++++++++++++++++++++++++ src/test/compile-fail/E0296.rs | 13 +++++++++++++ src/test/compile-fail/E0297.rs | 15 +++++++++++++++ src/test/compile-fail/E0301.rs | 17 +++++++++++++++++ src/test/compile-fail/E0302.rs | 17 +++++++++++++++++ src/test/compile-fail/E0303.rs | 17 +++++++++++++++++ 12 files changed, 217 insertions(+) create mode 100644 src/test/compile-fail/E0271.rs create mode 100644 src/test/compile-fail/E0275.rs create mode 100644 src/test/compile-fail/E0276.rs create mode 100644 src/test/compile-fail/E0277.rs create mode 100644 src/test/compile-fail/E0281.rs create mode 100644 src/test/compile-fail/E0282.rs create mode 100644 src/test/compile-fail/E0283.rs create mode 100644 src/test/compile-fail/E0296.rs create mode 100644 src/test/compile-fail/E0297.rs create mode 100644 src/test/compile-fail/E0301.rs create mode 100644 src/test/compile-fail/E0302.rs create mode 100644 src/test/compile-fail/E0303.rs diff --git a/src/test/compile-fail/E0271.rs b/src/test/compile-fail/E0271.rs new file mode 100644 index 000000000000..d322c8b1caf5 --- /dev/null +++ b/src/test/compile-fail/E0271.rs @@ -0,0 +1,21 @@ +// Copyright 2016 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 Trait { type AssociatedType; } + +fn foo(t: T) where T: Trait { + println!("in foo"); +} + +impl Trait for i8 { type AssociatedType = &'static str; } + +fn main() { + foo(3_i8); //~ ERROR E0271 +} diff --git a/src/test/compile-fail/E0275.rs b/src/test/compile-fail/E0275.rs new file mode 100644 index 000000000000..8dfd1d9b4afc --- /dev/null +++ b/src/test/compile-fail/E0275.rs @@ -0,0 +1,18 @@ +// Copyright 2016 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 Foo {} + +struct Bar(T); + +impl Foo for T where Bar: Foo {} //~ ERROR E0275 + +fn main() { +} diff --git a/src/test/compile-fail/E0276.rs b/src/test/compile-fail/E0276.rs new file mode 100644 index 000000000000..62e43b02ca85 --- /dev/null +++ b/src/test/compile-fail/E0276.rs @@ -0,0 +1,20 @@ +// Copyright 2016 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 Foo { + fn foo(x: T); +} + +impl Foo for bool { + fn foo(x: T) where T: Copy {} //~ ERROR E0276 +} + +fn main() { +} diff --git a/src/test/compile-fail/E0277.rs b/src/test/compile-fail/E0277.rs new file mode 100644 index 000000000000..7737f12ac371 --- /dev/null +++ b/src/test/compile-fail/E0277.rs @@ -0,0 +1,21 @@ +// Copyright 2016 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 Foo { + fn bar(&self); +} + +fn some_func(foo: T) { + foo.bar(); +} + +fn main() { + some_func(5i32); //~ ERROR E0277 +} diff --git a/src/test/compile-fail/E0281.rs b/src/test/compile-fail/E0281.rs new file mode 100644 index 000000000000..d468cd3ff1bf --- /dev/null +++ b/src/test/compile-fail/E0281.rs @@ -0,0 +1,16 @@ +// Copyright 2016 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 foo(x: F) { } + +fn main() { + foo(|y| { }); //~ ERROR E0281 + //~^ ERROR E0281 +} diff --git a/src/test/compile-fail/E0282.rs b/src/test/compile-fail/E0282.rs new file mode 100644 index 000000000000..dfc702670ce4 --- /dev/null +++ b/src/test/compile-fail/E0282.rs @@ -0,0 +1,13 @@ +// Copyright 2016 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 x = "hello".chars().rev().collect(); //~ ERROR E0282 +} diff --git a/src/test/compile-fail/E0283.rs b/src/test/compile-fail/E0283.rs new file mode 100644 index 000000000000..844c47f41b81 --- /dev/null +++ b/src/test/compile-fail/E0283.rs @@ -0,0 +1,29 @@ +// Copyright 2016 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 Generator { + fn create() -> u32; +} + +struct Impl; + +impl Generator for Impl { + fn create() -> u32 { 1 } +} + +struct AnotherImpl; + +impl Generator for AnotherImpl { + fn create() -> u32 { 2 } +} + +fn main() { + let cont: u32 = Generator::create(); //~ ERROR E0283 +} diff --git a/src/test/compile-fail/E0296.rs b/src/test/compile-fail/E0296.rs new file mode 100644 index 000000000000..562fd00a18aa --- /dev/null +++ b/src/test/compile-fail/E0296.rs @@ -0,0 +1,13 @@ +// Copyright 2016 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. + +#![recursion_limit] //~ ERROR E0296 + +fn main() {} diff --git a/src/test/compile-fail/E0297.rs b/src/test/compile-fail/E0297.rs new file mode 100644 index 000000000000..43166c1a9e83 --- /dev/null +++ b/src/test/compile-fail/E0297.rs @@ -0,0 +1,15 @@ +// Copyright 2016 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 xs : Vec> = vec!(Some(1), None); + + for Some(x) in xs {} //~ ERROR E0297 +} diff --git a/src/test/compile-fail/E0301.rs b/src/test/compile-fail/E0301.rs new file mode 100644 index 000000000000..06e98289b0d5 --- /dev/null +++ b/src/test/compile-fail/E0301.rs @@ -0,0 +1,17 @@ +// Copyright 2016 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() { + match Some(()) { + None => { }, + option if option.take().is_none() => {}, //~ ERROR E0301 + Some(_) => { } + } +} diff --git a/src/test/compile-fail/E0302.rs b/src/test/compile-fail/E0302.rs new file mode 100644 index 000000000000..6a5ad40b1090 --- /dev/null +++ b/src/test/compile-fail/E0302.rs @@ -0,0 +1,17 @@ +// Copyright 2016 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() { + match Some(()) { + None => { }, + option if { option = None; false } => { }, //~ ERROR E0302 + Some(_) => { } + } +} diff --git a/src/test/compile-fail/E0303.rs b/src/test/compile-fail/E0303.rs new file mode 100644 index 000000000000..67947fd087c0 --- /dev/null +++ b/src/test/compile-fail/E0303.rs @@ -0,0 +1,17 @@ +// Copyright 2016 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() { + match Some("hi".to_string()) { + ref op_string_ref @ Some(s) => {}, //~ ERROR E0303 + //~^ ERROR E0009 + None => {}, + } +}