]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/tests/ui/implicit_return.rs
New upstream version 1.74.1+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / implicit_return.rs
CommitLineData
064997fb 1#![feature(lint_reasons)]
f20569fa 2#![warn(clippy::implicit_return)]
17df50a5 3#![allow(clippy::needless_return, clippy::needless_bool, unused, clippy::never_loop)]
f20569fa
XL
4
5fn test_end_of_fn() -> bool {
6 if true {
7 // no error!
8 return true;
9 }
10
11 true
12}
13
f20569fa
XL
14fn test_if_block() -> bool {
15 if true { true } else { false }
16}
17
18#[rustfmt::skip]
19fn test_match(x: bool) -> bool {
20 match x {
21 true => false,
22 false => { true },
23 }
24}
25
f20569fa
XL
26fn test_match_with_unreachable(x: bool) -> bool {
27 match x {
28 true => return false,
29 false => unreachable!(),
30 }
31}
32
f20569fa
XL
33fn test_loop() -> bool {
34 loop {
35 break true;
36 }
37}
38
f20569fa
XL
39fn test_loop_with_block() -> bool {
40 loop {
41 {
42 break true;
43 }
44 }
45}
46
f20569fa
XL
47fn test_loop_with_nests() -> bool {
48 loop {
49 if true {
50 break true;
51 } else {
52 let _ = true;
53 }
54 }
55}
56
57#[allow(clippy::redundant_pattern_matching)]
58fn test_loop_with_if_let() -> bool {
59 loop {
60 if let Some(x) = Some(true) {
61 return x;
62 }
63 }
64}
65
66fn test_closure() {
67 #[rustfmt::skip]
68 let _ = || { true };
69 let _ = || true;
70}
71
72fn test_panic() -> bool {
73 panic!()
74}
75
76fn test_return_macro() -> String {
77 format!("test {}", "test")
78}
79
17df50a5
XL
80fn macro_branch_test() -> bool {
81 macro_rules! m {
82 ($t:expr, $f:expr) => {
83 if true { $t } else { $f }
84 };
85 }
86 m!(true, false)
87}
88
89fn loop_test() -> bool {
90 'outer: loop {
91 if true {
92 break true;
93 }
94
95 let _ = loop {
96 if false {
97 break 'outer false;
98 }
99 if true {
100 break true;
101 }
102 };
103 }
104}
105
106fn loop_macro_test() -> bool {
107 macro_rules! m {
108 ($e:expr) => {
109 break $e
110 };
111 }
112 loop {
113 m!(true);
114 }
115}
116
117fn divergent_test() -> bool {
118 fn diverge() -> ! {
119 panic!()
120 }
121 diverge()
f20569fa 122}
17df50a5
XL
123
124// issue #6940
125async fn foo() -> bool {
126 true
127}
128
129fn main() {}
064997fb
FG
130
131fn check_expect() -> bool {
132 if true {
133 // no error!
134 return true;
135 }
136
137 #[expect(clippy::implicit_return)]
138 true
139}