Rust-clippy: unused_lifetime false positive

Created on 17 Apr 2018  路  11Comments  路  Source: rust-lang/rust-clippy


I'm using this type of stuff in a -sys-crate:

unsafe extern "C" fn callback<'a>(data: *mut c_void) {
    let _s = Box::from_raw(data as *mut S<'a>);
}

and this triggers unused_lifetime.

Playground with more context (also shows the #2677 issue): https://play.rust-lang.org/?gist=21a412537258ede9cbda42350501b90a&version=nightly

L-enhancement good-first-issue hacktoberfest

All 11 comments

That lifetime is always going to be 'static, you should just do data as *mut S<'static> here.

Thanks, didn't know that. Then perhaps that should be specified in the warning text?

A note stating that all useless uses of the liftetime should be replaced with 'static is a good idea

Can I pick this up? I'm a rust n00b :)

@andreicristianpetcu great! it's all yours. If you have any questions, you can post here or open a WIP PR showing what you tried and ask for help there.

Sorry I did not have time to work on this and I might not have in the future either :(

Is it possible that I could handle this issue, @oli-obk?

@JacksonCoder jup!

Great, thanks!

Should I make this a separate warning, or integrate it with the unused_lifetime lint?
In the former case, we could call the lint unnecessary_lifetime or something else, where it points out that since the lifetime is unused in the function definition, we can just replace the usage of that unused lifetime with 'static.
In the latter case, is it possible to make 'notes' for a lint, just like with compiler warnings/errors for Rust? Because if so, we could basically make a note for each usage of that useless lifetime in similar wording to the former case.

The existing unused_lifetime lint should be extended. The best thing would be to add a suggestion (with the span_suggestion method) that replaces each lifetime with 'static. You probably need to record the spans of all lifetimes, because I think this isn't happening today.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

durka picture durka  路  17Comments

Manishearth picture Manishearth  路  26Comments

phansch picture phansch  路  17Comments

casey picture casey  路  19Comments

davemilter picture davemilter  路  18Comments