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