async-std icon indicating copy to clipboard operation
async-std copied to clipboard

println (and other macros) warning without .await

Open matthew-a-thomas opened this issue 4 years ago • 3 comments

It would be neat if println!("Hello, world"); could raise a compiler warning because of the missing .await.

Thanks!

matthew-a-thomas avatar May 03 '21 19:05 matthew-a-thomas

There is no missing await in this example.

Fishrock123 avatar May 17 '21 23:05 Fishrock123

I was going to comment exactly that, but was surprised to discover that async_std does in fact have async versions of the println macros https://docs.rs/async-std/1.9.0/async_std/macro.println.html

jbr avatar May 18 '21 00:05 jbr

Oh, I suppose that's not all that surprising, since println has some amount of blocking behavior normally, depending on what you ware writing to, and on which OS platform and (insert many Node.js issues about this exact problem).

I think this should warn anyways, since futures normally warn when you do not consume their output.

If not, then #[must_use] should be added to _print and _eprint: https://github.com/async-rs/async-std/blob/master/src/io/stdio.rs

if that doesn't resolve the problem because macros then there probably is not a solution.

Fishrock123 avatar May 18 '21 00:05 Fishrock123