diff --git a/src/items.rs b/src/items.rs index 9f079f15c151..b5e38c58267e 100644 --- a/src/items.rs +++ b/src/items.rs @@ -828,6 +828,7 @@ fn format_impl_ref_and_type( unsafety, polarity, defaultness, + constness, ref generics, of_trait: ref trait_ref, ref self_ty, @@ -851,6 +852,7 @@ fn format_impl_ref_and_type( }; let generics_str = rewrite_generics(context, "impl", generics, shape)?; result.push_str(&generics_str); + result.push_str(format_constness_right(constness)); let polarity_str = match polarity { ast::ImplPolarity::Negative(_) => "!", diff --git a/src/utils.rs b/src/utils.rs index bd419b2998ba..a3d0ed050e3f 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -100,6 +100,14 @@ 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/tests/source/impls.rs b/tests/source/impls.rs index fde7ad6d017d..fb8701989fa1 100644 --- a/tests/source/impls.rs +++ b/tests/source/impls.rs @@ -160,3 +160,11 @@ impl<'a, 'b, 'c> SomeThing for (&'a mut SomethingLong, &'b mut Someth // #2746 impl<'seq1, 'seq2, 'body, 'scope, Channel> Adc12< Dual, MasterRunningDma<'seq1, 'body, 'scope, Channel>, SlaveRunningDma<'seq2, 'body, 'scope>, > where Channel: DmaChannel, {} + +// #4084 +impl const std::default::Default for Struct { + #[inline] + fn default() -> Self { + Self { f: 12.5 } + } +} diff --git a/tests/target/impls.rs b/tests/target/impls.rs index 0777a7ed2498..bf63f924a33b 100644 --- a/tests/target/impls.rs +++ b/tests/target/impls.rs @@ -234,3 +234,11 @@ where Channel: DmaChannel, { } + +// #4084 +impl const std::default::Default for Struct { + #[inline] + fn default() -> Self { + Self { f: 12.5 } + } +}