Skip to content

Tokio's test-util feature depends on rt, sync, and time #4035

@asomers

Description

@asomers

Version
List the versions of all tokio crates you are using. The easiest way to get
this information is using cargo tree subcommand:

tokio v1.9.0 (/usr/home/somers/src/rust/tokio/tokio)
├── tokio-stream v0.1.7 (/usr/home/somers/src/rust/tokio/tokio-stream)
│   └── tokio v1.9.0 (/usr/home/somers/src/rust/tokio/tokio) (*)
└── tokio-test v0.4.2 (/usr/home/somers/src/rust/tokio/tokio-test)
    ├── tokio v1.9.0 (/usr/home/somers/src/rust/tokio/tokio) (*)
    └── tokio-stream v0.1.7 (/usr/home/somers/src/rust/tokio/tokio-stream) (*)

Platform
FreeBSD 14.0-CURRENT amd64

Description
Tokio's test-util feature implicitly depends on rt, sync, and time. Attempting to compile a crate that uses test-util will fail if those other features are not included.

I tried this code:

Build an empty crate with this Cargo.toml:

[package]
name = "powersettest"
version = "0.1.0"
edition = "2018"

[dependencies]
tokio = { version = "1.9.0", default-features = false, features = ["test-util", "time"], path = "../" }

[workspace]

I expected to see this happen: It should've built

Instead, this happened:

> cargo check 
   Compiling tokio v1.9.0 (/usr/home/somers/src/rust/tokio/tokio)
error[E0425]: cannot find function `yield_now` in module `crate::task`
   --> /usr/home/somers/src/rust/tokio/tokio/src/time/clock.rs:133:22
    |
133 |         crate::task::yield_now().await;
    |                      ^^^^^^^^^ not found in `crate::task`
    |
help: consider importing one of these items
    |
31  |     use crate::loom::thread::yield_now;
    |
31  |     use std::thread::yield_now;
    |

For more information about this error, try `rustc --explain E0425`.
error: could not compile `tokio` due to previous error

Note that this bug cannot be reproduced simply by using cargo check within tokio itself due to rust-lang/cargo#4866 . Instead, you must create a separate crate. I discovered this bug by doing cargo hack check --feature-powerset --no-dev-deps.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-tokioArea: The main tokio crateC-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions