Skip to content

Commit 2695846

Browse files
ayazhafizcalebcartwright
authored andcommitted
Include constness in impl blocks (rust-lang#4215)
Closes rust-lang#4084
1 parent 17bad2b commit 2695846

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

src/items.rs

+2
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,7 @@ fn format_impl_ref_and_type(
828828
unsafety,
829829
polarity,
830830
defaultness,
831+
constness,
831832
ref generics,
832833
of_trait: ref trait_ref,
833834
ref self_ty,
@@ -851,6 +852,7 @@ fn format_impl_ref_and_type(
851852
};
852853
let generics_str = rewrite_generics(context, "impl", generics, shape)?;
853854
result.push_str(&generics_str);
855+
result.push_str(format_constness_right(constness));
854856

855857
let polarity_str = match polarity {
856858
ast::ImplPolarity::Negative(_) => "!",

src/utils.rs

+8
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ pub(crate) fn format_constness(constness: ast::Const) -> &'static str {
100100
}
101101
}
102102

103+
#[inline]
104+
pub(crate) fn format_constness_right(constness: ast::Const) -> &'static str {
105+
match constness {
106+
ast::Const::Yes(..) => " const",
107+
ast::Const::No => "",
108+
}
109+
}
110+
103111
#[inline]
104112
pub(crate) fn format_defaultness(defaultness: ast::Defaultness) -> &'static str {
105113
match defaultness {

tests/source/impls.rs

+8
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,11 @@ impl<'a, 'b, 'c> SomeThing<Something> for (&'a mut SomethingLong, &'b mut Someth
160160

161161
// #2746
162162
impl<'seq1, 'seq2, 'body, 'scope, Channel> Adc12< Dual, MasterRunningDma<'seq1, 'body, 'scope, Channel>, SlaveRunningDma<'seq2, 'body, 'scope>, > where Channel: DmaChannel, {}
163+
164+
// #4084
165+
impl const std::default::Default for Struct {
166+
#[inline]
167+
fn default() -> Self {
168+
Self { f: 12.5 }
169+
}
170+
}

tests/target/impls.rs

+8
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,11 @@ where
234234
Channel: DmaChannel,
235235
{
236236
}
237+
238+
// #4084
239+
impl const std::default::Default for Struct {
240+
#[inline]
241+
fn default() -> Self {
242+
Self { f: 12.5 }
243+
}
244+
}

0 commit comments

Comments
 (0)