rust-lang / rustfmt

Format Rust code
https://rust-lang.github.io/rustfmt/
Apache License 2.0
6.05k stars 888 forks source link

--print-config current with use_small_heuristics = "Off": Could not output config: out-of-range value for u64 type #6364

Open antifuchs opened 1 month ago

antifuchs commented 1 month ago

I'm attempting to detect whether a project has unstable rustfmt features configured, and was hoping to use rustfmt to detect that. However, with a config file like:

edition = "2021"

condense_wildcard_suffixes = true
error_on_line_overflow = true
format_code_in_doc_comments = true
format_macro_bodies = true
format_macro_matchers = true
format_strings = true
group_imports = "StdExternalCrate"
hex_literal_case = "Upper"
imports_granularity = "Crate"
max_width = 80
newline_style = "Unix"
reorder_impl_items = true
use_field_init_shorthand = true
use_small_heuristics = "Off"
use_try_shorthand = true
wrap_comments = true

running the following only prints an error:

:;    rustfmt +nightly --print-config current main.rs
Could not output config: out-of-range value for u64 type

I would expect that config file to re-serialize correctly, as the formatter does do the work according to the config.

ytmimi commented 1 month ago

@antifuchs thanks for the report. What version of rustfmt are you using? Also, are all of these configs relevant to reproduce the error? Can you make the reproducible test case smaller?

antifuchs commented 1 month ago

This happens on both rustfmt 1.7.1-stable (eeb90cda 2024-09-04) and rustfmt 1.8.0-nightly (9ff5fc4ffb 2024-10-03).

I've reduced the config file that triggers that issue to the following:

use_small_heuristics = "Off"

Only Off triggers this, both Default and Max values result in correctly-written config. I'll adjust the issue title.