Skip to content

Commit 9d92af7

Browse files
committed
Auto merge of #9016 - Alexendoo:needless-return-test, r=giraffate
Use `RefCell` in `needless_return` tests changelog: none The stdio locks no longer fail to compile if the `return` is removed due to them now being `'static` (#9008)
2 parents e933bb6 + eeedf72 commit 9d92af7

File tree

3 files changed

+42
-46
lines changed

3 files changed

+42
-46
lines changed

tests/ui/needless_return.fixed

+12-14
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
)]
1111
#![warn(clippy::needless_return)]
1212

13+
use std::cell::RefCell;
14+
1315
macro_rules! the_answer {
1416
() => {
1517
42
@@ -86,17 +88,15 @@ fn test_nested_match(x: u32) {
8688
}
8789
}
8890

89-
fn read_line() -> String {
90-
use std::io::BufRead;
91-
let stdin = ::std::io::stdin();
92-
return stdin.lock().lines().next().unwrap().unwrap();
91+
fn temporary_outlives_local() -> String {
92+
let x = RefCell::<String>::default();
93+
return x.borrow().clone();
9394
}
9495

9596
fn borrows_but_not_last(value: bool) -> String {
9697
if value {
97-
use std::io::BufRead;
98-
let stdin = ::std::io::stdin();
99-
let _a = stdin.lock().lines().next().unwrap().unwrap();
98+
let x = RefCell::<String>::default();
99+
let _a = x.borrow().clone();
100100
String::from("test")
101101
} else {
102102
String::new()
@@ -197,17 +197,15 @@ async fn async_test_void_match(x: u32) {
197197
}
198198
}
199199

200-
async fn async_read_line() -> String {
201-
use std::io::BufRead;
202-
let stdin = ::std::io::stdin();
203-
return stdin.lock().lines().next().unwrap().unwrap();
200+
async fn async_temporary_outlives_local() -> String {
201+
let x = RefCell::<String>::default();
202+
return x.borrow().clone();
204203
}
205204

206205
async fn async_borrows_but_not_last(value: bool) -> String {
207206
if value {
208-
use std::io::BufRead;
209-
let stdin = ::std::io::stdin();
210-
let _a = stdin.lock().lines().next().unwrap().unwrap();
207+
let x = RefCell::<String>::default();
208+
let _a = x.borrow().clone();
211209
String::from("test")
212210
} else {
213211
String::new()

tests/ui/needless_return.rs

+12-14
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
)]
1111
#![warn(clippy::needless_return)]
1212

13+
use std::cell::RefCell;
14+
1315
macro_rules! the_answer {
1416
() => {
1517
42
@@ -86,17 +88,15 @@ fn test_nested_match(x: u32) {
8688
}
8789
}
8890

89-
fn read_line() -> String {
90-
use std::io::BufRead;
91-
let stdin = ::std::io::stdin();
92-
return stdin.lock().lines().next().unwrap().unwrap();
91+
fn temporary_outlives_local() -> String {
92+
let x = RefCell::<String>::default();
93+
return x.borrow().clone();
9394
}
9495

9596
fn borrows_but_not_last(value: bool) -> String {
9697
if value {
97-
use std::io::BufRead;
98-
let stdin = ::std::io::stdin();
99-
let _a = stdin.lock().lines().next().unwrap().unwrap();
98+
let x = RefCell::<String>::default();
99+
let _a = x.borrow().clone();
100100
return String::from("test");
101101
} else {
102102
return String::new();
@@ -197,17 +197,15 @@ async fn async_test_void_match(x: u32) {
197197
}
198198
}
199199

200-
async fn async_read_line() -> String {
201-
use std::io::BufRead;
202-
let stdin = ::std::io::stdin();
203-
return stdin.lock().lines().next().unwrap().unwrap();
200+
async fn async_temporary_outlives_local() -> String {
201+
let x = RefCell::<String>::default();
202+
return x.borrow().clone();
204203
}
205204

206205
async fn async_borrows_but_not_last(value: bool) -> String {
207206
if value {
208-
use std::io::BufRead;
209-
let stdin = ::std::io::stdin();
210-
let _a = stdin.lock().lines().next().unwrap().unwrap();
207+
let x = RefCell::<String>::default();
208+
let _a = x.borrow().clone();
211209
return String::from("test");
212210
} else {
213211
return String::new();

tests/ui/needless_return.stderr

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,91 @@
11
error: unneeded `return` statement
2-
--> $DIR/needless_return.rs:24:5
2+
--> $DIR/needless_return.rs:26:5
33
|
44
LL | return true;
55
| ^^^^^^^^^^^^ help: remove `return`: `true`
66
|
77
= note: `-D clippy::needless-return` implied by `-D warnings`
88

99
error: unneeded `return` statement
10-
--> $DIR/needless_return.rs:28:5
10+
--> $DIR/needless_return.rs:30:5
1111
|
1212
LL | return true;
1313
| ^^^^^^^^^^^^ help: remove `return`: `true`
1414

1515
error: unneeded `return` statement
16-
--> $DIR/needless_return.rs:33:9
16+
--> $DIR/needless_return.rs:35:9
1717
|
1818
LL | return true;
1919
| ^^^^^^^^^^^^ help: remove `return`: `true`
2020

2121
error: unneeded `return` statement
22-
--> $DIR/needless_return.rs:35:9
22+
--> $DIR/needless_return.rs:37:9
2323
|
2424
LL | return false;
2525
| ^^^^^^^^^^^^^ help: remove `return`: `false`
2626

2727
error: unneeded `return` statement
28-
--> $DIR/needless_return.rs:41:17
28+
--> $DIR/needless_return.rs:43:17
2929
|
3030
LL | true => return false,
3131
| ^^^^^^^^^^^^ help: remove `return`: `false`
3232

3333
error: unneeded `return` statement
34-
--> $DIR/needless_return.rs:43:13
34+
--> $DIR/needless_return.rs:45:13
3535
|
3636
LL | return true;
3737
| ^^^^^^^^^^^^ help: remove `return`: `true`
3838

3939
error: unneeded `return` statement
40-
--> $DIR/needless_return.rs:50:9
40+
--> $DIR/needless_return.rs:52:9
4141
|
4242
LL | return true;
4343
| ^^^^^^^^^^^^ help: remove `return`: `true`
4444

4545
error: unneeded `return` statement
46-
--> $DIR/needless_return.rs:52:16
46+
--> $DIR/needless_return.rs:54:16
4747
|
4848
LL | let _ = || return true;
4949
| ^^^^^^^^^^^ help: remove `return`: `true`
5050

5151
error: unneeded `return` statement
52-
--> $DIR/needless_return.rs:56:5
52+
--> $DIR/needless_return.rs:58:5
5353
|
5454
LL | return the_answer!();
5555
| ^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `the_answer!()`
5656

5757
error: unneeded `return` statement
58-
--> $DIR/needless_return.rs:60:5
58+
--> $DIR/needless_return.rs:62:5
5959
|
6060
LL | return;
6161
| ^^^^^^^ help: remove `return`
6262

6363
error: unneeded `return` statement
64-
--> $DIR/needless_return.rs:65:9
64+
--> $DIR/needless_return.rs:67:9
6565
|
6666
LL | return;
6767
| ^^^^^^^ help: remove `return`
6868

6969
error: unneeded `return` statement
70-
--> $DIR/needless_return.rs:67:9
70+
--> $DIR/needless_return.rs:69:9
7171
|
7272
LL | return;
7373
| ^^^^^^^ help: remove `return`
7474

7575
error: unneeded `return` statement
76-
--> $DIR/needless_return.rs:74:14
76+
--> $DIR/needless_return.rs:76:14
7777
|
7878
LL | _ => return,
7979
| ^^^^^^ help: replace `return` with a unit value: `()`
8080

8181
error: unneeded `return` statement
82-
--> $DIR/needless_return.rs:83:13
82+
--> $DIR/needless_return.rs:85:13
8383
|
8484
LL | return;
8585
| ^^^^^^^ help: remove `return`
8686

8787
error: unneeded `return` statement
88-
--> $DIR/needless_return.rs:85:14
88+
--> $DIR/needless_return.rs:87:14
8989
|
9090
LL | _ => return,
9191
| ^^^^^^ help: replace `return` with a unit value: `()`
@@ -205,19 +205,19 @@ LL | _ => return,
205205
| ^^^^^^ help: replace `return` with a unit value: `()`
206206

207207
error: unneeded `return` statement
208-
--> $DIR/needless_return.rs:211:9
208+
--> $DIR/needless_return.rs:209:9
209209
|
210210
LL | return String::from("test");
211211
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `String::from("test")`
212212

213213
error: unneeded `return` statement
214-
--> $DIR/needless_return.rs:213:9
214+
--> $DIR/needless_return.rs:211:9
215215
|
216216
LL | return String::new();
217217
| ^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `String::new()`
218218

219219
error: unneeded `return` statement
220-
--> $DIR/needless_return.rs:229:5
220+
--> $DIR/needless_return.rs:227:5
221221
|
222222
LL | return format!("Hello {}", "world!");
223223
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `format!("Hello {}", "world!")`

0 commit comments

Comments
 (0)