← Rule catalog

Source kernel · Reliability

block_on called inside async code

rust_doctor::source::block_on_in_async

Await the future instead; to run blocking work, move it to tokio::task::spawn_blocking, and build a runtime only in synchronous code such as main or a dedicated thread.

Category
Reliability
Default level
warn
Tier
P2
Producer
Source kernel
Diff scope
item

Not a defect when

The async block is never polled by an executor but driven by hand on a dedicated thread that owns no runtime.

Crates it waits for

It runs only where at least one of these crates is resolved, and every one resolved sits in the range it was validated on:

  • futures >=0.3, <0.4
  • tokio >=1, <2

What it reads

Source text, without resolving types or expanding macros.

Tier

Ordinary defect.

The tier bounds how severe a rule may be; its category bounds the tier.

Diff scope

The function or item around the changed line.

What --scope contextual looks at to decide whether a change caused the finding.

Change it

Turn it off, or make it blocking, without touching the code it flags:

rust-doctor --rule rust_doctor::source::block_on_in_async=off .
rust-doctor --rule rust_doctor::source::block_on_in_async=error .

Set it once in rust-doctor.toml

Other Reliability rules