Use RefCell in needless_return tests

This commit is contained in:
Alex Macleod 2022-06-18 16:36:47 +00:00
parent e933bb6bc3
commit eeedf72c33
3 changed files with 46 additions and 50 deletions

View File

@ -10,6 +10,8 @@
)] )]
#![warn(clippy::needless_return)] #![warn(clippy::needless_return)]
use std::cell::RefCell;
macro_rules! the_answer { macro_rules! the_answer {
() => { () => {
42 42
@ -86,17 +88,15 @@ fn test_nested_match(x: u32) {
} }
} }
fn read_line() -> String { fn temporary_outlives_local() -> String {
use std::io::BufRead; let x = RefCell::<String>::default();
let stdin = ::std::io::stdin(); return x.borrow().clone();
return stdin.lock().lines().next().unwrap().unwrap();
} }
fn borrows_but_not_last(value: bool) -> String { fn borrows_but_not_last(value: bool) -> String {
if value { if value {
use std::io::BufRead; let x = RefCell::<String>::default();
let stdin = ::std::io::stdin(); let _a = x.borrow().clone();
let _a = stdin.lock().lines().next().unwrap().unwrap();
String::from("test") String::from("test")
} else { } else {
String::new() String::new()
@ -197,17 +197,15 @@ async fn async_test_void_match(x: u32) {
} }
} }
async fn async_read_line() -> String { async fn async_temporary_outlives_local() -> String {
use std::io::BufRead; let x = RefCell::<String>::default();
let stdin = ::std::io::stdin(); return x.borrow().clone();
return stdin.lock().lines().next().unwrap().unwrap();
} }
async fn async_borrows_but_not_last(value: bool) -> String { async fn async_borrows_but_not_last(value: bool) -> String {
if value { if value {
use std::io::BufRead; let x = RefCell::<String>::default();
let stdin = ::std::io::stdin(); let _a = x.borrow().clone();
let _a = stdin.lock().lines().next().unwrap().unwrap();
String::from("test") String::from("test")
} else { } else {
String::new() String::new()

View File

@ -10,6 +10,8 @@
)] )]
#![warn(clippy::needless_return)] #![warn(clippy::needless_return)]
use std::cell::RefCell;
macro_rules! the_answer { macro_rules! the_answer {
() => { () => {
42 42
@ -86,17 +88,15 @@ fn test_nested_match(x: u32) {
} }
} }
fn read_line() -> String { fn temporary_outlives_local() -> String {
use std::io::BufRead; let x = RefCell::<String>::default();
let stdin = ::std::io::stdin(); return x.borrow().clone();
return stdin.lock().lines().next().unwrap().unwrap();
} }
fn borrows_but_not_last(value: bool) -> String { fn borrows_but_not_last(value: bool) -> String {
if value { if value {
use std::io::BufRead; let x = RefCell::<String>::default();
let stdin = ::std::io::stdin(); let _a = x.borrow().clone();
let _a = stdin.lock().lines().next().unwrap().unwrap();
return String::from("test"); return String::from("test");
} else { } else {
return String::new(); return String::new();
@ -197,17 +197,15 @@ async fn async_test_void_match(x: u32) {
} }
} }
async fn async_read_line() -> String { async fn async_temporary_outlives_local() -> String {
use std::io::BufRead; let x = RefCell::<String>::default();
let stdin = ::std::io::stdin(); return x.borrow().clone();
return stdin.lock().lines().next().unwrap().unwrap();
} }
async fn async_borrows_but_not_last(value: bool) -> String { async fn async_borrows_but_not_last(value: bool) -> String {
if value { if value {
use std::io::BufRead; let x = RefCell::<String>::default();
let stdin = ::std::io::stdin(); let _a = x.borrow().clone();
let _a = stdin.lock().lines().next().unwrap().unwrap();
return String::from("test"); return String::from("test");
} else { } else {
return String::new(); return String::new();

View File

@ -1,5 +1,5 @@
error: unneeded `return` statement error: unneeded `return` statement
--> $DIR/needless_return.rs:24:5 --> $DIR/needless_return.rs:26:5
| |
LL | return true; LL | return true;
| ^^^^^^^^^^^^ help: remove `return`: `true` | ^^^^^^^^^^^^ help: remove `return`: `true`
@ -7,65 +7,59 @@ LL | return true;
= note: `-D clippy::needless-return` implied by `-D warnings` = note: `-D clippy::needless-return` implied by `-D warnings`
error: unneeded `return` statement error: unneeded `return` statement
--> $DIR/needless_return.rs:28:5 --> $DIR/needless_return.rs:30:5
| |
LL | return true; LL | return true;
| ^^^^^^^^^^^^ help: remove `return`: `true` | ^^^^^^^^^^^^ help: remove `return`: `true`
error: unneeded `return` statement error: unneeded `return` statement
--> $DIR/needless_return.rs:33:9 --> $DIR/needless_return.rs:35:9
| |
LL | return true; LL | return true;
| ^^^^^^^^^^^^ help: remove `return`: `true` | ^^^^^^^^^^^^ help: remove `return`: `true`
error: unneeded `return` statement error: unneeded `return` statement
--> $DIR/needless_return.rs:35:9 --> $DIR/needless_return.rs:37:9
| |
LL | return false; LL | return false;
| ^^^^^^^^^^^^^ help: remove `return`: `false` | ^^^^^^^^^^^^^ help: remove `return`: `false`
error: unneeded `return` statement error: unneeded `return` statement
--> $DIR/needless_return.rs:41:17 --> $DIR/needless_return.rs:43:17
| |
LL | true => return false, LL | true => return false,
| ^^^^^^^^^^^^ help: remove `return`: `false` | ^^^^^^^^^^^^ help: remove `return`: `false`
error: unneeded `return` statement error: unneeded `return` statement
--> $DIR/needless_return.rs:43:13 --> $DIR/needless_return.rs:45:13
| |
LL | return true; LL | return true;
| ^^^^^^^^^^^^ help: remove `return`: `true` | ^^^^^^^^^^^^ help: remove `return`: `true`
error: unneeded `return` statement error: unneeded `return` statement
--> $DIR/needless_return.rs:50:9 --> $DIR/needless_return.rs:52:9
| |
LL | return true; LL | return true;
| ^^^^^^^^^^^^ help: remove `return`: `true` | ^^^^^^^^^^^^ help: remove `return`: `true`
error: unneeded `return` statement error: unneeded `return` statement
--> $DIR/needless_return.rs:52:16 --> $DIR/needless_return.rs:54:16
| |
LL | let _ = || return true; LL | let _ = || return true;
| ^^^^^^^^^^^ help: remove `return`: `true` | ^^^^^^^^^^^ help: remove `return`: `true`
error: unneeded `return` statement error: unneeded `return` statement
--> $DIR/needless_return.rs:56:5 --> $DIR/needless_return.rs:58:5
| |
LL | return the_answer!(); LL | return the_answer!();
| ^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `the_answer!()` | ^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `the_answer!()`
error: unneeded `return` statement error: unneeded `return` statement
--> $DIR/needless_return.rs:60:5 --> $DIR/needless_return.rs:62:5
| |
LL | return; LL | return;
| ^^^^^^^ help: remove `return` | ^^^^^^^ help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:65:9
|
LL | return;
| ^^^^^^^ help: remove `return`
error: unneeded `return` statement error: unneeded `return` statement
--> $DIR/needless_return.rs:67:9 --> $DIR/needless_return.rs:67:9
| |
@ -73,19 +67,25 @@ LL | return;
| ^^^^^^^ help: remove `return` | ^^^^^^^ help: remove `return`
error: unneeded `return` statement error: unneeded `return` statement
--> $DIR/needless_return.rs:74:14 --> $DIR/needless_return.rs:69:9
|
LL | return;
| ^^^^^^^ help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:76:14
| |
LL | _ => return, LL | _ => return,
| ^^^^^^ help: replace `return` with a unit value: `()` | ^^^^^^ help: replace `return` with a unit value: `()`
error: unneeded `return` statement error: unneeded `return` statement
--> $DIR/needless_return.rs:83:13 --> $DIR/needless_return.rs:85:13
| |
LL | return; LL | return;
| ^^^^^^^ help: remove `return` | ^^^^^^^ help: remove `return`
error: unneeded `return` statement error: unneeded `return` statement
--> $DIR/needless_return.rs:85:14 --> $DIR/needless_return.rs:87:14
| |
LL | _ => return, LL | _ => return,
| ^^^^^^ help: replace `return` with a unit value: `()` | ^^^^^^ help: replace `return` with a unit value: `()`
@ -205,19 +205,19 @@ LL | _ => return,
| ^^^^^^ help: replace `return` with a unit value: `()` | ^^^^^^ help: replace `return` with a unit value: `()`
error: unneeded `return` statement error: unneeded `return` statement
--> $DIR/needless_return.rs:211:9 --> $DIR/needless_return.rs:209:9
| |
LL | return String::from("test"); LL | return String::from("test");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `String::from("test")` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `String::from("test")`
error: unneeded `return` statement error: unneeded `return` statement
--> $DIR/needless_return.rs:213:9 --> $DIR/needless_return.rs:211:9
| |
LL | return String::new(); LL | return String::new();
| ^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `String::new()` | ^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `String::new()`
error: unneeded `return` statement error: unneeded `return` statement
--> $DIR/needless_return.rs:229:5 --> $DIR/needless_return.rs:227:5
| |
LL | return format!("Hello {}", "world!"); LL | return format!("Hello {}", "world!");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `format!("Hello {}", "world!")` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `format!("Hello {}", "world!")`