question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support use of rustfmt-nightly

See original GitHub issue

rust-lang announcement

This plugin exposes the action Reformat file with rustfmt. As far as I can tell, this works by running cargo fmt -- --write-mode=overwrite --skip-children.

We’re also changing the parsing library used in Rustfmt from Syntex to libsyntax (because Syntex is not going to be maintained). This won’t affect formatting or much else for end users, however, it means rustfmt will only work with the nightly toolchain.

[…]

Longer term, we are moving to distribute Rustfmt with the main Rust distro, so all users will be able to use libsyntax-based rustfmt.

If you have both stable and nightly compilers installed, you can install rustfmt-nightly with cargo +nightly install rustfmt-nightly and run it with cargo +nightly fmt, whether you are on stable or nightly at the time.

This plugin should allow the rustfmt action to use rustfmt-nightly as the previous crate will no longer be receiving updates.

Likely, this will need to be rolled into better UI-based support of using rustfmt as an external code formatter. The very minimum to avoid strange errors and questions is probably to catch cargo exit code -1073741515 and display a popup that cargo failed, likely because of running a nightly-compiled cargo on stable. Alternatively, just add the +nightly flag to the cargo call, which should (untested) cause cargo to complain “you don’t have nightly installed” if nightly is not installed. I don’t think there is a solution that works on stable with current rustfmt and on stable forcing nightly with rustfmt-nightly.

Oh, and if anyone wants to set up an IDEA run configuration to run rustfmt-nightly, I got it working with Command: +nightly and Additional arguments: fmt -- --write-mode=overwrite --skip-children. Unfortunately, if you put fmt as the command and +nightly into the additional arguments, cargo receives cargo fmt +nightly -- ... which fails in some manner I don’t quite understand.

EDIT: there’s a box to select the build channel right next to command. Set that to nightly and have your command as fmt.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Undincommented, Apr 23, 2018

Looks like that it’s outdated due to rustfmt-preview

0reactions
brokenthorncommented, Jan 8, 2019

Yes, but this needs to be clearer. Like for example add this to one of the first chapters in the book and stress the idea of proper uniform formatting, which can also help new comers learn/read/understand code easier, due to more recognizable patterns in formatting, code expression, etc.

Read more comments on GitHub >

github_iconTop Results From Across the Web

rustfmt-nightly - crates.io: Rust Package Registry
Tool to find and fix Rust formatting issues.
Read more >
How to install the latest nightly Rust that supports rustfmt (or ...
I wanted to use the excellent cargo expand command to dump the expanded macro code, but ran into a dependency issue: cargo expand...
Read more >
rustfmt-nightly 0.2.14 - Docs.rs
Most development happens on the master branch, however, this only supports nightly toolchains. If you use stable or beta Rust toolchains, you must...
Read more >
Which crate to use `rustfmt` or `rustfmt-nightly` - help
I am trying to use rustfmt APIs inside my code to format my generated rust code from within a library. It seems that...
Read more >
Use nightly rustfmt with stable compiler in CLion
search for formatter · select Rustfmt on the left column · add +nightly to the Additional arguments: box · check Use rustfmt instead...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found