about summary refs log tree commit diff
path: root/src/tools/clippy/tests/ui/panic.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/clippy/tests/ui/panic.rs')
-rw-r--r--src/tools/clippy/tests/ui/panic.rs61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/panic.rs b/src/tools/clippy/tests/ui/panic.rs
new file mode 100644
index 00000000000..6e004aa9a92
--- /dev/null
+++ b/src/tools/clippy/tests/ui/panic.rs
@@ -0,0 +1,61 @@
+#![warn(clippy::panic_params)]
+#![allow(clippy::assertions_on_constants)]
+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 main() {
+    missing();
+    ok_single();
+    ok_multiple();
+    ok_bracket();
+    ok_inner();
+    ok_nomsg();
+    ok_escaped();
+}