Search code examples
rustclionrustfmt

Use nightly rustfmt with stable compiler in CLion


I am running into an unexpected issue when it comes to toolchains in CLion. I want to use the stable channel for the compiler while using the nightly for rustfmt. The reason is that I want to use rustfmt features that are not available in the stable version. Unfortunately CLion only picks up the currently selected toolchain without any way to override or customize this and thus has not option to select the nightly of rustfmt for formatting. Is there any workaround or option I did not notice when looking for it?

In the comment there was the suggestion that cargo +nightly fmt might be what I am looking for. Even though it allows to used the nightly of rustfmt it is not integrated into the flow of CLion which seems to use the currently enabled version of the entire toolchain.


Solution

  • Under Clion | Preferences...:

    1. search for formatter
    2. select Rustfmt on the left column
    3. add +nightly to the Additional arguments: box
    4. check Use rustfmt instead of the built-in formatter
    5. click Ok

    Now Code | Reformat File with rustfmt should respect rustfmt nightly settings. (CLion 2022.2.4)

    CLion | Preferences... dialog box showing settings for nightly rustfmt on stable rustc