File tree 5 files changed +91
-0
lines changed
tests/ui/ergonomic-clones/closure
5 files changed +91
-0
lines changed Original file line number Diff line number Diff line change
1
+ #![ feature( ergonomic_clones) ]
2
+ #![ allow( warnings) ]
3
+
4
+ fn closure_expecting_bound < F > ( _: F )
5
+ where
6
+ F : FnOnce ( & u32 ) ,
7
+ {
8
+ }
9
+
10
+ fn expect_bound_supply_named < ' x > ( ) {
11
+ let mut f: Option < & u32 > = None ;
12
+
13
+ // Here we give a type annotation that `x` should be free. We get
14
+ // an error because of that.
15
+ closure_expecting_bound ( use |x: & ' x u32| {
16
+ //~^ ERROR lifetime may not live long enough
17
+ //~| ERROR lifetime may not live long enough
18
+
19
+ // Borrowck doesn't get a chance to run, but if it did it should error
20
+ // here.
21
+ f = Some ( x) ;
22
+ } ) ;
23
+ }
24
+
25
+ fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ error: lifetime may not live long enough
2
+ --> $DIR/expect-region.rs:15:34
3
+ |
4
+ LL | fn expect_bound_supply_named<'x>() {
5
+ | -- lifetime `'x` defined here
6
+ ...
7
+ LL | closure_expecting_bound(use |x: &'x u32| {
8
+ | ^ - let's call the lifetime of this reference `'1`
9
+ | |
10
+ | requires that `'1` must outlive `'x`
11
+
12
+ error: lifetime may not live long enough
13
+ --> $DIR/expect-region.rs:15:34
14
+ |
15
+ LL | fn expect_bound_supply_named<'x>() {
16
+ | -- lifetime `'x` defined here
17
+ ...
18
+ LL | closure_expecting_bound(use |x: &'x u32| {
19
+ | ^ requires that `'x` must outlive `'static`
20
+
21
+ error: aborting due to 2 previous errors
22
+
Original file line number Diff line number Diff line change
1
+ //@ run-rustfix
2
+
3
+ // Point at the captured immutable outer variable
4
+
5
+ #![feature(ergonomic_clones)]
6
+
7
+ fn foo(mut f: Box<dyn FnMut()>) {
8
+ f();
9
+ }
10
+
11
+ fn main() {
12
+ let mut y = true;
13
+ foo(Box::new(use || y = !y) as Box<_>);
14
+ //~^ ERROR cannot assign to `y`, as it is not declared as mutable
15
+ }
Original file line number Diff line number Diff line change
1
+ //@ run-rustfix
2
+
3
+ // Point at the captured immutable outer variable
4
+
5
+ #![ feature( ergonomic_clones) ]
6
+
7
+ fn foo ( mut f : Box < dyn FnMut ( ) > ) {
8
+ f ( ) ;
9
+ }
10
+
11
+ fn main ( ) {
12
+ let y = true ;
13
+ foo ( Box :: new ( use || y = !y) as Box < _ > ) ;
14
+ //~^ ERROR cannot assign to `y`, as it is not declared as mutable
15
+ }
Original file line number Diff line number Diff line change
1
+ error[E0594]: cannot assign to `y`, as it is not declared as mutable
2
+ --> $DIR/immutable-outer-variable.rs:13:25
3
+ |
4
+ LL | foo(Box::new(use || y = !y) as Box<_>);
5
+ | ^^^^^^ cannot assign
6
+ |
7
+ help: consider changing this to be mutable
8
+ |
9
+ LL | let mut y = true;
10
+ | +++
11
+
12
+ error: aborting due to 1 previous error
13
+
14
+ For more information about this error, try `rustc --explain E0594`.
You can’t perform that action at this time.
0 commit comments