VSCode; Nightly rustfmt, stable rustc

I want to be able to use nightly rustfmt (it has certain options I want), but stable rustc.

With vim this was easy; just let g:rustfmt_command = "rustup run nightly rustfmt".

Other developers around here like VSCode. I wanted to write a howto guide for them, but soon ran into some issues. I've been trying to use the "Rust 0.7.8" plugin, and when one opens the settings and searches for "rustfmt" there's an entry for "Rust: Rustfmt_path". Editing this in settings.json yields:

{
    "rust.rustfmt_path": ""
}

So far so good. But when I try to point that to nightly's rustfmt, nothing changes with regards to formatting (even though I have nightly-specific options in rustfmt.toml). After discovering others have noticed this as well I realized that while the option is there it doesn't actually do anything.

Is there some other plugin that provides completion and all that, but also allows nightly rustfmt? It looks like rust-analyzer also supports reconfiguring whaty rustfmt to use (or rather the arguments to it, and from what I've seen it's supposed to work). However, the developers working with vscode seem quite pleased with the old plugin, so I'm not happy about telling them to use another plugin if it wouldn't provide the same level of comfort.

Any tips on alternative plugins that support running nightly rustfmt without having to reconfigure default toolchain?

Have you tried https://rust-analyzer.github.io/, I switch to this a while ago - generally has more features and is faster then rust rls plugin, but not exactly sure about options for rustfmt.

But anyhow I usually using cargo fmt to format all project, so it would be easy to use nighly version with rustup.

2 Likes

I don't know how to bridge the gap from here to your IDE, but I've started using this on my stable projects with some comments in my .rustfmt.toml to remind me of settings that are still nightly-only:

# basic
cargo +nightly fmt
# opt in to nightly-only rustfmt settings
cargo +nightly fmt -- --config 'merge_imports=true'

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.