diff --git a/src/tools/rustfmt/src/items.rs b/src/tools/rustfmt/src/items.rs index 32f71703e019f..95b13eb4aac99 100644 --- a/src/tools/rustfmt/src/items.rs +++ b/src/tools/rustfmt/src/items.rs @@ -960,6 +960,7 @@ fn format_impl_ref_and_type( if let Some(of_trait) = of_trait.as_deref() { result.push_str(format_defaultness(of_trait.defaultness)); + result.push_str(format_constness(*constness)); result.push_str(format_safety(of_trait.safety)); } else { result.push_str(format_constness(*constness)); @@ -980,7 +981,6 @@ fn format_impl_ref_and_type( let trait_ref_overhead; if let Some(of_trait) = of_trait.as_deref() { - result.push_str(format_constness_right(*constness)); let polarity_str = match of_trait.polarity { ast::ImplPolarity::Negative(_) => "!", ast::ImplPolarity::Positive => "", diff --git a/src/tools/rustfmt/src/utils.rs b/src/tools/rustfmt/src/utils.rs index de72c9ce14bc3..6eb76c935a920 100644 --- a/src/tools/rustfmt/src/utils.rs +++ b/src/tools/rustfmt/src/utils.rs @@ -125,14 +125,6 @@ pub(crate) fn format_constness(constness: ast::Const) -> &'static str { } } -#[inline] -pub(crate) fn format_constness_right(constness: ast::Const) -> &'static str { - match constness { - ast::Const::Yes(..) => " const", - ast::Const::No => "", - } -} - #[inline] pub(crate) fn format_defaultness(defaultness: ast::Defaultness) -> &'static str { match defaultness { diff --git a/src/tools/rustfmt/tests/source/const_trait.rs b/src/tools/rustfmt/tests/source/const_trait.rs deleted file mode 100644 index 99414a74f250c..0000000000000 --- a/src/tools/rustfmt/tests/source/const_trait.rs +++ /dev/null @@ -1,14 +0,0 @@ -#![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 337a4cf4140e8..bb6ba1cd85b1d 100644 --- a/src/tools/rustfmt/tests/target/const_trait.rs +++ b/src/tools/rustfmt/tests/target/const_trait.rs @@ -4,10 +4,7 @@ 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 {} +const impl Bar for () {} struct X; diff --git a/src/tools/rustfmt/tests/target/impls.rs b/src/tools/rustfmt/tests/target/impls.rs index 99e02990e4177..71dfb5591e7ce 100644 --- a/src/tools/rustfmt/tests/target/impls.rs +++ b/src/tools/rustfmt/tests/target/impls.rs @@ -244,7 +244,7 @@ where } // #4084 -impl const std::default::Default for Struct { +const impl std::default::Default for Struct { #[inline] fn default() -> Self { Self { f: 12.5 } diff --git a/src/tools/rustfmt/tests/target/type.rs b/src/tools/rustfmt/tests/target/type.rs index 623192b72b8b7..4855f726ea3f9 100644 --- a/src/tools/rustfmt/tests/target/type.rs +++ b/src/tools/rustfmt/tests/target/type.rs @@ -153,7 +153,7 @@ const fn not_quite_const() -> i32 { ::CONST } -impl const T for U {} +const impl T for U {} fn apit(_: impl [const] T) {}