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 {}