https://gcc.gnu.org/g:504df471315374cba7b05d9eb2772809076d96f7
commit r17-4125-g504df471315374cba7b05d9eb2772809076d96f7 Author: Owen Avery <[email protected]> Date: Sun Aug 16 17:37:05 2026 -0400 gccrs: Add rust_debug_fmt This should allow the use of gcc diagnostic format specifiers in debug diagnostics, in exchange for stricter diagnostic quality checks. gcc/rust/ChangeLog: * rust-diagnostics.cc (rust_debug_fmt_at): New function definition. * rust-diagnostics.h (rust_debug_fmt): New function-like macro definition. (rust_debug_fmt_at): New function declaration. Signed-off-by: Owen Avery <[email protected]> Diff: --- gcc/rust/rust-diagnostics.cc | 13 +++++++++++++ gcc/rust/rust-diagnostics.h | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/gcc/rust/rust-diagnostics.cc b/gcc/rust/rust-diagnostics.cc index a87369c08cae..498805acc3e1 100644 --- a/gcc/rust/rust-diagnostics.cc +++ b/gcc/rust/rust-diagnostics.cc @@ -420,6 +420,19 @@ rust_debug_loc (const location_t location, const char *fmt, ...) rust_be_inform (location, rval); } +void +rust_debug_fmt_at (const location_t location, const char *fmt, ...) +{ + if (!rust_be_debug_p ()) + return; + + va_list ap; + + va_start (ap, fmt); + rust_be_inform (location, expand_message (fmt, ap)); + va_end (ap); +} + namespace Rust { /** diff --git a/gcc/rust/rust-diagnostics.h b/gcc/rust/rust-diagnostics.h index 76d784f58721..7fe2596e8d14 100644 --- a/gcc/rust/rust-diagnostics.h +++ b/gcc/rust/rust-diagnostics.h @@ -307,4 +307,10 @@ struct Error void rust_debug_loc (const location_t location, const char *fmt, ...) ATTRIBUTE_PRINTF_2; +// like rust_debug, but has gcc diagnostic formatting +#define rust_debug_fmt(...) rust_debug_fmt_at (UNDEF_LOCATION, __VA_ARGS__) + +void rust_debug_fmt_at (location_t location, const char *fmt, ...) + RUST_ATTRIBUTE_GCC_DIAG (2, 3); + #endif // !defined(RUST_DIAGNOSTICS_H)
