A way to force nightly fmt on stable

Hello Rustaceans!

What I have:

  • Ubuntu 19.04 with Rust stable and nightly installed via rustup,
  • Rust defaults to stable (not going to change that)
  • Component rustfmt installed in both toolchains

Of course, cargo fmt calls stable and cargo +nightly fmt calls nightly (thank you cpt. Obvoius).

My question: Is there a way to force global use of nightly rustfmt without switching of the whole toolchain to nightly? Some black magic in .cargo/config?


Edit: I need to change cargo fmt functionality, so tools that call it implicitly in background use nightly, like for example IntelliJ or cargo make. Alias in shell does not help here.

creating an alias?

echo "alias cfmt='cargo +nightly fmt'" >> ~/.bashrc

Added section to my question. Sorry, alias won’t do.

I already have r script calling update/build/test/doc/fmt/whatever. I need solution for programs implicitly calling cargo fmt.

IntelliJ lets you specify a toolchain IIRC, so you could use nightly for fmt.

Alias won’t work, as toolchains mentioned do not read them in, they do not even start through the shell.

Only thing I can think of that would work, is another shim in a folder thats before rustups cargo in PATH, which then checks for fmt beeing the subcommand and then changes to nightly, passing through remaining arguments, and generally passing through when not fmt.

This is somewhat dangerous though, as it would also affect projects of other people that you participate in.

In my opinion disabling IntelliJs autoformat and running cargo +nightly fmt is the most proper way to do, baked by a pre-commit hook to avoid forgetting to run it…

As of now, I disabled IntelliJ Rust plugin default Run rustfmt on Save and use File Watchers plugin to call nightly fmt.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.