Skip to content

Commit c9e52bf

Browse files
authored
Add #[automatically_derived] to the impls (#444)
* feat(strum_macros): add `#[automatically_derived]` to `enum_*` * feat(strum_macros): add `#[automatically_derived]` to `from_repr` * feat(strum_macros): add `#[automatically_derived]` to string traits
1 parent 1b00f89 commit c9e52bf

File tree

12 files changed

+28
-1
lines changed

12 files changed

+28
-1
lines changed

strum_macros/src/macros/enum_count.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub(crate) fn enum_count_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
2727

2828
Ok(quote! {
2929
// Implementation
30+
#[automatically_derived]
3031
impl #impl_generics #strum_module_path::EnumCount for #name #ty_generics #where_clause {
3132
const COUNT: usize = #n;
3233
}

strum_macros/src/macros/enum_discriminants.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ pub fn enum_discriminants_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
145145

146146
let (impl_generics, ty_generics, where_clause) = ast.generics.split_for_impl();
147147
let impl_from = quote! {
148+
#[automatically_derived]
148149
impl #impl_generics ::core::convert::From< #name #ty_generics > for #discriminants_name #where_clause {
149150
#[inline]
150151
fn from(val: #name #ty_generics) -> #discriminants_name {
@@ -163,6 +164,7 @@ pub fn enum_discriminants_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
163164
let (impl_generics, _, _) = generics.split_for_impl();
164165

165166
quote! {
167+
#[automatically_derived]
166168
impl #impl_generics ::core::convert::From< #enum_life #name #ty_generics > for #discriminants_name #where_clause {
167169
#[inline]
168170
fn from(val: #enum_life #name #ty_generics) -> #discriminants_name {
@@ -176,6 +178,7 @@ pub fn enum_discriminants_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
176178
let impl_into_discriminant = match type_properties.discriminant_vis {
177179
// If the visibilty is unspecified or `pub` then we implement IntoDiscriminant
178180
None | Some(syn::Visibility::Public(..)) => quote! {
181+
#[automatically_derived]
179182
impl #impl_generics #strum_module_path::IntoDiscriminant for #name #ty_generics #where_clause {
180183
type Discriminant = #discriminants_name;
181184

strum_macros/src/macros/enum_is.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub fn enum_is_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
3939
.collect();
4040

4141
Ok(quote! {
42+
#[automatically_derived]
4243
impl #impl_generics #enum_name #ty_generics #where_clause {
4344
#(#variants)*
4445
}

strum_macros/src/macros/enum_iter.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ pub fn enum_iter_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
8080
marker: ::core::marker::PhantomData #phantom_data,
8181
}
8282

83+
#[automatically_derived]
8384
impl #impl_generics ::core::fmt::Debug for #iter_name #ty_generics #where_clause {
8485
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
8586
// We don't know if the variants implement debug themselves so the only thing we
@@ -90,6 +91,7 @@ pub fn enum_iter_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
9091
}
9192
}
9293

94+
#[automatically_derived]
9395
impl #impl_generics #iter_name #ty_generics #where_clause {
9496
fn get(&self, idx: usize) -> ::core::option::Option<#name #ty_generics> {
9597
match idx {
@@ -98,6 +100,7 @@ pub fn enum_iter_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
98100
}
99101
}
100102

103+
#[automatically_derived]
101104
impl #impl_generics #strum_module_path::IntoEnumIterator for #name #ty_generics #where_clause {
102105
type Iterator = #iter_name #ty_generics;
103106

@@ -111,6 +114,7 @@ pub fn enum_iter_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
111114
}
112115
}
113116

117+
#[automatically_derived]
114118
impl #impl_generics Iterator for #iter_name #ty_generics #where_clause {
115119
type Item = #name #ty_generics;
116120

@@ -141,13 +145,15 @@ pub fn enum_iter_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
141145
}
142146
}
143147

148+
#[automatically_derived]
144149
impl #impl_generics ExactSizeIterator for #iter_name #ty_generics #where_clause {
145150
#[inline]
146151
fn len(&self) -> usize {
147152
self.size_hint().0
148153
}
149154
}
150155

156+
#[automatically_derived]
151157
impl #impl_generics DoubleEndedIterator for #iter_name #ty_generics #where_clause {
152158
#[inline]
153159
fn next_back(&mut self) -> ::core::option::Option<<Self as Iterator>::Item> {
@@ -166,8 +172,10 @@ pub fn enum_iter_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
166172
}
167173
}
168174

175+
#[automatically_derived]
169176
impl #impl_generics ::core::iter::FusedIterator for #iter_name #ty_generics #where_clause { }
170177

178+
#[automatically_derived]
171179
impl #impl_generics Clone for #iter_name #ty_generics #where_clause {
172180
#[inline]
173181
fn clone(&self) -> #iter_name #ty_generics {

strum_macros/src/macros/enum_messages.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ pub fn enum_message_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
112112
}
113113

114114
Ok(quote! {
115+
#[automatically_derived]
115116
impl #impl_generics #strum_module_path::EnumMessage for #name #ty_generics #where_clause {
116117
#[inline]
117118
fn get_message(&self) -> ::core::option::Option<&'static str> {

strum_macros/src/macros/enum_properties.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ pub fn enum_properties_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
8787
);
8888

8989
Ok(quote! {
90+
#[automatically_derived]
9091
impl #impl_generics #strum_module_path::EnumProperty for #name #ty_generics #where_clause {
9192
#[inline]
9293
fn get_str(&self, prop: &str) -> ::core::option::Option<&'static str> {

strum_macros/src/macros/enum_try_as.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ pub fn enum_try_as_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
7373
.collect();
7474

7575
Ok(quote! {
76+
#[automatically_derived]
7677
impl #impl_generics #enum_name #ty_generics #where_clause {
7778
#(#variants)*
7879
}

strum_macros/src/macros/from_repr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ pub fn from_repr_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
102102

103103
Ok(quote! {
104104
#[allow(clippy::use_self)]
105+
#[automatically_derived]
105106
impl #impl_generics #name #ty_generics #where_clause {
106107
#[doc = "Try to create [Self] from the raw representation"]
107108
#[inline]

strum_macros/src/macros/strings/as_ref_str.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ pub fn as_ref_str_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
7171
})?;
7272

7373
Ok(quote! {
74+
#[automatically_derived]
7475
impl #impl_generics ::core::convert::AsRef<str> for #name #ty_generics #where_clause {
7576
#[inline]
7677
fn as_ref(&self) -> &str {
@@ -110,6 +111,7 @@ pub fn as_static_str_inner(
110111

111112
Ok(match trait_variant {
112113
GenerateTraitVariant::AsStaticStr => quote! {
114+
#[automatically_derived]
113115
impl #impl_generics #strum_module_path::AsStaticRef<str> for #name #ty_generics #where_clause {
114116
#[inline]
115117
fn as_static(&self) -> &'static str {
@@ -120,6 +122,7 @@ pub fn as_static_str_inner(
120122
}
121123
},
122124
GenerateTraitVariant::From if !type_properties.const_into_str => quote! {
125+
#[automatically_derived]
123126
impl #impl_generics ::core::convert::From<#name #ty_generics> for &'static str #where_clause {
124127
#[inline]
125128
fn from(x: #name #ty_generics) -> &'static str {
@@ -128,6 +131,7 @@ pub fn as_static_str_inner(
128131
}
129132
}
130133
}
134+
#[automatically_derived]
131135
impl #impl_generics2 ::core::convert::From<&'_derivative_strum #name #ty_generics> for &'static str #where_clause {
132136
#[inline]
133137
fn from(x: &'_derivative_strum #name #ty_generics) -> &'static str {
@@ -138,21 +142,23 @@ pub fn as_static_str_inner(
138142
}
139143
},
140144
GenerateTraitVariant::From => quote! {
145+
#[automatically_derived]
141146
impl #impl_generics #name #ty_generics #where_clause {
142147
pub const fn into_str(&self) -> &'static str {
143148
match self {
144149
#(#arms),*
145150
}
146151
}
147152
}
148-
153+
#[automatically_derived]
149154
impl #impl_generics ::core::convert::From<#name #ty_generics> for &'static str #where_clause {
150155
fn from(x: #name #ty_generics) -> &'static str {
151156
match x {
152157
#(#arms),*
153158
}
154159
}
155160
}
161+
#[automatically_derived]
156162
impl #impl_generics2 ::core::convert::From<&'_derivative_strum #name #ty_generics> for &'static str #where_clause {
157163
fn from(x: &'_derivative_strum #name #ty_generics) -> &'static str {
158164
x.into_str()

strum_macros/src/macros/strings/display.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ pub fn display_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
160160
}
161161

162162
Ok(quote! {
163+
#[automatically_derived]
163164
impl #impl_generics ::core::fmt::Display for #name #ty_generics #where_clause {
164165
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::result::Result<(), ::core::fmt::Error> {
165166
match *self {

0 commit comments

Comments
 (0)