-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
needless_return
false positive when a temporary borrows a local variable
#5858
Comments
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 |
Great, thanks! |
I just found a possible instance of this with clippy use rusqlite::{Connection, ToSql, Error};
pub fn entry_query(query: &str, params: &[&dyn ToSql]) -> Result<Vec<String>, Error> {
let conn = Connection::open_in_memory().unwrap();
let mut stmt = conn.prepare(query).unwrap();
let entries = stmt.query_and_then(params, |row| {
row.get("id")
})?.collect();
entries
} Which gives this result:
If the suggestion is used the code fails to compile:
and of course the suggested code is the code that clippy complained about in the first place. |
I tried this code:
I expected to see this happen:
needless_return
does not fire because the call tolock()
borrowsstdin
and the temporary would be destroyed after the borrowed local, resulting in adoes 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. Theknown problems
section of the lint description could be updated too.Meta
cargo clippy -V
: clippy 0.0.212 (05762e3 2020-08-01)rustc -Vv
:The text was updated successfully, but these errors were encountered: