-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
semicolon_if_nothing_returned.rs
161 lines (132 loc) · 2.45 KB
/
semicolon_if_nothing_returned.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
//@aux-build:proc_macro_attr.rs
#![warn(clippy::semicolon_if_nothing_returned)]
#![allow(
clippy::redundant_closure,
clippy::uninlined_format_args,
clippy::needless_late_init,
clippy::empty_docs
)]
#[macro_use]
extern crate proc_macro_attr;
fn get_unit() {}
// the functions below trigger the lint
fn main() {
println!("Hello")
}
fn hello() {
get_unit()
}
fn basic101(x: i32) {
let y: i32;
y = x + 1
}
#[rustfmt::skip]
fn closure_error() {
let _d = || {
hello()
};
}
#[rustfmt::skip]
fn unsafe_checks_error() {
use std::mem::MaybeUninit;
use std::ptr;
let mut s = MaybeUninit::<String>::uninit();
let _d = || unsafe {
ptr::drop_in_place(s.as_mut_ptr())
};
}
// this is fine
fn print_sum(a: i32, b: i32) {
println!("{}", a + b);
assert_eq!(true, false);
}
fn foo(x: i32) {
let y: i32;
if x < 1 {
y = 4;
} else {
y = 5;
}
}
fn bar(x: i32) {
let y: i32;
match x {
1 => y = 4,
_ => y = 32,
}
}
fn foobar(x: i32) {
let y: i32;
'label: {
y = x + 1;
}
}
fn loop_test(x: i32) {
let y: i32;
for &ext in &["stdout", "stderr", "fixed"] {
println!("{}", ext);
}
}
fn closure() {
let _d = || hello();
}
#[rustfmt::skip]
fn closure_block() {
let _d = || { hello() };
}
unsafe fn some_unsafe_op() {}
unsafe fn some_other_unsafe_fn() {}
fn do_something() {
unsafe { some_unsafe_op() };
unsafe { some_other_unsafe_fn() };
}
fn unsafe_checks() {
use std::mem::MaybeUninit;
use std::ptr;
let mut s = MaybeUninit::<String>::uninit();
let _d = || unsafe { ptr::drop_in_place(s.as_mut_ptr()) };
}
// Issue #7768
#[rustfmt::skip]
fn macro_with_semicolon() {
macro_rules! repro {
() => {
while false {
}
};
}
repro!();
}
fn function_returning_option() -> Option<i32> {
Some(1)
}
// No warning
fn let_else_stmts() {
let Some(x) = function_returning_option() else {
return;
};
}
mod issue12123 {
#[rustfmt::skip]
mod this_triggers {
#[fake_main]
async fn main() {
}
}
mod and_this {
#[fake_main]
async fn main() {
println!("hello");
}
}
#[rustfmt::skip]
mod maybe_this {
/** */ #[fake_main]
async fn main() {
}
}
mod but_this_does_not {
#[fake_main]
async fn main() {}
}
}