]> git.lizzy.rs Git - rust.git/commit - src/tools/rustfmt
Rollup merge of #80160 - diondokter:move_async_fix, r=davidtwco
authorDylan DPC <dylan.dpc@gmail.com>
Fri, 25 Dec 2020 02:39:35 +0000 (03:39 +0100)
committerGitHub <noreply@github.com>
Fri, 25 Dec 2020 02:39:35 +0000 (03:39 +0100)
commit299c2fc69554998e8991715d09a611376a5b9cf3
tree05641710180166463da5ee00bc85217d0b80f838
parent787b016957fd10148c6f9ac516348f307748524a
parenta272d621bc7a2ca61d704fbe531dc532d49ab402
Rollup merge of #80160 - diondokter:move_async_fix, r=davidtwco

Implemented a compiler diagnostic for move async mistake

Fixes #79694

First time contributing, so I hope I'm doing everything right.
(If not, please correct me!)

This code performs a check when a move capture clause is parsed. The check is to detect if the user has reversed the async move keywords and to provide a diagnostic with a suggestion to fix it.

Checked code:
```rust
fn main() {
    move async { };
}
```

Previous output:
```txt
PS C:\Repos\move_async_test> cargo build
   Compiling move_async_test v0.1.0 (C:\Repos\move_async_test)
error: expected one of `|` or `||`, found keyword `async`
 --> src\main.rs:2:10
  |
2 |     move async { };
  |          ^^^^^ expected one of `|` or `||`

error: aborting due to previous error

error: could not compile `move_async_test`
```

New output:
```txt
PS C:\Repos\move_async_test> cargo +dev build
   Compiling move_async_test v0.1.0 (C:\Repos\move_async_test)
error: the order of `move` and `async` is incorrect
 --> src\main.rs:2:13
  |
2 |     let _ = move async { };
  |             ^^^^^^^^^^
  |
help: try switching the order
  |
2 |     let _ = async move { };
  |             ^^^^^^^^^^

error: aborting due to previous error

error: could not compile `move_async_test`
```

Is there a file/module where these kind of things are tested?
Would love some feedback ðŸ˜„
compiler/rustc_parse/src/parser/expr.rs