Skip to content

Improve error for nightly-only '--message-format' args#6780

Merged
ytmimi merged 1 commit intorust-lang:mainfrom
matthewhughes934:fix-json-format-error
Apr 29, 2026
Merged

Improve error for nightly-only '--message-format' args#6780
ytmimi merged 1 commit intorust-lang:mainfrom
matthewhughes934:fix-json-format-error

Conversation

@matthewhughes934
Copy link
Copy Markdown
Contributor

@matthewhughes934 matthewhughes934 commented Jan 25, 2026

Previously on a stable build (json is only supported in nightly builds):

$ cargo fmt --message-format json
Invalid value for `--emit` - using an unstable value without `--unstable-features`

With this change:

$ CFG_RELEASE_CHANNEL=stable cargo make bin-build
$ PATH="./target/debug:$PATH" cargo fmt --message-format json
--message-format json is only supported in nightly builds
This utility formats all bin and lib files of the current crate using rustfmt.
<-- SNIP: the rest of the usage follows -->

This behaviour is similar to how args to --emit are handled in rustfmt.

This change also drops displaying json as an option to --message-format on stable builds:

$ PATH="./target/debug:$PATH" cargo fmt --help | grep --max-count 1 --after-context 1 message-format
    --message-format <message-format>
        Specify message-format: short|human

This required rewriting the check for nightly builds (copying from the one in src/release_channel.rs) to be const so I could rewrite the --message-format flag's help string.

Fixes #6752

@rustbot rustbot added the S-waiting-on-review Status: awaiting review from the assignee but also interested parties. label Jan 25, 2026
@jieyouxu jieyouxu added the A-cargo-fmt Area: cargo-fmt label Feb 20, 2026
Previously on a stable build (`json` is only supported in `nightly`
builds):

    $ cargo fmt --message-format json
    Invalid value for `--emit` - using an unstable value without `--unstable-features`

With this change:

    $ CFG_RELEASE_CHANNEL=stable cargo make bin-build
    $ PATH="./target/debug:$PATH" cargo fmt --message-format json
    --message-format json is only supported in nightly builds
    This utility formats all bin and lib files of the current crate using rustfmt.
    <-- SNIP: the rest of the usage follows -->

This behaviour is similar to how args to `--emit` are handled in
`rustfmt`.

This change also drops displaying `json` as an option to
`--message-format` on stable builds:

    $ PATH="./target/debug:$PATH" cargo fmt --help | grep --max-count 1 --after-context 1 message-format
        --message-format <message-format>
            Specify message-format: short|human

This required rewriting the check for nightly builds (copying from the
one in `src/release_channel.rs`) to be `const` so I could rewrite the
`--message-format` flag's help string.

Issue: rust-lang#6752
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Feb 25, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

Copy link
Copy Markdown
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. The fix itself seems reasonable to me , just have a question for other maintainers.

View changes since this review

Comment thread src/cargo-fmt/main.rs
Comment thread src/cargo-fmt/main.rs
@jieyouxu jieyouxu added pr-ready-to-merge Status: PR is largely ready for merge, waiting for secondary review / last nits release-notes Needs an associated changelog entry labels Mar 1, 2026
Copy link
Copy Markdown
Contributor

@ytmimi ytmimi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jieyouxu thanks for taking a look and thank you @matthewhughes934 for working on this.

View changes since this review

@ytmimi ytmimi merged commit 5042b96 into rust-lang:main Apr 29, 2026
26 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: awaiting review from the assignee but also interested parties. label Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cargo-fmt Area: cargo-fmt pr-ready-to-merge Status: PR is largely ready for merge, waiting for secondary review / last nits release-notes Needs an associated changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cargo fmt --message-format json error is hard to understand (on stable).

4 participants