From 1aca8fa96cc498916fba912a2500d36a51593db5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20C=C3=A9spedes=20Tab=C3=A1rez?= <1295883+dertin@users.noreply.github.com> Date: Tue, 21 Jul 2026 16:26:13 -0300 Subject: [PATCH 1/2] Use formatting prefix for rustfmt errors --- src/bin/main.rs | 2 +- tests/rustfmt/main.rs | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/bin/main.rs b/src/bin/main.rs index 54b267bb445..6eaf709dab3 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -408,7 +408,7 @@ fn format_and_emit_report(session: &mut Session<'_, T>, input: Input) } } Err(msg) => { - eprintln!("Error writing files: {msg}"); + eprintln!("Error formatting files: {msg}"); session.add_operational_error(); } } diff --git a/tests/rustfmt/main.rs b/tests/rustfmt/main.rs index 4008c8d1435..3e91b040324 100644 --- a/tests/rustfmt/main.rs +++ b/tests/rustfmt/main.rs @@ -125,19 +125,22 @@ fn rustfmt_usage_text() { } #[test] -fn mod_resolution_error_multiple_candidate_files() { +fn check_mode_mod_resolution_error_uses_formatting_prefix() { // See also https://github.com/rust-lang/rustfmt/issues/5167 let default_path = Path::new("tests/mod-resolver/issue-5167/src/a.rs"); let secondary_path = Path::new("tests/mod-resolver/issue-5167/src/a/mod.rs"); let error_message = format!( - "file for module found at both {:?} and {:?}", + concat!( + "Error formatting files: failed to resolve mod `a`: ", + "file for module found at both {:?} and {:?}" + ), default_path.canonicalize().unwrap(), secondary_path.canonicalize().unwrap(), ); - let args = ["tests/mod-resolver/issue-5167/src/lib.rs"]; + let args = ["--check", "tests/mod-resolver/issue-5167/src/lib.rs"]; let (_stdout, stderr) = rustfmt(&args); - assert!(stderr.contains(&error_message)) + assert_eq!(stderr.trim(), error_message) } #[test] From 3b26500d7ca8fafdc71adbc4a9d9909439e0ff1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20C=C3=A9spedes=20Tab=C3=A1rez?= <1295883+dertin@users.noreply.github.com> Date: Tue, 21 Jul 2026 16:41:20 -0300 Subject: [PATCH 2/2] Make error prefix test tolerate warnings --- tests/rustfmt/main.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/rustfmt/main.rs b/tests/rustfmt/main.rs index 3e91b040324..b1ec556e2d9 100644 --- a/tests/rustfmt/main.rs +++ b/tests/rustfmt/main.rs @@ -125,22 +125,26 @@ fn rustfmt_usage_text() { } #[test] -fn check_mode_mod_resolution_error_uses_formatting_prefix() { +fn mod_resolution_error_multiple_candidate_files() { // See also https://github.com/rust-lang/rustfmt/issues/5167 let default_path = Path::new("tests/mod-resolver/issue-5167/src/a.rs"); let secondary_path = Path::new("tests/mod-resolver/issue-5167/src/a/mod.rs"); let error_message = format!( - concat!( - "Error formatting files: failed to resolve mod `a`: ", - "file for module found at both {:?} and {:?}" - ), + "file for module found at both {:?} and {:?}", default_path.canonicalize().unwrap(), secondary_path.canonicalize().unwrap(), ); + let args = ["tests/mod-resolver/issue-5167/src/lib.rs"]; + let (_stdout, stderr) = rustfmt(&args); + assert!(stderr.contains(&error_message)) +} + +#[test] +fn check_mode_error_uses_formatting_prefix() { let args = ["--check", "tests/mod-resolver/issue-5167/src/lib.rs"]; let (_stdout, stderr) = rustfmt(&args); - assert_eq!(stderr.trim(), error_message) + assert!(stderr.contains("Error formatting files:")) } #[test]