Closed
Description
For example, this is valid / working code on nightly:
#![allow(incomplete_features)]
#![feature(const_trait_impl)]
#[derive(Debug)]
struct Struct {
f: f32,
}
impl const std::default::Default for Struct {
#[inline]
fn default() -> Self {
Self { f: 12.5 }
}
}
const S: Struct = Default::default();
fn main() {
println!("{:?}", S);
}
However, if you run rustfmt
, it will not error but simply quietly delete the word const
between impl
and std::default
. This isn't great when using rustfmt
at the crate level as it will of course delete all instances of const
for trait impls, most likely breaking the build (and causing you to have to add them all back in).
The deletion seems like odd behavior in general, IMO: I'd expect rustfmt
to give a hard error on syntax it thinks is legitimately invalid (as it usually does), and just do its best to normally format anything else.