@@ -7,8 +7,8 @@ use rustc_session::declare_tool_lint;
77declare_clippy_lint ! {
88 /// **What it does:** Checks for unused written/read amount.
99 ///
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
1212 /// process the entire buffer. They return how many bytes were processed, which
1313 /// might be smaller
1414 /// 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 {
6868fn check_method_call ( cx : & LateContext < ' _ , ' _ > , call : & hir:: Expr < ' _ > , expr : & hir:: Expr < ' _ > ) {
6969 if let hir:: ExprKind :: MethodCall ( ref path, _, _) = call. kind {
7070 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 (
7376 cx,
7477 UNUSED_IO_AMOUNT ,
7578 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 (
8083 cx,
8184 UNUSED_IO_AMOUNT ,
8285 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+ _ => ( ) ,
8590 }
8691 }
8792}
0 commit comments