Skip to content
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

Clippy can run the wrong rustc, leading to "incompatible version of rustc" errors #9560

Open
jorendorff opened this issue Sep 30, 2022 · 12 comments
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@jorendorff
Copy link

jorendorff commented Sep 30, 2022

Summary

I had several versions of Rust installed (via rustup) and was surprised that Clippy would sometimes give errors like this:

error[E0514]: found crate `paste` compiled by an incompatible version of rustc
...
  = help: please recompile that crate using this compiler (rustc 1.64.0 ...)
  = note: the following crate versions were found:
          crate `paste` compiled by rustc 1.63.0: ...

1.64.0 was in fact the version I wanted to be using.

The surprise came when I did rustup toolchain remove 1.63.0, then cargo clean && cargo clippy, and still got the same error!

It turns out I had yet another copy of Rust 1.63.0 installed, via Homebrew, as /usr/local/bin/rustc.
I think I must have done brew install rust-analyzer at some point and that brought in the rust package.

Obviously that was bad and I just removed it. But this means cargo clippy sometimes results in two different rustc executables being used. I think that must be a bug.

Reproducer

Possible steps to reproduce, using code in https://github.com/jorendorff/incompavers:

  1. Have Homebrew and rustup installed

  2. Run these commands:

    brew install rust
    git clone https://github.com/jorendorff/incompavers.git
    cd incompavers
    cargo clean && cargo clippy --verbose
    

Expected behavior: Clippy should lint the crate.

Actual behavior: Clippy produced the errors below.

❯ cargo clean && cargo clippy --verbose
    Checking base64 v0.13.0
   Compiling paste v1.0.9
     Running `rustc --crate-name base64 --edition=2018 /Users/jorendorff/.cargo/registry/src/github.com-1ecc6299db9ec823/base64-0.13.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 --cfg 'feature="default"' --cfg 'feature="std"' -C metadata=bd37c0a895c55f89 -C extra-filename=-bd37c0a895c55f89 --out-dir /Users/jorendorff/src/incompavers/target/debug/deps -L dependency=/Users/jorendorff/src/incompavers/target/debug/deps --cap-lints allow`
     Running `rustc --crate-name paste --edition=2018 /Users/jorendorff/.cargo/registry/src/github.com-1ecc6299db9ec823/paste-1.0.9/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type proc-macro --emit=dep-info,link -C prefer-dynamic -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C metadata=1cc8d85ad06b00de -C extra-filename=-1cc8d85ad06b00de --out-dir /Users/jorendorff/src/incompavers/target/debug/deps -L dependency=/Users/jorendorff/src/incompavers/target/debug/deps --extern proc_macro --cap-lints allow`
    Checking incompavers v0.1.0 (/Users/jorendorff/src/incompavers)
     Running `/Users/jorendorff/.rustup/toolchains/stable-x86_64-apple-darwin/bin/clippy-driver rustc --crate-name incompavers --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C metadata=8f4097126ae0e3f7 -C extra-filename=-8f4097126ae0e3f7 --out-dir /Users/jorendorff/src/incompavers/target/debug/deps -C incremental=/Users/jorendorff/src/incompavers/target/debug/incremental -L dependency=/Users/jorendorff/src/incompavers/target/debug/deps --extern base64=/Users/jorendorff/src/incompavers/target/debug/deps/libbase64-bd37c0a895c55f89.rmeta --extern paste=/Users/jorendorff/src/incompavers/target/debug/deps/libpaste-1cc8d85ad06b00de.dylib`
error[E0514]: found crate `paste` compiled by an incompatible version of rustc
 --> src/lib.rs:1:9
  |
1 | pub use paste::paste;
  |         ^^^^^
  |
  = help: please recompile that crate using this compiler (rustc 1.64.0 (a55dd71d5 2022-09-19)) (consider running `cargo clean` first)
  = note: the following crate versions were found:
          crate `paste` compiled by rustc 1.63.0: /Users/jorendorff/src/incompavers/target/debug/deps/libpaste-1cc8d85ad06b00de.dylib

error[E0514]: found crate `base64` compiled by an incompatible version of rustc
  --> src/lib.rs:22:26
   |
22 |     println!("hello {}", base64::encode(b"world"));
   |                          ^^^^^^
   |
   = help: please recompile that crate using this compiler (rustc 1.64.0 (a55dd71d5 2022-09-19)) (consider running `cargo clean` first)
   = note: the following crate versions were found:
           crate `base64` compiled by rustc 1.63.0: /Users/jorendorff/src/incompavers/target/debug/deps/libbase64-bd37c0a895c55f89.rmeta

error: could not compile `incompavers` due to 2 previous errors

Caused by:
  process didn't exit successfully: `/Users/jorendorff/.rustup/toolchains/stable-x86_64-apple-darwin/bin/clippy-driver rustc --crate-name incompavers --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C metadata=8f4097126ae0e3f7 -C extra-filename=-8f4097126ae0e3f7 --out-dir /Users/jorendorff/src/incompavers/target/debug/deps -C incremental=/Users/jorendorff/src/incompavers/target/debug/incremental -L dependency=/Users/jorendorff/src/incompavers/target/debug/deps --extern base64=/Users/jorendorff/src/incompavers/target/debug/deps/libbase64-bd37c0a895c55f89.rmeta --extern paste=/Users/jorendorff/src/incompavers/target/debug/deps/libpaste-1cc8d85ad06b00de.dylib` (exit status: 1)

Version

rustc 1.64.0 (a55dd71d5 2022-09-19)
binary: rustc
commit-hash: a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52
commit-date: 2022-09-19
host: x86_64-apple-darwin
release: 1.64.0
LLVM version: 14.0.6

Additional Labels

No response

@jorendorff jorendorff added the C-bug Category: Clippy is not doing the correct thing label Sep 30, 2022
@fritzrehde
Copy link

I have encountered this problem as well.

@drueck
Copy link

drueck commented Dec 21, 2022

I'm running into this as well. I have another thing installed via homebrew that has rust as a dependency, and so I can't uninstall the system rust without first uninstalling the other thing (which I don't want to uninstall). Is there a workaround for this? Like a way to just configure clippy to use a specific rustc?

@ewoolsey
Copy link

I'm running into this as well. I have another thing installed via homebrew that has rust as a dependency, and so I can't uninstall the system rust without first uninstalling the other thing (which I don't want to uninstall). Is there a workaround for this? Like a way to just configure clippy to use a specific rustc?

Same here. Would love an update to this problem.

@your-diary
Copy link

Any workaround? cargo check and cargo build work. Only cargo clippy doesn't work.

@jorendorff
Copy link
Author

If your system is like mine, the workaround is brew uninstall rust.

@homologay
Copy link

I had this issue, it finally worked when I deleted rustc directly (by sudo rm /usr/bin/rustc) (or wherever your rustc lies). Then cargo clean and cargo clippy in my project directory.

rustc version 1.66.1
clippy version 0.1.66
cargo version 1.64.0
rustup 1.25.1
void linux x86_64 kernel 6.1.6_1

@milesj
Copy link

milesj commented Mar 10, 2023

Thank you for this thread. Clippy hasn't worked for weeks and it turns out that rust was somehow installed via homebrew. Uninstalling it fixed my problem.

@simonhammes
Copy link

I've also run into this and tried to debug the problem.
In my case, building something from source via Homebrew is also the most likely culprit.

I believe that this actually stems from a different cargo binary being used, as Clippy invokes cargo here:

let mut cmd = Command::new("cargo");

Running the following command on my local machine probably explains why this is happening:

find $(echo $PATH | tr ':' '\n') -type f,l -name "cargo"

Output:

/home/linuxbrew/.linuxbrew/bin/cargo
/home/$USER/.cargo/bin/cargo


=> cargo from brew comes first, which means that any command running cargo will use this binary

This issue probably references the same problem: Homebrew/brew#13281:
By default, /home/linuxbrew/.linuxbrew/bin/brew shellenv (which is in ~/.profile) prepends the brew bin directories to $PATH instead of appending them, causing the brew binaries to have a higher priority.

As Homebrew/brew#13281 (comment) suggests, setting $PATH yourself might be the correct solution, although I haven't tried that yet.


As I do not own a Mac, I can't verify whether this is the reason for the error in the OP.
But I would be glad if someone else would dig a little deeper and verify this ;)

@jorendorff
Copy link
Author

Nice debugging, @simonhammes.

It looks like this repo uses Command::new("cargo") in a few places. I wonder if using the CARGO environment variable instead would fix this bug.

@dvdsk
Copy link

dvdsk commented Aug 12, 2023

This issue is about to come up a lot more frequent I fear.

As rust is now used in the kernel 🥳 rustc has become part of the linux-headers package on Ubuntu and its derivatives. When I run clippy the system installed rustc is used.

Use dpkg-query -S rustc to see the packages that installed rustc.

Now the question is whether this goes wrong in clippy or cargo...

@hoijui
Copy link

hoijui commented Nov 22, 2023

Under Debian (probably also Ubuntu & co.):

# Removes the rustc installed though apt, leaving only the one installed though rustup (hopefully)
sudo apt-get remove rustc
# Removes all compile artifacts, including the ones compiled with the apt-installed rustc
cargo clean
# This should now work
cargo clippy

@Coconop
Copy link

Coconop commented Apr 30, 2024

I had this issue on Windows too because I initially installed the standalone version before using the rustup-init.exe.
Note that both cargo clippy and cargo check were raising erros.

Inspired by @simonhammes and this question on Rust users forum I looked up for conflicting installs from powershell:

rustup which rustc

Ouput: C:\Users\Coconop\.rustup\toolchains\stable-x86_64-pc-windows-msvc\bin\rustc.exe

On the other hand:

Get-Command rustc.exe

Output: C:\Program Files\Rust stable MSVC 1.77

I wasn't sure how to uninstall standalone version so I just updated the PATH environment variable to point to the rustup toolchain and now both cargo check and cargo clippy are happy :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing
Projects
None yet
Development

No branches or pull requests