5

I'm working on an extended deprecation lint that can decide if something already is or will be deprecated. There is one problem left, though: Crates do not appear to have version information. I know that I can get the current Crate's version using some environment variable that cargo will set, but that's not enough to distinguish deprecated parts of dependencies.

I can at least get the current crate path via ctx.sess.local_crate_source_file (as in fhahn's current PR.

So barring getting the filepath and finding and parsing Cargo.lock manually (which I consider to be fragile and hacky), is there a way to get the dependencies' version numbers and if so, how?

llogiq
  • 13,815
  • 8
  • 40
  • 72

1 Answers1

0

Use #[deprecated] instead, see Rust lang rfc 1270 for documentation. This is stable since Rust 1.9. Then the compiler does the job of the lint you want to create.

A way to instead implement what you asked for without touching the compiler or using a compiler feature is to include the version in the crate its public API and use that from your lint.

Jan Zerebecki
  • 825
  • 7
  • 18
  • I wrote that RFC. And sorry, in that case finding and parsing Cargo.lock is the better option. Thanks anyway. – llogiq Feb 25 '17 at 21:40
  • Why do you think that is also better than getting the version from the API of the crate whose deprecations you want to lint about? – Jan Zerebecki Feb 26 '17 at 00:45
  • I'm a bit late, but could you not put the version information into the crate at compile-time, e.g. with an `include!` macro and/or a build script? – TheTechRobo the Nerd Aug 08 '22 at 02:08