I tried this code:
#![allow(unused)]
fn read_line() -> String {
use std::io::BufRead;
let stdin = ::std::io::stdin();
return stdin.lock().lines().next().unwrap().unwrap();
}
I expected to see this happen: needless_return does not fire because the call to lock() borrows stdin and the temporary would be destroyed after the borrowed local, resulting in a does not live long enough compiler error.
Instead, this happened: it fired
The same fix that was applied for let_and_return in #5680 should work for this case. The known problems section of the lint description could be updated too.
cargo clippy -V: clippy 0.0.212 (05762e3 2020-08-01)rustc -Vv:
rustc 1.45.1 (c367798cf 2020-07-26)
binary: rustc
commit-hash: c367798cfd3817ca6ae908ce675d1d99242af148
commit-date: 2020-07-26
host: x86_64-unknown-linux-gnu
release: 1.45.1
LLVM version: 10.0
I'd like to give this issue a try
Don't hesitate to ask for support if you get stuck!
The general idea is to move the lint from early to late lint pass, probably reusing the let_and_return module, adapting the name.
Great, thanks!
Hi @ebroto,
I made the needless_return a late pass and added a borrow checker following fix #5680.
Also, added the mentioned function read_line() to the test cases. All tests are passing locally.
I have read the PR guideline and now I am opening a PR.