2

I'm working on a Rust workspace which uses tokio 0.2.6 and futures 0.3.0 and I get the following error trying to compile this code:

#[cfg(test)]
mod tests {

    #[test]
    fn test() {
        assert_eq!(true, true)
    }
}
error: the async keyword is missing from the function declaration
   --> api/src/order.rs:299:5
    |
299 |     fn test() {
    |     ^^

This error makes no sense to me, because it is just a plain-old unit test that doesn't do anything async. More over, the entire project this code is located in doesn't do async either. There are other projects in the workspace which are heavy on async code using both tokio and futures, but I'm not seeing how these affect each other.

user1870238
  • 447
  • 7
  • 20
  • 1
    Do you happen to have [`use tokio::test;`](https://docs.rs/tokio/0.2.6/tokio/attr.test.html) or `use tokio::*;`? – mcarton Jan 05 '20 at 13:36
  • I have `common` crate where I export all shared dependencies for crates in the workspace, so yes I do. I reckon this is the root of the problem? – user1870238 Jan 05 '20 at 13:44

2 Answers2

3

As user mcarton noted, the problem occurred because I had use tokio::*; in my project somewhere. Removing that import solved the problem.

user1870238
  • 447
  • 7
  • 20
2

For me it was:

#[macro_use]
extern crate tokio;

It only worked after I removed it.

Rodolfo
  • 1,091
  • 3
  • 13
  • 35