rust/tests/ui/unused_io_amount.stderr
Nick Mathewson 65d1f83d2c Extend [unused_io_amount] to cover AsyncRead and AsyncWrite.
Clippy helpfully warns about code like this, telling you that you
probably meant "write_all":

    fn say_hi<W:Write>(w: &mut W) {
       w.write(b"hello").unwrap();
    }

This patch attempts to extend the lint so it also covers this
case:

    async fn say_hi<W:AsyncWrite>(w: &mut W) {
       w.write(b"hello").await.unwrap();
    }

(I've run into this second case several times in my own programming,
and so have my coworkers, so unless we're especially accident-prone
in this area, it's probably worth addressing?)

This patch covers the Async{Read,Write}Ext traits in futures-rs,
and in tokio, since both are quite widely used.

changelog: [`unused_io_amount`] now supports AsyncReadExt and AsyncWriteExt.
2021-12-31 12:10:59 -05:00

105 lines
3.3 KiB
Plaintext

error: written amount is not handled. Use `Write::write_all` instead
--> $DIR/unused_io_amount.rs:9:5
|
LL | s.write(b"test")?;
| ^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::unused-io-amount` implied by `-D warnings`
error: read amount is not handled. Use `Read::read_exact` instead
--> $DIR/unused_io_amount.rs:11:5
|
LL | s.read(&mut buf)?;
| ^^^^^^^^^^^^^^^^^
error: written amount is not handled. Use `Write::write_all` instead
--> $DIR/unused_io_amount.rs:16:5
|
LL | s.write(b"test").unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error: read amount is not handled. Use `Read::read_exact` instead
--> $DIR/unused_io_amount.rs:18:5
|
LL | s.read(&mut buf).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error: read amount is not handled
--> $DIR/unused_io_amount.rs:22:5
|
LL | s.read_vectored(&mut [io::IoSliceMut::new(&mut [])])?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: written amount is not handled
--> $DIR/unused_io_amount.rs:23:5
|
LL | s.write_vectored(&[io::IoSlice::new(&[])])?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: read amount is not handled. Use `Read::read_exact` instead
--> $DIR/unused_io_amount.rs:30:5
|
LL | reader.read(&mut result).ok()?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: read amount is not handled. Use `Read::read_exact` instead
--> $DIR/unused_io_amount.rs:39:5
|
LL | reader.read(&mut result).or_else(|err| Err(err))?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: read amount is not handled. Use `Read::read_exact` instead
--> $DIR/unused_io_amount.rs:51:5
|
LL | reader.read(&mut result).or(Err(Error::Kind))?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: read amount is not handled. Use `Read::read_exact` instead
--> $DIR/unused_io_amount.rs:58:5
|
LL | / reader
LL | | .read(&mut result)
LL | | .or(Err(Error::Kind))
LL | | .or(Err(Error::Kind))
LL | | .expect("error");
| |________________________^
error: written amount is not handled. Use `AsyncWriteExt::write_all` instead
--> $DIR/unused_io_amount.rs:67:5
|
LL | w.write(b"hello world").await.unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: read amount is not handled. Use `AsyncReadExt::read_exact` instead
--> $DIR/unused_io_amount.rs:72:5
|
LL | r.read(&mut buf[..]).await.unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: written amount is not handled. Use `AsyncWriteExt::write_all` instead
--> $DIR/unused_io_amount.rs:85:9
|
LL | w.write(b"hello world").await?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: read amount is not handled. Use `AsyncReadExt::read_exact` instead
--> $DIR/unused_io_amount.rs:93:9
|
LL | r.read(&mut buf[..]).await.or(Err(Error::Kind))?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: written amount is not handled. Use `AsyncWriteExt::write_all` instead
--> $DIR/unused_io_amount.rs:101:5
|
LL | w.write(b"hello world").await.unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: read amount is not handled. Use `AsyncReadExt::read_exact` instead
--> $DIR/unused_io_amount.rs:106:5
|
LL | r.read(&mut buf[..]).await.unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 16 previous errors