简体   繁体   中英

Error in Rust unit test: "The async keyword is missing from the function declaration"

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.

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

For me it was:

#[macro_use]
extern crate tokio;

It only worked after I removed it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM