Add more tests
This commit is contained in:
parent
aa58439f87
commit
18d689c085
5 changed files with 91 additions and 0 deletions
25
tests/ui/ergonomic-clones/closure/expect-region.rs
Normal file
25
tests/ui/ergonomic-clones/closure/expect-region.rs
Normal file
|
@ -0,0 +1,25 @@
|
|||
#![feature(ergonomic_clones)]
|
||||
#![allow(warnings)]
|
||||
|
||||
fn closure_expecting_bound<F>(_: F)
|
||||
where
|
||||
F: FnOnce(&u32),
|
||||
{
|
||||
}
|
||||
|
||||
fn expect_bound_supply_named<'x>() {
|
||||
let mut f: Option<&u32> = None;
|
||||
|
||||
// Here we give a type annotation that `x` should be free. We get
|
||||
// an error because of that.
|
||||
closure_expecting_bound(use |x: &'x u32| {
|
||||
//~^ ERROR lifetime may not live long enough
|
||||
//~| ERROR lifetime may not live long enough
|
||||
|
||||
// Borrowck doesn't get a chance to run, but if it did it should error
|
||||
// here.
|
||||
f = Some(x);
|
||||
});
|
||||
}
|
||||
|
||||
fn main() {}
|
22
tests/ui/ergonomic-clones/closure/expect-region.stderr
Normal file
22
tests/ui/ergonomic-clones/closure/expect-region.stderr
Normal file
|
@ -0,0 +1,22 @@
|
|||
error: lifetime may not live long enough
|
||||
--> $DIR/expect-region.rs:15:34
|
||||
|
|
||||
LL | fn expect_bound_supply_named<'x>() {
|
||||
| -- lifetime `'x` defined here
|
||||
...
|
||||
LL | closure_expecting_bound(use |x: &'x u32| {
|
||||
| ^ - let's call the lifetime of this reference `'1`
|
||||
| |
|
||||
| requires that `'1` must outlive `'x`
|
||||
|
||||
error: lifetime may not live long enough
|
||||
--> $DIR/expect-region.rs:15:34
|
||||
|
|
||||
LL | fn expect_bound_supply_named<'x>() {
|
||||
| -- lifetime `'x` defined here
|
||||
...
|
||||
LL | closure_expecting_bound(use |x: &'x u32| {
|
||||
| ^ requires that `'x` must outlive `'static`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
//@ run-rustfix
|
||||
|
||||
// Point at the captured immutable outer variable
|
||||
|
||||
#![feature(ergonomic_clones)]
|
||||
|
||||
fn foo(mut f: Box<dyn FnMut()>) {
|
||||
f();
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut y = true;
|
||||
foo(Box::new(use || y = !y) as Box<_>);
|
||||
//~^ ERROR cannot assign to `y`, as it is not declared as mutable
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
//@ run-rustfix
|
||||
|
||||
// Point at the captured immutable outer variable
|
||||
|
||||
#![feature(ergonomic_clones)]
|
||||
|
||||
fn foo(mut f: Box<dyn FnMut()>) {
|
||||
f();
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let y = true;
|
||||
foo(Box::new(use || y = !y) as Box<_>);
|
||||
//~^ ERROR cannot assign to `y`, as it is not declared as mutable
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
error[E0594]: cannot assign to `y`, as it is not declared as mutable
|
||||
--> $DIR/immutable-outer-variable.rs:13:25
|
||||
|
|
||||
LL | foo(Box::new(use || y = !y) as Box<_>);
|
||||
| ^^^^^^ cannot assign
|
||||
|
|
||||
help: consider changing this to be mutable
|
||||
|
|
||||
LL | let mut y = true;
|
||||
| +++
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0594`.
|
Loading…
Add table
Add a link
Reference in a new issue