-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Incorrect lint: needless_lifetimes #5787
Comments
I can reproduce this, even without pub async fn wrap_something<'a>(
to_wrap: &'a mut Wrapped,
unrelated: &Unrelated,
) -> Wrapper<'a> { As far as I can tell, there is no possibility of eliding this, as the type system doesn't know from which of the arguments it should borrow without explicit lifetimes. |
Parameter lifetimes cannot be elided in async functions: pub async fn transaction<'a>(con: &'a mut PgClient) -> Result<Transaction<'a>> {
// does not compile
pub async fn transaction(con: &mut PgClient) -> Result<Transaction> { Note that this only applies to async functions. |
It seems to be a duplicate of #4746 |
Copying my comment from the other issue: Reproducer: Playground use std::sync::MutexGuard;
struct Foo;
impl Foo {
// doesn't get linted without async
pub async fn wait<'a, T>(&self, guard: MutexGuard<'a, T>) -> MutexGuard<'a, T> {
guard
}
} This is a self contained reproducer. |
I've reduced it further. async fn foo<'a>(_x: &i32, y: &'a str) -> &'a str {
y
}
And this doesn't triggers it. async fn foo<'a, 'b>(_x: &'b i32, y: &'a str) -> &'a str {
y
} |
In the async case, rust-clippy/clippy_lints/src/lifetimes.rs Lines 327 to 328 in e6665e4
The lint then only has |
Also adds a test for rust-lang#5787
Also adds a test for rust-lang#5787
I tried this code:
Clippy complains that this violates "needless_lifetimes". However trying to elide them cannot succeed due to the
&self
reference:Fails:
I'm not sure if there is actually an option for elision here at all...
Meta
cargo clippy -V
: clippy 0.0.212 (bb37a0f 2020-06-16)rustc -Vv
:Thanks in advance!
The text was updated successfully, but these errors were encountered: