summaryrefslogtreecommitdiffstats
path: root/tests/ui/closures/print
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/closures/print')
-rw-r--r--tests/ui/closures/print/closure-print-generic-1.rs23
-rw-r--r--tests/ui/closures/print/closure-print-generic-1.stderr20
-rw-r--r--tests/ui/closures/print/closure-print-generic-2.rs13
-rw-r--r--tests/ui/closures/print/closure-print-generic-2.stderr20
-rw-r--r--tests/ui/closures/print/closure-print-generic-trim-off-verbose-2.rs16
-rw-r--r--tests/ui/closures/print/closure-print-generic-trim-off-verbose-2.stderr20
-rw-r--r--tests/ui/closures/print/closure-print-generic-verbose-1.rs24
-rw-r--r--tests/ui/closures/print/closure-print-generic-verbose-1.stderr20
-rw-r--r--tests/ui/closures/print/closure-print-generic-verbose-2.rs16
-rw-r--r--tests/ui/closures/print/closure-print-generic-verbose-2.stderr20
-rw-r--r--tests/ui/closures/print/closure-print-verbose.rs12
-rw-r--r--tests/ui/closures/print/closure-print-verbose.stderr19
12 files changed, 223 insertions, 0 deletions
diff --git a/tests/ui/closures/print/closure-print-generic-1.rs b/tests/ui/closures/print/closure-print-generic-1.rs
new file mode 100644
index 000000000..504b4adbe
--- /dev/null
+++ b/tests/ui/closures/print/closure-print-generic-1.rs
@@ -0,0 +1,23 @@
+fn to_fn_once<F: FnOnce()>(f: F) -> F {
+ f
+}
+
+fn f<T: std::fmt::Display>(y: T) {
+ struct Foo<U: std::fmt::Display> {
+ x: U,
+ };
+
+ let foo = Foo { x: "x" };
+
+ let c = to_fn_once(move || {
+ println!("{} {}", foo.x, y);
+ });
+
+ c();
+ c();
+ //~^ ERROR use of moved value
+}
+
+fn main() {
+ f("S");
+}
diff --git a/tests/ui/closures/print/closure-print-generic-1.stderr b/tests/ui/closures/print/closure-print-generic-1.stderr
new file mode 100644
index 000000000..b21734f02
--- /dev/null
+++ b/tests/ui/closures/print/closure-print-generic-1.stderr
@@ -0,0 +1,20 @@
+error[E0382]: use of moved value: `c`
+ --> $DIR/closure-print-generic-1.rs:17:5
+ |
+LL | let c = to_fn_once(move || {
+ | - move occurs because `c` has type `[closure@$DIR/closure-print-generic-1.rs:12:24: 12:31]`, which does not implement the `Copy` trait
+...
+LL | c();
+ | --- `c` moved due to this call
+LL | c();
+ | ^ value used here after move
+ |
+note: this value implements `FnOnce`, which causes it to be moved when called
+ --> $DIR/closure-print-generic-1.rs:16:5
+ |
+LL | c();
+ | ^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0382`.
diff --git a/tests/ui/closures/print/closure-print-generic-2.rs b/tests/ui/closures/print/closure-print-generic-2.rs
new file mode 100644
index 000000000..3f77fd26b
--- /dev/null
+++ b/tests/ui/closures/print/closure-print-generic-2.rs
@@ -0,0 +1,13 @@
+mod mod1 {
+ pub fn f<T: std::fmt::Display>(t: T) {
+ let x = 20;
+
+ let c = || println!("{} {}", t, x);
+ let c1: () = c;
+ //~^ ERROR mismatched types
+ }
+}
+
+fn main() {
+ mod1::f(5i32);
+}
diff --git a/tests/ui/closures/print/closure-print-generic-2.stderr b/tests/ui/closures/print/closure-print-generic-2.stderr
new file mode 100644
index 000000000..e53277a93
--- /dev/null
+++ b/tests/ui/closures/print/closure-print-generic-2.stderr
@@ -0,0 +1,20 @@
+error[E0308]: mismatched types
+ --> $DIR/closure-print-generic-2.rs:6:22
+ |
+LL | let c = || println!("{} {}", t, x);
+ | -- the found closure
+LL | let c1: () = c;
+ | -- ^ expected `()`, found closure
+ | |
+ | expected due to this
+ |
+ = note: expected unit type `()`
+ found closure `[closure@$DIR/closure-print-generic-2.rs:5:17: 5:19]`
+help: use parentheses to call this closure
+ |
+LL | let c1: () = c();
+ | ++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/tests/ui/closures/print/closure-print-generic-trim-off-verbose-2.rs b/tests/ui/closures/print/closure-print-generic-trim-off-verbose-2.rs
new file mode 100644
index 000000000..07bf8fe4c
--- /dev/null
+++ b/tests/ui/closures/print/closure-print-generic-trim-off-verbose-2.rs
@@ -0,0 +1,16 @@
+// compile-flags: -Ztrim-diagnostic-paths=off -Zverbose
+
+mod mod1 {
+ pub fn f<T: std::fmt::Display>(t: T)
+ {
+ let x = 20;
+
+ let c = || println!("{} {}", t, x);
+ let c1 : () = c;
+ //~^ ERROR mismatched types
+ }
+}
+
+fn main() {
+ mod1::f(5i32);
+}
diff --git a/tests/ui/closures/print/closure-print-generic-trim-off-verbose-2.stderr b/tests/ui/closures/print/closure-print-generic-trim-off-verbose-2.stderr
new file mode 100644
index 000000000..ff89dd340
--- /dev/null
+++ b/tests/ui/closures/print/closure-print-generic-trim-off-verbose-2.stderr
@@ -0,0 +1,20 @@
+error[E0308]: mismatched types
+ --> $DIR/closure-print-generic-trim-off-verbose-2.rs:9:23
+ |
+LL | let c = || println!("{} {}", t, x);
+ | -- the found closure
+LL | let c1 : () = c;
+ | -- ^ expected `()`, found closure
+ | |
+ | expected due to this
+ |
+ = note: expected unit type `()`
+ found closure `[mod1::f<T>::{closure#0} closure_substs=(unavailable) substs=[T, _#16t, extern "rust-call" fn(()), _#15t]]`
+help: use parentheses to call this closure
+ |
+LL | let c1 : () = c();
+ | ++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/tests/ui/closures/print/closure-print-generic-verbose-1.rs b/tests/ui/closures/print/closure-print-generic-verbose-1.rs
new file mode 100644
index 000000000..67d37f1c5
--- /dev/null
+++ b/tests/ui/closures/print/closure-print-generic-verbose-1.rs
@@ -0,0 +1,24 @@
+// compile-flags: -Zverbose
+
+fn to_fn_once<F:FnOnce()>(f: F) -> F { f }
+
+fn f<T: std::fmt::Display>(y: T) {
+ struct Foo<U: std::fmt::Display> {
+ x: U
+ };
+
+ let foo = Foo{ x: "x" };
+
+ let c = to_fn_once(move|| {
+ println!("{} {}", foo.x, y);
+ });
+
+ c();
+ c();
+ //~^ ERROR use of moved value
+}
+
+
+fn main() {
+ f("S");
+}
diff --git a/tests/ui/closures/print/closure-print-generic-verbose-1.stderr b/tests/ui/closures/print/closure-print-generic-verbose-1.stderr
new file mode 100644
index 000000000..3ab7c66d1
--- /dev/null
+++ b/tests/ui/closures/print/closure-print-generic-verbose-1.stderr
@@ -0,0 +1,20 @@
+error[E0382]: use of moved value: `c`
+ --> $DIR/closure-print-generic-verbose-1.rs:17:5
+ |
+LL | let c = to_fn_once(move|| {
+ | - move occurs because `c` has type `[f<T>::{closure#0} closure_kind_ty=i32 closure_sig_as_fn_ptr_ty=extern "rust-call" fn(()) upvar_tys=(Foo<&'_#9r str>, T)]`, which does not implement the `Copy` trait
+...
+LL | c();
+ | --- `c` moved due to this call
+LL | c();
+ | ^ value used here after move
+ |
+note: this value implements `FnOnce`, which causes it to be moved when called
+ --> $DIR/closure-print-generic-verbose-1.rs:16:5
+ |
+LL | c();
+ | ^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0382`.
diff --git a/tests/ui/closures/print/closure-print-generic-verbose-2.rs b/tests/ui/closures/print/closure-print-generic-verbose-2.rs
new file mode 100644
index 000000000..f460fedff
--- /dev/null
+++ b/tests/ui/closures/print/closure-print-generic-verbose-2.rs
@@ -0,0 +1,16 @@
+// compile-flags: -Zverbose
+
+mod mod1 {
+ pub fn f<T: std::fmt::Display>(t: T)
+ {
+ let x = 20;
+
+ let c = || println!("{} {}", t, x);
+ let c1 : () = c;
+ //~^ ERROR mismatched types
+ }
+}
+
+fn main() {
+ mod1::f(5i32);
+}
diff --git a/tests/ui/closures/print/closure-print-generic-verbose-2.stderr b/tests/ui/closures/print/closure-print-generic-verbose-2.stderr
new file mode 100644
index 000000000..5bbf84f96
--- /dev/null
+++ b/tests/ui/closures/print/closure-print-generic-verbose-2.stderr
@@ -0,0 +1,20 @@
+error[E0308]: mismatched types
+ --> $DIR/closure-print-generic-verbose-2.rs:9:23
+ |
+LL | let c = || println!("{} {}", t, x);
+ | -- the found closure
+LL | let c1 : () = c;
+ | -- ^ expected `()`, found closure
+ | |
+ | expected due to this
+ |
+ = note: expected unit type `()`
+ found closure `[f<T>::{closure#0} closure_substs=(unavailable) substs=[T, _#16t, extern "rust-call" fn(()), _#15t]]`
+help: use parentheses to call this closure
+ |
+LL | let c1 : () = c();
+ | ++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/tests/ui/closures/print/closure-print-verbose.rs b/tests/ui/closures/print/closure-print-verbose.rs
new file mode 100644
index 000000000..4b0438a91
--- /dev/null
+++ b/tests/ui/closures/print/closure-print-verbose.rs
@@ -0,0 +1,12 @@
+// compile-flags: -Zverbose
+
+// Same as closure-coerce-fn-1.rs
+
+// Ensure that capturing closures are never coerced to fns
+// Especially interesting as non-capturing closures can be.
+
+fn main() {
+ let mut a = 0u8;
+ let foo: fn(u8) -> u8 = |v: u8| { a += v; a };
+ //~^ ERROR mismatched types
+}
diff --git a/tests/ui/closures/print/closure-print-verbose.stderr b/tests/ui/closures/print/closure-print-verbose.stderr
new file mode 100644
index 000000000..083717b33
--- /dev/null
+++ b/tests/ui/closures/print/closure-print-verbose.stderr
@@ -0,0 +1,19 @@
+error[E0308]: mismatched types
+ --> $DIR/closure-print-verbose.rs:10:29
+ |
+LL | let foo: fn(u8) -> u8 = |v: u8| { a += v; a };
+ | ------------ ^^^^^^^^^^^^^^^^^^^^^ expected fn pointer, found closure
+ | |
+ | expected due to this
+ |
+ = note: expected fn pointer `fn(u8) -> u8`
+ found closure `[main::{closure#0} closure_substs=(unavailable) substs=[i8, extern "rust-call" fn((u8,)) -> u8, _#6t]]`
+note: closures can only be coerced to `fn` types if they do not capture any variables
+ --> $DIR/closure-print-verbose.rs:10:39
+ |
+LL | let foo: fn(u8) -> u8 = |v: u8| { a += v; a };
+ | ^ `a` captured here
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.