about summary refs log tree commit diff
path: root/src/rustllvm/PassWrapper.cpp
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2018-01-02 15:25:53 -0800
committerEsteban Küber <esteban@kuber.com.ar>2018-01-15 07:04:38 -0800
commit846042161c17bcc696715b3dfe2e6c4970da0b34 (patch)
tree75069a38c6b18a3a7d1e8d7a2ad41c18529ff527 /src/rustllvm/PassWrapper.cpp
parentbb345a0be3ba3fa1970fe02789791c5c72788d8f (diff)
downloadrust-846042161c17bcc696715b3dfe2e6c4970da0b34.tar.gz
rust-846042161c17bcc696715b3dfe2e6c4970da0b34.zip
Custom error when moving arg outside of its closure
When given the following code:

```rust
fn give_any<F: for<'r> FnOnce(&'r ())>(f: F) {
    f(&());
}

fn main() {
    let mut x = None;
    give_any(|y| x = Some(y));
}
```

provide a custom error:

```
error: borrowed data cannot be moved outside of its closure
 --> file.rs:7:27
  |
6 |     let mut x = None;
  |         ----- binding declared outside of closure
7 |     give_any(|y| x = Some(y));
  |              ---          ^ cannot be assigned to binding outside of its closure
  |              |
  |              closure you can't escape
```

instead of the generic lifetime error:

```
error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
 --> file.rs:7:27
  |
7 |     give_any(|y| x = Some(y));
  |                           ^
  |
note: first, the lifetime cannot outlive the anonymous lifetime #2 defined on the body at 7:14...
 --> file.rs:7:14
  |
7 |     give_any(|y| x = Some(y));
  |              ^^^^^^^^^^^^^^^
note: ...so that expression is assignable (expected &(), found &())
 --> file.rs:7:27
  |
7 |     give_any(|y| x = Some(y));
  |                           ^
note: but, the lifetime must be valid for the block suffix following statement 0 at 6:5...
 --> file.rs:6:5
  |
6 | /     let mut x = None;
7 | |     give_any(|y| x = Some(y));
8 | | }
  | |_^
note: ...so that variable is valid at time of its declaration
 --> file.rs:6:9
  |
6 |     let mut x = None;
  |         ^^^^^
```
Diffstat (limited to 'src/rustllvm/PassWrapper.cpp')
0 files changed, 0 insertions, 0 deletions