簡體   English   中英

Rust 單元測試中的錯誤:“函數聲明中缺少 async 關鍵字”

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

我正在使用 tokio 0.2.6 和 futures 0.3.0 的 Rust 工作區工作,嘗試編譯此代碼時出現以下錯誤:

#[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() {
    |     ^^

這個錯誤對我來說毫無意義,因為它只是一個不做任何異步操作的普通單元測試。 此外,此代碼所在的整個項目也不執行異步操作。 工作區中還有其他項目使用 tokio 和 futures 都在使用異步代碼,但我沒有看到它們是如何相互影響的。

正如用戶 mcarton 所指出的,出現問題是因為我use tokio::*; 在我的項目中的某個地方。 刪除該導入解決了問題。

對我來說是:

#[macro_use]
extern crate tokio;

它只有在我刪除它后才起作用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM