Weird async syntax error with std futures + nightly

I have a one file crate with an example file here: https://github.com/osa1/tiny/tree/std_futures/term_input_std_futures

The library uses std futures and it builds fine.

If you try to build the example you get weird errors, like rustc not recognizing the async keyword:

$ cargo run --example test
   Compiling term_input_std_futures v0.1.5 (/home/omer/rust/tiny/term_input_std_futures)
error: expected one of `!`, `)`, `,`, `.`, `::`, `?`, `{`, or an operator, found `move`
  --> examples/test.rs:46:24
   |
46 |     tokio::spawn(async move || {
   |                        ^^^^ expected one of 8 possible tokens here

error[E0425]: cannot find value `async` in this scope
  --> examples/test.rs:46:18
   |
46 |     tokio::spawn(async move || {
   |                  ^^^^^ not found in this scope

...

Similarly you'll get different errors if you remove move, || etc.

If you copy the code in the test program to another file or play.rust-lang etc. and delete the dependency it builds fine (or rather, you get sensible error messages). So I feel like this may be a bug in rustup or cargo.

Any ideas on what I may be doing wrong?

Cannot test it out right now, but isn't Cargo.toml missing an edition 2018 key?

2 Likes

You are a hero. I wasted hours trying to debug this. Thanks.

1 Like