]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/open_options.rs
Auto merge of #3946 - rchaser53:issue-3920, r=flip1995
[rust.git] / clippy_lints / src / open_options.rs
index 9133192549fc5e7f58aa1680d2b71fee2bd98fa4..43c7f3884d3a220fcc4ce67148aa2e2a9c44aa00 100644 (file)
@@ -1,23 +1,25 @@
-use crate::rustc::hir::{Expr, ExprKind};
-use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
-use crate::rustc::{declare_tool_lint, lint_array};
-use crate::syntax::ast::LitKind;
-use crate::syntax::source_map::{Span, Spanned};
 use crate::utils::{match_type, paths, span_lint, walk_ptrs_ty};
+use rustc::hir::{Expr, ExprKind};
+use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
+use rustc::{declare_tool_lint, lint_array};
+use syntax::ast::LitKind;
+use syntax::source_map::{Span, Spanned};
 
-/// **What it does:** Checks for duplicate open options as well as combinations
-/// that make no sense.
-///
-/// **Why is this bad?** In the best case, the code will be harder to read than
-/// necessary. I don't know the worst case.
-///
-/// **Known problems:** None.
-///
-/// **Example:**
-/// ```rust
-/// OpenOptions::new().read(true).truncate(true)
-/// ```
 declare_clippy_lint! {
+    /// **What it does:** Checks for duplicate open options as well as combinations
+    /// that make no sense.
+    ///
+    /// **Why is this bad?** In the best case, the code will be harder to read than
+    /// necessary. I don't know the worst case.
+    ///
+    /// **Known problems:** None.
+    ///
+    /// **Example:**
+    /// ```rust
+    /// use std::fs::OpenOptions;
+    ///
+    /// OpenOptions::new().read(true).truncate(true);
+    /// ```
     pub NONSENSICAL_OPEN_OPTIONS,
     correctness,
     "nonsensical combination of options for opening a file"
@@ -30,6 +32,10 @@ impl LintPass for NonSensical {
     fn get_lints(&self) -> LintArray {
         lint_array!(NONSENSICAL_OPEN_OPTIONS)
     }
+
+    fn name(&self) -> &'static str {
+        "OpenOptions"
+    }
 }
 
 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSensical {
@@ -72,7 +78,7 @@ fn get_open_options(cx: &LateContext<'_, '_>, argument: &Expr, options: &mut Vec
                     if let Spanned {
                         node: LitKind::Bool(lit),
                         ..
-                    } = **span
+                    } = *span
                     {
                         if lit {
                             Argument::True
@@ -190,7 +196,12 @@ fn check_open_options(cx: &LateContext<'_, '_>, options: &[(OpenOption, Argument
     }
 
     if read && truncate && read_arg && truncate_arg && !(write && write_arg) {
-        span_lint(cx, NONSENSICAL_OPEN_OPTIONS, span, "file opened with \"truncate\" and \"read\"");
+        span_lint(
+            cx,
+            NONSENSICAL_OPEN_OPTIONS,
+            span,
+            "file opened with \"truncate\" and \"read\"",
+        );
     }
     if append && truncate && append_arg && truncate_arg {
         span_lint(