Skip to content

Lint on const RUNTIME: tokio<Runtime> #6088

Closed
@jyn514

Description

@jyn514

What it does

What does this lint do?

It errors on const tokio runtimes.

Categories (optional)

  • Kind: Correctness
  • Deny by default

What is the advantage of the recommended code over the original code

It avoids errors like the following:

Io(Custom { kind: Other, error: "reactor gone" })

const creates a new copy of the runtime every time it's used, while static uses the same runtime each time.
I was using this as RUNTIME.block_on(), which takes &mut, so possibly this could be expanded to any &mut use of a const.

Drawbacks

None.

Example

pub const RUNTIME: Lazy<Runtime> = Lazy::new(|| Runtime::new().unwrap());

should instead be

pub static RUNTIME: Lazy<Runtime> = Lazy::new(|| Runtime::new().unwrap());

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions