Skip to content

Commit e5169bb

Browse files
committed
Unspan From impl contents
1 parent c008375 commit e5169bb

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

impl/src/expand.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,15 @@ fn impl_struct(input: Struct) -> TokenStream {
169169
let from = unoptional_type(from_field.ty);
170170
let source_var = Ident::new("source", span);
171171
let body = from_initializer(from_field, backtrace_field, &source_var);
172+
let from_function = quote! {
173+
fn from(#source_var: #from) -> Self {
174+
#ty #body
175+
}
176+
};
172177
let from_impl = quote_spanned! {span=>
173178
#[automatically_derived]
174179
impl #impl_generics ::core::convert::From<#from> for #ty #ty_generics #where_clause {
175-
fn from(#source_var: #from) -> Self {
176-
#ty #body
177-
}
180+
#from_function
178181
}
179182
};
180183
Some(quote! {
@@ -436,12 +439,15 @@ fn impl_enum(input: Enum) -> TokenStream {
436439
let from = unoptional_type(from_field.ty);
437440
let source_var = Ident::new("source", span);
438441
let body = from_initializer(from_field, backtrace_field, &source_var);
442+
let from_function = quote! {
443+
fn from(#source_var: #from) -> Self {
444+
#ty::#variant #body
445+
}
446+
};
439447
let from_impl = quote_spanned! {span=>
440448
#[automatically_derived]
441449
impl #impl_generics ::core::convert::From<#from> for #ty #ty_generics #where_clause {
442-
fn from(#source_var: #from) -> Self {
443-
#ty::#variant #body
444-
}
450+
#from_function
445451
}
446452
};
447453
Some(quote! {

0 commit comments

Comments
 (0)