Weird async syntax error with std futures + nightly

I have a one file crate with an example file here:

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/
46 |     tokio::spawn(async move || {
   |                        ^^^^ expected one of 8 possible tokens here

error[E0425]: cannot find value `async` in this scope
  --> examples/
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?


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

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.