]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/unused_io_amount.rs
Auto merge of #3946 - rchaser53:issue-3920, r=flip1995
[rust.git] / clippy_lints / src / unused_io_amount.rs
index 82430a794b1f2a0aee75d2e0083f8a9298dffa6a..bf31b774bba24fd66c9f50c5de431805a3253f65 100644 (file)
@@ -1,30 +1,30 @@
-use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
-use crate::rustc::{declare_tool_lint, lint_array};
-use crate::rustc::hir;
 use crate::utils::{is_try, match_qpath, match_trait_method, paths, span_lint};
+use rustc::hir;
+use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
+use rustc::{declare_tool_lint, lint_array};
 
-/// **What it does:** Checks for unused written/read amount.
-///
-/// **Why is this bad?** `io::Write::write` and `io::Read::read` are not
-/// guaranteed to
-/// process the entire buffer. They return how many bytes were processed, which
-/// might be smaller
-/// than a given buffer's length. If you don't need to deal with
-/// partial-write/read, use
-/// `write_all`/`read_exact` instead.
-///
-/// **Known problems:** Detects only common patterns.
-///
-/// **Example:**
-/// ```rust,ignore
-/// use std::io;
-/// fn foo<W: io::Write>(w: &mut W) -> io::Result<()> {
-///     // must be `w.write_all(b"foo")?;`
-///     w.write(b"foo")?;
-///     Ok(())
-/// }
-/// ```
 declare_clippy_lint! {
+    /// **What it does:** Checks for unused written/read amount.
+    ///
+    /// **Why is this bad?** `io::Write::write` and `io::Read::read` are not
+    /// guaranteed to
+    /// process the entire buffer. They return how many bytes were processed, which
+    /// might be smaller
+    /// than a given buffer's length. If you don't need to deal with
+    /// partial-write/read, use
+    /// `write_all`/`read_exact` instead.
+    ///
+    /// **Known problems:** Detects only common patterns.
+    ///
+    /// **Example:**
+    /// ```rust,ignore
+    /// use std::io;
+    /// fn foo<W: io::Write>(w: &mut W) -> io::Result<()> {
+    ///     // must be `w.write_all(b"foo")?;`
+    ///     w.write(b"foo")?;
+    ///     Ok(())
+    /// }
+    /// ```
     pub UNUSED_IO_AMOUNT,
     correctness,
     "unused written/read amount"
@@ -36,17 +36,21 @@ impl LintPass for UnusedIoAmount {
     fn get_lints(&self) -> LintArray {
         lint_array!(UNUSED_IO_AMOUNT)
     }
+
+    fn name(&self) -> &'static str {
+        "UnusedIoAmount"
+    }
 }
 
 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedIoAmount {
     fn check_stmt(&mut self, cx: &LateContext<'_, '_>, s: &hir::Stmt) {
         let expr = match s.node {
-            hir::StmtKind::Semi(ref expr, _) | hir::StmtKind::Expr(ref expr, _) => &**expr,
+            hir::StmtKind::Semi(ref expr) | hir::StmtKind::Expr(ref expr) => &**expr,
             _ => return,
         };
 
         match expr.node {
-            hir::ExprKind::Match(ref res, _, _) if is_try(expr).is_some() => {
+            hir::ExprKind::Match(ref res, _, _) if is_try(cx, expr).is_some() => {
                 if let hir::ExprKind::Call(ref func, ref args) = res.node {
                     if let hir::ExprKind::Path(ref path) = func.node {
                         if match_qpath(path, &paths::TRY_INTO_RESULT) && args.len() == 1 {