How to disable rust-analyzer proc-macro warnings in neovim

Hello all,

I recently configured neovim (using the builtin LSP client) to work with rust-analyzer and my code has a lot of warnings like "proc macro x not expanded". I noticed there is a setting to enable or disable this but I can't seem to get it to work and was wondering if anyone else has?

My configuration is here. I haven't used lua before but the lua bits were taken from github snippets and articles.

I'm not sure whether these settings are actually being sent to rust-analyzer at all. My next step will to be to try to get some log output from the process and see what I can find there. Then I'll probably give up and rebuild it with hard-coded values which will probably be much easier than fiddling about with lua :slightly_smiling_face:.

I'd also love to be able to disable this in (Spac)emacs.

Generally, the answer to such questions should be found in the manual:

Admittedly, it is far from perfect, so please send PRs with improvements :wink:

Specific bits relevant here:

  • you can enable proc-macro support: procMacro = { enable = true },
  • you can disable this specific diagnostic: diagnostics = { disabled = ["unresolved-proc-macro"] }

I've send Document, how to view config in effect by matklad · Pull Request #7012 · rust-analyzer/rust-analyzer · GitHub to clarify how to verify that rust-analyzer is using the right config.


It's unfortunate that only VS Code seems to display these hint-level diagnostics as expected. They are not supposed to be this intrusive.

1 Like

Usually I can figure these things out but here I'm admitting defeat. Between the "... it’s up to the editor to decide on the exact format and location of configuration files.", the manual section on Emacs, notes on Spacemacs' lsp layer, and lsp-mode's own documentation, it's not clear to me where or how to set those values given above. If anyone has been successful at this, please let us know.

1 Like

Thanks very much, this was very helpful and got me to a working solution:

local lsp = require'lspconfig'

lsp.rust_analyzer.setup {                
    settings = {                      
        ["rust-analyzer"] = {
          diagnostics = {
              enable = true,
              disabled = {"unresolved-proc-macro"},
              enableExperimental = true,

Square brackets round the "unresolved-proc-macro" didn't work, but they can either be left out or braces used instead, which seems to be a lua array.

I should have read the documentation on the website. I did read it on github but that is missing some generated parts, which is why I found procMacro (which doesn't seem to affect this either way.) but not the diagnostic name. Edit: Enabling procMacro does solve this problem - I probably had a typo somewhere.

I'll look at opening a PR to try to make some of this clearer.

1 Like

Hehe, I remember spending couple of hours figuring out the ["rust-analyzer"] syntax when I was trying neovim's built-in LSP support :smiley:

1 Like

For Emacs, lsp-mode defines customization variables for most of these options (if there's one missing, feel free to report an issue or add it yourself). So for example, to turn on proc macros you need to do (setq lsp-rust-analyzer-proc-macro-enable t) (and probably also (setq lsp-rust-analyzer-cargo-load-out-dirs-from-check t)). You can also use the customize-group command with the lsp-rust group to see all the rust-analyzer options.

Setting either of the following will make the proc-macro warnings go away in Spacemacs:

(rust :variables lsp-rust-analyzer-diagnostics-disabled ["unresolved-proc-macro"])


(rust :variables
      lsp-rust-analyzer-cargo-load-out-dirs-from-check t
      lsp-rust-analyzer-proc-macro-enable t)

But unfortunately it is still giving me errors about actual macro use (for macros that are indeed in scope).

Please check whether those errors still occur in the newest nightly, and if so, report an issue. You can disable those errors as well though by adding "macro-error" to the disabled diagnostics.

1 Like

Admittedly I'm not on the most most recent version, due to those conflicts with lsp-types.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.