]>
git.proxmox.com Git - rustc.git/blob - src/tools/clippy/tests/ui/needless_return.rs
3 #![feature(lint_reasons)]
7 clippy
::if_same_then_else
,
10 clippy
::equatable_if_let
12 #![warn(clippy::needless_return)]
14 use std
::cell
::RefCell
;
16 macro_rules
! the_answer
{
22 fn test_end_of_fn() -> bool
{
30 fn test_no_semicolon() -> bool
{
35 fn test_multiple_semicolon() -> bool
{
40 fn test_multiple_semicolon_with_spaces() -> bool
{
44 fn test_if_block() -> bool
{
52 fn test_match(x
: bool
) -> bool
{
65 let _
= || return true;
68 fn test_macro_call() -> i32 {
76 fn test_void_if_fun(b
: bool
) {
84 fn test_void_match(x
: u32) {
91 fn test_nested_match(x
: u32) {
102 fn temporary_outlives_local() -> String
{
103 let x
= RefCell
::<String
>::default();
104 return x
.borrow().clone();
107 fn borrows_but_not_last(value
: bool
) -> String
{
109 let x
= RefCell
::<String
>::default();
110 let _a
= x
.borrow().clone();
111 return String
::from("test");
113 return String
::new();
117 macro_rules
! needed_return
{
125 fn test_return_in_macro() {
126 // This will return and the macro below won't be executed. Removing the `return` from the macro
127 // will change semantics.
133 #[allow(clippy::unnecessary_lazy_evaluations)]
134 fn foo(bar
: Result
<(), ()>) {
135 bar
.unwrap_or_else(|_
| return)
146 #[allow(clippy::unnecessary_lazy_evaluations)]
147 fn bar(res
: Result
<Foo
, u8>) -> Foo
{
148 res
.unwrap_or_else(|_
| return Foo
)
152 async
fn async_test_end_of_fn() -> bool
{
160 async
fn async_test_no_semicolon() -> bool
{
164 async
fn async_test_if_block() -> bool
{
172 async
fn async_test_match(x
: bool
) -> bool
{
174 true => return false,
181 async
fn async_test_closure() {
185 let _
= || return true;
188 async
fn async_test_macro_call() -> i32 {
189 return the_answer
!();
192 async
fn async_test_void_fun() {
196 async
fn async_test_void_if_fun(b
: bool
) {
204 async
fn async_test_void_match(x
: u32) {
211 async
fn async_temporary_outlives_local() -> String
{
212 let x
= RefCell
::<String
>::default();
213 return x
.borrow().clone();
216 async
fn async_borrows_but_not_last(value
: bool
) -> String
{
218 let x
= RefCell
::<String
>::default();
219 let _a
= x
.borrow().clone();
220 return String
::from("test");
222 return String
::new();
226 async
fn async_test_return_in_macro() {
232 let Some(1) = Some(1) else { return }
;
235 fn needless_return_macro() -> String
{
238 return format
!("Hello {}", "world!");
241 fn issue_9361() -> i32 {
242 #[allow(clippy::integer_arithmetic)]
246 fn issue8336(x
: i32) -> bool
{
248 println
!("something");
255 fn issue8156(x
: u8) -> u64 {
266 // Ideally the compiler should throw `unused_braces` in this case
267 fn issue9192() -> i32 {
273 fn issue9503(x
: usize) -> isize {
276 return *(x
as *const isize);
278 return !*(x
as *const isize);
284 pub fn with_newline() {
296 fn issue9947() -> Result
<(), String
> {
300 // without anyhow, but triggers the same bug I believe
301 #[expect(clippy::useless_format)]
302 fn issue10051() -> Result
<String
, String
> {
304 return Ok(format
!("ok!"));
306 return Err(format
!("err!"));
312 return if true { 1 }
else { 2 }
;
315 fn multiple(b1
: bool
, b2
: bool
, b3
: bool
) -> u32 {
316 return if b1 { 0 }
else { 1 }
| if b2 { 2 }
else { 3 }
| if b3 { 4 }
else { 5 }
;
320 fn test_match_as_stmt() {