about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorleonardo.yvens <leoyvens@gmail.com>2017-10-12 19:00:30 -0300
committerleonardo.yvens <leoyvens@gmail.com>2017-11-03 16:13:21 -0200
commitacf50ee236abae0ad416360eda2a3afa8873d2a0 (patch)
treec7f27bbc25abda902bba285a40c1214c70debf8a /src/test
parent37dfc0c5982029ea0793699eead1d8ec4c5cef73 (diff)
downloadrust-acf50ee236abae0ad416360eda2a3afa8873d2a0.tar.gz
rust-acf50ee236abae0ad416360eda2a3afa8873d2a0.zip
Add tests for `auto trait`, fix parsing bug
Now we can do the well formedness checks in the parser, yay!
Diffstat (limited to 'src/test')
-rw-r--r--src/test/compile-fail/auto-is-contextual.rs29
-rw-r--r--src/test/compile-fail/feature-gate-optin-builtin-traits.rs3
-rw-r--r--src/test/parse-fail/auto-trait-no-generics.rs14
-rw-r--r--src/test/parse-fail/auto-trait-no-rename.rs14
-rw-r--r--src/test/parse-fail/auto-trait-no-super.rs14
-rw-r--r--src/test/run-pass/auto-traits.rs35
6 files changed, 109 insertions, 0 deletions
diff --git a/src/test/compile-fail/auto-is-contextual.rs b/src/test/compile-fail/auto-is-contextual.rs
new file mode 100644
index 00000000000..3d3cb9ab104
--- /dev/null
+++ b/src/test/compile-fail/auto-is-contextual.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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+type A0 = auto;
+//~^ ERROR cannot find type `auto` in this scope
+type A1 = auto::auto;
+//~^ ERROR Use of undeclared type or module `auto`
+type A2 = auto<auto, auto>;
+//~^ ERROR cannot find type `auto` in this scope
+//~| ERROR cannot find type `auto` in this scope
+//~| ERROR cannot find type `auto` in this scope
+type A3 = auto<<auto as auto>::auto>;
+//~^ ERROR cannot find type `auto` in this scope
+//~| ERROR cannot find type `auto` in this scope
+//~| ERROR Use of undeclared type or module `auto`
+type A4 = auto(auto, auto) -> auto;
+//~^ ERROR cannot find type `auto` in this scope
+//~| ERROR cannot find type `auto` in this scope
+//~| ERROR cannot find type `auto` in this scope
+//~| ERROR cannot find type `auto` in this scope
+
+fn main() {}
diff --git a/src/test/compile-fail/feature-gate-optin-builtin-traits.rs b/src/test/compile-fail/feature-gate-optin-builtin-traits.rs
index db6b30c06d8..6f57266b3e1 100644
--- a/src/test/compile-fail/feature-gate-optin-builtin-traits.rs
+++ b/src/test/compile-fail/feature-gate-optin-builtin-traits.rs
@@ -17,6 +17,9 @@ trait DummyTrait {
     fn dummy(&self) {}
 }
 
+auto trait AutoDummyTrait {}
+//~^ ERROR auto traits are experimental and possibly buggy
+
 impl DummyTrait for .. {}
 //~^ ERROR auto trait implementations are experimental and possibly buggy
 
diff --git a/src/test/parse-fail/auto-trait-no-generics.rs b/src/test/parse-fail/auto-trait-no-generics.rs
new file mode 100644
index 00000000000..59c88691bb6
--- /dev/null
+++ b/src/test/parse-fail/auto-trait-no-generics.rs
@@ -0,0 +1,14 @@
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// compile-flags: -Z parse-only
+
+auto trait Auto<T> { }
+//~^ ERROR: expected `{`, found `<`
diff --git a/src/test/parse-fail/auto-trait-no-rename.rs b/src/test/parse-fail/auto-trait-no-rename.rs
new file mode 100644
index 00000000000..2754546779d
--- /dev/null
+++ b/src/test/parse-fail/auto-trait-no-rename.rs
@@ -0,0 +1,14 @@
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// compile-flags: -Z parse-only
+
+auto trait Auto { fn item() }
+//~^ ERROR: expected `}`, found `fn`
diff --git a/src/test/parse-fail/auto-trait-no-super.rs b/src/test/parse-fail/auto-trait-no-super.rs
new file mode 100644
index 00000000000..bc0d9c1aa09
--- /dev/null
+++ b/src/test/parse-fail/auto-trait-no-super.rs
@@ -0,0 +1,14 @@
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// compile-flags: -Z parse-only
+
+auto trait Auto : Send { }
+//~^ ERROR: expected `{`, found `:`
diff --git a/src/test/run-pass/auto-traits.rs b/src/test/run-pass/auto-traits.rs
new file mode 100644
index 00000000000..94fa104e5b2
--- /dev/null
+++ b/src/test/run-pass/auto-traits.rs
@@ -0,0 +1,35 @@
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(optin_builtin_traits)]
+
+auto trait Auto {}
+// Redundant but accepted until we remove it.
+impl Auto for .. {}
+
+unsafe auto trait AutoUnsafe {}
+
+impl !Auto for bool {}
+impl !AutoUnsafe for bool {}
+
+struct AutoBool(bool);
+
+impl Auto for AutoBool {}
+unsafe impl AutoUnsafe for AutoBool {}
+
+fn take_auto<T: Auto>(_: T) {}
+fn take_auto_unsafe<T: AutoUnsafe>(_: T) {}
+
+fn main() {
+    take_auto(0);
+    take_auto(AutoBool(true));
+    take_auto_unsafe(0);
+    take_auto_unsafe(AutoBool(true));
+}