3 #![feature(lint_reasons)]
6 clippy::if_same_then_else,
9 clippy::equatable_if_let
11 #![warn(clippy::needless_return)]
13 use std::cell::RefCell;
15 macro_rules! the_answer {
21 fn test_end_of_fn() -> bool {
29 fn test_no_semicolon() -> bool {
33 fn test_if_block() -> bool {
41 fn test_match(x: bool) -> bool {
54 let _ = || return true;
57 fn test_macro_call() -> i32 {
65 fn test_void_if_fun(b: bool) {
73 fn test_void_match(x: u32) {
80 fn test_nested_match(x: u32) {
91 fn temporary_outlives_local() -> String {
92 let x = RefCell::<String>::default();
93 return x.borrow().clone();
96 fn borrows_but_not_last(value: bool) -> String {
98 let x = RefCell::<String>::default();
99 let _a = x.borrow().clone();
100 return String::from("test");
102 return String::new();
106 macro_rules! needed_return {
114 fn test_return_in_macro() {
115 // This will return and the macro below won't be executed. Removing the `return` from the macro
116 // will change semantics.
122 #[allow(clippy::unnecessary_lazy_evaluations)]
123 fn foo(bar: Result<(), ()>) {
124 bar.unwrap_or_else(|_| return)
135 #[allow(clippy::unnecessary_lazy_evaluations)]
136 fn bar(res: Result<Foo, u8>) -> Foo {
137 res.unwrap_or_else(|_| return Foo)
141 async fn async_test_end_of_fn() -> bool {
149 async fn async_test_no_semicolon() -> bool {
153 async fn async_test_if_block() -> bool {
161 async fn async_test_match(x: bool) -> bool {
163 true => return false,
170 async fn async_test_closure() {
174 let _ = || return true;
177 async fn async_test_macro_call() -> i32 {
178 return the_answer!();
181 async fn async_test_void_fun() {
185 async fn async_test_void_if_fun(b: bool) {
193 async fn async_test_void_match(x: u32) {
200 async fn async_temporary_outlives_local() -> String {
201 let x = RefCell::<String>::default();
202 return x.borrow().clone();
205 async fn async_borrows_but_not_last(value: bool) -> String {
207 let x = RefCell::<String>::default();
208 let _a = x.borrow().clone();
209 return String::from("test");
211 return String::new();
215 async fn async_test_return_in_macro() {
221 let Some(1) = Some(1) else { return };
224 fn needless_return_macro() -> String {
227 return format!("Hello {}", "world!");
230 fn issue_9361() -> i32 {
231 #[allow(clippy::integer_arithmetic)]
235 fn issue8336(x: i32) -> bool {
237 println!("something");
244 fn issue8156(x: u8) -> u64 {
255 // Ideally the compiler should throw `unused_braces` in this case
256 fn issue9192() -> i32 {
262 fn issue9503(x: usize) -> isize {
265 return *(x as *const isize);
267 return !*(x as *const isize);
273 pub fn with_newline() {