Skip to content

Commit b6bcf0c

Browse files
committed
unused_io_amount: Use span_lint_and_help.
This improves the quality of the genrated output and makes it more in line with other lint messages. changelog: [`unused_io_amount`]: Improve help text
1 parent 65d1f83 commit b6bcf0c

File tree

2 files changed

+58
-23
lines changed

2 files changed

+58
-23
lines changed

clippy_lints/src/unused_io_amount.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use clippy_utils::diagnostics::span_lint;
1+
use clippy_utils::diagnostics::{span_lint, span_lint_and_help};
22
use clippy_utils::{is_try, match_trait_method, paths};
33
use rustc_hir as hir;
44
use rustc_lint::{LateContext, LateLintPass};
@@ -126,32 +126,40 @@ fn check_method_call(cx: &LateContext<'_>, call: &hir::Expr<'_>, expr: &hir::Exp
126126
};
127127

128128
match (read_trait, write_trait, symbol, is_await) {
129-
(true, _, "read", false) => span_lint(
129+
(true, _, "read", false) => span_lint_and_help(
130130
cx,
131131
UNUSED_IO_AMOUNT,
132132
expr.span,
133-
"read amount is not handled. Use `Read::read_exact` instead",
133+
"read amount is not handled",
134+
None,
135+
"use `Read::read_exact` instead, or handle partial reads",
134136
),
135-
(true, _, "read", true) => span_lint(
137+
(true, _, "read", true) => span_lint_and_help(
136138
cx,
137139
UNUSED_IO_AMOUNT,
138140
expr.span,
139-
"read amount is not handled. Use `AsyncReadExt::read_exact` instead",
141+
"read amount is not handled",
142+
None,
143+
"use `AsyncReadExt::read_exact` instead, or handle partial reads",
140144
),
141145
(true, _, "read_vectored", _) => {
142146
span_lint(cx, UNUSED_IO_AMOUNT, expr.span, "read amount is not handled");
143147
},
144-
(_, true, "write", false) => span_lint(
148+
(_, true, "write", false) => span_lint_and_help(
145149
cx,
146150
UNUSED_IO_AMOUNT,
147151
expr.span,
148-
"written amount is not handled. Use `Write::write_all` instead",
152+
"written amount is not handled",
153+
None,
154+
"use `Write::write_all` instead, or handle partial writes",
149155
),
150-
(_, true, "write", true) => span_lint(
156+
(_, true, "write", true) => span_lint_and_help(
151157
cx,
152158
UNUSED_IO_AMOUNT,
153159
expr.span,
154-
"written amount is not handled. Use `AsyncWriteExt::write_all` instead",
160+
"written amount is not handled",
161+
None,
162+
"use `AsyncWriteExt::write_all` instead, or handle partial writes",
155163
),
156164
(_, true, "write_vectored", _) => {
157165
span_lint(cx, UNUSED_IO_AMOUNT, expr.span, "written amount is not handled");

tests/ui/unused_io_amount.stderr

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,35 @@
1-
error: written amount is not handled. Use `Write::write_all` instead
1+
error: written amount is not handled
22
--> $DIR/unused_io_amount.rs:9:5
33
|
44
LL | s.write(b"test")?;
55
| ^^^^^^^^^^^^^^^^^
66
|
77
= note: `-D clippy::unused-io-amount` implied by `-D warnings`
8+
= help: use `Write::write_all` instead, or handle partial writes
89

9-
error: read amount is not handled. Use `Read::read_exact` instead
10+
error: read amount is not handled
1011
--> $DIR/unused_io_amount.rs:11:5
1112
|
1213
LL | s.read(&mut buf)?;
1314
| ^^^^^^^^^^^^^^^^^
15+
|
16+
= help: use `Read::read_exact` instead, or handle partial reads
1417

15-
error: written amount is not handled. Use `Write::write_all` instead
18+
error: written amount is not handled
1619
--> $DIR/unused_io_amount.rs:16:5
1720
|
1821
LL | s.write(b"test").unwrap();
1922
| ^^^^^^^^^^^^^^^^^^^^^^^^^
23+
|
24+
= help: use `Write::write_all` instead, or handle partial writes
2025

21-
error: read amount is not handled. Use `Read::read_exact` instead
26+
error: read amount is not handled
2227
--> $DIR/unused_io_amount.rs:18:5
2328
|
2429
LL | s.read(&mut buf).unwrap();
2530
| ^^^^^^^^^^^^^^^^^^^^^^^^^
31+
|
32+
= help: use `Read::read_exact` instead, or handle partial reads
2633

2734
error: read amount is not handled
2835
--> $DIR/unused_io_amount.rs:22:5
@@ -36,25 +43,31 @@ error: written amount is not handled
3643
LL | s.write_vectored(&[io::IoSlice::new(&[])])?;
3744
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3845

39-
error: read amount is not handled. Use `Read::read_exact` instead
46+
error: read amount is not handled
4047
--> $DIR/unused_io_amount.rs:30:5
4148
|
4249
LL | reader.read(&mut result).ok()?;
4350
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
51+
|
52+
= help: use `Read::read_exact` instead, or handle partial reads
4453

45-
error: read amount is not handled. Use `Read::read_exact` instead
54+
error: read amount is not handled
4655
--> $DIR/unused_io_amount.rs:39:5
4756
|
4857
LL | reader.read(&mut result).or_else(|err| Err(err))?;
4958
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
59+
|
60+
= help: use `Read::read_exact` instead, or handle partial reads
5061

51-
error: read amount is not handled. Use `Read::read_exact` instead
62+
error: read amount is not handled
5263
--> $DIR/unused_io_amount.rs:51:5
5364
|
5465
LL | reader.read(&mut result).or(Err(Error::Kind))?;
5566
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
67+
|
68+
= help: use `Read::read_exact` instead, or handle partial reads
5669

57-
error: read amount is not handled. Use `Read::read_exact` instead
70+
error: read amount is not handled
5871
--> $DIR/unused_io_amount.rs:58:5
5972
|
6073
LL | / reader
@@ -63,42 +76,56 @@ LL | | .or(Err(Error::Kind))
6376
LL | | .or(Err(Error::Kind))
6477
LL | | .expect("error");
6578
| |________________________^
79+
|
80+
= help: use `Read::read_exact` instead, or handle partial reads
6681

67-
error: written amount is not handled. Use `AsyncWriteExt::write_all` instead
82+
error: written amount is not handled
6883
--> $DIR/unused_io_amount.rs:67:5
6984
|
7085
LL | w.write(b"hello world").await.unwrap();
7186
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
87+
|
88+
= help: use `AsyncWriteExt::write_all` instead, or handle partial writes
7289

73-
error: read amount is not handled. Use `AsyncReadExt::read_exact` instead
90+
error: read amount is not handled
7491
--> $DIR/unused_io_amount.rs:72:5
7592
|
7693
LL | r.read(&mut buf[..]).await.unwrap();
7794
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
95+
|
96+
= help: use `AsyncReadExt::read_exact` instead, or handle partial reads
7897

79-
error: written amount is not handled. Use `AsyncWriteExt::write_all` instead
98+
error: written amount is not handled
8099
--> $DIR/unused_io_amount.rs:85:9
81100
|
82101
LL | w.write(b"hello world").await?;
83102
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
103+
|
104+
= help: use `AsyncWriteExt::write_all` instead, or handle partial writes
84105

85-
error: read amount is not handled. Use `AsyncReadExt::read_exact` instead
106+
error: read amount is not handled
86107
--> $DIR/unused_io_amount.rs:93:9
87108
|
88109
LL | r.read(&mut buf[..]).await.or(Err(Error::Kind))?;
89110
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
111+
|
112+
= help: use `AsyncReadExt::read_exact` instead, or handle partial reads
90113

91-
error: written amount is not handled. Use `AsyncWriteExt::write_all` instead
114+
error: written amount is not handled
92115
--> $DIR/unused_io_amount.rs:101:5
93116
|
94117
LL | w.write(b"hello world").await.unwrap();
95118
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
119+
|
120+
= help: use `AsyncWriteExt::write_all` instead, or handle partial writes
96121

97-
error: read amount is not handled. Use `AsyncReadExt::read_exact` instead
122+
error: read amount is not handled
98123
--> $DIR/unused_io_amount.rs:106:5
99124
|
100125
LL | r.read(&mut buf[..]).await.unwrap();
101126
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
127+
|
128+
= help: use `AsyncReadExt::read_exact` instead, or handle partial reads
102129

103130
error: aborting due to 16 previous errors
104131

0 commit comments

Comments
 (0)