Fix tests after rebase
This commit is contained in:
parent
edddb62099
commit
d863978f89
@ -16,9 +16,10 @@ pub use core::future::*;
|
||||
///
|
||||
/// This function returns a `GenFuture` underneath, but hides it in `impl Trait` to give
|
||||
/// better error messages (`impl Future` rather than `GenFuture<[closure.....]>`).
|
||||
// This is `const` to avoid extra errors after we recover from `const async fn`
|
||||
#[doc(hidden)]
|
||||
#[unstable(feature = "gen_future", issue = "50547")]
|
||||
pub fn from_generator<T: Generator<Yield = ()>>(x: T) -> impl Future<Output = T::Return> {
|
||||
pub const fn from_generator<T: Generator<Yield = ()>>(x: T) -> impl Future<Output = T::Return> {
|
||||
GenFuture(x)
|
||||
}
|
||||
|
||||
|
@ -3,3 +3,4 @@
|
||||
|
||||
pub const async fn x() {}
|
||||
//~^ ERROR functions cannot be both `const` and `async`
|
||||
//~| ERROR `impl Trait` in const fn is unstable
|
||||
|
@ -7,5 +7,15 @@ LL | pub const async fn x() {}
|
||||
| | `async` because of this
|
||||
| `const` because of this
|
||||
|
||||
error: aborting due to previous error
|
||||
error[E0723]: `impl Trait` in const fn is unstable
|
||||
--> $DIR/no-const-async.rs:4:24
|
||||
|
|
||||
LL | pub const async fn x() {}
|
||||
| ^
|
||||
|
|
||||
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
|
||||
= help: add `#![feature(const_fn)]` to the crate attributes to enable
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0723`.
|
||||
|
@ -0,0 +1,14 @@
|
||||
#![feature(unboxed_closures)]
|
||||
|
||||
// Tests that we can't assign to or mutably borrow upvars from `Fn`
|
||||
// closures (issue #17780)
|
||||
|
||||
fn main() {}
|
||||
|
||||
fn bar() -> impl Fn() -> usize {
|
||||
let mut x = 0;
|
||||
move || {
|
||||
x += 1; //~ ERROR cannot assign
|
||||
x
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
error[E0594]: cannot assign to `x`, as it is a captured variable in a `Fn` closure
|
||||
--> $DIR/borrow-immutable-upvar-mutation-impl-trait.rs:11:9
|
||||
|
|
||||
LL | fn bar() -> impl Fn() -> usize {
|
||||
| --- ------------------ change this to return `FnMut` instead of `Fn`
|
||||
LL | let mut x = 0;
|
||||
LL | / move || {
|
||||
LL | | x += 1;
|
||||
| | ^^^^^^ cannot assign
|
||||
LL | | x
|
||||
LL | | }
|
||||
| |_____- in this closure
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0594`.
|
@ -3,10 +3,16 @@
|
||||
// Tests that we can't assign to or mutably borrow upvars from `Fn`
|
||||
// closures (issue #17780)
|
||||
|
||||
fn set(x: &mut usize) { *x = 5; }
|
||||
fn set(x: &mut usize) {
|
||||
*x = 5;
|
||||
}
|
||||
|
||||
fn to_fn<A,F:Fn<A>>(f: F) -> F { f }
|
||||
fn to_fn_mut<A,F:FnMut<A>>(f: F) -> F { f }
|
||||
fn to_fn<A, F: Fn<A>>(f: F) -> F {
|
||||
f
|
||||
}
|
||||
fn to_fn_mut<A, F: FnMut<A>>(f: F) -> F {
|
||||
f
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// By-ref captures
|
||||
@ -33,7 +39,11 @@ fn main() {
|
||||
let _g = to_fn(move || set(&mut y)); //~ ERROR cannot borrow
|
||||
|
||||
let mut z = 0;
|
||||
let _h = to_fn_mut(move || { set(&mut z); to_fn(move || z = 42); }); //~ ERROR cannot assign
|
||||
let _h = to_fn_mut(move || {
|
||||
set(&mut z);
|
||||
to_fn(move || z = 42);
|
||||
//~^ ERROR cannot assign
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,11 +54,3 @@ fn foo() -> Box<dyn Fn() -> usize> {
|
||||
x
|
||||
})
|
||||
}
|
||||
|
||||
fn bar() -> impl Fn() -> usize {
|
||||
let mut x = 0;
|
||||
move || {
|
||||
x += 1; //~ ERROR cannot assign
|
||||
x
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
error[E0594]: cannot assign to `x`, as it is a captured variable in a `Fn` closure
|
||||
--> $DIR/borrow-immutable-upvar-mutation.rs:15:27
|
||||
--> $DIR/borrow-immutable-upvar-mutation.rs:21:27
|
||||
|
|
||||
LL | fn to_fn<A,F:Fn<A>>(f: F) -> F { f }
|
||||
| - change this to accept `FnMut` instead of `Fn`
|
||||
LL | fn to_fn<A, F: Fn<A>>(f: F) -> F {
|
||||
| - change this to accept `FnMut` instead of `Fn`
|
||||
...
|
||||
LL | let _f = to_fn(|| x = 42);
|
||||
| ----- ^^^^^^ cannot assign
|
||||
@ -10,10 +10,10 @@ LL | let _f = to_fn(|| x = 42);
|
||||
| expects `Fn` instead of `FnMut`
|
||||
|
||||
error[E0596]: cannot borrow `y` as mutable, as it is a captured variable in a `Fn` closure
|
||||
--> $DIR/borrow-immutable-upvar-mutation.rs:18:31
|
||||
--> $DIR/borrow-immutable-upvar-mutation.rs:24:31
|
||||
|
|
||||
LL | fn to_fn<A,F:Fn<A>>(f: F) -> F { f }
|
||||
| - change this to accept `FnMut` instead of `Fn`
|
||||
LL | fn to_fn<A, F: Fn<A>>(f: F) -> F {
|
||||
| - change this to accept `FnMut` instead of `Fn`
|
||||
...
|
||||
LL | let _g = to_fn(|| set(&mut y));
|
||||
| ----- ^^^^^^ cannot borrow as mutable
|
||||
@ -21,10 +21,10 @@ LL | let _g = to_fn(|| set(&mut y));
|
||||
| expects `Fn` instead of `FnMut`
|
||||
|
||||
error[E0594]: cannot assign to `z`, as it is a captured variable in a `Fn` closure
|
||||
--> $DIR/borrow-immutable-upvar-mutation.rs:23:22
|
||||
--> $DIR/borrow-immutable-upvar-mutation.rs:29:22
|
||||
|
|
||||
LL | fn to_fn<A,F:Fn<A>>(f: F) -> F { f }
|
||||
| - change this to accept `FnMut` instead of `Fn`
|
||||
LL | fn to_fn<A, F: Fn<A>>(f: F) -> F {
|
||||
| - change this to accept `FnMut` instead of `Fn`
|
||||
...
|
||||
LL | to_fn(|| z = 42);
|
||||
| ----- ^^^^^^ cannot assign
|
||||
@ -32,10 +32,10 @@ LL | to_fn(|| z = 42);
|
||||
| expects `Fn` instead of `FnMut`
|
||||
|
||||
error[E0594]: cannot assign to `x`, as it is a captured variable in a `Fn` closure
|
||||
--> $DIR/borrow-immutable-upvar-mutation.rs:30:32
|
||||
--> $DIR/borrow-immutable-upvar-mutation.rs:36:32
|
||||
|
|
||||
LL | fn to_fn<A,F:Fn<A>>(f: F) -> F { f }
|
||||
| - change this to accept `FnMut` instead of `Fn`
|
||||
LL | fn to_fn<A, F: Fn<A>>(f: F) -> F {
|
||||
| - change this to accept `FnMut` instead of `Fn`
|
||||
...
|
||||
LL | let _f = to_fn(move || x = 42);
|
||||
| ----- ^^^^^^ cannot assign
|
||||
@ -43,10 +43,10 @@ LL | let _f = to_fn(move || x = 42);
|
||||
| expects `Fn` instead of `FnMut`
|
||||
|
||||
error[E0596]: cannot borrow `y` as mutable, as it is a captured variable in a `Fn` closure
|
||||
--> $DIR/borrow-immutable-upvar-mutation.rs:33:36
|
||||
--> $DIR/borrow-immutable-upvar-mutation.rs:39:36
|
||||
|
|
||||
LL | fn to_fn<A,F:Fn<A>>(f: F) -> F { f }
|
||||
| - change this to accept `FnMut` instead of `Fn`
|
||||
LL | fn to_fn<A, F: Fn<A>>(f: F) -> F {
|
||||
| - change this to accept `FnMut` instead of `Fn`
|
||||
...
|
||||
LL | let _g = to_fn(move || set(&mut y));
|
||||
| ----- ^^^^^^ cannot borrow as mutable
|
||||
@ -54,18 +54,18 @@ LL | let _g = to_fn(move || set(&mut y));
|
||||
| expects `Fn` instead of `FnMut`
|
||||
|
||||
error[E0594]: cannot assign to `z`, as it is a captured variable in a `Fn` closure
|
||||
--> $DIR/borrow-immutable-upvar-mutation.rs:36:65
|
||||
--> $DIR/borrow-immutable-upvar-mutation.rs:44:27
|
||||
|
|
||||
LL | fn to_fn<A,F:Fn<A>>(f: F) -> F { f }
|
||||
| - change this to accept `FnMut` instead of `Fn`
|
||||
LL | fn to_fn<A, F: Fn<A>>(f: F) -> F {
|
||||
| - change this to accept `FnMut` instead of `Fn`
|
||||
...
|
||||
LL | let _h = to_fn_mut(move || { set(&mut z); to_fn(move || z = 42); });
|
||||
| ----- ^^^^^^ cannot assign
|
||||
| |
|
||||
| expects `Fn` instead of `FnMut`
|
||||
LL | to_fn(move || z = 42);
|
||||
| ----- ^^^^^^ cannot assign
|
||||
| |
|
||||
| expects `Fn` instead of `FnMut`
|
||||
|
||||
error[E0594]: cannot assign to `x`, as it is a captured variable in a `Fn` closure
|
||||
--> $DIR/borrow-immutable-upvar-mutation.rs:43:9
|
||||
--> $DIR/borrow-immutable-upvar-mutation.rs:53:9
|
||||
|
|
||||
LL | fn foo() -> Box<dyn Fn() -> usize> {
|
||||
| --- ---------------------- change this to return `FnMut` instead of `Fn`
|
||||
@ -78,20 +78,7 @@ LL | | x
|
||||
LL | | })
|
||||
| |_____- in this closure
|
||||
|
||||
error[E0594]: cannot assign to `x`, as it is a captured variable in a `Fn` closure
|
||||
--> $DIR/borrow-immutable-upvar-mutation.rs:51:9
|
||||
|
|
||||
LL | fn bar() -> impl Fn() -> usize {
|
||||
| --- ------------------ change this to return `FnMut` instead of `Fn`
|
||||
LL | let mut x = 0;
|
||||
LL | / move || {
|
||||
LL | | x += 1;
|
||||
| | ^^^^^^ cannot assign
|
||||
LL | | x
|
||||
LL | | }
|
||||
| |_____- in this closure
|
||||
|
||||
error: aborting due to 8 previous errors
|
||||
error: aborting due to 7 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0594, E0596.
|
||||
For more information about an error, try `rustc --explain E0594`.
|
||||
|
Loading…
x
Reference in New Issue
Block a user