]> git.lizzy.rs Git - rust.git/blob - tests/ui/panic_unimplemented.rs
Auto merge of #3603 - xfix:random-state-lint, r=phansch
[rust.git] / tests / ui / panic_unimplemented.rs
1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10 #![warn(clippy::panic_params, clippy::unimplemented)]
11
12 fn missing() {
13     if true {
14         panic!("{}");
15     } else if false {
16         panic!("{:?}");
17     } else {
18         assert!(true, "here be missing values: {}");
19     }
20
21     panic!("{{{this}}}");
22 }
23
24 fn ok_single() {
25     panic!("foo bar");
26 }
27
28 fn ok_inner() {
29     // Test for #768
30     assert!("foo bar".contains(&format!("foo {}", "bar")));
31 }
32
33 fn ok_multiple() {
34     panic!("{}", "This is {ok}");
35 }
36
37 fn ok_bracket() {
38     match 42 {
39         1337 => panic!("{so is this"),
40         666 => panic!("so is this}"),
41         _ => panic!("}so is that{"),
42     }
43 }
44
45 const ONE: u32 = 1;
46
47 fn ok_nomsg() {
48     assert!({ 1 == ONE });
49     assert!(if 1 == ONE { ONE == 1 } else { false });
50 }
51
52 fn ok_escaped() {
53     panic!("{{ why should this not be ok? }}");
54     panic!(" or {{ that ?");
55     panic!(" or }} this ?");
56     panic!(" {or {{ that ?");
57     panic!(" }or }} this ?");
58     panic!("{{ test }");
59     panic!("{case }}");
60 }
61
62 fn unimplemented() {
63     let a = 2;
64     unimplemented!();
65     let b = a + 2;
66 }
67
68 fn main() {
69     missing();
70     ok_single();
71     ok_multiple();
72     ok_bracket();
73     ok_inner();
74     ok_nomsg();
75     ok_escaped();
76     unimplemented();
77 }