Emacs: configure rust-analyzer for eglot

January 12, 2026

The LSP Server for Rust, rust-analyzer, by default insert a type when filling a match arms. I prefer to use Self. Fortunately, it has one configuration option just for that.

rust-analyzer.assist.preferSelf

Default: false

Prefer to use Self over the type name when inserting a type (e.g. in “fill match arms” assist).

In emacs I use eglot, so I need a way to pass this config to it. I found the following useful post.

Now, all I need is to add the following to my init.el:

(use-package eglot
  :init
  :config (add-to-list 'eglot-server-programs
                       `(rust-mode . ("rust-analyzer" :initializationOptions
                                      (:assist (:preferSelf t)))))
  :hook
  ((rust-mode) . eglot-ensure))