blob: 5664a2b0b31403024ce5ab927760d630d5ddc9a4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
tree c460fe4d703963cc82b888704532ea2022ec96cb
parent 044d99e162bd8c1780b5288e0e5cf13fc0bdac51
parent 59cdb51ef3865582588f2735dc5479e9c205ddb6
author bors[bot] <26634292+bors[bot]@users.noreply.github.com> 1628461837 +0000
committer GitHub <noreply@github.com> 1628461837 +0000
gpgsig -----BEGIN PGP SIGNATURE-----
wsBcBAABCAAQBQJhEFsNCRBK7hj4Ov3rIwAA9D8IAEimYPX6H9Eg9RGMUt5pPAZY
Ok9M2kc0FbOyzG2kLjWNtUJzC8w4XRK0UkEm+1CFp7oAPUMHiPMWZC+JD2SSNYhX
Ic5cDuQBD6KQIfjPxXrAZd3+kKGz7+CQgZcFgaURccuaGtQS1CyV8seA5H6JA2Tz
/fy5Jk1CDKubfVkNX/mNahSLw3M8wJinVEk0y+fPrG/PedCFcil7b7/zxgeJE3iP
nDjQzAiPCfu4BJYrjHMAabI5S5LWSwN0X6TFPKhgh3IKtACPXHbqp80CqehKoyFa
Mc7Bxhp1qa4qSn+D7nEoZjwAeMJNkSVo85wjpZiN8mPdS4DIWPItR/JXasDAgfQ=
=uOLD
-----END PGP SIGNATURE-----
Merge #9814
9814: Generate default impl when converting `#[derive(Debug)]` to manual impl r=yoshuawuyts a=yoshuawuyts
This patch makes it so when you convert `#[derive(Debug)]` to a manual impl, a default body is provided that's equivalent to the original output of `#[derive(Debug)]`. This should make it drastically easier to write custom `Debug` impls, especially when all you want to do is quickly omit a single field which is `!Debug`.
This is implemented for enums, record structs, tuple structs, empty structs - and it sets us up to implement variations on this in the future for other traits (like `PartialEq` and `Hash`).
Thanks!
## Codegen diff
This is the difference in codegen for record structs with this patch:
```diff
struct Foo {
bar: String,
}
impl fmt::Debug for Foo {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- todo!();
+ f.debug_struct("Foo").field("bar", &self.bar).finish()
}
}
```
Co-authored-by: Irina Shestak <shestak.irina@gmail.com>
Co-authored-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
Co-authored-by: Yoshua Wuyts <yoshuawuyts+github@gmail.com>
|