]>
Commit | Line | Data |
---|---|---|
f20569fa | 1 | #![warn(clippy::semicolon_if_nothing_returned)] |
2b03887a | 2 | #![allow(clippy::redundant_closure, clippy::uninlined_format_args)] |
f20569fa XL |
3 | |
4 | fn get_unit() {} | |
5 | ||
6 | // the functions below trigger the lint | |
7 | fn main() { | |
8 | println!("Hello") | |
9 | } | |
10 | ||
11 | fn hello() { | |
12 | get_unit() | |
13 | } | |
14 | ||
15 | fn basic101(x: i32) { | |
16 | let y: i32; | |
17 | y = x + 1 | |
18 | } | |
19 | ||
136023e0 XL |
20 | #[rustfmt::skip] |
21 | fn closure_error() { | |
22 | let _d = || { | |
23 | hello() | |
24 | }; | |
25 | } | |
26 | ||
27 | #[rustfmt::skip] | |
28 | fn unsafe_checks_error() { | |
29 | use std::mem::MaybeUninit; | |
30 | use std::ptr; | |
31 | ||
32 | let mut s = MaybeUninit::<String>::uninit(); | |
c295e0f8 XL |
33 | let _d = || unsafe { |
34 | ptr::drop_in_place(s.as_mut_ptr()) | |
136023e0 XL |
35 | }; |
36 | } | |
37 | ||
f20569fa XL |
38 | // this is fine |
39 | fn print_sum(a: i32, b: i32) { | |
40 | println!("{}", a + b); | |
41 | assert_eq!(true, false); | |
42 | } | |
43 | ||
44 | fn foo(x: i32) { | |
45 | let y: i32; | |
46 | if x < 1 { | |
47 | y = 4; | |
48 | } else { | |
49 | y = 5; | |
50 | } | |
51 | } | |
52 | ||
53 | fn bar(x: i32) { | |
54 | let y: i32; | |
55 | match x { | |
56 | 1 => y = 4, | |
57 | _ => y = 32, | |
58 | } | |
59 | } | |
60 | ||
61 | fn foobar(x: i32) { | |
62 | let y: i32; | |
63 | 'label: { | |
64 | y = x + 1; | |
65 | } | |
66 | } | |
67 | ||
68 | fn loop_test(x: i32) { | |
69 | let y: i32; | |
70 | for &ext in &["stdout", "stderr", "fixed"] { | |
71 | println!("{}", ext); | |
72 | } | |
73 | } | |
136023e0 XL |
74 | |
75 | fn closure() { | |
76 | let _d = || hello(); | |
77 | } | |
78 | ||
79 | #[rustfmt::skip] | |
80 | fn closure_block() { | |
81 | let _d = || { hello() }; | |
82 | } | |
83 | ||
84 | unsafe fn some_unsafe_op() {} | |
85 | unsafe fn some_other_unsafe_fn() {} | |
86 | ||
87 | fn do_something() { | |
88 | unsafe { some_unsafe_op() }; | |
89 | ||
90 | unsafe { some_other_unsafe_fn() }; | |
91 | } | |
92 | ||
93 | fn unsafe_checks() { | |
94 | use std::mem::MaybeUninit; | |
95 | use std::ptr; | |
96 | ||
97 | let mut s = MaybeUninit::<String>::uninit(); | |
98 | let _d = || unsafe { ptr::drop_in_place(s.as_mut_ptr()) }; | |
99 | } | |
3c0e092e XL |
100 | |
101 | // Issue #7768 | |
102 | #[rustfmt::skip] | |
103 | fn macro_with_semicolon() { | |
104 | macro_rules! repro { | |
105 | () => { | |
106 | while false { | |
107 | } | |
108 | }; | |
109 | } | |
110 | repro!(); | |
111 | } | |
a2a8927a XL |
112 | |
113 | fn function_returning_option() -> Option<i32> { | |
114 | Some(1) | |
115 | } | |
116 | ||
117 | // No warning | |
118 | fn let_else_stmts() { | |
119 | let Some(x) = function_returning_option() else { return; }; | |
120 | } |