Skip to content

Commit

Permalink
Include constness in impl blocks (rust-lang#4215)
Browse files Browse the repository at this point in the history
  • Loading branch information
ayazhafiz authored and calebcartwright committed Jan 27, 2021
1 parent 17bad2b commit f49e199
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,7 @@ fn format_impl_ref_and_type(
unsafety,
polarity,
defaultness,
constness,
ref generics,
of_trait: ref trait_ref,
ref self_ty,
Expand All @@ -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(_) => "!",
Expand Down
8 changes: 8 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions tests/source/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
}
8 changes: 8 additions & 0 deletions tests/target/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,11 @@ where
Channel: DmaChannel,
{
}

// #4084
impl const std::default::Default for Struct {
#[inline]
fn default() -> Self {
Self { f: 12.5 }
}
}

0 comments on commit f49e199

Please sign in to comment.