This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +130
-6
lines changed Expand file tree Collapse file tree 3 files changed +130
-6
lines changed Original file line number Diff line number Diff line change 1+ //@run-rustfix
2+ #![warn(clippy::semicolon_if_nothing_returned)]
3+ #![allow(clippy::redundant_closure, clippy::uninlined_format_args, clippy::needless_late_init)]
4+
5+ fn get_unit() {}
6+
7+ // the functions below trigger the lint
8+ fn main() {
9+ println!("Hello");
10+ }
11+
12+ fn hello() {
13+ get_unit();
14+ }
15+
16+ fn basic101(x: i32) {
17+ let y: i32;
18+ y = x + 1;
19+ }
20+
21+ #[rustfmt::skip]
22+ fn closure_error() {
23+ let _d = || {
24+ hello();
25+ };
26+ }
27+
28+ #[rustfmt::skip]
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
40+ fn print_sum(a: i32, b: i32) {
41+ println!("{}", a + b);
42+ assert_eq!(true, false);
43+ }
44+
45+ fn foo(x: i32) {
46+ let y: i32;
47+ if x < 1 {
48+ y = 4;
49+ } else {
50+ y = 5;
51+ }
52+ }
53+
54+ fn bar(x: i32) {
55+ let y: i32;
56+ match x {
57+ 1 => y = 4,
58+ _ => y = 32,
59+ }
60+ }
61+
62+ fn foobar(x: i32) {
63+ let y: i32;
64+ 'label: {
65+ y = x + 1;
66+ }
67+ }
68+
69+ fn loop_test(x: i32) {
70+ let y: i32;
71+ for &ext in &["stdout", "stderr", "fixed"] {
72+ println!("{}", ext);
73+ }
74+ }
75+
76+ fn closure() {
77+ let _d = || hello();
78+ }
79+
80+ #[rustfmt::skip]
81+ fn closure_block() {
82+ let _d = || { hello() };
83+ }
84+
85+ unsafe fn some_unsafe_op() {}
86+ unsafe fn some_other_unsafe_fn() {}
87+
88+ fn do_something() {
89+ unsafe { some_unsafe_op() };
90+
91+ unsafe { some_other_unsafe_fn() };
92+ }
93+
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]
104+ fn macro_with_semicolon() {
105+ macro_rules! repro {
106+ () => {
107+ while false {
108+ }
109+ };
110+ }
111+ repro!();
112+ }
113+
114+ fn function_returning_option() -> Option<i32> {
115+ Some(1)
116+ }
117+
118+ // No warning
119+ fn let_else_stmts() {
120+ let Some(x) = function_returning_option() else {
121+ return;
122+ };
123+ }
Original file line number Diff line number Diff line change 1+ //@run-rustfix
12#![ warn( clippy:: semicolon_if_nothing_returned) ]
2- #![ allow( clippy:: redundant_closure, clippy:: uninlined_format_args) ]
3+ #![ allow( clippy:: redundant_closure, clippy:: uninlined_format_args, clippy :: needless_late_init ) ]
34
45fn get_unit ( ) { }
56
Original file line number Diff line number Diff line change 11error: consider adding a `;` to the last statement for consistent formatting
2- --> $DIR/semicolon_if_nothing_returned.rs:8 :5
2+ --> $DIR/semicolon_if_nothing_returned.rs:9 :5
33 |
44LL | println!("Hello")
55 | ^^^^^^^^^^^^^^^^^ help: add a `;` here: `println!("Hello");`
66 |
77 = note: `-D clippy::semicolon-if-nothing-returned` implied by `-D warnings`
88
99error: consider adding a `;` to the last statement for consistent formatting
10- --> $DIR/semicolon_if_nothing_returned.rs:12 :5
10+ --> $DIR/semicolon_if_nothing_returned.rs:13 :5
1111 |
1212LL | get_unit()
1313 | ^^^^^^^^^^ help: add a `;` here: `get_unit();`
1414
1515error: consider adding a `;` to the last statement for consistent formatting
16- --> $DIR/semicolon_if_nothing_returned.rs:17 :5
16+ --> $DIR/semicolon_if_nothing_returned.rs:18 :5
1717 |
1818LL | y = x + 1
1919 | ^^^^^^^^^ help: add a `;` here: `y = x + 1;`
2020
2121error: consider adding a `;` to the last statement for consistent formatting
22- --> $DIR/semicolon_if_nothing_returned.rs:23 :9
22+ --> $DIR/semicolon_if_nothing_returned.rs:24 :9
2323 |
2424LL | hello()
2525 | ^^^^^^^ help: add a `;` here: `hello();`
2626
2727error: consider adding a `;` to the last statement for consistent formatting
28- --> $DIR/semicolon_if_nothing_returned.rs:34 :9
28+ --> $DIR/semicolon_if_nothing_returned.rs:35 :9
2929 |
3030LL | ptr::drop_in_place(s.as_mut_ptr())
3131 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add a `;` here: `ptr::drop_in_place(s.as_mut_ptr());`
You can’t perform that action at this time.
0 commit comments