about summary refs log tree commit diff
path: root/src/test/codegen/align-struct.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-01-22 05:30:37 +0000
committerbors <bors@rust-lang.org>2018-01-22 05:30:37 +0000
commitbc072ed0ca8e2e9f8c79fb04e85b47b5c0e8d6ae (patch)
tree2f4b8f1a04496f95c61c20a355b7b247052f5138 /src/test/codegen/align-struct.rs
parentff2a7c85757542f454934e00605355bbca7bc196 (diff)
parent6f9ecaa7cf0a15db46d13d72932acb2d678c29f1 (diff)
downloadrust-bc072ed0ca8e2e9f8c79fb04e85b47b5c0e8d6ae.tar.gz
rust-bc072ed0ca8e2e9f8c79fb04e85b47b5c0e8d6ae.zip
Auto merge of #47144 - estebank:moved-closure-arg, r=nikomatsakis
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;
  |         ----- borrowed data cannot be moved into here...
7 |     give_any(|y| x = Some(y));
  |              ---          ^ cannot be moved outside of its closure
  |              |
  |              ...because it cannot outlive this closure
```

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;
  |         ^^^^^
```

Fix #45983.
Diffstat (limited to 'src/test/codegen/align-struct.rs')
0 files changed, 0 insertions, 0 deletions