Rustfmt: Many configuration options are "only available in nightly channel"

Created on 3 Dec 2017  路  15Comments  路  Source: rust-lang/rustfmt

Just updated to 0.2.17:

>cargo fmt
Warning: can't set `fn_single_line = true`, unstable features are only available in nightly channel.
Warning: can't set `reorder_imports = true`, unstable features are only available in nightly channel.
Warning: can't set `reorder_imports_in_group = true`, unstable features are only available in nightly channel.
Warning: can't set `reorder_imported_names = true`, unstable features are only available in nightly channel.
Warning: can't set `match_block_trailing_comma = true`, unstable features are only available in nightly channel.
Warning: can't set `use_try_shorthand = true`, unstable features are only available in nightly channel.
Warning: can't set `fn_single_line = true`, unstable features are only available in nightly channel.
Warning: can't set `reorder_imports = true`, unstable features are only available in nightly channel.
Warning: can't set `reorder_imports_in_group = true`, unstable features are only available in nightly channel.
Warning: can't set `reorder_imported_names = true`, unstable features are only available in nightly channel.
Warning: can't set `match_block_trailing_comma = true`, unstable features are only available in nightly channel.
Warning: can't set `use_try_shorthand = true`, unstable features are only available in nightly channel.
Warning: can't set `fn_single_line = true`, unstable features are only available in nightly channel.
Warning: can't set `reorder_imports = true`, unstable features are only available in nightly channel.
Warning: can't set `reorder_imports_in_group = true`, unstable features are only available in nightly channel.
Warning: can't set `reorder_imported_names = true`, unstable features are only available in nightly channel.
Warning: can't set `match_block_trailing_comma = true`, unstable features are only available in nightly channel.
Warning: can't set `use_try_shorthand = true`, unstable features are only available in nightly channel.
Warning: can't set `fn_single_line = true`, unstable features are only available in nightly channel.
Warning: can't set `reorder_imports = true`, unstable features are only available in nightly channel.
Warning: can't set `reorder_imports_in_group = true`, unstable features are only available in nightly channel.
Warning: can't set `reorder_imported_names = true`, unstable features are only available in nightly channel.
Warning: can't set `match_block_trailing_comma = true`, unstable features are only available in nightly channel.
Warning: can't set `use_try_shorthand = true`, unstable features are only available in nightly channel.
Warning: can't set `fn_single_line = true`, unstable features are only available in nightly channel.
Warning: can't set `reorder_imports = true`, unstable features are only available in nightly channel.
Warning: can't set `reorder_imports_in_group = true`, unstable features are only available in nightly channel.
Warning: can't set `reorder_imported_names = true`, unstable features are only available in nightly channel.
Warning: can't set `match_block_trailing_comma = true`, unstable features are only available in nightly channel.
Warning: can't set `use_try_shorthand = true`, unstable features are only available in nightly channel.

Summary of the situation:

0.2.17

Pushed a change to hide most configuration behind a flag. This was a breaking change (as it disabled configuration options), and probably should have been released as 0.3.0, to indicate it as such.

Detection of nightly toolchain detection is done via CFG_RELEASE_CHANNEL _at runtime_. You can enable the options that "are only available in nightly channel" by setting the environment variable CFG_RELEASE_CHANNEL to nightly and setting unstable_options = true in your rustfmt.toml or by passing --unstable-options to rustfmt.

Master

The check against CFG_RELEASE_CHANNEL was changed from a runtime check to a compile time check. We want to hide the unstable configuration options when distributed as an official tool through rustup, if we're not on the nightly channel. CFG_RELEASE_CHANNEL is the tool by which rustc handles enabling you to unlock feature gates, and we're trying to piggyback off of that here. _There is no consistent way to tell which toolchain you are being built by, except by asking nicely._

Future

https://github.com/rust-lang-nursery/rustfmt/pull/2249 will set the default when the variable is not set to allow turning unstable features on when built through cargo install. https://github.com/rust-lang-nursery/rustfmt/pull/2228 adds documentation of this feature gate.

Most helpful comment

@YaLTeR @Eijebong @CraZySacX @daboross

I updated the OP here such that it should be clearer what the situation is here.

The TL;DR of it is that on 0.2.17 (current crates.io version), you need to set the environment variable CFG_RELEASE_CHANNEL to nightly. Then, you can either cargo +nightly fmt -- --unstable-features or just set unstable_features=true in your rustfmt.toml and cargo +nightly fmt.

Once a new build is published, you will no longer need to set CFG_RELEASE_CHANNEL at runtime, and it will be a compile time check. If #2249 is merged, you will be able to set unstable features when building with cargo, and if not, CFG_RELEASE_CHANNEL will need to be set when building rustfmt in order to enable unstable features.

IMHO, @nrc, we should yank 0.2.17 (since it had breaking changes, disabling configuration options), merge #2249 ASAP, and publish a new build as 0.3.0.

All 15 comments

If this is intended, I'd like to see some mention of what features are and aren't "nightly" at Configurations.md, as well as how to enable "nightly" execution mode.

OK, I found #1998. Going to write up and PR a patch so that Configurations.md mentions this.

Going to write up and PR a patch so that Configurations.md mentions this.

That would be great, thanks!

@nrc I'm really confused by #1998. To me it looks like a breaking change that should have been released as 0.3.

I filed https://github.com/rust-lang-nursery/rustfmt/pull/2232 for the options that already exist in the stable version of rustfmt.

To me it looks like a breaking change that should have been released as 0.3.

I guess it probably should. OTOH, pre-1.0, semver is more of a guideline than a rule.

I guess it probably should. OTOH, pre-1.0, semver is more of a guideline than a rule.

It is not in Cargo. With 0.y.z versions, y is the major version and z the minor. A foo = "0.2" dependency will not select a 0.3.z version.

I can't seem to get them to work. rustup run nightly cargo fmt -- --unstable-options tells me that it didn't recognize the last argument (looks like it fails to pass stuff after -- to rustfmt as it states in its help message); rustup run nightly rustfmt --write-mode=overwrite --unstable-features src/lib.rs tells me that unstable features are only available on the nightly channel (which I'm clearly on).

Same here

It appears that unless you compile rustfmt with the CFG_RELEASE_CHANNEL set, you will never be able to use --unstable-features due to the code at https://github.com/tmahmood/rustfmt/blob/685c9d332fe728e58ccf1bb6df5c096faaa3c172/src/bin/rustfmt.rs#L72-L81

        let rust_nightly = option_env!("CFG_RELEASE_CHANNEL")
            .map(|c| c == "nightly")
            .unwrap_or(false);
        if unstable_features && !rust_nightly {
            return Err(FmtError::from(format!(
                "Unstable features are only available on Nightly channel"
            )));
        } else {
            options.unstable_features = unstable_features;
        }

option_env! is a compile time check so if CFG_RELEASE_CHANNEL is not set, it'll default to None, which will set rust_nightly to false at compile time.

I don't know if cargo sends that env var to rustc at compile time, but my hunch is that it doesn't, as I compile rustfmt with nightly and am also experiencing this issue.

IMO, unstable features should be hidden behind a compile time feature flag rather than a command line switch. I also briefly looked for an easy way to check if you are running nightly at runtime, but was unable to find one. I'm working on a PR with a quick fix (option_env! -> std::env::var) which should allow you to set CFG_RELEASE_CHANNEL before running rustfmt and use unstable features.

-- in cargo fmt seems to only be correctly handled when used via cargo +nightly fmt and not rustup run nightly cargo fmt.

Looks like I missed some open PRs on this #2228, #2249. I've also put in a PR that changes the behavior to a runtime check (#2259). My local build works now running cargo fmt -- --unstable features if I set CFG_RELEASE_CHANNEL to "nightly". I also cannot get the rustup run nightly cargo fmt -- --unstable-features command to work.

This is quite a thing to find! Since I have everything defaulting to nightly, CFG_RELEASE_CHANNEL is never set. I guess for now we should just recompile rustfmt setting CFG_RELEASE_CHANNEL manually?

@YaLTeR @Eijebong @CraZySacX @daboross

I updated the OP here such that it should be clearer what the situation is here.

The TL;DR of it is that on 0.2.17 (current crates.io version), you need to set the environment variable CFG_RELEASE_CHANNEL to nightly. Then, you can either cargo +nightly fmt -- --unstable-features or just set unstable_features=true in your rustfmt.toml and cargo +nightly fmt.

Once a new build is published, you will no longer need to set CFG_RELEASE_CHANNEL at runtime, and it will be a compile time check. If #2249 is merged, you will be able to set unstable features when building with cargo, and if not, CFG_RELEASE_CHANNEL will need to be set when building rustfmt in order to enable unstable features.

IMHO, @nrc, we should yank 0.2.17 (since it had breaking changes, disabling configuration options), merge #2249 ASAP, and publish a new build as 0.3.0.

OK #2249 is merged and I've released 0.3.0 with the change. Hopefully things should be fixed with that. I'm not sure about yanking 0.2.17, it is pretty broken, but only if you're using unstable options, which should obviously have a weaker 'breaking changes' guarantee.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Diggsey picture Diggsey  路  4Comments

gnzlbg picture gnzlbg  路  3Comments

tkilbourn picture tkilbourn  路  5Comments

scampi picture scampi  路  4Comments

cramertj picture cramertj  路  4Comments