Skip to content
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

False positive for redundant_closure involving lifetimes #5594

Closed
Kixunil opened this issue May 13, 2020 · 2 comments
Closed

False positive for redundant_closure involving lifetimes #5594

Kixunil opened this issue May 13, 2020 · 2 comments
Labels
C-bug Category: Clippy is not doing the correct thing E-hard Call for participation: This a hard problem and requires more experience or effort to work on I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@Kixunil
Copy link

Kixunil commented May 13, 2020

I hit a false positive when contributing to rusqlite. The code in the PR can not be written without that closure as it doesn't seem to unify for some reason. Not sure if it's a bug in the compiler or some kind of deficiency in my code (please look at that TryFrom impl, if you think you could help). Would love to file issue against rustc, if relevant, but I don't even know what keywords to use for searching for existing issues. :(

Without the closure I got:

   --> src/row.rs:382:76
    |
382 |         let val = conn.query_row("SELECT a FROM test", std::iter::empty(), <(u32,)>::try_from)
    |                                                                            ^^^^^^^^^^^^^^^^^^
    |                                                                            |
    |                                                                            expected signature of `for<'r, 's> fn(&'r row::Row<'s>) -> _`
    |                                                                            found signature of `fn(_) -> _`

error[E0271]: type mismatch resolving `for<'r, 's> <fn(_) -> std::result::Result<(u32,), <(u32,) as std::convert::TryFrom<_>>::Error> {<(u32,) as std::convert::TryFrom<_>>::try_from} as std::ops::FnOnce<(&'r row::Row<'s>,)>>::Output == std::result::Result<_, error::Error>`

Edit: sorry for forgetting to paste version. I don't know the version from rusqlite CI, but same issue is present in clippy 0.0.212 (69f99e7 2019-12-14). I also tried to impl TryFrom using a single lifetime - same problem.

@flip1995
Copy link
Member

Minimal example:

struct S;

impl From<&S> for u32 {
    fn from(_: &S) -> Self {
        42
    }
}

fn query<T, F>(s: S, f: F) -> T
where
    F: FnOnce(&S) -> T,
{
    f(&s)
}

fn main() {
    query(S, |s| <u32>::from(s));
    // this is suggested by Clippy, but fails because the HRTBs of the `&S` type
    // cannot be inferred
    // query(S, <u32>::from);
}

Playground

@flip1995 flip1995 added E-hard Call for participation: This a hard problem and requires more experience or effort to work on C-bug Category: Clippy is not doing the correct thing labels May 13, 2020
Kixunil added a commit to Kixunil/rusqlite that referenced this issue May 17, 2020
closure is impossible. See
rust-lang/rust-clippy#5594

Allow this lint until the issue is resolved in clippy or the compiler.
thomcc pushed a commit to rusqlite/rusqlite that referenced this issue May 21, 2020
closure is impossible. See
rust-lang/rust-clippy#5594

Allow this lint until the issue is resolved in clippy or the compiler.
@phansch phansch added the I-false-positive Issue: The lint was triggered on code it shouldn't have label Dec 19, 2020
@Jarcho
Copy link
Contributor

Jarcho commented Apr 11, 2022

This was fixed by #7661.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing E-hard Call for participation: This a hard problem and requires more experience or effort to work on I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

No branches or pull requests

4 participants