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