about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/test/run-pass/impl-trait-in-bindings.rs56
-rw-r--r--src/test/ui/impl-trait/bindings-opaque.rs23
-rw-r--r--src/test/ui/impl-trait/bindings-opaque.stderr21
-rw-r--r--src/test/ui/impl-trait/bindings.rs35
-rw-r--r--src/test/ui/impl-trait/bindings.stderr35
-rw-r--r--src/test/ui/impl-trait/where-allowed.rs1
6 files changed, 170 insertions, 1 deletions
diff --git a/src/test/run-pass/impl-trait-in-bindings.rs b/src/test/run-pass/impl-trait-in-bindings.rs
new file mode 100644
index 00000000000..631967c3f08
--- /dev/null
+++ b/src/test/run-pass/impl-trait-in-bindings.rs
@@ -0,0 +1,56 @@
+// Copyright 2018 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(impl_trait_in_bindings)]
+
+use std::fmt::Debug;
+
+const FOO: impl Debug + Clone + PartialEq<i32> = 42;
+
+static BAR: impl Debug + Clone + PartialEq<i32> = 42;
+
+fn a<T: Clone>(x: T) {
+    let y: impl Clone = x;
+    let _ = y.clone();
+}
+
+fn b<T: Clone>(x: T) {
+    let f = move || {
+        let y: impl Clone = x;
+        let _ = y.clone();
+    };
+    f();
+}
+
+trait Foo<T: Clone> {
+    fn a(x: T) {
+        let y: impl Clone = x;
+        let _ = y.clone();
+    }
+}
+
+impl<T: Clone> Foo<T> for i32 {
+    fn a(x: T) {
+        let y: impl Clone = x;
+        let _ = y.clone();
+    }
+}
+
+fn main() {
+    let foo: impl Debug + Clone + PartialEq<i32> = 42;
+
+    assert_eq!(FOO.clone(), 42);
+    assert_eq!(BAR.clone(), 42);
+    assert_eq!(foo.clone(), 42);
+
+    a(42);
+    b(42);
+    i32::a(42);
+}
diff --git a/src/test/ui/impl-trait/bindings-opaque.rs b/src/test/ui/impl-trait/bindings-opaque.rs
new file mode 100644
index 00000000000..88b7a52af7f
--- /dev/null
+++ b/src/test/ui/impl-trait/bindings-opaque.rs
@@ -0,0 +1,23 @@
+// Copyright 2018 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(impl_trait_in_bindings)]
+
+const FOO: impl Copy = 42;
+
+static BAR: impl Copy = 42;
+
+fn main() {
+    let foo: impl Copy = 42;
+
+    let _ = FOO.count_ones();
+    let _ = BAR.count_ones();
+    let _ = foo.count_ones();
+}
diff --git a/src/test/ui/impl-trait/bindings-opaque.stderr b/src/test/ui/impl-trait/bindings-opaque.stderr
new file mode 100644
index 00000000000..00358ee502e
--- /dev/null
+++ b/src/test/ui/impl-trait/bindings-opaque.stderr
@@ -0,0 +1,21 @@
+error[E0599]: no method named `count_ones` found for type `impl std::marker::Copy` in the current scope
+  --> $DIR/bindings-opaque.rs:20:17
+   |
+LL |     let _ = FOO.count_ones();
+   |                 ^^^^^^^^^^
+
+error[E0599]: no method named `count_ones` found for type `impl std::marker::Copy` in the current scope
+  --> $DIR/bindings-opaque.rs:21:17
+   |
+LL |     let _ = BAR.count_ones();
+   |                 ^^^^^^^^^^
+
+error[E0599]: no method named `count_ones` found for type `impl std::marker::Copy` in the current scope
+  --> $DIR/bindings-opaque.rs:22:17
+   |
+LL |     let _ = foo.count_ones();
+   |                 ^^^^^^^^^^
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0599`.
diff --git a/src/test/ui/impl-trait/bindings.rs b/src/test/ui/impl-trait/bindings.rs
new file mode 100644
index 00000000000..571571aa751
--- /dev/null
+++ b/src/test/ui/impl-trait/bindings.rs
@@ -0,0 +1,35 @@
+// Copyright 2018 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(impl_trait_in_bindings)]
+
+fn a<T: Clone>(x: T) {
+    const foo: impl Clone = x;
+}
+
+fn b<T: Clone>(x: T) {
+    let _ = move || {
+        const foo: impl Clone = x;
+    };
+}
+
+trait Foo<T: Clone> {
+    fn a(x: T) {
+        const foo: impl Clone = x;
+    }
+}
+
+impl<T: Clone> Foo<T> for i32 {
+    fn a(x: T) {
+        const foo: impl Clone = x;
+    }
+}
+
+fn main() { }
diff --git a/src/test/ui/impl-trait/bindings.stderr b/src/test/ui/impl-trait/bindings.stderr
new file mode 100644
index 00000000000..70a736d2fd1
--- /dev/null
+++ b/src/test/ui/impl-trait/bindings.stderr
@@ -0,0 +1,35 @@
+error[E0434]: can't capture dynamic environment in a fn item
+  --> $DIR/bindings.rs:14:29
+   |
+LL |     const foo: impl Clone = x;
+   |                             ^
+   |
+   = help: use the `|| { ... }` closure form instead
+
+error[E0434]: can't capture dynamic environment in a fn item
+  --> $DIR/bindings.rs:19:33
+   |
+LL |         const foo: impl Clone = x;
+   |                                 ^
+   |
+   = help: use the `|| { ... }` closure form instead
+
+error[E0434]: can't capture dynamic environment in a fn item
+  --> $DIR/bindings.rs:25:33
+   |
+LL |         const foo: impl Clone = x;
+   |                                 ^
+   |
+   = help: use the `|| { ... }` closure form instead
+
+error[E0434]: can't capture dynamic environment in a fn item
+  --> $DIR/bindings.rs:31:33
+   |
+LL |         const foo: impl Clone = x;
+   |                                 ^
+   |
+   = help: use the `|| { ... }` closure form instead
+
+error: aborting due to 4 previous errors
+
+For more information about this error, try `rustc --explain E0434`.
diff --git a/src/test/ui/impl-trait/where-allowed.rs b/src/test/ui/impl-trait/where-allowed.rs
index 69f6d202f14..4c5592c119c 100644
--- a/src/test/ui/impl-trait/where-allowed.rs
+++ b/src/test/ui/impl-trait/where-allowed.rs
@@ -232,4 +232,3 @@ fn main() {
     let _in_return_in_local_variable = || -> impl Fn() { || {} };
     //~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
 }
-