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