diff options
| author | hafiz <20735482+ayazhafiz@users.noreply.github.com> | 2020-05-31 03:36:08 -0500 |
|---|---|---|
| committer | Caleb Cartwright <calebcartwright@users.noreply.github.com> | 2021-01-27 18:50:03 -0600 |
| commit | 269584634a7657d1026cee2db1c38d75cebbbd31 (patch) | |
| tree | 47b3f2f061f724ea85bc18678a7c4265b29bdf8d | |
| parent | 17bad2b3c0e4a11968d47b91857f793f404aeb70 (diff) | |
| download | rust-269584634a7657d1026cee2db1c38d75cebbbd31.tar.gz rust-269584634a7657d1026cee2db1c38d75cebbbd31.zip | |
Include constness in impl blocks (#4215)
Closes #4084
| -rw-r--r-- | src/items.rs | 2 | ||||
| -rw-r--r-- | src/utils.rs | 8 | ||||
| -rw-r--r-- | tests/source/impls.rs | 8 | ||||
| -rw-r--r-- | tests/target/impls.rs | 8 |
4 files changed, 26 insertions, 0 deletions
diff --git a/src/items.rs b/src/items.rs index 9f079f15c15..b5e38c58267 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 bd419b2998b..a3d0ed050e3 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -101,6 +101,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 { ast::Defaultness::Default(..) => "default ", diff --git a/tests/source/impls.rs b/tests/source/impls.rs index fde7ad6d017..fb8701989fa 100644 --- a/tests/source/impls.rs +++ b/tests/source/impls.rs @@ -160,3 +160,11 @@ impl<'a, 'b, 'c> SomeThing<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 0777a7ed249..bf63f924a33 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 } + } +} |
