Skip to content

Commit 48817c6

Browse files
committed
Use automatically_derived for ::core::fmt::Debug implementations
1 parent 5e3d988 commit 48817c6

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

custom_debug_derive/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ fn custom_debug_derive(mut structure: Structure) -> Result<TokenStream> {
2525
structure.each_variant(|variant| generate_match_arm_body(variant).into_stream());
2626

2727
Ok(structure.gen_impl(quote! {
28+
#[automatically_derived]
2829
gen impl ::core::fmt::Debug for @Self {
2930
fn fmt(&self, fmt: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3031
match self {
@@ -108,17 +109,20 @@ fn generate_debug_impl(binding: &BindingInfo, debug_format: &DebugFormat) -> Tok
108109
DebugFormat::Format(format) => quote! { &format_args!(#format, #binding) },
109110
DebugFormat::With(with) => quote! {
110111
{
112+
#[automatically_derived]
111113
struct DebugWith<'a, T: 'a> {
112114
data: &'a T,
113115
fmt: fn(&T, &mut ::core::fmt::Formatter) -> ::core::fmt::Result,
114116
}
115117

118+
#[automatically_derived]
116119
impl<'a, T: 'a> ::core::fmt::Debug for DebugWith<'a, T> {
117120
fn fmt(&self, fmt: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
118121
(self.fmt)(self.data, fmt)
119122
}
120123
}
121124

125+
#[automatically_derived]
122126
&DebugWith {
123127
data: #binding,
124128
fmt: #with,

custom_debug_derive/src/tests.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ fn test_default_struct() {
1414

1515
expands to {
1616
const _: () = {
17+
#[automatically_derived]
1718
impl ::core::fmt::Debug for Point {
1819
fn fmt(&self, fmt: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
1920
match self {
@@ -44,6 +45,7 @@ fn test_format() {
4445

4546
expands to {
4647
const _: () = {
48+
#[automatically_derived]
4749
impl ::core::fmt::Debug for Point {
4850
fn fmt(&self, fmt: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4951
match self {
@@ -76,23 +78,27 @@ fn test_with() {
7678

7779
expands to {
7880
const _: () = {
81+
#[automatically_derived]
7982
impl ::core::fmt::Debug for Point {
8083
fn fmt(&self, fmt: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
8184
match self {
8285
Point { x: ref __binding_0, y: ref __binding_1, } => {
8386
let mut debug_builder = fmt.debug_struct("Point");
8487
debug_builder.field("x", {
88+
#[automatically_derived]
8589
struct DebugWith<'a, T: 'a> {
8690
data: &'a T,
8791
fmt: fn(&T, &mut ::core::fmt::Formatter) -> ::core::fmt::Result,
8892
}
8993

94+
#[automatically_derived]
9095
impl<'a, T: 'a> ::core::fmt::Debug for DebugWith<'a, T> {
9196
fn fmt(&self, fmt: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
9297
(self.fmt)(self.data, fmt)
9398
}
9499
}
95100

101+
#[automatically_derived]
96102
&DebugWith {
97103
data: __binding_0,
98104
fmt: my_fmt,
@@ -125,6 +131,7 @@ fn test_skip() {
125131

126132
expands to {
127133
const _: () = {
134+
#[automatically_derived]
128135
impl ::core::fmt::Debug for Point {
129136
fn fmt(&self, fmt: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
130137
match self {
@@ -158,6 +165,7 @@ fn test_conditional_skip() {
158165

159166
expands to {
160167
const _: () = {
168+
#[automatically_derived]
161169
impl ::core::fmt::Debug for Point {
162170
fn fmt(&self, fmt: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
163171
match self {
@@ -194,6 +202,7 @@ fn test_enum() {
194202

195203
expands to {
196204
const _: () = {
205+
#[automatically_derived]
197206
impl ::core::fmt::Debug for Foo {
198207
fn fmt(&self, fmt: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
199208
match self {
@@ -251,6 +260,7 @@ fn test_bounds_on_skipped() {
251260

252261
expands to {
253262
const _: () = {
263+
#[automatically_derived]
254264
impl<T> ::core::fmt::Debug for WantDebug<T>
255265
where
256266
TemplatedType<T>: ::core::fmt::Debug
@@ -295,6 +305,7 @@ fn test_bounds_on_fields_only() {
295305

296306
expands to {
297307
const _: () = {
308+
#[automatically_derived]
298309
impl<T> ::core::fmt::Debug for WantDebug<T>
299310
where
300311
TemplatedType<T>: ::core::fmt::Debug,

0 commit comments

Comments
 (0)