]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/panicking_macros.rs
Rollup merge of #97411 - raiyansayeed:print-stderr-consistently, r=Mark-Simulacrum
[rust.git] / src / tools / clippy / tests / ui / panicking_macros.rs
1 #![allow(clippy::assertions_on_constants, clippy::eq_op, clippy::let_unit_value)]
2 #![feature(inline_const)]
3 #![warn(clippy::unimplemented, clippy::unreachable, clippy::todo, clippy::panic)]
4
5 extern crate core;
6
7 const _: () = {
8     if 1 == 0 {
9         panic!("A balanced diet means a cupcake in each hand");
10     }
11 };
12
13 fn inline_const() {
14     let _ = const {
15         if 1 == 0 {
16             panic!("When nothing goes right, go left")
17         }
18     };
19 }
20
21 fn panic() {
22     let a = 2;
23     panic!();
24     panic!("message");
25     panic!("{} {}", "panic with", "multiple arguments");
26     let b = a + 2;
27 }
28
29 fn todo() {
30     let a = 2;
31     todo!();
32     todo!("message");
33     todo!("{} {}", "panic with", "multiple arguments");
34     let b = a + 2;
35 }
36
37 fn unimplemented() {
38     let a = 2;
39     unimplemented!();
40     unimplemented!("message");
41     unimplemented!("{} {}", "panic with", "multiple arguments");
42     let b = a + 2;
43 }
44
45 fn unreachable() {
46     let a = 2;
47     unreachable!();
48     unreachable!("message");
49     unreachable!("{} {}", "panic with", "multiple arguments");
50     let b = a + 2;
51 }
52
53 fn core_versions() {
54     use core::{panic, todo, unimplemented, unreachable};
55     panic!();
56     todo!();
57     unimplemented!();
58     unreachable!();
59 }
60
61 fn assert() {
62     assert!(true);
63     assert_eq!(true, true);
64     assert_ne!(true, false);
65 }
66
67 fn assert_msg() {
68     assert!(true, "this should not panic");
69     assert_eq!(true, true, "this should not panic");
70     assert_ne!(true, false, "this should not panic");
71 }
72
73 fn debug_assert() {
74     debug_assert!(true);
75     debug_assert_eq!(true, true);
76     debug_assert_ne!(true, false);
77 }
78
79 fn debug_assert_msg() {
80     debug_assert!(true, "test");
81     debug_assert_eq!(true, true, "test");
82     debug_assert_ne!(true, false, "test");
83 }
84
85 fn main() {
86     panic();
87     todo();
88     unimplemented();
89     unreachable();
90     core_versions();
91     assert();
92     assert_msg();
93     debug_assert();
94     debug_assert_msg();
95 }