Setup Emacs for Rust on MacOS

  1. Install Rustup

curl https://sh.rustup.rs -sSf | sh

you may need to uninstall existing rust on your machine

sudo /usr/local/lib/rustlib/uninstall.sh

Install Racer

rustup component add rust-src
source $HOME/.cargo/env
cargo install racer

Start your emacs

make sure “melpa” is in your package-archives

(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))

 Make Sure you installed racer-mode and company packages, you can view activated packaged list by C-h v package-activated-list 

Add following code in your emacs init file

(add-hook 'rust-mode-hook #'racer-mode)
(add-hook 'racer-mode-hook #'eldoc-mode)
(add-hook 'racer-mode-hook #'company-mode)

(require 'rust-mode)
(define-key rust-mode-map (kbd "TAB") #'company-indent-or-complete-common)
(setq company-tooltip-align-annotations t)

you can find your init file by M-: (Alt + Shift + ; ) and type (find-file user-init-file)

you can let emacs to eval your new setting by type M-x eval-buffer

References