rustrustfmt

Why do I get 'unstable features are only available in nightly channel' when running rustfmt?


I have just updated my Rust to rustc 1.63.0 (4b91a6ea7 2022-08-08)

In my .rustfmt.toml file

# Basic
hard_tabs = true
max_width = 100
use_small_heuristics = "Max"

# Imports
imports_granularity = "Crate"
reorder_imports = true

# Consistency
newline_style = "Unix"

# Misc
binop_separator = "Back"
chain_width = 80
match_arm_blocks = false
match_arm_leading_pipes = "Preserve"
match_block_trailing_comma = true
reorder_impl_items = false
spaces_around_ranges = false
trailing_comma = "Vertical"
trailing_semicolon = false
use_field_init_shorthand = true

To install rustfmt via Rust nightly toolchain

rustup toolchain add nightly && rustup component add rustfmt --toolchain nightly

I got nightly-x86_64-unknown-linux-gnu unchanged - rustc 1.65.0-nightly (015a824f2 2022-08-22)

Then to run rustfmt to check my code format...

cargo +nightly fmt
cargo fmt --check

I got a bunch of warnings!

Warning: can't set `imports_granularity = Crate`, unstable features are only available in nightly channel.
Warning: can't set `reorder_impl_items = false`, unstable features are only available in nightly channel.
Warning: can't set `spaces_around_ranges = false`, unstable features are only available in nightly channel.
Warning: can't set `binop_separator = Back`, unstable features are only available in nightly channel.
Warning: can't set `match_arm_blocks = false`, unstable features are only available in nightly channel.
Warning: can't set `trailing_semicolon = false`, unstable features are only available in nightly channel.
Warning: can't set `trailing_comma = Vertical`, unstable features are only available in nightly channel.

how can I solve these warnings? what is missing in my rustfmt.toml ?


Solution

  • Use the nightly toolchain explicitly for each cargo fmt call:

    cargo +nightly fmt --check