-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 unused_lifetimes warning #77217
Comments
The issue is that the field This is not ideal, but not sure on where exactly we want to lint here. If we have functions |
Then why does the warning not show up if |
Furthermore, this code, which clearly does use #![warn(unused_lifetimes)]
pub struct Thingy<'x> {
x: &'x u32,
y: &'static str,
}
impl<'x> Thingy<'x> {
pub fn new(x: &'x u32) -> Self {
Self{x, y: "hello"}
}
pub async fn foo(&self) -> &'static str {
self.y
}
pub async fn bar(&self) -> u32 {
*self.x
}
} Meanwhile, if I change both |
Yeah, that is an actual bug 👍 thanks |
So this is probably related to the desugaring somehow: rust/compiler/rustc_ast_lowering/src/lib.rs Lines 1882 to 1927 in 4d52dc4
but I don't exactly know how yet. Maybe applying the desugaring to the example will help to see it. |
I can also trigger a #![warn(single_use_lifetimes)]
pub async fn foo<'a>(x: &'a u32) -> &'a u32 {
x
} Again, this only happens with an |
I also encountered this bug, and if I add |
@hyd-dev Yes, it is the same bug and I fixed it in this #79689 PR. |
@rustbot claim |
Update tests of "unused_lifetimes" lint for async functions and corresponding source code Before this PR the following code would cause an error: ``` #![deny(unused_lifetimes)] async fn f<'a>(_: &'a i32) {} fn main() {} ``` It was happening because of the desugaring of return type in async functions. As a result of the desugaring, the return type contains all lifetimes involved in the function signature. And these lifetimes were interpreted separately from the same in the function scope => so they are unused. Now, all lifetimes from the return type are interpreted as used. It is also not perfect, but at least this lint doesn't cause wrong errors now. This PR connected to issues rust-lang#78522, rust-lang#77217
Update tests of "unused_lifetimes" lint for async functions and corresponding source code Before this PR the following code would cause an error: ``` #![deny(unused_lifetimes)] async fn f<'a>(_: &'a i32) {} fn main() {} ``` It was happening because of the desugaring of return type in async functions. As a result of the desugaring, the return type contains all lifetimes involved in the function signature. And these lifetimes were interpreted separately from the same in the function scope => so they are unused. Now, all lifetimes from the return type are interpreted as used. It is also not perfect, but at least this lint doesn't cause wrong errors now. This PR connected to issues rust-lang#78522, rust-lang#77217
Update tests of "unused_lifetimes" lint for async functions and corresponding source code Before this PR the following code would cause an error: ``` #![deny(unused_lifetimes)] async fn f<'a>(_: &'a i32) {} fn main() {} ``` It was happening because of the desugaring of return type in async functions. As a result of the desugaring, the return type contains all lifetimes involved in the function signature. And these lifetimes were interpreted separately from the same in the function scope => so they are unused. Now, all lifetimes from the return type are interpreted as used. It is also not perfect, but at least this lint doesn't cause wrong errors now. This PR connected to issues rust-lang#78522, rust-lang#77217
Presumably fixed in #79689, leaving this open to try the original example in the next nightly. |
Triage: Confirmed that this is fixed in nightly. |
I tried this code:
I got a warning “lifetime parameter
'x
never used”, on theimpl
line. But it clearly is used. The warning goes away if I delete the functionfoo
, or make it a regular function instead of an asynchronous function.Meta
rustc --version --verbose
:I saw #61115 and rust-lang/rust-clippy#3988, but those were both closed at least a year ago and this is still happening in 1.46.0 which was just released recently, so I assume it’s not the same bug.
The text was updated successfully, but these errors were encountered: