From 6bf9f0c5a2a6e203e8fd512337291ed079923af7 Mon Sep 17 00:00:00 2001 From: Matthew Hughes Date: Sun, 15 Feb 2026 13:44:17 +0000 Subject: [PATCH 1/4] Update docs for `Session.format` To stop referencing parameters `out` and `config` that were both moved into the `Session` object with 71d3d04270474ae0afdeeb410fdcc168a54714b7 --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index d3379a4564b..70e488a4d39 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -461,7 +461,7 @@ impl<'b, T: Write + 'b> Session<'b, T> { } /// The main entry point for Rustfmt. Formats the given input according to the - /// given config. `out` is only necessary if required by the configuration. + /// session's config. pub fn format(&mut self, input: Input) -> Result { self.format_input_inner(input, false) } From c6e73cbf3310f0984bad070b481ed0b94f4c8ccf Mon Sep 17 00:00:00 2001 From: Matthew Hughes Date: Sun, 15 Feb 2026 13:46:12 +0000 Subject: [PATCH 2/4] Move stray `imports_granularity` test Move this to be with all the other tests for this config option --- tests/source/{ => imports}/imports_granularity_one.rs | 0 tests/target/{ => imports}/imports_granularity_one.rs | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename tests/source/{ => imports}/imports_granularity_one.rs (100%) rename tests/target/{ => imports}/imports_granularity_one.rs (100%) diff --git a/tests/source/imports_granularity_one.rs b/tests/source/imports/imports_granularity_one.rs similarity index 100% rename from tests/source/imports_granularity_one.rs rename to tests/source/imports/imports_granularity_one.rs diff --git a/tests/target/imports_granularity_one.rs b/tests/target/imports/imports_granularity_one.rs similarity index 100% rename from tests/target/imports_granularity_one.rs rename to tests/target/imports/imports_granularity_one.rs From a26a137378f414dc6009a61b73a2ff51673b8b7c Mon Sep 17 00:00:00 2001 From: Matthew Hughes Date: Sun, 15 Feb 2026 21:36:12 +0000 Subject: [PATCH 3/4] Silence expected parser errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I find otherwise the test output can be a bit noisy, and in particular the error messages make me think some test somewhere failed when even when it's all passing, for example, one such removed error: error: mismatched closing delimiter: `}` --> tests/parser/unclosed-delims/issue_4466.rs:3:17 | 2 | if true { | - closing delimiter possibly meant for this 3 | println!("answer: {}", a_func(); | ^ unclosed delimiter 4 | } else { | ^ mismatched closing delimiter This also removes some noisy warnings like: warning: whitespace symbol '\u{a0}' is not skipped --> tests/target/string_lit_unicode_ws.rs:3:22 | 3 | let str = "hello \ | ______________________^ 4 | |  world"; | | ^ whitespace symbol '\u{a0}' is not skipped | |_| | --- src/test/mod.rs | 4 +++- tests/parser/issue-4126/lib.rs | 2 ++ tests/parser/issue_4418.rs | 4 +++- tests/parser/stashed-diag.rs | 2 ++ tests/parser/stashed-diag2.rs | 2 ++ tests/parser/unclosed-delims/issue_4466.rs | 4 +++- tests/source/string_lit_unicode_ws.rs | 2 ++ tests/target/string_lit_unicode_ws.rs | 2 ++ 8 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/test/mod.rs b/src/test/mod.rs index 20193df5a7c..eca9e761f59 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -587,7 +587,9 @@ fn stdin_parser_panic_caught() { // See issue #3239. for text in ["{", "}"].iter().cloned().map(String::from) { let mut buf = vec![]; - let mut session = Session::new(Default::default(), Some(&mut buf)); + let mut config = Config::default(); + config.set().show_parse_errors(false); + let mut session = Session::new(config, Some(&mut buf)); let _ = session.format(Input::Text(text)); assert!(session.has_parsing_errors()); diff --git a/tests/parser/issue-4126/lib.rs b/tests/parser/issue-4126/lib.rs index aac63e3557f..68b904cd316 100644 --- a/tests/parser/issue-4126/lib.rs +++ b/tests/parser/issue-4126/lib.rs @@ -1 +1,3 @@ +// rustfmt-show_parse_errors: false + mod invalid; diff --git a/tests/parser/issue_4418.rs b/tests/parser/issue_4418.rs index ff30235f076..ed148f84e46 100644 --- a/tests/parser/issue_4418.rs +++ b/tests/parser/issue_4418.rs @@ -1 +1,3 @@ -} \ No newline at end of file +// rustfmt-show_parse_errors: false + +} diff --git a/tests/parser/stashed-diag.rs b/tests/parser/stashed-diag.rs index 3b0b543e610..836e25658c3 100644 --- a/tests/parser/stashed-diag.rs +++ b/tests/parser/stashed-diag.rs @@ -1,3 +1,5 @@ +// rustfmt-show_parse_errors: false + #![u={static N;}] fn main() {} diff --git a/tests/parser/stashed-diag2.rs b/tests/parser/stashed-diag2.rs index 579a69def16..1fe6802d35b 100644 --- a/tests/parser/stashed-diag2.rs +++ b/tests/parser/stashed-diag2.rs @@ -1,3 +1,5 @@ +// rustfmt-show_parse_errors: false + trait Trait<'1> { s> {} fn main() {} diff --git a/tests/parser/unclosed-delims/issue_4466.rs b/tests/parser/unclosed-delims/issue_4466.rs index 2c2c81c91d1..452a0c1d3aa 100644 --- a/tests/parser/unclosed-delims/issue_4466.rs +++ b/tests/parser/unclosed-delims/issue_4466.rs @@ -1,3 +1,5 @@ +// rustfmt-show_parse_errors: false + fn main() { if true { println!("answer: {}", a_func(); @@ -8,4 +10,4 @@ fn main() { fn a_func() -> i32 { 42 -} \ No newline at end of file +} diff --git a/tests/source/string_lit_unicode_ws.rs b/tests/source/string_lit_unicode_ws.rs index f944711e14f..fff135fbc4f 100644 --- a/tests/source/string_lit_unicode_ws.rs +++ b/tests/source/string_lit_unicode_ws.rs @@ -1,3 +1,5 @@ +// rustfmt-show_parse_errors: false + // Test Unicode whitespace characters in string literal line continuation fn main() { let str = "hello \ diff --git a/tests/target/string_lit_unicode_ws.rs b/tests/target/string_lit_unicode_ws.rs index f944711e14f..fff135fbc4f 100644 --- a/tests/target/string_lit_unicode_ws.rs +++ b/tests/target/string_lit_unicode_ws.rs @@ -1,3 +1,5 @@ +// rustfmt-show_parse_errors: false + // Test Unicode whitespace characters in string literal line continuation fn main() { let str = "hello \ From 153f93d5f30ad4cddd11102477e14a0b8df358d1 Mon Sep 17 00:00:00 2001 From: Matthew Hughes Date: Sat, 7 Mar 2026 19:28:02 +0000 Subject: [PATCH 4/4] Remove warning on explicit default config value in tests This was added with f7a25a1177c86541071932a9e578819c7ae33d5a, this was to address an issue with the worthy goal[1]: > It is probably worth auditing the tests and where they are not deliberately testing an option, removing any options they set. However, given the number of warnings this produces: $ cargo test -- --nocapture |& grep -c 'Default value.*used explicitly' 236 I think this approach did not work, one could enforce this approach by changing this to be an error, but I think there are valid cases to use defaults, e.g. a reproduction of an issue relating to line length uses the default `max_width`: it's simplest to add a test verifying the behaviour with an explicit `max_width: 100` rather than adjusting the reproduction. Link: https://github.com/rust-lang/rustfmt/issues/1720 [1] --- src/test/mod.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/test/mod.rs b/src/test/mod.rs index eca9e761f59..69d773a2567 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -19,7 +19,7 @@ use crate::{ }; use rustfmt_config_proc_macro::nightly_only_test; -use tracing::{debug, warn}; +use tracing::debug; mod configuration_snippet; mod mod_resolver; @@ -829,9 +829,6 @@ fn read_config(filename: &Path) -> Config { for (key, val) in &sig_comments { if key != "target" && key != "config" && key != "unstable" { config.override_value(key, val); - if config.is_default(key) { - warn!("Default value {} used explicitly for {}", val, key); - } } }