Skip to content

Commit d227f18

Browse files
committed
Auto merge of rust-lang#10225 - evantypanski:et/issue10132, r=flip1995
[`unused_io_amount`]: Lint with `is_ok` and `is_err` Fixes rust-lang#10132 changelog: Apply [`unused_io_amount`] lint to `is_ok` and `is_err` without checking read/write amount
2 parents e1224cd + f9f75e0 commit d227f18

File tree

3 files changed

+47
-7
lines changed

3 files changed

+47
-7
lines changed

clippy_lints/src/unused_io_amount.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedIoAmount {
6565
}
6666
},
6767
hir::ExprKind::MethodCall(path, arg_0, ..) => match path.ident.as_str() {
68-
"expect" | "unwrap" | "unwrap_or" | "unwrap_or_else" => {
68+
"expect" | "unwrap" | "unwrap_or" | "unwrap_or_else" | "is_ok" | "is_err" => {
6969
check_map_error(cx, arg_0, expr);
7070
},
7171
_ => (),

tests/ui/unused_io_amount.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ fn combine_or(file: &str) -> Result<(), Error> {
6363
Ok(())
6464
}
6565

66+
fn is_ok_err<T: io::Read + io::Write>(s: &mut T) {
67+
s.write(b"ok").is_ok();
68+
s.write(b"err").is_err();
69+
let mut buf = [0u8; 0];
70+
s.read(&mut buf).is_ok();
71+
s.read(&mut buf).is_err();
72+
}
73+
6674
async fn bad_async_write<W: AsyncWrite + Unpin>(w: &mut W) {
6775
w.write(b"hello world").await.unwrap();
6876
}

tests/ui/unused_io_amount.stderr

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,50 +82,82 @@ LL | | .expect("error");
8282
error: written amount is not handled
8383
--> $DIR/unused_io_amount.rs:67:5
8484
|
85+
LL | s.write(b"ok").is_ok();
86+
| ^^^^^^^^^^^^^^^^^^^^^^
87+
|
88+
= help: use `Write::write_all` instead, or handle partial writes
89+
90+
error: written amount is not handled
91+
--> $DIR/unused_io_amount.rs:68:5
92+
|
93+
LL | s.write(b"err").is_err();
94+
| ^^^^^^^^^^^^^^^^^^^^^^^^
95+
|
96+
= help: use `Write::write_all` instead, or handle partial writes
97+
98+
error: read amount is not handled
99+
--> $DIR/unused_io_amount.rs:70:5
100+
|
101+
LL | s.read(&mut buf).is_ok();
102+
| ^^^^^^^^^^^^^^^^^^^^^^^^
103+
|
104+
= help: use `Read::read_exact` instead, or handle partial reads
105+
106+
error: read amount is not handled
107+
--> $DIR/unused_io_amount.rs:71:5
108+
|
109+
LL | s.read(&mut buf).is_err();
110+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
111+
|
112+
= help: use `Read::read_exact` instead, or handle partial reads
113+
114+
error: written amount is not handled
115+
--> $DIR/unused_io_amount.rs:75:5
116+
|
85117
LL | w.write(b"hello world").await.unwrap();
86118
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
87119
|
88120
= help: use `AsyncWriteExt::write_all` instead, or handle partial writes
89121

90122
error: read amount is not handled
91-
--> $DIR/unused_io_amount.rs:72:5
123+
--> $DIR/unused_io_amount.rs:80:5
92124
|
93125
LL | r.read(&mut buf[..]).await.unwrap();
94126
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
95127
|
96128
= help: use `AsyncReadExt::read_exact` instead, or handle partial reads
97129

98130
error: written amount is not handled
99-
--> $DIR/unused_io_amount.rs:85:9
131+
--> $DIR/unused_io_amount.rs:93:9
100132
|
101133
LL | w.write(b"hello world").await?;
102134
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
103135
|
104136
= help: use `AsyncWriteExt::write_all` instead, or handle partial writes
105137

106138
error: read amount is not handled
107-
--> $DIR/unused_io_amount.rs:93:9
139+
--> $DIR/unused_io_amount.rs:101:9
108140
|
109141
LL | r.read(&mut buf[..]).await.or(Err(Error::Kind))?;
110142
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
111143
|
112144
= help: use `AsyncReadExt::read_exact` instead, or handle partial reads
113145

114146
error: written amount is not handled
115-
--> $DIR/unused_io_amount.rs:101:5
147+
--> $DIR/unused_io_amount.rs:109:5
116148
|
117149
LL | w.write(b"hello world").await.unwrap();
118150
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
119151
|
120152
= help: use `AsyncWriteExt::write_all` instead, or handle partial writes
121153

122154
error: read amount is not handled
123-
--> $DIR/unused_io_amount.rs:106:5
155+
--> $DIR/unused_io_amount.rs:114:5
124156
|
125157
LL | r.read(&mut buf[..]).await.unwrap();
126158
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
127159
|
128160
= help: use `AsyncReadExt::read_exact` instead, or handle partial reads
129161

130-
error: aborting due to 16 previous errors
162+
error: aborting due to 20 previous errors
131163

0 commit comments

Comments
 (0)