about summary refs log tree commit diff
path: root/src/tools/clippy/tests
diff options
context:
space:
mode:
authorCamelid <camelidcamel@gmail.com>2020-11-17 12:16:15 -0800
committerCamelid <camelidcamel@gmail.com>2020-11-17 12:16:15 -0800
commit95eff664269adc18daca51b0de969b699a4ddb01 (patch)
tree3739e7cb8bb549aff3c06bab8babab2e20c619e0 /src/tools/clippy/tests
parent603ab5bd6e0ffefafa7411cd8bd23a6ca82bcff0 (diff)
downloadrust-95eff664269adc18daca51b0de969b699a4ddb01.tar.gz
rust-95eff664269adc18daca51b0de969b699a4ddb01.zip
Fix handling of panic calls
This should make Clippy more resilient and will unblock #78343.

This PR is made against rust-lang/rust to avoid the need for a subtree
sync at @flip1995's suggestion in rust-lang/rust-clippy#6310.
Diffstat (limited to 'src/tools/clippy/tests')
-rw-r--r--src/tools/clippy/tests/ui/panicking_macros.rs11
-rw-r--r--src/tools/clippy/tests/ui/panicking_macros.stderr50
2 files changed, 48 insertions, 13 deletions
diff --git a/src/tools/clippy/tests/ui/panicking_macros.rs b/src/tools/clippy/tests/ui/panicking_macros.rs
index f91ccfaed74..77fcb8dfd02 100644
--- a/src/tools/clippy/tests/ui/panicking_macros.rs
+++ b/src/tools/clippy/tests/ui/panicking_macros.rs
@@ -1,6 +1,8 @@
 #![warn(clippy::unimplemented, clippy::unreachable, clippy::todo, clippy::panic)]
 #![allow(clippy::assertions_on_constants)]
 
+extern crate core;
+
 fn panic() {
     let a = 2;
     panic!();
@@ -33,9 +35,18 @@ fn unreachable() {
     let b = a + 2;
 }
 
+fn core_versions() {
+    use core::{panic, todo, unimplemented, unreachable};
+    panic!();
+    todo!();
+    unimplemented!();
+    unreachable!();
+}
+
 fn main() {
     panic();
     todo();
     unimplemented();
     unreachable();
+    core_versions();
 }
diff --git a/src/tools/clippy/tests/ui/panicking_macros.stderr b/src/tools/clippy/tests/ui/panicking_macros.stderr
index 37c11d72a57..83234c0ed92 100644
--- a/src/tools/clippy/tests/ui/panicking_macros.stderr
+++ b/src/tools/clippy/tests/ui/panicking_macros.stderr
@@ -1,5 +1,5 @@
 error: `panic` should not be present in production code
-  --> $DIR/panicking_macros.rs:6:5
+  --> $DIR/panicking_macros.rs:8:5
    |
 LL |     panic!();
    |     ^^^^^^^^^
@@ -7,7 +7,7 @@ LL |     panic!();
    = note: `-D clippy::panic` implied by `-D warnings`
 
 error: `panic` should not be present in production code
-  --> $DIR/panicking_macros.rs:7:5
+  --> $DIR/panicking_macros.rs:9:5
    |
 LL |     panic!("message");
    |     ^^^^^^^^^^^^^^^^^^
@@ -15,7 +15,7 @@ LL |     panic!("message");
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: `panic` should not be present in production code
-  --> $DIR/panicking_macros.rs:8:5
+  --> $DIR/panicking_macros.rs:10:5
    |
 LL |     panic!("{} {}", "panic with", "multiple arguments");
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -23,7 +23,7 @@ LL |     panic!("{} {}", "panic with", "multiple arguments");
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: `todo` should not be present in production code
-  --> $DIR/panicking_macros.rs:14:5
+  --> $DIR/panicking_macros.rs:16:5
    |
 LL |     todo!();
    |     ^^^^^^^^
@@ -31,19 +31,19 @@ LL |     todo!();
    = note: `-D clippy::todo` implied by `-D warnings`
 
 error: `todo` should not be present in production code
-  --> $DIR/panicking_macros.rs:15:5
+  --> $DIR/panicking_macros.rs:17:5
    |
 LL |     todo!("message");
    |     ^^^^^^^^^^^^^^^^^
 
 error: `todo` should not be present in production code
-  --> $DIR/panicking_macros.rs:16:5
+  --> $DIR/panicking_macros.rs:18:5
    |
 LL |     todo!("{} {}", "panic with", "multiple arguments");
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error: `unimplemented` should not be present in production code
-  --> $DIR/panicking_macros.rs:22:5
+  --> $DIR/panicking_macros.rs:24:5
    |
 LL |     unimplemented!();
    |     ^^^^^^^^^^^^^^^^^
@@ -51,19 +51,19 @@ LL |     unimplemented!();
    = note: `-D clippy::unimplemented` implied by `-D warnings`
 
 error: `unimplemented` should not be present in production code
-  --> $DIR/panicking_macros.rs:23:5
+  --> $DIR/panicking_macros.rs:25:5
    |
 LL |     unimplemented!("message");
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error: `unimplemented` should not be present in production code
-  --> $DIR/panicking_macros.rs:24:5
+  --> $DIR/panicking_macros.rs:26:5
    |
 LL |     unimplemented!("{} {}", "panic with", "multiple arguments");
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error: `unreachable` should not be present in production code
-  --> $DIR/panicking_macros.rs:30:5
+  --> $DIR/panicking_macros.rs:32:5
    |
 LL |     unreachable!();
    |     ^^^^^^^^^^^^^^^
@@ -71,7 +71,7 @@ LL |     unreachable!();
    = note: `-D clippy::unreachable` implied by `-D warnings`
 
 error: `unreachable` should not be present in production code
-  --> $DIR/panicking_macros.rs:31:5
+  --> $DIR/panicking_macros.rs:33:5
    |
 LL |     unreachable!("message");
    |     ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -79,10 +79,34 @@ LL |     unreachable!("message");
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: `unreachable` should not be present in production code
-  --> $DIR/panicking_macros.rs:32:5
+  --> $DIR/panicking_macros.rs:34:5
    |
 LL |     unreachable!("{} {}", "panic with", "multiple arguments");
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
-error: aborting due to 12 previous errors
+error: `panic` should not be present in production code
+  --> $DIR/panicking_macros.rs:40:5
+   |
+LL |     panic!();
+   |     ^^^^^^^^^
+
+error: `todo` should not be present in production code
+  --> $DIR/panicking_macros.rs:41:5
+   |
+LL |     todo!();
+   |     ^^^^^^^^
+
+error: `unimplemented` should not be present in production code
+  --> $DIR/panicking_macros.rs:42:5
+   |
+LL |     unimplemented!();
+   |     ^^^^^^^^^^^^^^^^^
+
+error: `unreachable` should not be present in production code
+  --> $DIR/panicking_macros.rs:43:5
+   |
+LL |     unreachable!();
+   |     ^^^^^^^^^^^^^^^
+
+error: aborting due to 16 previous errors