Right way to update Clippy?


#1

Hi all,
I’m playing with Rust, and want to learn to write idiomatic code. I was using clippy last weekend, installed using “cargo install clippy”. This weekend I "rustup update"d, which updated my nightly rust install, and then went to “cargo clippy” some code. It failed to run (which didn’t surprise me because it hadn’t been updated after the rustup update).

So, I then looked for a “cargo update clippy” or equivalent. There was no such thing. So then I tried “cargo install clippy --force”, and got compile errors:

   Compiling clippy_lints v0.0.136
error[E0432]: unresolved import `rustc::ty::MethodCall`
 --> .cargo/registry/src/github.com-1ecc6299db9ec823/clippy_lints-0.0.136/src/mut_reference.rs:2:43
  |
2 | use rustc::ty::{TypeAndMut, TypeVariants, MethodCall, TyS};
  |                                           ^^^^^^^^^^ no `MethodCall` in `ty`

I’m only playing around with Rust on weekends. I assume I’m “holding it wrong”, but can’t see what I’m missing. Is there an ‘it just works’ approach to this? e.g. Is there a way to get clippy with rustup so that it gets updated reliably at the same time as the compiler?

Thanks for any suggestions,

Will :-}


#2

That’s a known issue. Will have to wait until it’s fixed.


#3

Ok. Sigh. It would be nice if clippy were available on the stable branch.

So to get clippy working I have to look at the clippy changelog. Find the latest version of rust listed. Then it looks like I get the date of that version, e.g. nightly-2017-05-26, and pin my toolchain there with rustup default nightly-2017-05-26. Finally I reinstall clippy with cargo install clippy --force.

That gives me yet another error:

   Compiling clippy_lints v0.0.136
error: no field `ident` on type `&rustc::hir::def::Export`
   --> /home/will_uther/.cargo/registry/src/github.com-1ecc6299db9ec823/clippy_lints-0.0.136/src/utils/mod.rs:291:25
    |
291 |                 if item.ident.name == *segment {
    |                         ^^^^^

So let’s try surrounding dates:

; rustup default nightly-2017-05-25
info: syncing channel updates for 'nightly-2017-05-25-x86_64-unknown-linux-gnu'
error: no release found for 'nightly-2017-05-25'
; rustup default nightly-2017-05-27
  nightly-2017-05-27-x86_64-unknown-linux-gnu installed - rustc 1.19.0-nightly (557967766 2017-05-26)
; cargo install clippy --force     

That seems to work.

Looking at what rustup installed, it appears you need to take the date from the changelog and use the nightly release from the day after that.

This is not exactly a smooth experience.


#4

Yep, it’s a real pain at the moment. There’s work in progress to get Clippy integrated into the Rust release process, then you’ll be able to install it via rustup (something like rustup component add clippy I believe). This will even allow you to install it for stable Rust as well :slight_smile:. I’m not sure of the exact timeline for this though.

For now I generally use a pinned nightly + Clippy version per project on Travis (e.g. for cargo-lichking). Occasionally I’ll update both together (going through basically the same process you listed), but not all that often. Locally I’ll just use whatever version I last updated to when updating a pin in a project and hope there’s no inconsistencies with what’s running on Travis.