From adddae65368c28d36c4202458aa9bf387c5a6d06 Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Wed, 27 Aug 2025 06:06:11 +0900 Subject: [PATCH 1/2] stop returning errors when format foreign has trailing dollar --- .../rustc_builtin_macros/src/format_foreign.rs | 2 +- .../macros/format-foreign-dollar-without-spec.rs | 4 ++++ .../format-foreign-dollar-without-spec.stderr | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 tests/ui/macros/format-foreign-dollar-without-spec.rs create mode 100644 tests/ui/macros/format-foreign-dollar-without-spec.stderr diff --git a/compiler/rustc_builtin_macros/src/format_foreign.rs b/compiler/rustc_builtin_macros/src/format_foreign.rs index 3e5a26c055689..cf563a53973ca 100644 --- a/compiler/rustc_builtin_macros/src/format_foreign.rs +++ b/compiler/rustc_builtin_macros/src/format_foreign.rs @@ -416,7 +416,7 @@ pub(crate) mod printf { // Yes, this *is* the parameter. Some(('$', end2)) => { state = Flags; - parameter = Some(at.slice_between(end).unwrap().parse().unwrap()); + parameter = at.slice_between(end).unwrap().parse().ok(); move_to!(end2); } // Wait, no, actually, it's the width. diff --git a/tests/ui/macros/format-foreign-dollar-without-spec.rs b/tests/ui/macros/format-foreign-dollar-without-spec.rs new file mode 100644 index 0000000000000..3e6a833e24a7f --- /dev/null +++ b/tests/ui/macros/format-foreign-dollar-without-spec.rs @@ -0,0 +1,4 @@ +fn main() { + println!("%65536$", 1); + //~^ ERROR never used +} diff --git a/tests/ui/macros/format-foreign-dollar-without-spec.stderr b/tests/ui/macros/format-foreign-dollar-without-spec.stderr new file mode 100644 index 0000000000000..a20c34a1f85dd --- /dev/null +++ b/tests/ui/macros/format-foreign-dollar-without-spec.stderr @@ -0,0 +1,16 @@ +error: argument never used + --> $DIR/format-foreign-dollar-without-spec.rs:2:25 + | +LL | println!("%65536$", 1); + | ^ argument never used + | +note: format specifiers use curly braces, and the conversion specifier ` + ` is unknown or unsupported + --> $DIR/format-foreign-dollar-without-spec.rs:2:15 + | +LL | println!("%65536$", 1); + | ^^^^^^^^ + = note: printf formatting is not supported; see the documentation for `std::fmt` + +error: aborting due to 1 previous error + From 2c361f826756fa9c14e611c01b6f6717ecbd19f2 Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Wed, 27 Aug 2025 14:39:33 +0900 Subject: [PATCH 2/2] remove old crash test --- tests/crashes/137580.rs | 4 ---- tests/ui/macros/format-foreign-dollar-without-spec.rs | 1 + tests/ui/macros/format-foreign-dollar-without-spec.stderr | 4 ++-- 3 files changed, 3 insertions(+), 6 deletions(-) delete mode 100644 tests/crashes/137580.rs diff --git a/tests/crashes/137580.rs b/tests/crashes/137580.rs deleted file mode 100644 index 246c80ef5560f..0000000000000 --- a/tests/crashes/137580.rs +++ /dev/null @@ -1,4 +0,0 @@ -//@ known-bug: #137580 -fn main() { - println!("%65536$", 1); -} diff --git a/tests/ui/macros/format-foreign-dollar-without-spec.rs b/tests/ui/macros/format-foreign-dollar-without-spec.rs index 3e6a833e24a7f..c57c1382c8dda 100644 --- a/tests/ui/macros/format-foreign-dollar-without-spec.rs +++ b/tests/ui/macros/format-foreign-dollar-without-spec.rs @@ -1,3 +1,4 @@ +// https://github.com/rust-lang/rust/issues/137580 fn main() { println!("%65536$", 1); //~^ ERROR never used diff --git a/tests/ui/macros/format-foreign-dollar-without-spec.stderr b/tests/ui/macros/format-foreign-dollar-without-spec.stderr index a20c34a1f85dd..d5a07c50f00d0 100644 --- a/tests/ui/macros/format-foreign-dollar-without-spec.stderr +++ b/tests/ui/macros/format-foreign-dollar-without-spec.stderr @@ -1,12 +1,12 @@ error: argument never used - --> $DIR/format-foreign-dollar-without-spec.rs:2:25 + --> $DIR/format-foreign-dollar-without-spec.rs:3:25 | LL | println!("%65536$", 1); | ^ argument never used | note: format specifiers use curly braces, and the conversion specifier ` ` is unknown or unsupported - --> $DIR/format-foreign-dollar-without-spec.rs:2:15 + --> $DIR/format-foreign-dollar-without-spec.rs:3:15 | LL | println!("%65536$", 1); | ^^^^^^^^