Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't enable unstable features #4353

Closed
austinglaser opened this issue Jul 26, 2020 · 7 comments
Closed

Can't enable unstable features #4353

austinglaser opened this issue Jul 26, 2020 · 7 comments

Comments

@austinglaser
Copy link

Describe the bug

rustfmt does not appear to accept the unstable_features = true option (documented here) in rustfmt.toml

To Reproduce

  • Create an empty cargo project
  • Write the following rustfmt.toml:
    unstable_features = true
    merge_imports = true
  • Invoke rustfmt
$ cargo fmt
Warning: can't set `merge_imports = true`, unstable features are only available in nightly channel.
Warning: can't set `unstable_features = true`, unstable features are only available in nightly channel.
$ rustfmt src/main.rs
Warning: can't set `merge_imports = true`, unstable features are only available in nightly channel.
Warning: can't set `unstable_features = true`, unstable features are only available in nightly channel.

Interestingly, I cannot override this on the command line:

$ rustfmt src/main.rs --config unstable_features=true
Warning: can't set `merge_imports = true`, unstable features are only available in nightly channel.
Warning: can't set `unstable_features = true`, unstable features are only available in nightly channel.

If I change rustfmt.toml to simply be

merge_imports = true

I get

$ rustfmt src/main.rs --config unstable_features=true
Warning: can't set `merge_imports = true`, unstable features are only available in nightly channel.

However, with an empty rustfmt.toml, the following works:

$ rustfmt src/main.rs --config unstable_features=true --config merge_imports=true

So it looks like perhaps this is associated solely with loading the config?

Expected behavior

When unstable_features = true is set in rustfmt.toml, rustfmt should accept and act on unstable options like merge_imports without producing warnings.

Furthermore, a command-line specification of --config unstable_features=true should enable unstable features when loaded from rustfmt.toml

Meta

  • rustfmt version: rustfmt 1.4.15-stable (530eadf4 2020-06-02)
  • From where did you install rustfmt?: rustup
  • How do you run rustfmt: primarily cargo fmt and editor on-save hooks, but see above
@austinglaser austinglaser added the bug Panic, non-idempotency, invalid code, etc. label Jul 26, 2020
@austinglaser
Copy link
Author

This seems potentially related to #3872, in that the decision to print a warning or enable the feature should be deferred until after parsing the entire config

@calebcartwright
Copy link
Member

calebcartwright commented Jul 26, 2020

Thanks for reaching out @austinglaser. TL;DR - You cannot use unstable features on stable with rustfmt 1.x, and the link you referenced in the issue description is for a different/newer version of rustfmt than the version you are actually using (v1.4.15)

From the Configuring Rustfmt section of the readme (emphasis mine):

Configuration options are either stable or unstable. Stable options can always be used on any channel. Unstable options are always available on nightly, but can only be used on stable and beta with an explicit opt-in (starting in Rustfmt v2.0).

Unstable options are not available on stable/beta with Rustfmt v1.x.

When looking at the configuration page, make sure to use the version selection dropdown to pick the version of rustfmt you are using.

Direct link to config docs for v1.4.15
https://rust-lang.github.io/rustfmt/?version=v1.4.15

Direct link to unstable_features option in v1.4.15
https://rust-lang.github.io/rustfmt/?version=v1.4.15#unstable_features

@calebcartwright calebcartwright removed the bug Panic, non-idempotency, invalid code, etc. label Jul 26, 2020
@austinglaser
Copy link
Author

Ah, I missed the "starting in rustfmt v2.0." Thanks very much!

@Luthaf
Copy link

Luthaf commented Jun 30, 2021

Since rustfmt 2.0 will not be available via rustup/to the general developer population anytime soon, would you consider enabling something like this for the 1.x releases? Maybe using something like RUSTC_BOOTSTRAP/#4884 in addition to unstable_features = true to make it even more opt-in?

I'll be willing to contribute to the implementation of such feature, since there are multiple unstable features I'd like to use for my own code, and I don't mind occasional breaking changes in formatting.

@calebcartwright
Copy link
Member

@Luthaf thank you for your willingness to contribute, but no this isn't going to happen (at least not any time soon) for the reasons I described here; it's not a technical/bandwidth matter

@Luthaf
Copy link

Luthaf commented Jul 6, 2021

OK, thanks for the answer. I see where the teams are coming from, but for me that mean using rustfmt is harder for me. The default output have less than ideal for my code since the first version. Nowadays, the unstable configuration options are enough for me to consider using it again; but I can not move the whole team on nightly just to be able to use the formatter.

I guess the other option is to work toward stabilizing the options I would like to use. Is there any way I can help to make them stable faster?

@appetrosyan
Copy link

@calebcartwright Sorry to necrobump, but the mythical rustfmt version 2.0 seems not to be released as of March 2022. Is it possible to estimate how long is it going to finally release 2.0 to the public?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants