From cf8d0c82dc2e3de67d29a09389dbf035c5723c57 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Wed, 24 Dec 2025 14:42:14 -0500 Subject: [PATCH] fix rustfmt on `const impl Ty {}` --- src/tools/rustfmt/src/items.rs | 2 +- src/tools/rustfmt/tests/source/const_trait.rs | 14 ++++++++++++++ src/tools/rustfmt/tests/target/const_trait.rs | 9 +++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 src/tools/rustfmt/tests/source/const_trait.rs diff --git a/src/tools/rustfmt/src/items.rs b/src/tools/rustfmt/src/items.rs index d1778f324c6aa..c9e32492c50b0 100644 --- a/src/tools/rustfmt/src/items.rs +++ b/src/tools/rustfmt/src/items.rs @@ -971,7 +971,7 @@ fn format_impl_ref_and_type( result.push_str(format_defaultness(of_trait.defaultness)); result.push_str(format_safety(of_trait.safety)); } else { - result.push_str(format_constness_right(*constness)); + result.push_str(format_constness(*constness)); } let shape = if context.config.style_edition() >= StyleEdition::Edition2024 { diff --git a/src/tools/rustfmt/tests/source/const_trait.rs b/src/tools/rustfmt/tests/source/const_trait.rs new file mode 100644 index 0000000000000..99414a74f250c --- /dev/null +++ b/src/tools/rustfmt/tests/source/const_trait.rs @@ -0,0 +1,14 @@ +#![feature(trait_alias, const_trait_impl)] + +const trait Bar {} + +const trait Foo = Bar; + +impl const Bar for () {} + +// const impl gets reformatted to impl const.. for now +const impl Bar for u8 {} + +struct X; + +const impl X {} diff --git a/src/tools/rustfmt/tests/target/const_trait.rs b/src/tools/rustfmt/tests/target/const_trait.rs index c4c88b17fc500..337a4cf4140e8 100644 --- a/src/tools/rustfmt/tests/target/const_trait.rs +++ b/src/tools/rustfmt/tests/target/const_trait.rs @@ -3,3 +3,12 @@ const trait Bar {} const trait Foo = Bar; + +impl const Bar for () {} + +// const impl gets reformatted to impl const.. for now +impl const Bar for u8 {} + +struct X; + +const impl X {}