Rustfmt option `trailing_semicolon` not respected by rust-analyzer


Assume you have a directory with the following rustfmt.toml configuration file:

trailing_semicolon = false

And there's another file in that directory src/ with the following code:

fn foo() -> u32 {
    let a: u32 = 1;
    let b: u32 = 2;
    return a + b

fn main() {
    println!("{}", foo());

And the following VSCode user settings:

"editor.formatOnSave": true,
"[rust]": {
  "editor.defaultFormatter": "rust-lang.rust-analyzer"

Now, when I open this directory in VSCode, I expected the rust-analyzer extension not to add a trailing semicolon on line 4 (the return statement) when I hit CMD + S. But this is exactly what it does!

return a + b;

I have debugged this for hours and I just can't find the reason for why it happens. What am I missing? Is there any setting I have to apply to make the rust-analyzer extension read the settings from the rustfmt.toml configuration file?


  • macOS v12.4
  • VSCode v1.69.2
  • rust-analyzer v0.3.1131
  • rustfmt v1.4.38-stable
  • rustc 1.62.0 (a8314ef7d 2022-06-27)

Nevermind, I figured this out on my own. trailing_semicolon is an unstable option, so it's only available in the nightly release of rustfmt. But it turns out that by default, rust-analyzer runs the stable release of rustfmt.

Here's the one line I added to my VSCode user settings to fix this:

"rust-analyzer.rustfmt.extraArgs": ["+nightly"]

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.