]> git.lizzy.rs Git - rust.git/commitdiff
initialization misspell
authorwhodi <whodi@pop-os.localdomain>
Fri, 15 Apr 2022 19:00:44 +0000 (15:00 -0400)
committerManish Goregaokar <manishsmail@gmail.com>
Fri, 15 Apr 2022 21:19:00 +0000 (14:19 -0700)
clippy_dev/src/setup/git_hook.rs
clippy_lints/src/matches/infallible_destructuring_match.rs [new file with mode: 0644]
clippy_lints/src/matches/infallible_detructuring_match.rs [deleted file]
clippy_lints/src/types/mod.rs
tests/ui/needless_late_init.stderr
tests/ui/needless_late_init_fixable.stderr

index ad4b96f7ff34739453748b7cdfac75b0ee4e4af6..3fbb77d59235c32604ec8079fcb1c57081a73521 100644 (file)
@@ -18,7 +18,7 @@ pub fn install_hook(force_override: bool) {
 
     // So a little bit of a funny story. Git on unix requires the pre-commit file
     // to have the `execute` permission to be set. The Rust functions for modifying
-    // these flags doesn't seem to work when executed with normal user permissions. 
+    // these flags doesn't seem to work when executed with normal user permissions.
     //
     // However, there is a little hack that is also being used by Rust itself in their
     // setup script. Git saves the `execute` flag when syncing files. This means
diff --git a/clippy_lints/src/matches/infallible_destructuring_match.rs b/clippy_lints/src/matches/infallible_destructuring_match.rs
new file mode 100644 (file)
index 0000000..2472acb
--- /dev/null
@@ -0,0 +1,44 @@
+use clippy_utils::diagnostics::span_lint_and_sugg;
+use clippy_utils::source::snippet_with_applicability;
+use clippy_utils::{path_to_local_id, peel_blocks, strip_pat_refs};
+use rustc_errors::Applicability;
+use rustc_hir::{ExprKind, Local, MatchSource, PatKind, QPath};
+use rustc_lint::LateContext;
+
+use super::INFALLIBLE_DESTRUCTURING_MATCH;
+
+pub(crate) fn check(cx: &LateContext<'_>, local: &Local<'_>) -> bool {
+    if_chain! {
+        if !local.span.from_expansion();
+        if let Some(expr) = local.init;
+        if let ExprKind::Match(target, arms, MatchSource::Normal) = expr.kind;
+        if arms.len() == 1 && arms[0].guard.is_none();
+        if let PatKind::TupleStruct(
+            QPath::Resolved(None, variant_name), args, _) = arms[0].pat.kind;
+        if args.len() == 1;
+        if let PatKind::Binding(_, arg, ..) = strip_pat_refs(&args[0]).kind;
+        let body = peel_blocks(arms[0].body);
+        if path_to_local_id(body, arg);
+
+        then {
+            let mut applicability = Applicability::MachineApplicable;
+            span_lint_and_sugg(
+                cx,
+                INFALLIBLE_DESTRUCTURING_MATCH,
+                local.span,
+                "you seem to be trying to use `match` to destructure a single infallible pattern. \
+                Consider using `let`",
+                "try this",
+                format!(
+                    "let {}({}) = {};",
+                    snippet_with_applicability(cx, variant_name.span, "..", &mut applicability),
+                    snippet_with_applicability(cx, local.pat.span, "..", &mut applicability),
+                    snippet_with_applicability(cx, target.span, "..", &mut applicability),
+                ),
+                applicability,
+            );
+            return true;
+        }
+    }
+    false
+}
diff --git a/clippy_lints/src/matches/infallible_detructuring_match.rs b/clippy_lints/src/matches/infallible_detructuring_match.rs
deleted file mode 100644 (file)
index 2472acb..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-use clippy_utils::diagnostics::span_lint_and_sugg;
-use clippy_utils::source::snippet_with_applicability;
-use clippy_utils::{path_to_local_id, peel_blocks, strip_pat_refs};
-use rustc_errors::Applicability;
-use rustc_hir::{ExprKind, Local, MatchSource, PatKind, QPath};
-use rustc_lint::LateContext;
-
-use super::INFALLIBLE_DESTRUCTURING_MATCH;
-
-pub(crate) fn check(cx: &LateContext<'_>, local: &Local<'_>) -> bool {
-    if_chain! {
-        if !local.span.from_expansion();
-        if let Some(expr) = local.init;
-        if let ExprKind::Match(target, arms, MatchSource::Normal) = expr.kind;
-        if arms.len() == 1 && arms[0].guard.is_none();
-        if let PatKind::TupleStruct(
-            QPath::Resolved(None, variant_name), args, _) = arms[0].pat.kind;
-        if args.len() == 1;
-        if let PatKind::Binding(_, arg, ..) = strip_pat_refs(&args[0]).kind;
-        let body = peel_blocks(arms[0].body);
-        if path_to_local_id(body, arg);
-
-        then {
-            let mut applicability = Applicability::MachineApplicable;
-            span_lint_and_sugg(
-                cx,
-                INFALLIBLE_DESTRUCTURING_MATCH,
-                local.span,
-                "you seem to be trying to use `match` to destructure a single infallible pattern. \
-                Consider using `let`",
-                "try this",
-                format!(
-                    "let {}({}) = {};",
-                    snippet_with_applicability(cx, variant_name.span, "..", &mut applicability),
-                    snippet_with_applicability(cx, local.pat.span, "..", &mut applicability),
-                    snippet_with_applicability(cx, target.span, "..", &mut applicability),
-                ),
-                applicability,
-            );
-            return true;
-        }
-    }
-    false
-}
index b1b2addb9a1608b124d95259ead0f01cc2bd0c3a..353a6f6b899ea3e743ed57982b8acd130d185e14 100644 (file)
@@ -432,8 +432,8 @@ pub fn new(vec_box_size_threshold: u64, type_complexity_threshold: u64, avoid_br
     fn check_fn_decl(&mut self, cx: &LateContext<'_>, decl: &FnDecl<'_>, context: CheckTyContext) {
         // Ignore functions in trait implementations as they are usually forced by the trait definition.
         //
-        // FIXME: ideally we would like to warn *if the complicated type can be simplified*, but it's hard to
-        // check.
+        // FIXME: ideally we would like to warn *if the complicated type can be simplified*, but it's hard
+        // to check.
         if context.is_in_trait_impl {
             return;
         }
index 9ef8bb23df6a6230b034ef5547ada393056b1328..124fe5592c31c70822c4f980f2ea123a0721b842 100644 (file)
@@ -1,4 +1,4 @@
-error: unneeded late initalization
+error: unneeded late initialization
   --> $DIR/needless_late_init.rs:5:5
    |
 LL |     let a;
@@ -20,7 +20,7 @@ help: add a semicolon after the `match` expression
 LL |     };
    |      +
 
-error: unneeded late initalization
+error: unneeded late initialization
   --> $DIR/needless_late_init.rs:14:5
    |
 LL |     let b;
@@ -41,7 +41,7 @@ help: add a semicolon after the `if` expression
 LL |     };
    |      +
 
-error: unneeded late initalization
+error: unneeded late initialization
   --> $DIR/needless_late_init.rs:21:5
    |
 LL |     let c;
@@ -62,7 +62,7 @@ help: add a semicolon after the `if` expression
 LL |     };
    |      +
 
-error: unneeded late initalization
+error: unneeded late initialization
   --> $DIR/needless_late_init.rs:28:5
    |
 LL |     let d;
@@ -83,7 +83,7 @@ help: add a semicolon after the `if` expression
 LL |     };
    |      +
 
-error: unneeded late initalization
+error: unneeded late initialization
   --> $DIR/needless_late_init.rs:36:5
    |
 LL |     let e;
@@ -104,7 +104,7 @@ help: add a semicolon after the `if` expression
 LL |     };
    |      +
 
-error: unneeded late initalization
+error: unneeded late initialization
   --> $DIR/needless_late_init.rs:43:5
    |
 LL |     let f;
@@ -120,7 +120,7 @@ LL -         1 => f = "three",
 LL +         1 => "three",
    | 
 
-error: unneeded late initalization
+error: unneeded late initialization
   --> $DIR/needless_late_init.rs:49:5
    |
 LL |     let g: usize;
@@ -140,7 +140,7 @@ help: add a semicolon after the `if` expression
 LL |     };
    |      +
 
-error: unneeded late initalization
+error: unneeded late initialization
   --> $DIR/needless_late_init.rs:64:5
    |
 LL |     let a;
@@ -161,7 +161,7 @@ help: add a semicolon after the `match` expression
 LL |     };
    |      +
 
-error: unneeded late initalization
+error: unneeded late initialization
   --> $DIR/needless_late_init.rs:81:5
    |
 LL |     let a;
index 3f3d4f5286b2b2e088a737288c3759955bbcd1af..34dccc2cec8bab2943eeff36218c108f995b4dea 100644 (file)
@@ -1,4 +1,4 @@
-error: unneeded late initalization
+error: unneeded late initialization
   --> $DIR/needless_late_init_fixable.rs:6:5
    |
 LL |     let a;
@@ -10,7 +10,7 @@ help: declare `a` here
 LL |     let a = "zero";
    |     ~~~~~
 
-error: unneeded late initalization
+error: unneeded late initialization
   --> $DIR/needless_late_init_fixable.rs:9:5
    |
 LL |     let b;
@@ -21,7 +21,7 @@ help: declare `b` here
 LL |     let b = 1;
    |     ~~~~~
 
-error: unneeded late initalization
+error: unneeded late initialization
   --> $DIR/needless_late_init_fixable.rs:10:5
    |
 LL |     let c;
@@ -32,7 +32,7 @@ help: declare `c` here
 LL |     let c = 2;
    |     ~~~~~
 
-error: unneeded late initalization
+error: unneeded late initialization
   --> $DIR/needless_late_init_fixable.rs:14:5
    |
 LL |     let d: usize;
@@ -43,7 +43,7 @@ help: declare `d` here
 LL |     let d: usize = 1;
    |     ~~~~~~~~~~~~
 
-error: unneeded late initalization
+error: unneeded late initialization
   --> $DIR/needless_late_init_fixable.rs:17:5
    |
 LL |     let mut e;
@@ -54,7 +54,7 @@ help: declare `e` here
 LL |     let mut e = 1;
    |     ~~~~~~~~~
 
-error: unneeded late initalization
+error: unneeded late initialization
   --> $DIR/needless_late_init_fixable.rs:21:5
    |
 LL |     let h;