summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-04-05 17:45:43 +0000
committerbors <bors@rust-lang.org>2019-04-05 17:45:43 +0000
commitacd8dd6a50d505057a7d7ad8d0d7a4c2bd274200 (patch)
treedb3cdcdf3bc1a839ef3ce43ca6eddef9225c1094 /src/test
parent20dbf28624db446c0cf67be4cc71a85931947907 (diff)
parent812d89c87d9346ac4b70426b67a8eb989a13c853 (diff)
downloadrust-acd8dd6a50d505057a7d7ad8d0d7a4c2bd274200.tar.gz
rust-acd8dd6a50d505057a7d7ad8d0d7a4c2bd274200.zip
Auto merge of #59500 - crlf0710:boxed-closure-impls, r=cramertj
Unsized rvalues: implement boxed closure impls. (2nd try)

This is a rebase of S-blocked-closed PR #55431 to current master. LLVM has moved forward since then, so maybe we can check whether the new LLVM 8.0 version unblocked this work.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/run-pass/unsized-locals/box-fnonce.rs8
-rw-r--r--src/test/run-pass/unsized-locals/fnbox-compat.rs12
-rw-r--r--src/test/ui/borrowck/two-phase-nonrecv-autoref.ast.nll.stderr36
-rw-r--r--src/test/ui/borrowck/two-phase-nonrecv-autoref.ast.stderr22
-rw-r--r--src/test/ui/borrowck/two-phase-nonrecv-autoref.nll.stderr36
-rw-r--r--src/test/ui/borrowck/two-phase-nonrecv-autoref.rs16
-rw-r--r--src/test/ui/span/borrowck-call-is-borrow-issue-12224.nll.stderr2
-rw-r--r--src/test/ui/span/borrowck-call-is-borrow-issue-12224.rs2
-rw-r--r--src/test/ui/span/borrowck-call-is-borrow-issue-12224.stderr4
9 files changed, 63 insertions, 75 deletions
diff --git a/src/test/run-pass/unsized-locals/box-fnonce.rs b/src/test/run-pass/unsized-locals/box-fnonce.rs
new file mode 100644
index 00000000000..16bdeae4fad
--- /dev/null
+++ b/src/test/run-pass/unsized-locals/box-fnonce.rs
@@ -0,0 +1,8 @@
+fn call_it<T>(f: Box<dyn FnOnce() -> T>) -> T {
+    f()
+}
+
+fn main() {
+    let s = "hello".to_owned();
+    assert_eq!(&call_it(Box::new(|| s)) as &str, "hello");
+}
diff --git a/src/test/run-pass/unsized-locals/fnbox-compat.rs b/src/test/run-pass/unsized-locals/fnbox-compat.rs
new file mode 100644
index 00000000000..5ec54ada13b
--- /dev/null
+++ b/src/test/run-pass/unsized-locals/fnbox-compat.rs
@@ -0,0 +1,12 @@
+#![feature(fnbox)]
+
+use std::boxed::FnBox;
+
+fn call_it<T>(f: Box<dyn FnBox() -> T>) -> T {
+    f()
+}
+
+fn main() {
+    let s = "hello".to_owned();
+    assert_eq!(&call_it(Box::new(|| s)) as &str, "hello");
+}
diff --git a/src/test/ui/borrowck/two-phase-nonrecv-autoref.ast.nll.stderr b/src/test/ui/borrowck/two-phase-nonrecv-autoref.ast.nll.stderr
index d026f81b7aa..223de36f0df 100644
--- a/src/test/ui/borrowck/two-phase-nonrecv-autoref.ast.nll.stderr
+++ b/src/test/ui/borrowck/two-phase-nonrecv-autoref.ast.nll.stderr
@@ -7,17 +7,15 @@ LL |         f(f(10));
    |         first mutable borrow occurs here
    |         first borrow later used by call
 
-error[E0382]: use of moved value: `*f`
+error[E0382]: use of moved value: `f`
   --> $DIR/two-phase-nonrecv-autoref.rs:69:11
    |
 LL |     fn twice_ten_so<F: FnOnce(i32) -> i32>(f: Box<F>) {
-   |                     - consider adding a `Copy` constraint to this type argument
+   |                                            - move occurs because `f` has type `std::boxed::Box<F>`, which does not implement the `Copy` trait
 LL |         f(f(10));
    |         - ^ value used here after move
    |         |
    |         value moved here
-   |
-   = note: move occurs because `*f` has type `F`, which does not implement the `Copy` trait
 
 error[E0499]: cannot borrow `*f` as mutable more than once at a time
   --> $DIR/two-phase-nonrecv-autoref.rs:76:11
@@ -28,30 +26,18 @@ LL |         f(f(10));
    |         first mutable borrow occurs here
    |         first borrow later used by call
 
-error[E0161]: cannot move a value of type dyn std::ops::FnOnce(i32) -> i32: the size of dyn std::ops::FnOnce(i32) -> i32 cannot be statically determined
-  --> $DIR/two-phase-nonrecv-autoref.rs:85:9
-   |
-LL |         f(f(10));
-   |         ^
-
-error[E0161]: cannot move a value of type dyn std::ops::FnOnce(i32) -> i32: the size of dyn std::ops::FnOnce(i32) -> i32 cannot be statically determined
-  --> $DIR/two-phase-nonrecv-autoref.rs:85:11
-   |
-LL |         f(f(10));
-   |           ^
-
-error[E0382]: use of moved value: `*f`
+error[E0382]: use of moved value: `f`
   --> $DIR/two-phase-nonrecv-autoref.rs:85:11
    |
+LL |     fn twice_ten_oo(f: Box<FnOnce(i32) -> i32>) {
+   |                     - move occurs because `f` has type `std::boxed::Box<dyn std::ops::FnOnce(i32) -> i32>`, which does not implement the `Copy` trait
 LL |         f(f(10));
    |         - ^ value used here after move
    |         |
    |         value moved here
-   |
-   = note: move occurs because `*f` has type `dyn std::ops::FnOnce(i32) -> i32`, which does not implement the `Copy` trait
 
 error[E0502]: cannot borrow `a` as immutable because it is also borrowed as mutable
-  --> $DIR/two-phase-nonrecv-autoref.rs:129:27
+  --> $DIR/two-phase-nonrecv-autoref.rs:125:27
    |
 LL |     double_access(&mut a, &a);
    |     ------------- ------  ^^ immutable borrow occurs here
@@ -60,7 +46,7 @@ LL |     double_access(&mut a, &a);
    |     mutable borrow later used by call
 
 error[E0502]: cannot borrow `i` as immutable because it is also borrowed as mutable
-  --> $DIR/two-phase-nonrecv-autoref.rs:157:7
+  --> $DIR/two-phase-nonrecv-autoref.rs:153:7
    |
 LL |     i[i[3]] = 4;
    |     --^----
@@ -70,7 +56,7 @@ LL |     i[i[3]] = 4;
    |     mutable borrow later used here
 
 error[E0502]: cannot borrow `i` as immutable because it is also borrowed as mutable
-  --> $DIR/two-phase-nonrecv-autoref.rs:163:7
+  --> $DIR/two-phase-nonrecv-autoref.rs:159:7
    |
 LL |     i[i[3]] = i[4];
    |     --^----
@@ -79,7 +65,7 @@ LL |     i[i[3]] = i[4];
    |     mutable borrow occurs here
    |     mutable borrow later used here
 
-error: aborting due to 9 previous errors
+error: aborting due to 7 previous errors
 
-Some errors occurred: E0161, E0382, E0499, E0502.
-For more information about an error, try `rustc --explain E0161`.
+Some errors occurred: E0382, E0499, E0502.
+For more information about an error, try `rustc --explain E0382`.
diff --git a/src/test/ui/borrowck/two-phase-nonrecv-autoref.ast.stderr b/src/test/ui/borrowck/two-phase-nonrecv-autoref.ast.stderr
index 426939f371c..d98b272944f 100644
--- a/src/test/ui/borrowck/two-phase-nonrecv-autoref.ast.stderr
+++ b/src/test/ui/borrowck/two-phase-nonrecv-autoref.ast.stderr
@@ -15,7 +15,7 @@ LL |         f(f(10));
    |         | second mutable borrow occurs here
    |         first mutable borrow occurs here
 
-error[E0382]: use of moved value: `*f`
+error[E0382]: use of moved value: `f`
   --> $DIR/two-phase-nonrecv-autoref.rs:69:11
    |
 LL |         f(f(10));
@@ -23,7 +23,7 @@ LL |         f(f(10));
    |         |
    |         value moved here
    |
-   = note: move occurs because `*f` has type `F`, which does not implement the `Copy` trait
+   = note: move occurs because `f` has type `std::boxed::Box<F>`, which does not implement the `Copy` trait
 
 error[E0499]: cannot borrow `*f` as mutable more than once at a time
   --> $DIR/two-phase-nonrecv-autoref.rs:76:11
@@ -34,7 +34,7 @@ LL |         f(f(10));
    |         | second mutable borrow occurs here
    |         first mutable borrow occurs here
 
-error[E0382]: use of moved value: `*f`
+error[E0382]: use of moved value: `f`
   --> $DIR/two-phase-nonrecv-autoref.rs:85:11
    |
 LL |         f(f(10));
@@ -42,10 +42,10 @@ LL |         f(f(10));
    |         |
    |         value moved here
    |
-   = note: move occurs because `*f` has type `(dyn std::ops::FnOnce(i32) -> i32 + 'static)`, which does not implement the `Copy` trait
+   = note: move occurs because `f` has type `std::boxed::Box<(dyn std::ops::FnOnce(i32) -> i32 + 'static)>`, which does not implement the `Copy` trait
 
 error[E0502]: cannot borrow `a` as immutable because it is also borrowed as mutable
-  --> $DIR/two-phase-nonrecv-autoref.rs:129:28
+  --> $DIR/two-phase-nonrecv-autoref.rs:125:28
    |
 LL |     double_access(&mut a, &a);
    |                        -   ^- mutable borrow ends here
@@ -54,7 +54,7 @@ LL |     double_access(&mut a, &a);
    |                        mutable borrow occurs here
 
 error[E0502]: cannot borrow `a` as immutable because it is also borrowed as mutable
-  --> $DIR/two-phase-nonrecv-autoref.rs:135:9
+  --> $DIR/two-phase-nonrecv-autoref.rs:131:9
    |
 LL |     a.m(a.i(10));
    |     -   ^      - mutable borrow ends here
@@ -63,7 +63,7 @@ LL |     a.m(a.i(10));
    |     mutable borrow occurs here
 
 error[E0502]: cannot borrow `i` as immutable because it is also borrowed as mutable
-  --> $DIR/two-phase-nonrecv-autoref.rs:157:7
+  --> $DIR/two-phase-nonrecv-autoref.rs:153:7
    |
 LL |     i[i[3]] = 4;
    |     - ^   - mutable borrow ends here
@@ -72,7 +72,7 @@ LL |     i[i[3]] = 4;
    |     mutable borrow occurs here
 
 error[E0502]: cannot borrow `i` as immutable because it is also borrowed as mutable
-  --> $DIR/two-phase-nonrecv-autoref.rs:163:7
+  --> $DIR/two-phase-nonrecv-autoref.rs:159:7
    |
 LL |     i[i[3]] = i[4];
    |     - ^   - mutable borrow ends here
@@ -81,7 +81,7 @@ LL |     i[i[3]] = i[4];
    |     mutable borrow occurs here
 
 error[E0502]: cannot borrow `v` as immutable because it is also borrowed as mutable
-  --> $DIR/two-phase-nonrecv-autoref.rs:172:12
+  --> $DIR/two-phase-nonrecv-autoref.rs:168:12
    |
 LL |     v.push(v.len());
    |     -      ^      - mutable borrow ends here
@@ -90,7 +90,7 @@ LL |     v.push(v.len());
    |     mutable borrow occurs here
 
 error[E0502]: cannot borrow `s` as immutable because it is also borrowed as mutable
-  --> $DIR/two-phase-nonrecv-autoref.rs:183:9
+  --> $DIR/two-phase-nonrecv-autoref.rs:179:9
    |
 LL |     s.m(s.i(10));
    |     -   ^      - mutable borrow ends here
@@ -99,7 +99,7 @@ LL |     s.m(s.i(10));
    |     mutable borrow occurs here
 
 error[E0502]: cannot borrow `t` as immutable because it is also borrowed as mutable
-  --> $DIR/two-phase-nonrecv-autoref.rs:188:9
+  --> $DIR/two-phase-nonrecv-autoref.rs:184:9
    |
 LL |     t.m(t.i(10));
    |     -   ^      - mutable borrow ends here
diff --git a/src/test/ui/borrowck/two-phase-nonrecv-autoref.nll.stderr b/src/test/ui/borrowck/two-phase-nonrecv-autoref.nll.stderr
index d026f81b7aa..223de36f0df 100644
--- a/src/test/ui/borrowck/two-phase-nonrecv-autoref.nll.stderr
+++ b/src/test/ui/borrowck/two-phase-nonrecv-autoref.nll.stderr
@@ -7,17 +7,15 @@ LL |         f(f(10));
    |         first mutable borrow occurs here
    |         first borrow later used by call
 
-error[E0382]: use of moved value: `*f`
+error[E0382]: use of moved value: `f`
   --> $DIR/two-phase-nonrecv-autoref.rs:69:11
    |
 LL |     fn twice_ten_so<F: FnOnce(i32) -> i32>(f: Box<F>) {
-   |                     - consider adding a `Copy` constraint to this type argument
+   |                                            - move occurs because `f` has type `std::boxed::Box<F>`, which does not implement the `Copy` trait
 LL |         f(f(10));
    |         - ^ value used here after move
    |         |
    |         value moved here
-   |
-   = note: move occurs because `*f` has type `F`, which does not implement the `Copy` trait
 
 error[E0499]: cannot borrow `*f` as mutable more than once at a time
   --> $DIR/two-phase-nonrecv-autoref.rs:76:11
@@ -28,30 +26,18 @@ LL |         f(f(10));
    |         first mutable borrow occurs here
    |         first borrow later used by call
 
-error[E0161]: cannot move a value of type dyn std::ops::FnOnce(i32) -> i32: the size of dyn std::ops::FnOnce(i32) -> i32 cannot be statically determined
-  --> $DIR/two-phase-nonrecv-autoref.rs:85:9
-   |
-LL |         f(f(10));
-   |         ^
-
-error[E0161]: cannot move a value of type dyn std::ops::FnOnce(i32) -> i32: the size of dyn std::ops::FnOnce(i32) -> i32 cannot be statically determined
-  --> $DIR/two-phase-nonrecv-autoref.rs:85:11
-   |
-LL |         f(f(10));
-   |           ^
-
-error[E0382]: use of moved value: `*f`
+error[E0382]: use of moved value: `f`
   --> $DIR/two-phase-nonrecv-autoref.rs:85:11
    |
+LL |     fn twice_ten_oo(f: Box<FnOnce(i32) -> i32>) {
+   |                     - move occurs because `f` has type `std::boxed::Box<dyn std::ops::FnOnce(i32) -> i32>`, which does not implement the `Copy` trait
 LL |         f(f(10));
    |         - ^ value used here after move
    |         |
    |         value moved here
-   |
-   = note: move occurs because `*f` has type `dyn std::ops::FnOnce(i32) -> i32`, which does not implement the `Copy` trait
 
 error[E0502]: cannot borrow `a` as immutable because it is also borrowed as mutable
-  --> $DIR/two-phase-nonrecv-autoref.rs:129:27
+  --> $DIR/two-phase-nonrecv-autoref.rs:125:27
    |
 LL |     double_access(&mut a, &a);
    |     ------------- ------  ^^ immutable borrow occurs here
@@ -60,7 +46,7 @@ LL |     double_access(&mut a, &a);
    |     mutable borrow later used by call
 
 error[E0502]: cannot borrow `i` as immutable because it is also borrowed as mutable
-  --> $DIR/two-phase-nonrecv-autoref.rs:157:7
+  --> $DIR/two-phase-nonrecv-autoref.rs:153:7
    |
 LL |     i[i[3]] = 4;
    |     --^----
@@ -70,7 +56,7 @@ LL |     i[i[3]] = 4;
    |     mutable borrow later used here
 
 error[E0502]: cannot borrow `i` as immutable because it is also borrowed as mutable
-  --> $DIR/two-phase-nonrecv-autoref.rs:163:7
+  --> $DIR/two-phase-nonrecv-autoref.rs:159:7
    |
 LL |     i[i[3]] = i[4];
    |     --^----
@@ -79,7 +65,7 @@ LL |     i[i[3]] = i[4];
    |     mutable borrow occurs here
    |     mutable borrow later used here
 
-error: aborting due to 9 previous errors
+error: aborting due to 7 previous errors
 
-Some errors occurred: E0161, E0382, E0499, E0502.
-For more information about an error, try `rustc --explain E0161`.
+Some errors occurred: E0382, E0499, E0502.
+For more information about an error, try `rustc --explain E0382`.
diff --git a/src/test/ui/borrowck/two-phase-nonrecv-autoref.rs b/src/test/ui/borrowck/two-phase-nonrecv-autoref.rs
index 1a14cb90f38..1005da05297 100644
--- a/src/test/ui/borrowck/two-phase-nonrecv-autoref.rs
+++ b/src/test/ui/borrowck/two-phase-nonrecv-autoref.rs
@@ -67,9 +67,9 @@ fn overloaded_call_traits() {
     }
     fn twice_ten_so<F: FnOnce(i32) -> i32>(f: Box<F>) {
         f(f(10));
-        //[nll]~^   ERROR use of moved value: `*f`
-        //[g2p]~^^  ERROR use of moved value: `*f`
-        //[ast]~^^^ ERROR use of moved value: `*f`
+        //[nll]~^   ERROR use of moved value: `f`
+        //[g2p]~^^  ERROR use of moved value: `f`
+        //[ast]~^^^ ERROR use of moved value: `f`
     }
 
     fn twice_ten_om(f: &mut FnMut(i32) -> i32) {
@@ -83,13 +83,9 @@ fn overloaded_call_traits() {
     }
     fn twice_ten_oo(f: Box<FnOnce(i32) -> i32>) {
         f(f(10));
-        //[nll]~^          ERROR cannot move a value of type
-        //[nll]~^^         ERROR cannot move a value of type
-        //[nll]~^^^        ERROR use of moved value: `*f`
-        //[g2p]~^^^^       ERROR cannot move a value of type
-        //[g2p]~^^^^^      ERROR cannot move a value of type
-        //[g2p]~^^^^^^     ERROR use of moved value: `*f`
-        //[ast]~^^^^^^^    ERROR use of moved value: `*f`
+        //[nll]~^   ERROR use of moved value: `f`
+        //[g2p]~^^  ERROR use of moved value: `f`
+        //[ast]~^^^ ERROR use of moved value: `f`
     }
 
     twice_ten_sm(&mut |x| x + 1);
diff --git a/src/test/ui/span/borrowck-call-is-borrow-issue-12224.nll.stderr b/src/test/ui/span/borrowck-call-is-borrow-issue-12224.nll.stderr
index 1a5ab7a7d56..4e2ab59f822 100644
--- a/src/test/ui/span/borrowck-call-is-borrow-issue-12224.nll.stderr
+++ b/src/test/ui/span/borrowck-call-is-borrow-issue-12224.nll.stderr
@@ -18,7 +18,7 @@ LL | fn test2<F>(f: &F) where F: FnMut() {
 LL |     (*f)();
    |     ^^^^ `f` is a `&` reference, so the data it refers to cannot be borrowed as mutable
 
-error[E0596]: cannot borrow `*f.f` as mutable, as it is behind a `&` reference
+error[E0596]: cannot borrow `f.f` as mutable, as it is behind a `&` reference
   --> $DIR/borrowck-call-is-borrow-issue-12224.rs:34:5
    |
 LL | fn test4(f: &Test) {
diff --git a/src/test/ui/span/borrowck-call-is-borrow-issue-12224.rs b/src/test/ui/span/borrowck-call-is-borrow-issue-12224.rs
index cfebd6f7003..f246f1118bf 100644
--- a/src/test/ui/span/borrowck-call-is-borrow-issue-12224.rs
+++ b/src/test/ui/span/borrowck-call-is-borrow-issue-12224.rs
@@ -32,7 +32,7 @@ fn test3<F>(f: &mut F) where F: FnMut() {
 
 fn test4(f: &Test) {
     f.f.call_mut(())
-    //~^ ERROR: cannot borrow `Box` content `*f.f` of immutable binding as mutable
+    //~^ ERROR: cannot borrow field `f.f` of immutable binding as mutable
 }
 
 fn test5(f: &mut Test) {
diff --git a/src/test/ui/span/borrowck-call-is-borrow-issue-12224.stderr b/src/test/ui/span/borrowck-call-is-borrow-issue-12224.stderr
index 6c8f477e310..a61ee8334af 100644
--- a/src/test/ui/span/borrowck-call-is-borrow-issue-12224.stderr
+++ b/src/test/ui/span/borrowck-call-is-borrow-issue-12224.stderr
@@ -19,13 +19,13 @@ LL | fn test2<F>(f: &F) where F: FnMut() {
 LL |     (*f)();
    |     ^^^^ cannot borrow as mutable
 
-error[E0596]: cannot borrow `Box` content `*f.f` of immutable binding as mutable
+error[E0596]: cannot borrow field `f.f` of immutable binding as mutable
   --> $DIR/borrowck-call-is-borrow-issue-12224.rs:34:5
    |
 LL | fn test4(f: &Test) {
    |             ----- use `&mut Test` here to make mutable
 LL |     f.f.call_mut(())
-   |     ^^^ cannot borrow as mutable
+   |     ^^^ cannot mutably borrow field of immutable binding
 
 error[E0504]: cannot move `f` into closure because it is borrowed
   --> $DIR/borrowck-call-is-borrow-issue-12224.rs:56:13