@@ -7,8 +7,8 @@ use rustc_session::declare_tool_lint;
7
7
declare_clippy_lint ! {
8
8
/// **What it does:** Checks for unused written/read amount.
9
9
///
10
- /// **Why is this bad?** `io::Write::write` and `io::Read::read` are not
11
- /// guaranteed to
10
+ /// **Why is this bad?** `io::Write::write(_vectored) ` and
11
+ /// `io::Read::read(_vectored)` are not guaranteed to
12
12
/// process the entire buffer. They return how many bytes were processed, which
13
13
/// might be smaller
14
14
/// than a given buffer's length. If you don't need to deal with
@@ -68,20 +68,25 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedIoAmount {
68
68
fn check_method_call ( cx : & LateContext < ' _ , ' _ > , call : & hir:: Expr < ' _ > , expr : & hir:: Expr < ' _ > ) {
69
69
if let hir:: ExprKind :: MethodCall ( ref path, _, _) = call. kind {
70
70
let symbol = & * path. ident . as_str ( ) ;
71
- if match_trait_method ( cx, call, & paths:: IO_READ ) && symbol == "read" {
72
- span_lint (
71
+ let read_trait = match_trait_method ( cx, call, & paths:: IO_READ ) ;
72
+ let write_trait = match_trait_method ( cx, call, & paths:: IO_WRITE ) ;
73
+
74
+ match ( read_trait, write_trait, symbol) {
75
+ ( true , _, "read" ) => span_lint (
73
76
cx,
74
77
UNUSED_IO_AMOUNT ,
75
78
expr. span ,
76
- "handle read amount returned or use `Read::read_exact` instead" ,
77
- ) ;
78
- } else if match_trait_method ( cx , call , & paths :: IO_WRITE ) && symbol == "write" {
79
- span_lint (
79
+ "read amount is not handled. Use `Read::read_exact` instead" ,
80
+ ) ,
81
+ ( true , _ , "read_vectored" ) => span_lint ( cx , UNUSED_IO_AMOUNT , expr . span , "read amount is not handled" ) ,
82
+ ( _ , true , "write" ) => span_lint (
80
83
cx,
81
84
UNUSED_IO_AMOUNT ,
82
85
expr. span ,
83
- "handle written amount returned or use `Write::write_all` instead" ,
84
- ) ;
86
+ "written amount is not handled. Use `Write::write_all` instead" ,
87
+ ) ,
88
+ ( _, true , "write_vectored" ) => span_lint ( cx, UNUSED_IO_AMOUNT , expr. span , "written amount is not handled" ) ,
89
+ _ => ( ) ,
85
90
}
86
91
}
87
92
}
0 commit comments