Skip to content

Commit d863978

Browse files
committed
Fix tests after rebase
1 parent edddb62 commit d863978

7 files changed

+82
-51
lines changed

src/libstd/future.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ pub use core::future::*;
1616
///
1717
/// This function returns a `GenFuture` underneath, but hides it in `impl Trait` to give
1818
/// better error messages (`impl Future` rather than `GenFuture<[closure.....]>`).
19+
// This is `const` to avoid extra errors after we recover from `const async fn`
1920
#[doc(hidden)]
2021
#[unstable(feature = "gen_future", issue = "50547")]
21-
pub fn from_generator<T: Generator<Yield = ()>>(x: T) -> impl Future<Output = T::Return> {
22+
pub const fn from_generator<T: Generator<Yield = ()>>(x: T) -> impl Future<Output = T::Return> {
2223
GenFuture(x)
2324
}
2425

src/test/ui/async-await/no-const-async.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33

44
pub const async fn x() {}
55
//~^ ERROR functions cannot be both `const` and `async`
6+
//~| ERROR `impl Trait` in const fn is unstable

src/test/ui/async-await/no-const-async.stderr

+11-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,15 @@ LL | pub const async fn x() {}
77
| | `async` because of this
88
| `const` because of this
99

10-
error: aborting due to previous error
10+
error[E0723]: `impl Trait` in const fn is unstable
11+
--> $DIR/no-const-async.rs:4:24
12+
|
13+
LL | pub const async fn x() {}
14+
| ^
15+
|
16+
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
17+
= help: add `#![feature(const_fn)]` to the crate attributes to enable
18+
19+
error: aborting due to 2 previous errors
1120

21+
For more information about this error, try `rustc --explain E0723`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![feature(unboxed_closures)]
2+
3+
// Tests that we can't assign to or mutably borrow upvars from `Fn`
4+
// closures (issue #17780)
5+
6+
fn main() {}
7+
8+
fn bar() -> impl Fn() -> usize {
9+
let mut x = 0;
10+
move || {
11+
x += 1; //~ ERROR cannot assign
12+
x
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0594]: cannot assign to `x`, as it is a captured variable in a `Fn` closure
2+
--> $DIR/borrow-immutable-upvar-mutation-impl-trait.rs:11:9
3+
|
4+
LL | fn bar() -> impl Fn() -> usize {
5+
| --- ------------------ change this to return `FnMut` instead of `Fn`
6+
LL | let mut x = 0;
7+
LL | / move || {
8+
LL | | x += 1;
9+
| | ^^^^^^ cannot assign
10+
LL | | x
11+
LL | | }
12+
| |_____- in this closure
13+
14+
error: aborting due to previous error
15+
16+
For more information about this error, try `rustc --explain E0594`.

src/test/ui/borrowck/borrow-immutable-upvar-mutation.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@
33
// Tests that we can't assign to or mutably borrow upvars from `Fn`
44
// closures (issue #17780)
55

6-
fn set(x: &mut usize) { *x = 5; }
6+
fn set(x: &mut usize) {
7+
*x = 5;
8+
}
79

8-
fn to_fn<A,F:Fn<A>>(f: F) -> F { f }
9-
fn to_fn_mut<A,F:FnMut<A>>(f: F) -> F { f }
10+
fn to_fn<A, F: Fn<A>>(f: F) -> F {
11+
f
12+
}
13+
fn to_fn_mut<A, F: FnMut<A>>(f: F) -> F {
14+
f
15+
}
1016

1117
fn main() {
1218
// By-ref captures
@@ -33,7 +39,11 @@ fn main() {
3339
let _g = to_fn(move || set(&mut y)); //~ ERROR cannot borrow
3440

3541
let mut z = 0;
36-
let _h = to_fn_mut(move || { set(&mut z); to_fn(move || z = 42); }); //~ ERROR cannot assign
42+
let _h = to_fn_mut(move || {
43+
set(&mut z);
44+
to_fn(move || z = 42);
45+
//~^ ERROR cannot assign
46+
});
3747
}
3848
}
3949

@@ -44,11 +54,3 @@ fn foo() -> Box<dyn Fn() -> usize> {
4454
x
4555
})
4656
}
47-
48-
fn bar() -> impl Fn() -> usize {
49-
let mut x = 0;
50-
move || {
51-
x += 1; //~ ERROR cannot assign
52-
x
53-
}
54-
}
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,71 @@
11
error[E0594]: cannot assign to `x`, as it is a captured variable in a `Fn` closure
2-
--> $DIR/borrow-immutable-upvar-mutation.rs:15:27
2+
--> $DIR/borrow-immutable-upvar-mutation.rs:21:27
33
|
4-
LL | fn to_fn<A,F:Fn<A>>(f: F) -> F { f }
5-
| - change this to accept `FnMut` instead of `Fn`
4+
LL | fn to_fn<A, F: Fn<A>>(f: F) -> F {
5+
| - change this to accept `FnMut` instead of `Fn`
66
...
77
LL | let _f = to_fn(|| x = 42);
88
| ----- ^^^^^^ cannot assign
99
| |
1010
| expects `Fn` instead of `FnMut`
1111

1212
error[E0596]: cannot borrow `y` as mutable, as it is a captured variable in a `Fn` closure
13-
--> $DIR/borrow-immutable-upvar-mutation.rs:18:31
13+
--> $DIR/borrow-immutable-upvar-mutation.rs:24:31
1414
|
15-
LL | fn to_fn<A,F:Fn<A>>(f: F) -> F { f }
16-
| - change this to accept `FnMut` instead of `Fn`
15+
LL | fn to_fn<A, F: Fn<A>>(f: F) -> F {
16+
| - change this to accept `FnMut` instead of `Fn`
1717
...
1818
LL | let _g = to_fn(|| set(&mut y));
1919
| ----- ^^^^^^ cannot borrow as mutable
2020
| |
2121
| expects `Fn` instead of `FnMut`
2222

2323
error[E0594]: cannot assign to `z`, as it is a captured variable in a `Fn` closure
24-
--> $DIR/borrow-immutable-upvar-mutation.rs:23:22
24+
--> $DIR/borrow-immutable-upvar-mutation.rs:29:22
2525
|
26-
LL | fn to_fn<A,F:Fn<A>>(f: F) -> F { f }
27-
| - change this to accept `FnMut` instead of `Fn`
26+
LL | fn to_fn<A, F: Fn<A>>(f: F) -> F {
27+
| - change this to accept `FnMut` instead of `Fn`
2828
...
2929
LL | to_fn(|| z = 42);
3030
| ----- ^^^^^^ cannot assign
3131
| |
3232
| expects `Fn` instead of `FnMut`
3333

3434
error[E0594]: cannot assign to `x`, as it is a captured variable in a `Fn` closure
35-
--> $DIR/borrow-immutable-upvar-mutation.rs:30:32
35+
--> $DIR/borrow-immutable-upvar-mutation.rs:36:32
3636
|
37-
LL | fn to_fn<A,F:Fn<A>>(f: F) -> F { f }
38-
| - change this to accept `FnMut` instead of `Fn`
37+
LL | fn to_fn<A, F: Fn<A>>(f: F) -> F {
38+
| - change this to accept `FnMut` instead of `Fn`
3939
...
4040
LL | let _f = to_fn(move || x = 42);
4141
| ----- ^^^^^^ cannot assign
4242
| |
4343
| expects `Fn` instead of `FnMut`
4444

4545
error[E0596]: cannot borrow `y` as mutable, as it is a captured variable in a `Fn` closure
46-
--> $DIR/borrow-immutable-upvar-mutation.rs:33:36
46+
--> $DIR/borrow-immutable-upvar-mutation.rs:39:36
4747
|
48-
LL | fn to_fn<A,F:Fn<A>>(f: F) -> F { f }
49-
| - change this to accept `FnMut` instead of `Fn`
48+
LL | fn to_fn<A, F: Fn<A>>(f: F) -> F {
49+
| - change this to accept `FnMut` instead of `Fn`
5050
...
5151
LL | let _g = to_fn(move || set(&mut y));
5252
| ----- ^^^^^^ cannot borrow as mutable
5353
| |
5454
| expects `Fn` instead of `FnMut`
5555

5656
error[E0594]: cannot assign to `z`, as it is a captured variable in a `Fn` closure
57-
--> $DIR/borrow-immutable-upvar-mutation.rs:36:65
57+
--> $DIR/borrow-immutable-upvar-mutation.rs:44:27
5858
|
59-
LL | fn to_fn<A,F:Fn<A>>(f: F) -> F { f }
60-
| - change this to accept `FnMut` instead of `Fn`
59+
LL | fn to_fn<A, F: Fn<A>>(f: F) -> F {
60+
| - change this to accept `FnMut` instead of `Fn`
6161
...
62-
LL | let _h = to_fn_mut(move || { set(&mut z); to_fn(move || z = 42); });
63-
| ----- ^^^^^^ cannot assign
64-
| |
65-
| expects `Fn` instead of `FnMut`
62+
LL | to_fn(move || z = 42);
63+
| ----- ^^^^^^ cannot assign
64+
| |
65+
| expects `Fn` instead of `FnMut`
6666

6767
error[E0594]: cannot assign to `x`, as it is a captured variable in a `Fn` closure
68-
--> $DIR/borrow-immutable-upvar-mutation.rs:43:9
68+
--> $DIR/borrow-immutable-upvar-mutation.rs:53:9
6969
|
7070
LL | fn foo() -> Box<dyn Fn() -> usize> {
7171
| --- ---------------------- change this to return `FnMut` instead of `Fn`
@@ -78,20 +78,7 @@ LL | | x
7878
LL | | })
7979
| |_____- in this closure
8080

81-
error[E0594]: cannot assign to `x`, as it is a captured variable in a `Fn` closure
82-
--> $DIR/borrow-immutable-upvar-mutation.rs:51:9
83-
|
84-
LL | fn bar() -> impl Fn() -> usize {
85-
| --- ------------------ change this to return `FnMut` instead of `Fn`
86-
LL | let mut x = 0;
87-
LL | / move || {
88-
LL | | x += 1;
89-
| | ^^^^^^ cannot assign
90-
LL | | x
91-
LL | | }
92-
| |_____- in this closure
93-
94-
error: aborting due to 8 previous errors
81+
error: aborting due to 7 previous errors
9582

9683
Some errors have detailed explanations: E0594, E0596.
9784
For more information about an error, try `rustc --explain E0594`.

0 commit comments

Comments
 (0)