Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint on const RUNTIME: tokio<Runtime> #6088

Closed
jyn514 opened this issue Sep 26, 2020 · 2 comments
Closed

Lint on const RUNTIME: tokio<Runtime> #6088

jyn514 opened this issue Sep 26, 2020 · 2 comments
Labels
A-lint Area: New lints

Comments

@jyn514
Copy link
Member

jyn514 commented Sep 26, 2020

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());
@jyn514 jyn514 added the A-lint Area: New lints label Sep 26, 2020
@ebroto
Copy link
Member

ebroto commented Sep 27, 2020

@jyn514 would const_item_mutation solve your use case? To be landed in 1.48.

@jyn514
Copy link
Member Author

jyn514 commented Sep 27, 2020

Yes it would! Thank you :D https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=5329dc009d37cefba58f5acaab8d4be7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

No branches or pull requests

2 participants