error: Unknown binary 'rust-analyzer'

As I am setting up my new machine, I came across this error when emacs tried to use rust-analyzer

error: Unknown binary 'rust-analyzer' in official toolchain 'stable-x86_64-apple-darwin'.

As mentioned in this SO question, which rust-analyzer did not show any error.1

Luckily, the same SO question also had the solution

I needed to explicitly install it via rustup component add rust-analyzer

  1. Luckily, the comment in the accepted answer also explained why which works. It is a wrapper, which is created/installed by default, but platform specific binary needs to be installed explicitly. See this comment ↩︎