1
Fork 0

Add more tests

This commit is contained in:
Santiago Pastorino 2025-02-14 15:51:01 -03:00
parent aa58439f87
commit 18d689c085
No known key found for this signature in database
GPG key ID: 8131A24E0C79EFAF
5 changed files with 91 additions and 0 deletions

View 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() {}

View 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

View file

@ -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
}

View file

@ -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
}

View file

@ -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`.