Generally when I write a manual Debug implementation, I almost always destructure self so I know to update the implementation when I add/remove/rename fields. I think when rust-analyzer generates a manual Debug implementation, it should always do that or at least have an option to make it always do that.
This came up on Zulip here.
So, to be clear, I don't want it to destructure self in the function argument if that becomes a feature, instead it should generate code like:
struct MyStruct<T: ?Sized> {
field1: Foo,
field2: Bar,
field3: Baz,
field4: T,
}
impl<T: ?Sized + fmt::Debug> fmt::Debug for MyStruct<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let Self {
field1,
field2,
field3,
field4,
} = self;
f.debug_struct("MyStruct")
.field("field1", field1)
.field("field2", field2)
.field("field3", field3)
.field("field4", &field4) // reference needed since T: ?Sized
.finish()
}
}
Generally when I write a manual
Debugimplementation, I almost always destructureselfso I know to update the implementation when I add/remove/rename fields. I think when rust-analyzer generates a manualDebugimplementation, it should always do that or at least have an option to make it always do that.This came up on Zulip here.
So, to be clear, I don't want it to destructure self in the function argument if that becomes a feature, instead it should generate code like: