]> git.lizzy.rs Git - rust.git/commitdiff
Rename panic files to panic_unimplemented
authorMichael A. Plikk <michael@aptoma.com>
Thu, 24 May 2018 06:59:54 +0000 (08:59 +0200)
committerMichael A. Plikk <michael@aptoma.com>
Thu, 24 May 2018 08:04:18 +0000 (10:04 +0200)
clippy_lints/src/lib.rs
clippy_lints/src/panic.rs [deleted file]
clippy_lints/src/panic_unimplemented.rs [new file with mode: 0644]
tests/ui/panic.rs [deleted file]
tests/ui/panic.stderr [deleted file]
tests/ui/panic_unimplemented.rs [new file with mode: 0644]
tests/ui/panic_unimplemented.stderr [new file with mode: 0644]

index 9dd9a364be7c0bd7542ade66311f88c5de6c7ea4..1f9b2512d3be51e1691ee8e71659e06573565a9f 100644 (file)
@@ -177,7 +177,7 @@ macro_rules! declare_clippy_lint {
 pub mod ok_if_let;
 pub mod open_options;
 pub mod overflow_check_conditional;
-pub mod panic;
+pub mod panic_unimplemented;
 pub mod partialeq_ne_impl;
 pub mod precedence;
 pub mod ptr;
@@ -352,7 +352,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
     reg.register_late_lint_pass(box escape::Pass{too_large_for_stack: conf.too_large_for_stack});
     reg.register_early_lint_pass(box misc_early::MiscEarly);
     reg.register_late_lint_pass(box array_indexing::ArrayIndexing);
-    reg.register_late_lint_pass(box panic::Pass);
+    reg.register_late_lint_pass(box panic_unimplemented::Pass);
     reg.register_late_lint_pass(box strings::StringLitAsBytes);
     reg.register_late_lint_pass(box derive::Derive);
     reg.register_late_lint_pass(box types::CharLitAsU8);
@@ -626,8 +626,8 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
         ok_if_let::IF_LET_SOME_RESULT,
         open_options::NONSENSICAL_OPEN_OPTIONS,
         overflow_check_conditional::OVERFLOW_CHECK_CONDITIONAL,
-        panic::PANIC_PARAMS,
-        panic::UNIMPLEMENTED,
+        panic_unimplemented::PANIC_PARAMS,
+        panic_unimplemented::UNIMPLEMENTED,
         partialeq_ne_impl::PARTIALEQ_NE_IMPL,
         precedence::PRECEDENCE,
         ptr::CMP_NULL,
@@ -749,8 +749,8 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
         non_expressive_names::JUST_UNDERSCORES_AND_DIGITS,
         non_expressive_names::MANY_SINGLE_CHAR_NAMES,
         ok_if_let::IF_LET_SOME_RESULT,
-        panic::PANIC_PARAMS,
-        panic::UNIMPLEMENTED,
+        panic_unimplemented::PANIC_PARAMS,
+        panic_unimplemented::UNIMPLEMENTED,
         ptr::CMP_NULL,
         ptr::PTR_ARG,
         question_mark::QUESTION_MARK,
diff --git a/clippy_lints/src/panic.rs b/clippy_lints/src/panic.rs
deleted file mode 100644 (file)
index 7f1b677..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-use rustc::hir::*;
-use rustc::lint::*;
-use syntax::ast::LitKind;
-use syntax::ptr::P;
-use utils::{is_direct_expn_of, is_expn_of, match_def_path, opt_def_id, paths, resolve_node, span_lint};
-
-/// **What it does:** Checks for missing parameters in `panic!`.
-///
-/// **Why is this bad?** Contrary to the `format!` family of macros, there are
-/// two forms of `panic!`: if there are no parameters given, the first argument
-/// is not a format string and used literally. So while `format!("{}")` will
-/// fail to compile, `panic!("{}")` will not.
-///
-/// **Known problems:** None.
-///
-/// **Example:**
-/// ```rust
-/// panic!("This `panic!` is probably missing a parameter there: {}");
-/// ```
-declare_clippy_lint! {
-    pub PANIC_PARAMS,
-    style,
-    "missing parameters in `panic!` calls"
-}
-
-/// **What it does:** Checks for usage of `unimplemented!`.
-///
-/// **Why is this bad?** This macro should not be present in production code
-///
-/// **Known problems:** None.
-///
-/// **Example:**
-/// ```rust
-/// unimplemented!();
-/// ```
-declare_clippy_lint! {
-    pub UNIMPLEMENTED,
-    style,
-    "`unimplemented!` should not be present in production code"
-}
-
-#[allow(missing_copy_implementations)]
-pub struct Pass;
-
-impl LintPass for Pass {
-    fn get_lints(&self) -> LintArray {
-        lint_array!(PANIC_PARAMS, UNIMPLEMENTED)
-    }
-}
-
-impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
-    fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
-        if_chain! {
-            if let ExprBlock(ref block, _) = expr.node;
-            if let Some(ref ex) = block.expr;
-            if let ExprCall(ref fun, ref params) = ex.node;
-            if let ExprPath(ref qpath) = fun.node;
-            if let Some(fun_def_id) = opt_def_id(resolve_node(cx, qpath, fun.hir_id));
-            if match_def_path(cx.tcx, fun_def_id, &paths::BEGIN_PANIC);
-            if params.len() == 2;
-            then {
-                if is_expn_of(expr.span, "unimplemented").is_some() {
-                    span_lint(cx, UNIMPLEMENTED, expr.span,
-                              "`unimplemented` should not be present in production code");
-                } else {
-                    match_panic(params, expr, cx);
-                }
-            }
-        }
-    }
-}
-
-fn match_panic(params: &P<[Expr]>, expr: &Expr, cx: &LateContext) {
-    if_chain! {
-        if let ExprLit(ref lit) = params[0].node;
-        if is_direct_expn_of(expr.span, "panic").is_some();
-        if let LitKind::Str(ref string, _) = lit.node;
-        let string = string.as_str().replace("{{", "").replace("}}", "");
-        if let Some(par) = string.find('{');
-        if string[par..].contains('}');
-        if params[0].span.source_callee().is_none();
-        if params[0].span.lo() != params[0].span.hi();
-        then {
-            span_lint(cx, PANIC_PARAMS, params[0].span,
-                      "you probably are missing some parameter in your format string");
-        }
-    }
-}
diff --git a/clippy_lints/src/panic_unimplemented.rs b/clippy_lints/src/panic_unimplemented.rs
new file mode 100644 (file)
index 0000000..7f1b677
--- /dev/null
@@ -0,0 +1,88 @@
+use rustc::hir::*;
+use rustc::lint::*;
+use syntax::ast::LitKind;
+use syntax::ptr::P;
+use utils::{is_direct_expn_of, is_expn_of, match_def_path, opt_def_id, paths, resolve_node, span_lint};
+
+/// **What it does:** Checks for missing parameters in `panic!`.
+///
+/// **Why is this bad?** Contrary to the `format!` family of macros, there are
+/// two forms of `panic!`: if there are no parameters given, the first argument
+/// is not a format string and used literally. So while `format!("{}")` will
+/// fail to compile, `panic!("{}")` will not.
+///
+/// **Known problems:** None.
+///
+/// **Example:**
+/// ```rust
+/// panic!("This `panic!` is probably missing a parameter there: {}");
+/// ```
+declare_clippy_lint! {
+    pub PANIC_PARAMS,
+    style,
+    "missing parameters in `panic!` calls"
+}
+
+/// **What it does:** Checks for usage of `unimplemented!`.
+///
+/// **Why is this bad?** This macro should not be present in production code
+///
+/// **Known problems:** None.
+///
+/// **Example:**
+/// ```rust
+/// unimplemented!();
+/// ```
+declare_clippy_lint! {
+    pub UNIMPLEMENTED,
+    style,
+    "`unimplemented!` should not be present in production code"
+}
+
+#[allow(missing_copy_implementations)]
+pub struct Pass;
+
+impl LintPass for Pass {
+    fn get_lints(&self) -> LintArray {
+        lint_array!(PANIC_PARAMS, UNIMPLEMENTED)
+    }
+}
+
+impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
+    fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
+        if_chain! {
+            if let ExprBlock(ref block, _) = expr.node;
+            if let Some(ref ex) = block.expr;
+            if let ExprCall(ref fun, ref params) = ex.node;
+            if let ExprPath(ref qpath) = fun.node;
+            if let Some(fun_def_id) = opt_def_id(resolve_node(cx, qpath, fun.hir_id));
+            if match_def_path(cx.tcx, fun_def_id, &paths::BEGIN_PANIC);
+            if params.len() == 2;
+            then {
+                if is_expn_of(expr.span, "unimplemented").is_some() {
+                    span_lint(cx, UNIMPLEMENTED, expr.span,
+                              "`unimplemented` should not be present in production code");
+                } else {
+                    match_panic(params, expr, cx);
+                }
+            }
+        }
+    }
+}
+
+fn match_panic(params: &P<[Expr]>, expr: &Expr, cx: &LateContext) {
+    if_chain! {
+        if let ExprLit(ref lit) = params[0].node;
+        if is_direct_expn_of(expr.span, "panic").is_some();
+        if let LitKind::Str(ref string, _) = lit.node;
+        let string = string.as_str().replace("{{", "").replace("}}", "");
+        if let Some(par) = string.find('{');
+        if string[par..].contains('}');
+        if params[0].span.source_callee().is_none();
+        if params[0].span.lo() != params[0].span.hi();
+        then {
+            span_lint(cx, PANIC_PARAMS, params[0].span,
+                      "you probably are missing some parameter in your format string");
+        }
+    }
+}
diff --git a/tests/ui/panic.rs b/tests/ui/panic.rs
deleted file mode 100644 (file)
index 56d06f2..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-
-
-
-#![warn(panic_params, unimplemented)]
-
-fn missing() {
-    if true {
-        panic!("{}");
-    } else if false {
-        panic!("{:?}");
-    } else {
-        assert!(true, "here be missing values: {}");
-    }
-
-    panic!("{{{this}}}");
-}
-
-fn ok_single() {
-    panic!("foo bar");
-}
-
-fn ok_inner() {
-    // Test for #768
-    assert!("foo bar".contains(&format!("foo {}", "bar")));
-}
-
-fn ok_multiple() {
-    panic!("{}", "This is {ok}");
-}
-
-fn ok_bracket() {
-    match 42 {
-        1337 => panic!("{so is this"),
-        666 => panic!("so is this}"),
-        _ => panic!("}so is that{"),
-    }
-}
-
-const ONE : u32= 1;
-
-fn ok_nomsg() {
-    assert!({ 1 == ONE });
-    assert!(if 1 == ONE { ONE == 1 } else { false });
-}
-
-fn ok_escaped() {
-    panic!("{{ why should this not be ok? }}");
-    panic!(" or {{ that ?");
-    panic!(" or }} this ?");
-    panic!(" {or {{ that ?");
-    panic!(" }or }} this ?");
-    panic!("{{ test }");
-    panic!("{case }}");
-}
-
-fn unimplemented() {
-    unimplemented!();
-}
-
-fn main() {
-    missing();
-    ok_single();
-    ok_multiple();
-    ok_bracket();
-    ok_inner();
-    ok_nomsg();
-    ok_escaped();
-    unimplemented();
-}
diff --git a/tests/ui/panic.stderr b/tests/ui/panic.stderr
deleted file mode 100644 (file)
index 786a20c..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-error: you probably are missing some parameter in your format string
- --> $DIR/panic.rs:8:16
-  |
-8 |         panic!("{}");
-  |                ^^^^
-  |
-  = note: `-D panic-params` implied by `-D warnings`
-
-error: you probably are missing some parameter in your format string
-  --> $DIR/panic.rs:10:16
-   |
-10 |         panic!("{:?}");
-   |                ^^^^^^
-
-error: you probably are missing some parameter in your format string
-  --> $DIR/panic.rs:12:23
-   |
-12 |         assert!(true, "here be missing values: {}");
-   |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-error: you probably are missing some parameter in your format string
-  --> $DIR/panic.rs:15:12
-   |
-15 |     panic!("{{{this}}}");
-   |            ^^^^^^^^^^^^
-
-error: `unimplemented` should not be present in production code
-  --> $DIR/panic.rs:57:5
-   |
-57 |     unimplemented!();
-   |     ^^^^^^^^^^^^^^^^^
-   |
-   = note: `-D unimplemented` implied by `-D warnings`
-   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
-
-error: aborting due to 5 previous errors
-
diff --git a/tests/ui/panic_unimplemented.rs b/tests/ui/panic_unimplemented.rs
new file mode 100644 (file)
index 0000000..56d06f2
--- /dev/null
@@ -0,0 +1,69 @@
+
+
+
+#![warn(panic_params, unimplemented)]
+
+fn missing() {
+    if true {
+        panic!("{}");
+    } else if false {
+        panic!("{:?}");
+    } else {
+        assert!(true, "here be missing values: {}");
+    }
+
+    panic!("{{{this}}}");
+}
+
+fn ok_single() {
+    panic!("foo bar");
+}
+
+fn ok_inner() {
+    // Test for #768
+    assert!("foo bar".contains(&format!("foo {}", "bar")));
+}
+
+fn ok_multiple() {
+    panic!("{}", "This is {ok}");
+}
+
+fn ok_bracket() {
+    match 42 {
+        1337 => panic!("{so is this"),
+        666 => panic!("so is this}"),
+        _ => panic!("}so is that{"),
+    }
+}
+
+const ONE : u32= 1;
+
+fn ok_nomsg() {
+    assert!({ 1 == ONE });
+    assert!(if 1 == ONE { ONE == 1 } else { false });
+}
+
+fn ok_escaped() {
+    panic!("{{ why should this not be ok? }}");
+    panic!(" or {{ that ?");
+    panic!(" or }} this ?");
+    panic!(" {or {{ that ?");
+    panic!(" }or }} this ?");
+    panic!("{{ test }");
+    panic!("{case }}");
+}
+
+fn unimplemented() {
+    unimplemented!();
+}
+
+fn main() {
+    missing();
+    ok_single();
+    ok_multiple();
+    ok_bracket();
+    ok_inner();
+    ok_nomsg();
+    ok_escaped();
+    unimplemented();
+}
diff --git a/tests/ui/panic_unimplemented.stderr b/tests/ui/panic_unimplemented.stderr
new file mode 100644 (file)
index 0000000..534bfba
--- /dev/null
@@ -0,0 +1,37 @@
+error: you probably are missing some parameter in your format string
+ --> $DIR/panic_unimplemented.rs:8:16
+  |
+8 |         panic!("{}");
+  |                ^^^^
+  |
+  = note: `-D panic-params` implied by `-D warnings`
+
+error: you probably are missing some parameter in your format string
+  --> $DIR/panic_unimplemented.rs:10:16
+   |
+10 |         panic!("{:?}");
+   |                ^^^^^^
+
+error: you probably are missing some parameter in your format string
+  --> $DIR/panic_unimplemented.rs:12:23
+   |
+12 |         assert!(true, "here be missing values: {}");
+   |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: you probably are missing some parameter in your format string
+  --> $DIR/panic_unimplemented.rs:15:12
+   |
+15 |     panic!("{{{this}}}");
+   |            ^^^^^^^^^^^^
+
+error: `unimplemented` should not be present in production code
+  --> $DIR/panic_unimplemented.rs:57:5
+   |
+57 |     unimplemented!();
+   |     ^^^^^^^^^^^^^^^^^
+   |
+   = note: `-D unimplemented` implied by `-D warnings`
+   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
+
+error: aborting due to 5 previous errors
+